-- introducing stack behaviour for xpath parsing
[bkell-clj.git] / src / depth_adapter.clj
blob52dab7a4c322fe35dfb2a9d4200695de8295913e
2 (ns depth_adapter
3   (:import com.interrupt.bookkeeping.cc.analysis.DepthFirstAdapter) 
4    
5         (:require clojure.contrib.str-utils2) 
6         (:require clojure.contrib.http.agent) 
7         (:require clojure.contrib.io) 
8         (:require clojure.contrib.string) 
9   
10   (:require helpers) 
11   
12   (:require xml_handler)
13   (:require opts_handler)
14   (:require xpath_handler)
15   
19 (use 'clj-stacktrace.repl)
20 (comment try
21  ("foo")
22  (catch Exception e
23    (clj-stacktrace.repl/pst e)))
26 (defn operate-dep-inputtype 
27         [node handler_block]    ;; input args ; for now we are going to load by ID 
28         
29         (let [ checks [ xml_handler option_handler xpath_handler/xpath_handler ] ]
30                         
31                         (doseq [ each_check checks ] 
32                                 (do
33                                         (println "DEBUG > each... " each_check) 
34                                         (each_check node handler_block)
35                                 )
36                         )
37                         
38         )
39         
42 (defn get-depth-adapter [] 
43          
44    (proxy [DepthFirstAdapter] [] 
45          
46          ;; EXIT command 
47          (caseAExitCommand4 [node] 
48             
49             (println (str "DEBUG > caseAExitCommand4: " node))
50             
51             (proxy-super inAExitCommand4 node) 
52             (proxy-super outAExitCommand4 node) 
53                         
54             (. System exit 0) 
55          )
57          
58          ;; LOGIN command 
59          (caseALoginCommand3 [node] 
60             (println "DEBUG > caseALoginCommand3: " node)
61             
62             
63             (proxy-super inALoginCommand3 node) 
64             
65             (if (not= (. node getLogin ) nil) 
66                (.. node getLogin (apply this) ) )
67             
68             (if (not= (. node getLbracket ) nil) 
69                (.. node getLbracket (apply this) ) )
70             
71       (if (not= (. node getCommandInput ) nil) 
72               
73               (do 
74                 
75                 (.. node getCommandInput (apply this) ) 
76                         
77                         ;; execute LOGIN 
78                                         (operate-dep-inputtype node 
79                                                                                                                                 (fn [result_seq] 
80                                                                                                                                         
81                                                                                                                                         (dosync (alter com.interrupt.bookkeeping/shell conj { :logged-in-user result_seq } )) 
82                                                                                                                                         (println "DEBUG > logged-in-user > " ((deref com.interrupt.bookkeeping/shell) :logged-in-user))
83                                                                                                                                 ))
84                 )
85             )
86             
87       (if (not= (. node getRbracket ) nil) 
88                (.. node getRbracket (apply this) ) )
89             
90       (proxy-super outALoginCommand3 node) 
91             
92          )
93          
94          ;; PRINT command 
95          (caseAPrintCommand6 [node] 
96             (println (str "caseAPrintCommand6: " node)) )
97          
98          
99          ;; LOAD command 
100          (caseALoadCommand3 [node] 
101             (println "DEBUG > caseALoadCommand3 [" (class (. node getCommandInput)) "]: " node) 
102             
103             (comment "replicating java calls in the 'DepthFirstAdapter.caseALoadCommand3'")
104             
105             
106             (proxy-super inALoadCommand3 node) 
107             
108             (if (not= (. node getLoad ) nil) 
109                (.. node getLoad (apply this) ) )
110             
111             (if (not= (. node getLbracket ) nil) 
112                (.. node getLbracket (apply this) ) )
113              
114             (if (not= (. node getCommandInput ) nil) 
115                
116                     (do ;; execute 'if' block 
117                                   (.. node getCommandInput (apply this) ) 
118                                   
119                                   
120                                         (if (not (contains? (deref com.interrupt.bookkeeping/shell) :logged-in-user ))  ;; check if there is a 'logged-in-user' 
121                                 
122                                 ;;throw an error if no 'logged-in-user' 
123                                 (println "ERROR - NO logged-in-user") 
124                                 
125                                 ;; execute LOAD 
126                                 (operate-dep-inputtype node (fn [result_seq] 
127                                                                                                                                                         
128                                                                                                                                                         (println "loading... " result_seq)
129                                                                                                                                                         
130                                                                                                                                                 ))
131                                 
132                                   )
133                                   
134                     )
135             )
136             
137             (if (not= (. node getRbracket ) nil) 
138                (.. node getRbracket (apply this) ) )
139             
140             
141             (proxy-super outALoadCommand3 node) 
142             
143          )
144          
145          ;; TODO - 'load' based on xpath 
146          ;; TODO - handle variables 
147          ;; TODO - ADD command (for registering users too) 
148                   ;; 1. check that there's not an existing user 
149                   ;; 2. add corresponding default group to the new user 
150                   ;; 3. add to aauth.groups 
151                   ;; 4. add to aauth.users 
152                   ;; 5. add Associated Bookkeeping to Group 
153          ;; TODO - finish 'print' command 
154          
155         )