4 (:import com.interrupt.bookkeeping.cc.analysis.DepthFirstAdapter)
6 ;;(:require clojure.contrib.str-utils2)
7 (:require clojure.contrib.http.agent)
8 (:require clojure.contrib.io)
9 (:require clojure.contrib.string)
14 (:require xml_handler)
15 (:require opts_handler)
16 (:require xpath_handler)
18 (:require commands.add)
19 (:require commands.authenticate)
24 (use 'clj-stacktrace.repl)
28 (clj-stacktrace.repl/pst e)))
31 (defn operate-dep-inputtype
32 [node handler_block] ;; input args ; for now we are going to load by ID
34 (let [ checks [ xml_handler option_handler xpath_handler/xpath_handler ] ]
36 (doseq [ each_check checks ]
38 ;;(println "DEBUG > each > check[" each_check "] > node[" node "]" )
39 (each_check node handler_block)
47 (defn get-depth-adapter []
49 (proxy [DepthFirstAdapter] []
52 (caseAExitCommand4 [node]
54 (println (str "DEBUG > caseAExitCommand4: " node))
56 (proxy-super inAExitCommand4 node)
57 (proxy-super outAExitCommand4 node)
60 (alter bkell/shell conj ;; make the shell inactive to disable loop
67 (caseALoginCommand3 [node]
68 (println "DEBUG > caseALoginCommand3: " node)
71 (proxy-super inALoginCommand3 node)
73 (if (not= (. node getLogin ) nil)
74 (.. node getLogin (apply this) ) )
76 (if (not= (. node getLbracket ) nil)
77 (.. node getLbracket (apply this) ) )
79 (if (not= (. node getCommandInput ) nil)
83 (.. node getCommandInput (apply this) )
86 (operate-dep-inputtype node
89 (login-user result_seq)
90 (println "DEBUG > logged-in-user > " (@bkell/shell :logged-in-user))
95 (if (not= (. node getRbracket ) nil)
96 (.. node getRbracket (apply this) ) )
98 (proxy-super outALoginCommand3 node)
103 (caseAPrintCommand6 [node]
104 ;;(println (str "caseAPrintCommand6: " node))
106 (proxy-super inAPrintCommand6 node)
108 (if (not= (. node getPrint) nil)
109 (.. node getPrint (apply this)))
112 (if (not= (. node getLbracket) nil)
113 (.. node getLbracket (apply this)))
115 (if (not= (. node getCommandInput) nil)
116 (.. node getCommandInput (apply this))
120 (println " > " (:previous @bkell/shell))
122 (if (not= (. node getRbracket) nil)
123 (.. node getRbracket (apply this)))
125 (proxy-super outAPrintCommand6 node)
130 (caseACreateCommand3 [node]
132 (proxy-super inACreateCommand3 node)
134 (if (not= (. node getCreate) nil)
135 (.. node getCreate (apply this)))
137 (if (not= (. node getLbracket) nil)
138 (.. node getLbracket (apply this)))
140 (if (not= (. node getCommandInput) nil)
143 (.. node getCommandInput (apply this))
146 (operate-dep-inputtype node
149 (println "DEBUG > create result > " result_seq)
150 (dosync (alter bkell/shell conj { :previous result_seq }))
155 (if (not= (. node getRbracket) nil)
156 (.. node getRbracket (apply this)))
158 (proxy-super outACreateCommand3 node)
164 (caseAUpdateCommand1 [node] ;; AUpdateCommand1 node
166 (proxy-super inAUpdateCommand1 node)
168 (if (not= (. node getUpdate) nil)
169 (.. node getUpdate (apply this)))
171 (if (not= (. node getLbdepth1) nil)
172 (.. node getLbdepth1 (apply this)))
174 (if (not= (. node getLbdepth2) nil)
175 (.. node getLbdepth2 (apply this)))
177 (if (not= (. node getC1) nil)
180 (.. node getC1 (apply this))
181 (operate-dep-inputtype (. node getC1)
184 (println "DEBUG > update CONTEXT result > " result_seq)
185 (dosync (alter bkell/shell conj { :previous result_seq }))
190 (if (not= (. node getRbdepth2) nil)
191 (.. node getRbdepth2 (apply this)))
193 (if (not= (. node getC2) nil)
196 (.. node getC2 (apply this))
197 (operate-dep-inputtype (. node getC2)
200 (println "DEBUG > update CLIENT input [ " (.. node getC1) " ] > result > " result_seq)
202 (dosync (alter bkell/shell assoc :mode "update"))
203 (dosync (alter bkell/shell conj { :previous result_seq }))
208 (if (not= (. node getRbdepth1) nil)
209 (.. node getRbdepth1 (apply this)))
211 (proxy-super outAUpdateCommand1 node)
216 (caseACommitCommand7 [node] ;; ACommitCommand7 node
218 (proxy-super inACommitCommand7 node)
220 (if (not= (. node getCommit ) nil)
221 (.. node getCommit (applythis)))
223 (if (not= (. node getLbdepth1) nil)
224 (.. node getLbdepth1 (apply this)))
226 (if (not= (. node getLbdepth2) nil)
227 (.. node getLbdepth2 (apply this)))
229 (if (not= (. node getInput1 ) nil)
231 (.. node getInput1 (apply this))
235 (if (not= (. node getRbdepth2) nil)
236 (.. node getRbdepth2 (apply this)))
238 (if (not= (. node getInput2) nil)
240 (.. node getInput2 (apply this))
244 (if (not= (. node getRbdepth1) nil)
245 (.. node getRbdepth1 (apply this)))
247 (proxy-super outACommitCommand7 node)
253 ;; VARIABLE assignment
254 (caseATwohandexpr [node] ;; ATwohandexpr node
257 (proxy-super inATwohandexpr node)
259 (if (not= (. node getVar ) nil)
260 (.. node getVar (apply this)))
262 (if (not= (. node getWord) nil)
265 (.. node getWord (apply this)))
267 (if (not= (. node getEquals) nil)
268 (.. node getEquals (apply this)))
270 (if (not= (. node getCommand ) nil)
272 (.. node getCommand (apply this)) )
275 ;; the 'previousCommandResult' has already been set
277 (let [variableName (.. node getWord getText trim)]
279 (println "putting variableName into memory[" variableName "] > previous > " (:previous @bkell/shell) )
281 ;; setting the variableName to the command result
282 (dosync (alter bkell/shell assoc
283 (keyword variableName)
284 (:previous @bkell/shell)
289 (proxy-super outATwohandexpr node)
294 (caseAVarCommandInput [node] ;; AVarCommandInput node
296 (proxy-super inAVarCommandInput node)
298 (if (not= (. node getVarname ) nil)
300 (.. node getVarname (apply this))
302 ;; remove the '@' sign
303 ;;** if this fails, then the user only put in the '@'
304 (let [variableName (.. node getVarname toString (substring 1) trim) ]
306 (dosync (alter bkell/shell assoc
308 ((keyword variableName) @bkell/shell)
314 (proxy-super outAVarCommandInput node )
319 (caseALoadCommand3 [node]
320 (println "DEBUG > caseALoadCommand3 [" (class (. node getCommandInput)) "]: " node)
322 (comment "replicating java calls in the 'DepthFirstAdapter.caseALoadCommand3'")
325 (proxy-super inALoadCommand3 node)
327 (if (not= (. node getLoad ) nil)
328 (.. node getLoad (apply this) ) )
330 (if (not= (. node getLbracket ) nil)
331 (.. node getLbracket (apply this) ) )
333 (if (not= (. node getCommandInput ) nil)
335 (do ;; execute 'if' block
336 (.. node getCommandInput (apply this) )
339 (if (not (contains? @bkell/shell :logged-in-user )) ;; check if there is a 'logged-in-user'
341 ;;throw an error if no 'logged-in-user'
342 (println "ERROR - NO logged-in-user")
345 (operate-dep-inputtype node (fn [result_seq]
347 (println "loading... " result_seq)
348 (dosync (alter bkell/shell conj
349 { :previous result_seq }))
357 (if (not= (. node getRbracket ) nil)
358 (.. node getRbracket (apply this) ) )
361 (proxy-super outALoadCommand3 node)
367 (println "DEBUG > caseStart CALLED > bkell/shell[" @bkell/shell "]")
369 (proxy-super inStart node)
371 (.. node getPExpr (apply this) )
372 (.. node getEOF (apply this) )
374 (proxy-super outStart node)
378 (caseAAddCommand1 [node] ;; public void caseAAddCommand1(AAddCommand1 node)
380 (println "DEBUG > caseAAddCommand1 [" (class (. node getCommandInput)) "]: " node)
383 (proxy-super inAAddCommand1 node)
385 (if (not= (. node getAdd ) nil)
386 (.. node getAdd (apply this) ) )
388 (if (not= (. node getLbdepth1 ) nil)
389 (.. node getLbdepth1 (apply this) ) )
391 (if (not= (. node getLbdepth2 ) nil)
392 (.. node getLbdepth2 (apply this) ) )
394 (if (not= (. node getCommandInput ) nil)
398 ;; any i) 'load' ii) direct XML or iii) variable should be in the shell's :previous
399 (.. node getCommandInput (apply this) )
401 ;; set the :previous result as the :command-context
402 (operate-dep-inputtype node
405 (println "DEBUG > add CONTEXT result > " result_seq)
406 (dosync (alter bkell/shell conj
407 { :command-context result_seq } ))
412 (if (not= (. node getRbdepth2 ) nil)
413 (.. node getRbdepth2 (apply this) ) )
416 (println "shell > before arguments > [" @bkell/shell "]")
417 (let [ copy (. node getIlist) ]
419 (doseq [ each_copy copy ]
422 ;; apply each element in the list
423 (. each_copy apply this)
424 (operate-dep-inputtype each_copy
428 (conj ( :command-context @bkell/shell )
429 { :content (assoc result_seq :mode "create")})
431 (dosync (alter bkell/shell conj
432 { :previous aclient } ) )
434 (println "shell > F3 > [" @bkell/shell "]")
440 (if (not= (. node getRbdepth1 ) nil)
441 (.. node getRbdepth1 (apply this) ) )
443 (proxy-super outAAddCommand1 node)