fixed the add command to work with xpath
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / ExpressionVisitor.java
bloba9db039aa78337835ad227a1f73dd979eed13672
1 package com.interrupt.bookkeeping.cc;
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import org.apache.log4j.Logger;
9 import com.interrupt.bob.base.Bob;
10 import com.interrupt.bob.base.IBob;
11 import com.interrupt.bob.base.IVisitor;
12 import com.interrupt.bookkeeping.cc.bkell.aauth.Aauthentication;
13 import com.interrupt.bookkeeping.cc.bkell.command.IMemory;
14 import com.interrupt.bookkeeping.ISystem;
15 import com.interrupt.bookkeeping.cc.analysis.DepthFirstAdapter;
16 import com.interrupt.bookkeeping.cc.bkell.Bkell;
17 import com.interrupt.bookkeeping.cc.bkell.command.AddCommand;
18 import com.interrupt.bookkeeping.cc.bkell.command.CommitCommand;
19 import com.interrupt.bookkeeping.cc.bkell.command.CreateCommand;
20 import com.interrupt.bookkeeping.cc.bkell.command.FindCommand;
21 import com.interrupt.bookkeeping.cc.bkell.command.FindVisitor;
22 import com.interrupt.bookkeeping.cc.bkell.command.GResult;
23 import com.interrupt.bookkeeping.cc.bkell.command.GTokenLiterals;
24 import com.interrupt.bookkeeping.cc.bkell.command.IResult;
25 import com.interrupt.bookkeeping.cc.bkell.command.ITokenLiterals;
26 import com.interrupt.bookkeeping.cc.bkell.command.IVariable;
27 import com.interrupt.bookkeeping.cc.bkell.command.LoadCommand;
28 import com.interrupt.bookkeeping.cc.bkell.command.LoginCommand;
29 import com.interrupt.bookkeeping.cc.bkell.command.LogoutCommand;
30 import com.interrupt.bookkeeping.cc.bkell.command.ReverseCommand;
31 import com.interrupt.bookkeeping.cc.bkell.command.Variable;
32 import com.interrupt.bookkeeping.cc.executor.CreateExecutor;
33 import com.interrupt.bookkeeping.cc.executor.CreateHelper;
34 import com.interrupt.bookkeeping.cc.executor.LoadExecutor;
35 import com.interrupt.bookkeeping.cc.executor.LoadHelper;
36 import com.interrupt.bookkeeping.cc.executor.VisitorApplyAdd;
37 import com.interrupt.bookkeeping.cc.executor.VisitorApplyRemove;
38 import com.interrupt.bookkeeping.cc.node.AAddCommand1;
39 import com.interrupt.bookkeeping.cc.node.AC1Command;
40 import com.interrupt.bookkeeping.cc.node.AC2Command;
41 import com.interrupt.bookkeeping.cc.node.AC3Command;
42 import com.interrupt.bookkeeping.cc.node.AC4Command;
43 import com.interrupt.bookkeeping.cc.node.AC5Command;
44 import com.interrupt.bookkeeping.cc.node.ACmdCommandInput;
45 import com.interrupt.bookkeeping.cc.node.ACmdExpr;
46 import com.interrupt.bookkeeping.cc.node.ACommitCommand7;
47 import com.interrupt.bookkeeping.cc.node.ACreateCommand3;
48 import com.interrupt.bookkeeping.cc.node.AExitCommand4;
49 import com.interrupt.bookkeeping.cc.node.AFindCommand2;
50 import com.interrupt.bookkeeping.cc.node.AIlist;
51 import com.interrupt.bookkeeping.cc.node.AListCommand2;
52 import com.interrupt.bookkeeping.cc.node.ALoadCommand3;
53 import com.interrupt.bookkeeping.cc.node.ALoginCommand3;
54 import com.interrupt.bookkeeping.cc.node.ALogoutCommand4;
55 import com.interrupt.bookkeeping.cc.node.AOptsCommandInput;
56 import com.interrupt.bookkeeping.cc.node.APrintCommand6;
57 import com.interrupt.bookkeeping.cc.node.ARemoveCommand1;
58 import com.interrupt.bookkeeping.cc.node.AReverseCommand5;
59 import com.interrupt.bookkeeping.cc.node.ATwohandexpr;
60 import com.interrupt.bookkeeping.cc.node.AUpdateCommand1;
61 import com.interrupt.bookkeeping.cc.node.AVarCommandInput;
62 import com.interrupt.bookkeeping.cc.node.AXmlCommandInput;
63 import com.interrupt.bookkeeping.cc.node.AXmlCommandInputRef;
64 import com.interrupt.bookkeeping.cc.node.Node;
65 import com.interrupt.bookkeeping.cc.node.PCommandInput;
66 import com.interrupt.bookkeeping.cc.node.PIlist;
67 import com.interrupt.bookkeeping.exception.AuthorisationException;
68 import com.interrupt.bookkeeping.journal.IEntries;
69 import com.interrupt.bookkeeping.system.BookkeepingSystem;
70 import com.interrupt.bookkeeping.users.IUser;
71 import com.interrupt.bookkeeping.users.IUserSession;
72 import com.interrupt.bookkeeping.users.User;
73 import com.interrupt.bookkeeping.util.Util;
74 import com.interrupt.spittoon.Spittoon;
76 public class ExpressionVisitor extends DepthFirstAdapter implements Serializable {
79 private Logger logger = Logger.getLogger(ExpressionVisitor.class);
81 private IUserSession userSession = null;
82 private Aauthentication aauthentication = null;
83 private AXmlCommandInputRef previousCommandResult = null;
84 private Bkell _bkellEnv = null;
85 private boolean active = true;
86 private Spittoon spittoon = null;
88 public ExpressionVisitor() {
90 public ExpressionVisitor(Spittoon spitt) {
91 spittoon = spitt;
95 public boolean isActive() {
96 return active;
98 public void setActive(boolean active) {
99 this.active = active;
103 public Bkell getBkellEnv() {
104 return _bkellEnv;
106 public void setBkellEnv(Bkell env) {
107 _bkellEnv = env;
111 public AXmlCommandInputRef getPreviousCommandResult() {
112 return previousCommandResult;
114 public void setPreviousCommandResult(AXmlCommandInputRef previousCommandResult) {
115 this.previousCommandResult = previousCommandResult;
118 public Aauthentication getAauthentication() {
119 return aauthentication;
121 public void setAauthentication(Aauthentication aauthentication) {
122 this.aauthentication = aauthentication;
126 public IUserSession getUserSession() {
127 return userSession;
129 public void setUserSession(IUserSession userSession) {
130 this.userSession = userSession;
134 /*********************
135 * COMMANDS
138 /* EXPR scenarios
139 * writing out a variable to memory
141 public void caseACmdExpr(ACmdExpr node) {
144 inACmdExpr(node);
146 // get variable name
147 String variableName = "previous";
148 IBob commandResult = null;
149 if(node.getCommand() != null) {
151 //** the 'node' should now be an 'AXmlCommandInput'
152 node.getCommand().apply(this);
154 // get result of command
155 if(this.getPreviousCommandResult() != null) {
157 //logger.debug("caseCmdExpr / Previous Command ["+this.getPreviousCommandResult()+"] / Previous XML ["+this.getPreviousCommandResult().getXmlCommandInput()+"] / Reference ["+this.getPreviousCommandResult().getReference()+"]");
158 //logger.debug("caseCmdExpr / Previous Command ["+this.getPreviousCommandResult()+"] / Previous XML ["+this.getPreviousCommandResult().getXmlCommandInput()+"] / Reference ["+this.getPreviousCommandResult().getReference()+"]");
160 //commandResult = this._createBlock(this.getPreviousCommandResult().getXmlCommandInput());
161 commandResult = this.getPreviousCommandResult().getReference();
165 if(node.getSemicolon() != null) {
167 node.getSemicolon().apply(this);
171 // the 'previousCommandResult' has already been evaluated
172 // ...
174 // store in the bkell environments
175 IVariable variable = new Variable();
176 variable.setName(variableName);
177 variable.addChild(commandResult);
178 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(variableName);
179 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variable);
181 outACmdExpr(node);
185 public void caseATwohandexpr(ATwohandexpr node) {
188 inATwohandexpr(node);
190 String variableName = null;
191 IBob commandResult = null;
193 if(node.getVar() != null) {
195 node.getVar().apply(this);
197 if(node.getWord() != null) {
199 node.getWord().apply(this);
201 // get variable name
202 variableName = node.getWord().getText();
203 variableName.trim();
204 //logger.debug("putting variableName into memory["+variableName+"]");
207 if(node.getEquals() != null) {
209 node.getEquals().apply(this);
211 if(node.getCommand() != null) {
213 node.getCommand().apply(this);
215 // get result of command
216 commandResult = this._createBlock(this.getPreviousCommandResult().getXmlCommandInput());
220 // the 'previousCommandResult' has already been set
221 // ...
223 // store in the bkell environments
224 String previousVarName = "previous";
225 IVariable variablePrev = new Variable();
226 variablePrev.setName(previousVarName);
227 variablePrev.addChild(commandResult);
228 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(previousVarName);
229 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variablePrev);
231 IVariable variable = new Variable();
232 variable.setName(variableName);
233 variable.addChild(commandResult);
234 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(variableName);
235 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variable);
237 outATwohandexpr(node);
242 /* reading a variable as input
244 public void caseAVarCommandInput(AVarCommandInput node) {
246 inAVarCommandInput(node);
248 String variableName = null;
249 if(node.getVarname() != null) {
251 node.getVarname().apply(this);
252 variableName = node.getVarname().toString();
254 // remove all spaces that sablecc inserts - very annoying
255 //variableName = variableName.replaceAll(' ');
257 // remove the '@' sign
258 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
259 variableName = variableName.trim();
264 // retrieve from the bkell environments
265 //logger.debug("");
266 //logger.debug("Printing out the systems memory / Seeking variable name["+variableName+"]");
267 IBob commandResult = null;
268 IMemory memory = (IMemory)this.getBkellEnv().findMemoryById("main.memory");
269 if(variableName.equals("memory")) {
271 HashMap allPrefixes = new HashMap();
273 IBob eachbob = null;
274 ISystem system = BookkeepingSystem.instance().getMODEL();
275 while(system.canPull()) {
277 eachbob = system.pullNext();
278 allPrefixes.putAll(eachbob.getPrefixMappings());
280 memory.setPrefixMappings(allPrefixes);
281 commandResult = memory;
283 else {
285 IVariable variable = memory.findVariableByName(variableName);
286 commandResult = (IBob)variable.getChildren().get(0);
290 // setting the 'previousCommandResult'
291 AXmlCommandInput replacor = LoadHelper.reparse(commandResult.toXML(false));
292 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
293 replacorReference.setXmlCommandInput(replacor);
294 replacorReference.setReference(commandResult);
295 this.setPreviousCommandResult(replacorReference);
298 node.replaceBy(replacor);
300 outAVarCommandInput(node);
306 /* commit command
308 public void caseACommitCommand7(ACommitCommand7 node) {
310 inACommitCommand7(node);
312 String cxpath = null;
313 String inputXML = null;
315 if(this.userSession == null) {
316 throw new AuthorisationException("You are not logged in");
318 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
321 inACommitCommand7(node);
322 if(node.getCommit() != null)
324 node.getCommit().apply(this);
326 if(node.getLbdepth1() != null)
328 node.getLbdepth1().apply(this);
330 if(node.getLbdepth2() != null)
332 node.getLbdepth2().apply(this);
334 if(node.getInput1() != null) {
336 node.getInput1().apply(this);
337 cxpath = node.getInput1().toString();
338 cxpath = cxpath.replaceAll("`", "");
339 cxpath = cxpath.replaceAll(" ", "");
340 cxpath = cxpath.trim();
342 if(node.getRbdepth2() != null)
344 node.getRbdepth2().apply(this);
346 if(node.getInput2() != null) {
348 node.getInput2().apply(this);
350 logger.debug("caseACommitCommand7::getInput2 > class["+node.getInput2().getClass()+"] > data["+node.getInput2().toString()+"]");
352 if( node.getInput2().getClass() == AXmlCommandInput.class ) { // raw XML input
354 /*AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
355 replacorReference.setXmlCommandInput((AXmlCommandInput)node.getInput2());
356 this.setPreviousCommandResult(replacorReference);
357 String cinput_s = replacorReference.getXmlCommandInput().toString();
359 String cinput_s = node.getInput2().toString();
360 String input_3 = Util.filterSpacesFromXML(cinput_s);
361 logger.debug("XML input > BEFORE["+cinput_s+"] > AFTER["+input_3+"]");
363 IBob created = new Bob().load( input_3, "xml/bookkeeping.system.xml" );
364 inputXML = created.toXML(false);
366 else if( node.getInput2().getClass() == AVarCommandInput.class ) { // VARIABLE input
368 inputXML = node.getInput2().toString();
370 else { // result from PREVIOUS command
372 AXmlCommandInputRef cinput = this.getPreviousCommandResult();
373 String cinput_s = cinput.getXmlCommandInput().toString();
374 String input_3 = Util.filterSpacesFromXML(cinput_s);
376 IBob created = new Bob().load( input_3, "xml/bookkeeping.system.xml" );
377 inputXML = created.toXML(false);
380 logger.debug("caseACommitCommand7:: setContextXPath["+cxpath+"] > setInputXML["+inputXML+"]");
381 CommitCommand commitc = new CommitCommand(spittoon);
382 commitc.setAauthentication(this.getAauthentication());
383 commitc.setContextXPath(cxpath);
384 commitc.setInputXML(inputXML);
386 commitc.execute(user);
389 if(node.getRbdepth1() != null)
391 node.getRbdepth1().apply(this);
393 outACommitCommand7(node);
398 /* print command
400 public void caseAPrintCommand6(APrintCommand6 node) {
402 inAPrintCommand6(node);
403 if(node.getPrint() != null) {
405 node.getPrint().apply(this);
407 if(node.getLbracket() != null) {
409 node.getLbracket().apply(this);
411 if(node.getCommandInput() != null) {
414 node.getCommandInput().apply(this);
416 if(this.userSession == null) {
417 throw new AuthorisationException("You are not logged in");
419 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
421 CreateCommand ccmd = new CreateCommand();
422 ccmd.setAauthentication(this.aauthentication);
424 IResult result = CreateHelper.execute(user, ccmd, this.getPreviousCommandResult().getXmlCommandInput());
425 if(result.allChildren().get(0) != null) {
427 IBob bobResult = (IBob)result.allChildren().get(0);
428 //logger.debug("");
429 bobResult.toXML(System.out);
430 logger.debug("");
435 if(node.getRbracket() != null) {
437 node.getRbracket().apply(this);
439 outAPrintCommand6(node);
444 /* bookkeeping structure manipulations - create, load, add, remove, reverse, find, list
446 public void caseACreateCommand3(ACreateCommand3 node) {
449 IResult result = null;
450 IBob bobReplacor = null;
452 inACreateCommand3(node);
454 //logger.debug("caseACreateCommand3["+node+"] CALLED");
455 if(node.getCreate() != null) {
457 node.getCreate().apply(this);
459 if(node.getLbracket() != null) {
461 node.getLbracket().apply(this);
463 if(node.getCommandInput() != null) {
465 node.getCommandInput().apply(this);
468 CreateExecutor cexecutor = new CreateExecutor();
469 cexecutor.setAauthenticationToInject(this.aauthentication);
471 if(this.userSession == null) {
472 throw new AuthorisationException("You are not logged in");
474 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
475 result = cexecutor.execute(user, node);
477 // replaceby XMLCommandInput
478 //logger.debug("1. "+ node.getClass());
479 //logger.debug("2. "+ node.parent().getClass());
480 //logger.debug("3. "+ node.parent().parent().getClass());
481 //logger.debug("4. "+ node.parent().parent().parent().getClass());
484 List children = result.getChildren();
485 bobReplacor = (IBob)children.get(0);
488 //if(node.parent().parent() instanceof ACmdCommandInput) {
490 // setting the 'previousCommandResult'
491 AXmlCommandInput replacor = LoadHelper.reparse(bobReplacor.toXML(false));
492 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
493 replacorReference.setXmlCommandInput(replacor);
494 replacorReference.setReference(bobReplacor);
495 this.setPreviousCommandResult(replacorReference);
497 System.out.println("1. caseACreateCommand3: setting the previous command result - : "+ result.toXML(false));
499 // for commands that use the result of create, we are replacing this node with the XML result
500 // - replaceby XMLCommandInput
501 //node.parent().parent().replaceBy(replacor);
506 if(node.getRbracket() != null) {
508 node.getRbracket().apply(this);
511 System.out.println("2. caseACreateCommand3: setting the previous command result: "+ result.toXML(false));
513 outACreateCommand3(node);
515 //logger.debug("Create THE END: ["+bobReplacor+"] CALLED");
519 public void caseALoadCommand3(ALoadCommand3 node) {
522 inALoadCommand3(node);
524 //logger.debug("caseALoadCommand3["+node+"] CALLED");
525 //BookkeepingSystem bsystem = BookkeepingSystem.instance();
526 //ISystem model = bsystem.getMODEL();
529 if(node.getLoad() != null) {
530 node.getLoad().apply(this);
532 if(node.getLbracket() != null) {
533 node.getLbracket().apply(this);
535 if(node.getCommandInput() != null) {
537 // collect tag & all attributes
538 // list all possible closest results
539 // return first one; warn user that there were other possibilities, and to isolate search
540 logger.debug("caseALoadCommand3 > CommandInput type ["+node.getCommandInput().getClass()+"]");
542 IResult result = null;
543 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
545 logger.debug("TODO - Re-Implement load via - AOptsCommandInput");
547 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput) {
549 String cxpath = node.getCommandInput().toString();
550 logger.debug("contextXPath BEFORE ["+ cxpath +"]");
552 cxpath = cxpath.replaceAll("`", "");
553 cxpath = cxpath.replaceAll(" ", "");
554 cxpath = cxpath.trim();
555 logger.debug("contextXPath AFTER ["+ cxpath +"]");
557 //**
558 node.getCommandInput().apply(this);
559 LoadExecutor lexecutor = new LoadExecutor();
560 if(this.userSession == null) {
561 throw new AuthorisationException("You are not logged in");
563 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
565 lexecutor.setAauthenticationToInject( this.getAauthentication() );
566 lexecutor.setSpittoon(spittoon);
567 lexecutor.setContextXPath( cxpath );
568 result = lexecutor.execute(user, node);
571 //logger.debug("1. "+ node.getClass());
572 //logger.debug("2. "+ node.parent().getClass());
573 //logger.debug("3. "+ node.parent().parent().getClass());
574 //logger.debug("4. "+ node.parent().parent().parent().getClass());
576 List children = result.getChildren();
577 IBob bobReplacor = (IBob)children.get(0);
579 // set nsprefixes to null
580 /*class NSPrefixVisitor extends com.interrupt.bob.base.Visitor {
581 public void visit(IBob bob) {
582 //logger.debug("NSPrefixVisitor / tag["+bob.getTagName()+"] / ns["+bob.getNamespace()+"] / ns visible["+bob.isNSVisible()+"]");
583 bob.setNSPrefix(null);
586 bobReplacor.accept(new NSPrefixVisitor());
589 // replace by XMLCommandInput
590 Logger.getLogger("bobstate").debug(bobReplacor.toXML(false));
592 AXmlCommandInput replacor = LoadHelper.reparse(bobReplacor.toXML(false));
593 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
594 replacorReference.setXmlCommandInput(replacor);
595 replacorReference.setReference(bobReplacor);
597 // setting the 'previousCommandResult'
598 this.setPreviousCommandResult(replacorReference);
599 if(node.parent().parent() instanceof ACmdCommandInput) {
600 node.parent().parent().replaceBy(replacor);
604 if(node.getRbracket() != null) {
605 node.getRbracket().apply(this);
607 outALoadCommand3(node);
611 public void caseALoginCommand3(ALoginCommand3 node) {
614 inALoginCommand3(node);
615 if(node.getLogin() != null) {
616 node.getLogin().apply(this);
618 if(node.getLbracket() != null) {
619 node.getLbracket().apply(this);
621 if(node.getCommandInput() != null) {
624 node.getCommandInput().apply(this);
625 logger.debug("caseALoginCommand3 > CommandInput type ["+ node.getCommandInput().getClass() +"]");
627 IResult userResult = null;
628 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
630 PCommandInput cinput = node.getCommandInput();
631 LoginCommand lcommand = new LoginCommand(spittoon);
632 lcommand.setParent(this.getBkellEnv()); // ** TODO - a kludge to make searchTree work
635 CommandOptionVisitor covisitor = new CommandOptionVisitor();
636 covisitor.setCommand(lcommand);
637 cinput.apply(covisitor);
639 userResult = lcommand.execute(null); // null user entry b/c this is the command that will log the user in
640 if(userResult == null) {
641 throw new AuthorisationException("Incorrect username / password combination");
644 this.aauthentication = (Aauthentication)userResult.getChildren().get(0);
645 this.userSession = this.aauthentication.getUserSession();
646 logger.debug("caseALoginCommand3::userSession: "+ this.userSession.toXML(false));
648 AXmlCommandInput replacor = LoadHelper.reparse(this.userSession.toXML(false));
649 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
650 replacorReference.setXmlCommandInput(replacor);
651 replacorReference.setReference(this.userSession);
653 // setting the 'previousCommandResult'
654 this.setPreviousCommandResult(replacorReference);
657 if(node.getRbracket() != null) {
658 node.getRbracket().apply(this);
660 outALoginCommand3(node);
662 logger.debug("Login: userSession: " + this.userSession);
666 public void caseALogoutCommand4(ALogoutCommand4 node) {
668 inALogoutCommand4(node);
669 if(node.getLogout() != null) {
671 node.getLogout().apply(this);
673 if(this.userSession == null) {
674 throw new AuthorisationException("You are not logged in");
676 //IUser user = this.aauthentication.findUser(this.userSession.getUserid());
677 LogoutCommand lcommand = new LogoutCommand(this.aauthentication);
678 lcommand.execute(this.aauthentication.findUser("root")); // null user entry b/c this is the command that will log te user in
681 outALogoutCommand4(node);
685 public void caseAAddCommand1(AAddCommand1 node) {
688 IBob addee = null;
689 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
690 String variableName = null;
691 String originalTagId = null;
692 boolean varInput = false;
693 AVarCommandInput ceeOne = null;
696 inAAddCommand1(node);
697 if(node.getAdd() != null) {
698 node.getAdd().apply(this);
700 if(node.getLbdepth1() != null) {
701 node.getLbdepth1().apply(this);
703 if(node.getLbdepth2() != null) {
704 node.getLbdepth2().apply(this);
706 if(node.getCommandInput() != null) {
709 if(node.getCommandInput() instanceof AVarCommandInput) {
710 varInput = true;
711 ceeOne = (AVarCommandInput)node.getCommandInput();
713 //ceeOne.getVarname().apply(this);
714 variableName = ceeOne.getVarname().toString();
716 // remove the '@' sign
717 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
718 variableName = variableName.trim();
721 /**
722 * The Token Acceptor
724 * IMPORTANT. XML, Options, or Command will be the input option
725 * [X] i. The Command will be processed in the visitor.
726 * [OK] ii. and the XML should be processed (not loaded)
727 * [OK] iii. We do want to process the Options though
729 node.getCommandInput().apply(this);
732 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput) {
734 String cxpath = node.getCommandInput().toString();
735 logger.debug("contextXPath BEFORE ["+ cxpath +"]");
737 cxpath = cxpath.replaceAll("`", "");
738 cxpath = cxpath.replaceAll(" ", "");
739 cxpath = cxpath.trim();
740 logger.debug("contextXPath AFTER ["+ cxpath +"]");
742 CreateExecutor cexecutor = new CreateExecutor();
743 if(this.userSession == null) {
744 throw new AuthorisationException("You are not logged in");
747 cexecutor.setAauthenticationToInject( this.getAauthentication() );
748 cexecutor.setSpittoon(spittoon);
749 cexecutor.setContextXPath( cxpath );
750 addee = cexecutor.execute(user, node);
752 else if(node.getCommandInput() instanceof AXmlCommandInput) {
754 // if the input was raw XML, reparse into Bob object
755 CreateCommand createCommand = new CreateCommand();
756 createCommand.setAauthentication(this.getAauthentication());
758 IResult result = CreateHelper.execute(user, createCommand, (AXmlCommandInput)node.getCommandInput());
759 addee = (IBob)result.getChild(0);
761 /*CreateExecutor cexecutor = new CreateExecutor();
762 if(this.userSession == null) {
763 throw new AuthorisationException("You are not logged in");
766 cexecutor.setAauthenticationToInject( this.getAauthentication() );
767 cexecutor.setSpittoon(spittoon);
768 addee = cexecutor.execute(user, node);
771 else {
772 addee = this.getPreviousCommandResult().getReference();
776 if(addee instanceof IResult) {
777 addee = (IBob)addee.allChildren().get(0);
779 logger.debug("caseAAddCommand1 addee: "+ addee.toXML(false));
781 originalTagId = addee.getAttributeValue("id");
784 if(node.getRbdepth2() != null) {
785 node.getRbdepth2().apply(this);
789 //logger.debug( "caseAAddCommand1 addee: "+ ((ISystem)addee).findAauthenticationById("main.authentication") );
790 //** process list of inputs...
792 AddCommand addCommand = new AddCommand();
793 addCommand.setTokenReciever(addee);
795 List<PIlist> copy = new ArrayList<PIlist>(node.getIlist());
796 for(PIlist e : copy) {
798 e.apply(this);
799 logger.debug("caseAAddCommand1 each input["+e+"] / input class["+e.getClass()+"] / previous["+this.getPreviousCommandResult()+"]");
802 //** now add the gear
803 if( ((AIlist)e).getCommandInput() instanceof AXmlCommandInput ) {
805 CreateCommand createCommand = new CreateCommand();
806 createCommand.setAauthentication(this.getAauthentication());
808 IResult result = CreateHelper.execute(user, createCommand, (AXmlCommandInput)((AIlist)e).getCommandInput());
809 addCommand.getTokenLiterals().addChild((IBob)result.allChildren().get(0));
810 logger.debug("caseAAddCommand1 <AXmlCommandInput>: " + (IBob)result.allChildren().get(0));
813 else if(this.getPreviousCommandResult() != null) {
815 logger.debug("caseAAddCommand1 <previous command result>: "+ this.getPreviousCommandResult().getReference());
816 addCommand.getTokenLiterals().addChild(this.getPreviousCommandResult().getReference());
823 //logger.debug( "caseAAddCommand2 addee USERS: "+ ((Aauthentication)((ISystem)addee).findAauthenticationById("main.authentication")).getUsers() );
824 addCommand.setAauthentication(this.getAauthentication());
825 addCommand.execute(user); //**
829 if(node.getRbdepth1() != null) {
830 node.getRbdepth1().apply(this);
832 outAAddCommand1(node);
834 //logger.debug("Add: THE END ["+addee+"]");
835 if(varInput) {
837 logger.debug(">> main memory: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")) );
838 logger.debug(">> variable name ["+ variableName +"] / variable ["+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
839 .findVariableByName(variableName) +"]");
841 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
842 .findVariableByName(variableName).replace(addee.getTagName(), originalTagId, addee);
845 // setting the 'previousCommandResult'
846 AXmlCommandInput replacor = LoadHelper.reparse(addee.toXML(false));
847 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
848 replacorReference.setXmlCommandInput(replacor);
849 replacorReference.setReference(addee);
850 this.setPreviousCommandResult(replacorReference);
851 //logger.debug("Add / Previous Command "+ addee.toXML());
855 public void caseAUpdateCommand1(AUpdateCommand1 node) {
857 IBob updatee = null;
858 String originalTagId = null;
859 String variableName = null;
860 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
862 logger.debug("c1 class["+node.getC1().getClass()+"]");
863 logger.debug(node.getC1() instanceof AXmlCommandInput);
864 logger.debug(node.getC1() instanceof com.interrupt.bookkeeping.cc.node.AVarCommandInput);
866 /**
867 * KLUDGE since 'node.getC1()' gets converted to an 'AXmlCommandInput' on first apply
869 boolean xmlInput = false;
870 boolean varInput = false;
871 AVarCommandInput ceeOne = null;
872 if(node.getC1() instanceof AXmlCommandInput) {
873 xmlInput = true;
875 else if(node.getC1() instanceof com.interrupt.bookkeeping.cc.node.AVarCommandInput) {
876 varInput = true;
877 ceeOne = (AVarCommandInput)node.getC1();
881 inAUpdateCommand1(node);
882 if(node.getUpdate() != null)
884 node.getUpdate().apply(this);
886 if(node.getLbdepth1() != null)
888 node.getLbdepth1().apply(this);
890 if(node.getLbdepth2() != null)
892 node.getLbdepth2().apply(this);
894 if(node.getC1() != null)
897 logger.debug("Grrr 1");
900 node.getC1().apply(this);
901 if(xmlInput) {
903 logger.debug("Grrr 2");
905 // 1. for raw XML
906 IResult result = CreateHelper.execute(user, new CreateCommand(), (AXmlCommandInput)node.getC1());
907 updatee = (IBob)result.getChild(0);
909 else if (varInput) {
911 logger.debug("Grrr 3");
913 // 2. for variable name
914 if( ceeOne != null) {
916 ceeOne.getVarname().apply(this);
917 variableName = ceeOne.getVarname().toString();
919 // remove the '@' sign
920 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
921 variableName = variableName.trim();
925 // retrieve from the bkell environments
926 IMemory memory = (IMemory)this.getBkellEnv().findMemoryById("main.memory");
927 if(variableName.equals("memory")) {
929 HashMap allPrefixes = new HashMap();
930 IBob eachbob = null;
931 ISystem system = BookkeepingSystem.instance().getMODEL();
932 while(system.canPull()) {
934 eachbob = system.pullNext();
935 allPrefixes.putAll(eachbob.getPrefixMappings());
937 memory.setPrefixMappings(allPrefixes);
938 updatee = memory;
940 else {
942 IVariable variable = memory.findVariableByName(variableName);
943 updatee = (IBob)variable.getChildren().get(0);
947 else {
949 logger.debug("Grrr 4");
951 // 3. for function result
952 updatee = ((IResult)this.getPreviousCommandResult().getReference()).getChild(0);
955 logger.debug("caseAUpdateCommand1 updatee 1: "+ updatee.toXML(false));
956 if(updatee instanceof IResult) {
957 logger.debug("here 1");
958 updatee = updatee.getChild(0);
961 logger.debug("caseAUpdateCommand1 updatee 2: "+ updatee.toXML(false));
962 originalTagId = updatee.getAttributeValue("id");
965 if(node.getRbdepth2() != null)
967 node.getRbdepth2().apply(this);
969 if(node.getC2() != null)
972 logger.debug("Grrr 5");
974 IBob updator = null;
975 boolean xmlInput2 = false;
976 boolean varInput2 = false;
977 AVarCommandInput ceeTwo = null;
978 if(node.getC2() instanceof AXmlCommandInput) {
979 xmlInput2 = true;
981 else if(node.getC2() instanceof AVarCommandInput) {
982 varInput2 = true;
983 ceeTwo = (AVarCommandInput)node.getC2();
987 node.getC2().apply(this);
988 if( xmlInput2 ) {
990 IResult result = CreateHelper.execute(user, new CreateCommand(), (AXmlCommandInput)node.getC2());
992 updator = (IBob)result.allChildren().get(0);
993 updatee = updator;
995 logger.debug("caseAUpdateCommand1 ZING 2!!!! " + updatee.toXML(false));
998 else if( varInput2 ) {
1000 logger.debug("caseAUpdateCommand1 ZING 3!!!!");
1001 updator = this.getPreviousCommandResult().getReference();
1002 updatee = updator;
1005 logger.debug("Grrr 6");
1007 // ** replace variable in mem if applicable
1008 if ( varInput ) {
1010 logger.debug("Grrr 7");
1011 logger.debug("caseAUpdateCommand1 ZING 4!!!! A. / "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1012 .findVariableByName(variableName).find(updatee.getTagName(), originalTagId) );
1014 logger.debug("caseAUpdateCommand1 ZING 4!!!! B. / updatee: "+ updatee);
1015 logger.debug("caseAUpdateCommand1 ZING 4!!!! D. / tagName["+updatee.getTagName()+"] / originalId["+originalTagId+"]");
1017 logger.debug("caseAUpdateCommand1 ZING 4!!!! E. / to replace: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).findVariableByName(variableName));
1019 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1020 .findVariableByName(variableName).replace(updatee.getTagName(), originalTagId, updator);
1025 if(node.getRbdepth1() != null)
1027 node.getRbdepth1().apply(this);
1029 outAUpdateCommand1(node);
1031 // setting the 'previousCommandResult'
1032 AXmlCommandInput replacor = LoadHelper.reparse(updatee.toXML(false));
1033 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1034 replacorReference.setXmlCommandInput(replacor);
1035 replacorReference.setReference(updatee);
1036 this.setPreviousCommandResult(replacorReference);
1040 public void caseARemoveCommand1(ARemoveCommand1 node) {
1043 IBob removee = null;
1044 String variableName = null;
1045 boolean varInput = false;
1046 AVarCommandInput ceeOne = null;
1047 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1048 String originalTagId = null;
1050 inARemoveCommand1(node);
1051 if(node.getRemove() != null) {
1052 node.getRemove().apply(this);
1054 if(node.getLbdepth1() != null) {
1055 node.getLbdepth1().apply(this);
1057 if(node.getLbdepth2() != null) {
1058 node.getLbdepth2().apply(this);
1060 if(node.getCommandInput() != null) {
1062 logger.debug(">> remove / varInput["+ (node.getCommandInput() instanceof AVarCommandInput) +"]");
1063 logger.debug(">> remove / class["+ node.getCommandInput().getClass() +"]");
1064 if(node.getCommandInput() instanceof AVarCommandInput) {
1066 varInput = true;
1067 ceeOne = (AVarCommandInput)node.getCommandInput();
1069 //ceeOne.getVarname().apply(this);
1070 variableName = ceeOne.getVarname().toString();
1072 // remove the '@' sign
1073 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
1074 variableName = variableName.trim();
1076 logger.debug(">> remove / varName["+ variableName +"]");
1080 //**
1081 node.getCommandInput().apply(this);
1083 /**
1084 * The Token Acceptor
1086 * IMPORTANT. XML, Options, or Command will be the input option
1087 * [X] i. The Command will be processed in the visitor.
1088 * [OK] ii. and the XML should be processed (not loaded)
1089 * [OK] iii. We do want to process the Options though
1091 node.getCommandInput().apply(this);
1092 if(node.getCommandInput() instanceof AXmlCommandInput) {
1094 // if the input was raw XML, reparse into Bob object
1095 IResult result = CreateHelper.execute(user, new CreateCommand(), (AXmlCommandInput)node.getCommandInput());
1096 removee = (IBob)result.getChild(0);
1098 else {
1100 removee = this.getPreviousCommandResult().getReference();
1103 originalTagId = removee.getAttributeValue("id");
1106 if(node.getRbdepth2() != null) {
1107 node.getRbdepth2().apply(this);
1113 VisitorApplyRemove vremove = new VisitorApplyRemove();
1114 vremove.setUser(user);
1115 vremove.setRemovee(removee);
1117 //logger.debug("HERE REMOVE: 4");
1119 //** process list of inputs...
1120 List<PIlist> copy = new ArrayList<PIlist>(node.getIlist());
1121 for(PIlist e : copy) {
1123 e.apply(this);
1125 //** now remove the gear
1126 e.apply(vremove);
1130 if(varInput) {
1132 //logger.debug(">> main memory: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")) );
1133 logger.debug(">> variable name ["+ variableName +"] / variable ["+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1134 .findVariableByName(variableName) +"]");
1136 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1137 .findVariableByName(variableName).replace(removee.getTagName(), originalTagId, removee);
1143 if(node.getRbdepth1() != null) {
1144 node.getRbdepth1().apply(this);
1146 outARemoveCommand1(node);
1148 //logger.debug("Remove: THE END ["+removee+"]");
1151 // setting the 'previousCommandResult'
1152 AXmlCommandInput replacor = LoadHelper.reparse(removee.toXML(false));
1153 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1154 replacorReference.setXmlCommandInput(replacor);
1155 replacorReference.setReference(removee);
1156 this.setPreviousCommandResult(replacorReference);
1162 public void caseAReverseCommand5(AReverseCommand5 node) {
1165 IBob parentReversee = null;
1166 IBob reversee = null;
1167 IBob reversor = null;
1169 IResult result = null;
1171 inAReverseCommand5(node);
1172 if(node.getReverse() != null) {
1174 node.getReverse().apply(this);
1176 if(node.getLbdepth1() != null) {
1178 node.getLbdepth1().apply(this);
1180 if(node.getLbdepth2() != null){
1182 node.getLbdepth2().apply(this);
1184 if(node.getCi1() != null){
1186 //**
1187 node.getCi1().apply(this);
1188 //parentReversee = this._addRemoveReverseLoadBlock(node.getCi1());
1189 parentReversee = this.getPreviousCommandResult().getReference();
1192 if(node.getRbdepth2() != null){
1194 node.getRbdepth2().apply(this);
1196 if(node.getLbdepth3() != null){
1198 node.getLbdepth3().apply(this);
1200 if(node.getCi2() != null){
1202 //**
1203 node.getCi2().apply(this);
1204 reversee = this._addRemoveReverseLoadBlock(node.getCi2());
1207 if(node.getRbdepth3() != null){
1209 node.getRbdepth3().apply(this);
1211 if(node.getCi3() != null){
1213 //**
1214 node.getCi3().apply(this);
1215 reversor = this._addRemoveReverseLoadBlock(node.getCi3());
1217 ITokenLiterals tliterals = new GTokenLiterals();
1218 tliterals.addChild(reversor);
1220 ReverseCommand rcommand = new ReverseCommand();
1221 rcommand.setTokenRecieverParent((IEntries)parentReversee);
1222 rcommand.setTokenReciever(reversee);
1223 rcommand.setTokenLiterals(tliterals);
1225 IUser user = new User();
1226 user.setId("root");
1227 user.setUsername("root");
1228 this.aauthentication.authenticate("webkell", user);
1229 result = rcommand.execute(user);
1232 if(node.getRbdepth1() != null){
1234 node.getRbdepth1().apply(this);
1236 outAReverseCommand5(node);
1238 IBob bobResult = (IBob)result.getChildren().get(0);
1239 //logger.debug("Reverse: THE END ["+ bobResult +"]");
1242 // setting the 'previousCommandResult'
1243 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1244 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1245 replacorReference.setXmlCommandInput(replacor);
1246 replacorReference.setReference(bobResult);
1247 this.setPreviousCommandResult(replacorReference);
1254 public void caseAFindCommand2(AFindCommand2 node) {
1257 IBob findContext = null;
1258 IBob bobResult = null;
1259 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1261 inAFindCommand2(node);
1262 if(node.getFind() != null) {
1263 node.getFind().apply(this);
1265 if(node.getLbdepth1() != null) {
1266 node.getLbdepth1().apply(this);
1268 if(node.getLbdepth2() != null) {
1269 node.getLbdepth2().apply(this);
1271 if(node.getC1() != null) {
1273 //**
1274 node.getC1().apply(this);
1275 findContext = this.getPreviousCommandResult().getReference();
1278 if(node.getRbdepth2() != null) {
1279 node.getRbdepth2().apply(this);
1281 if(node.getC2() != null) {
1283 boolean isOptions = (node.getC2().getClass() == AOptsCommandInput.class);
1285 //**
1286 node.getC2().apply(this);
1288 ////////////
1289 if( isOptions ) {
1291 FindCommand fcommand = new FindCommand();
1292 fcommand.setTokenReciever(findContext);
1294 CommandOptionVisitor covisitor = new CommandOptionVisitor();
1295 covisitor.setCommand(fcommand);
1296 node.getC2().apply(covisitor);
1298 // execute command
1299 //Logger.getLogger("bobstate").debug(loadCommand);
1301 bobResult = fcommand.execute(user);
1304 else {
1306 // if we are dealing with XML
1308 IBob findor = this._addRemoveReverseLoadBlock(node.getC2());
1310 logger.debug("findee ["+findContext+"]");
1311 logger.debug("findor ["+findor+"]");
1313 //--> load this 'tliteral' xml from system
1314 FindVisitor fvisitor = new FindVisitor();
1315 fvisitor.setTagName(
1316 findor.getTagName()
1319 // go
1320 findContext.accept(fvisitor);
1322 // results
1323 List presults = fvisitor.getPossibleResults();
1324 List presults2 = new FindCommand().isolateSearchList( //** TODO - this is really bad, but I need the isolate function
1325 findor.getAttributes()
1326 , presults);
1328 //logger.debug("WARNING. These are possible results. Returning first one");
1329 //logger.debug(presults2);
1331 if(presults2.size() > 0) {
1333 bobResult = (IBob)presults2.get(0);
1336 ////////////
1339 if(node.getRbdepth1() != null) {
1340 node.getRbdepth1().apply(this);
1342 outAFindCommand2(node);
1344 //logger.debug("Find: THE END ["+ result +"]");
1347 // setting the 'previousCommandResult'
1348 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1349 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1350 replacorReference.setXmlCommandInput(replacor);
1351 replacorReference.setReference(bobResult);
1352 this.setPreviousCommandResult(replacorReference);
1357 public void caseAListCommand2(AListCommand2 node) {
1360 IBob listee = null;
1361 IResult result = new GResult();
1363 inAListCommand2(node);
1364 if(node.getList() != null) {
1365 node.getList().apply(this);
1367 if(node.getLbdepth1() != null) {
1368 node.getLbdepth1().apply(this);
1370 if(node.getLbdepth2() != null) {
1371 node.getLbdepth2().apply(this);
1373 if(node.getC1() != null) {
1375 //**
1376 node.getC1().apply(this);
1377 //listee = this._addRemoveReverseLoadBlock(node.getC1());
1378 listee = this.getPreviousCommandResult().getReference();
1381 if(node.getRbdepth2() != null) {
1382 node.getRbdepth2().apply(this);
1384 if(node.getC2() != null) {
1386 //**
1387 node.getC2().apply(this);
1389 IBob listor = this._addRemoveReverseLoadBlock(node.getC2());
1390 //logger.debug("listee ["+listee+"]");
1391 //logger.debug("listor ["+listor+"]");
1393 //--> load this 'tliteral' xml from system
1394 FindVisitor fvisitor = new FindVisitor();
1395 fvisitor.setTagName(
1396 listor.getTagName()
1399 // go
1400 listee.accept(fvisitor);
1402 // results
1403 List presults = fvisitor.getPossibleResults();
1406 //logger.debug("ExpressionVisitor.caseAListCommand2: BEFORE isolate / Attribute size["+listor.getAttributes().getLength()+"]");
1407 //logger.debug(presults);
1409 if(listor.getAttributes().getLength() > 0) {
1411 presults = new FindCommand().isolateSearchList( //** this is really bad, but I need the isolate function
1412 listor.getAttributes()
1413 , presults);
1416 //logger.debug("");
1417 //logger.debug("ExpressionVisitor.caseAListCommand2: WARNING. These are possible results. Returning first one");
1418 //logger.debug(presults);
1420 if(presults.size() > 0) {
1422 result.addChildren(presults);
1427 if(node.getRbdepth1() != null) {
1428 node.getRbdepth1().apply(this);
1430 outAListCommand2(node);
1432 //logger.debug("List: THE END ["+ result +"]");
1435 // setting the 'previousCommandResult'
1436 IBob bobResult = (IBob)result.getChildren().get(0);
1437 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1438 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1439 replacorReference.setXmlCommandInput(replacor);
1440 replacorReference.setReference(bobResult);
1441 this.setPreviousCommandResult(replacorReference);
1446 public void caseAExitCommand4(AExitCommand4 node) {
1448 inAExitCommand4(node);
1449 if(node.getExit() != null) {
1450 node.getExit().apply(this);
1453 //** turn off this visitor's switch
1454 this.setActive(false);
1455 outAExitCommand4(node);
1459 private IBob _createBlock(Node cinput) {
1462 IBob bobee = null;
1463 CreateCommand createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
1464 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
1466 if(this.userSession == null) {
1467 throw new AuthorisationException("You are not logged in");
1469 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1471 createCommand.setAauthentication(this.getAauthentication());
1472 IResult addee_r = CreateHelper.execute(user, createCommand, (AXmlCommandInput)cinput);
1473 List addeeList = addee_r.allChildren();
1474 bobee = (IBob)addeeList.get(0);
1476 return bobee;
1479 private IBob _addRemoveReverseLoadBlock(PCommandInput cinput) {
1482 IBob bobee = null;
1484 LoadCommand loadCommand = (com.interrupt.bookkeeping.cc.bkell.command.LoadCommand)
1485 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.LoadCommand" );
1486 CreateCommand createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
1487 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
1489 if(cinput instanceof AXmlCommandInput) {
1491 if(this.userSession == null) {
1492 throw new AuthorisationException("You are not logged in");
1494 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1495 IResult addee_r = CreateHelper.execute(user, createCommand, (AXmlCommandInput)cinput);
1496 List addeeList = addee_r.allChildren();
1497 bobee = (IBob)addeeList.get(0);
1500 else if(cinput instanceof AOptsCommandInput) {
1502 if(this.userSession == null) {
1503 throw new AuthorisationException("You are not logged in");
1505 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1506 IResult addee_r = LoadHelper.execute(user, loadCommand, (AOptsCommandInput)cinput);
1507 List addeeList = addee_r.allChildren();
1508 bobee = (IBob)addeeList.get(0);
1512 return bobee;
1516 public static void main(String args[]) {
1519 // setup command
1520 Bob bob = new Bob();
1521 (System.getProperties()).setProperty("bob.gen", "gen/");
1522 (System.getProperties()).setProperty("bob.base", ".");
1525 //logger.debug("HERE 1");
1527 String input_s = "< account xmlns = ' com / interrupt / bookkeeping / account ' id = ' 1 ' name = ' office equipment ' type = ' asset ' counterWeight = ' debit ' > < debit xmlns = ' com / interrupt / bookkeeping / account ' id = ' ' amount = ' 10.00 ' entryid = ' ' accountid = ' 1 ' / > < / account >";
1528 String input_1 = input_s.replaceAll("< ", "<");
1529 String input_2 = input_1.replaceAll("\\/ >", "/>");
1530 String input_x = input_2.replaceAll("< \\/", "</");
1531 String input_y = input_x.replaceAll("<\\/ ", "</");
1532 String input_xx = input_y.replaceAll(" \\/ ", "/");
1533 String input_3 = input_xx.replaceAll(" = ", "=");
1535 //String input_3 = "<account xmlns = 'com/interrupt/bookkeeping/account' id = ' 1 ' name = ' office equipment ' type = ' asset ' counterWeight = ' debit ' > <debit xmlns = 'com/interrupt/bookkeeping/account' id = ' ' amount = ' 10.00 ' entryid = ' ' accountid = ' 1 ' /> </account>";
1537 //logger.debug("HERE 2 ["+ input_3 +"]");
1539 IBob created = bob.load( input_3, "xml/bookkeeping.system.xml" );
1540 //IBob created = bob.load( "<account xmlns='com/interrupt/bookkeeping/account' id='1' name='office equipment' type='asset' counterWeight='debit' > <debit xmlns='com/interrupt/bookkeeping/account' id='' amount='10.00' entryid='' accountid = ' 1 ' /> </account>",
1541 // "xml/bookkeeping.2.bookkeeping.xml xml/bookkeeping.2.transactions.xml xml/bookkeeping.2.users.xml" );
1545 //logger.debug("HERE 3");
1547 //created.toXML(System.out);
1553 /**
1554 * return XMLCommandInput from these commands
1556 public void caseAC1Command(AC1Command node) {
1558 inAC1Command(node);
1559 if(node.getCommand1() != null) {
1560 node.getCommand1().apply(this);
1562 outAC1Command(node);
1566 public void caseAC2Command(AC2Command node) {
1568 inAC2Command(node);
1569 if(node.getCommand2() != null) {
1570 node.getCommand2().apply(this);
1572 outAC2Command(node);
1576 public void caseAC5Command(AC5Command node) {
1578 inAC5Command(node);
1579 if(node.getCommand5() != null) {
1580 node.getCommand5().apply(this);
1582 outAC5Command(node);
1585 public void caseAC3Command(AC3Command node) {
1587 inAC3Command(node);
1588 if(node.getCommand3() != null) {
1589 node.getCommand3().apply(this);
1591 outAC3Command(node);
1594 public void caseAC4Command(AC4Command node) {
1596 inAC4Command(node);
1597 if(node.getCommand4() != null) {
1598 node.getCommand4().apply(this);
1600 outAC4Command(node);