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)
23 (use 'clj-stacktrace.repl)
27 (clj-stacktrace.repl/pst e)))
30 (defn operate-dep-inputtype
31 [node handler_block] ;; input args ; for now we are going to load by ID
33 (let [ checks [ xml_handler option_handler xpath_handler/xpath_handler ] ]
35 (doseq [ each_check checks ]
37 ;;(println "DEBUG > each > check[" each_check "] > node[" node "]" )
38 (each_check node handler_block)
46 (defn get-depth-adapter []
48 (proxy [DepthFirstAdapter] []
51 (caseAExitCommand4 [node]
53 (println (str "DEBUG > caseAExitCommand4: " node))
55 (proxy-super inAExitCommand4 node)
56 (proxy-super outAExitCommand4 node)
63 (caseALoginCommand3 [node]
64 (println "DEBUG > caseALoginCommand3: " node)
67 (proxy-super inALoginCommand3 node)
69 (if (not= (. node getLogin ) nil)
70 (.. node getLogin (apply this) ) )
72 (if (not= (. node getLbracket ) nil)
73 (.. node getLbracket (apply this) ) )
75 (if (not= (. node getCommandInput ) nil)
79 (.. node getCommandInput (apply this) )
82 (operate-dep-inputtype node
86 (alter com.interrupt.bookkeeping/shell conj
87 { :logged-in-user result_seq } )
88 (alter com.interrupt.bookkeeping/shell conj
89 { :previous result_seq }))
90 (println "DEBUG > logged-in-user > " ((deref com.interrupt.bookkeeping/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)) )
108 (caseALoadCommand3 [node]
109 (println "DEBUG > caseALoadCommand3 [" (class (. node getCommandInput)) "]: " node)
111 (comment "replicating java calls in the 'DepthFirstAdapter.caseALoadCommand3'")
114 (proxy-super inALoadCommand3 node)
116 (if (not= (. node getLoad ) nil)
117 (.. node getLoad (apply this) ) )
119 (if (not= (. node getLbracket ) nil)
120 (.. node getLbracket (apply this) ) )
122 (if (not= (. node getCommandInput ) nil)
124 (do ;; execute 'if' block
125 (.. node getCommandInput (apply this) )
128 (if (not (contains? (deref com.interrupt.bookkeeping/shell) :logged-in-user )) ;; check if there is a 'logged-in-user'
130 ;;throw an error if no 'logged-in-user'
131 (println "ERROR - NO logged-in-user")
134 (operate-dep-inputtype node (fn [result_seq]
136 (println "loading... " result_seq)
137 (dosync (alter com.interrupt.bookkeeping/shell conj
138 { :previous result_seq }))
146 (if (not= (. node getRbracket ) nil)
147 (.. node getRbracket (apply this) ) )
150 (proxy-super outALoadCommand3 node)
156 (println "DEBUG > caseStart CALLED > com.interrupt.bookkeeping/shell[" (deref com.interrupt.bookkeeping/shell) "]")
158 (proxy-super inStart node)
160 (.. node getPExpr (apply this) )
161 (.. node getEOF (apply this) )
163 (proxy-super outStart node)
167 (caseAAddCommand1 [node] ;; public void caseAAddCommand1(AAddCommand1 node)
169 (println "DEBUG > caseAAddCommand1 [" (class (. node getCommandInput)) "]: " node)
172 (proxy-super inAAddCommand1 node)
174 (if (not= (. node getAdd ) nil)
175 (.. node getAdd (apply this) ) )
177 (if (not= (. node getLbdepth1 ) nil)
178 (.. node getLbdepth1 (apply this) ) )
180 (if (not= (. node getLbdepth2 ) nil)
181 (.. node getLbdepth2 (apply this) ) )
183 (if (not= (. node getCommandInput ) nil)
187 ;; any i) 'load' ii) direct XML or iii) variable should be in the shell's :previous
188 (.. node getCommandInput (apply this) )
190 ;; set the :previous result as the :command-context
191 (dosync (alter com.interrupt.bookkeeping/shell conj
192 { :command-context (:previous @com.interrupt.bookkeeping/shell) } ))
196 (if (not= (. node getRbdepth2 ) nil)
197 (.. node getRbdepth2 (apply this) ) )
200 (println "shell > before arguments > [" @com.interrupt.bookkeeping/shell "]")
201 (let [ copy (. node getIlist) ]
203 (doseq [ each_copy copy ]
206 ;; apply each element in the list
207 (. each_copy apply this)
208 (operate-dep-inputtype each_copy
212 (alter com.interrupt.bookkeeping/shell conj
213 { :previous result_seq }))
217 (println "Add command > context[" (:tag (:command-context @com.interrupt.bookkeeping/shell ))
218 "] > users?[" (= (keyword "users") (:tag (:command-context @com.interrupt.bookkeeping/shell )))
219 "] > :previous / each_copy["(:previous @com.interrupt.bookkeeping/shell)"] > match?["
220 (and (= (keyword "users") (:tag (:command-context @com.interrupt.bookkeeping/shell )))
221 (= (keyword "user") (:tag (:previous @com.interrupt.bookkeeping/shell )))) "]")
223 ;; check if we are adding a 'User' to 'Users'
224 (and (= (keyword "users") (:tag (:command-context @com.interrupt.bookkeeping/shell )))
225 (= (keyword "user") (:tag (:previous @com.interrupt.bookkeeping/shell )))
227 (add-user db-base-URL db-system-DIR)
234 (if (not= (. node getRbdepth1 ) nil)
235 (.. node getRbdepth1 (apply this) ) )
239 (proxy-super outAAddCommand1 node)
243 ;; TODO - handle variables
245 ;; TODO - finish 'print' command