finished basic account add
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / ExpressionVisitor.java
blob1d1a8651f5baeefe3e89dd0565911b5695ca807f
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.AbstractCommand;
18 import com.interrupt.bookkeeping.cc.bkell.command.AddCommand;
19 import com.interrupt.bookkeeping.cc.bkell.command.CommitCommand;
20 import com.interrupt.bookkeeping.cc.bkell.command.CreateCommand;
21 import com.interrupt.bookkeeping.cc.bkell.command.FindCommand;
22 import com.interrupt.bookkeeping.cc.bkell.command.FindVisitor;
23 import com.interrupt.bookkeeping.cc.bkell.command.GResult;
24 import com.interrupt.bookkeeping.cc.bkell.command.GTokenLiterals;
25 import com.interrupt.bookkeeping.cc.bkell.command.IOption;
26 import com.interrupt.bookkeeping.cc.bkell.command.IResult;
27 import com.interrupt.bookkeeping.cc.bkell.command.ITokenLiterals;
28 import com.interrupt.bookkeeping.cc.bkell.command.IVariable;
29 import com.interrupt.bookkeeping.cc.bkell.command.LoadCommand;
30 import com.interrupt.bookkeeping.cc.bkell.command.LoginCommand;
31 import com.interrupt.bookkeeping.cc.bkell.command.LogoutCommand;
32 import com.interrupt.bookkeeping.cc.bkell.command.ReverseCommand;
33 import com.interrupt.bookkeeping.cc.bkell.command.Variable;
34 import com.interrupt.bookkeeping.cc.executor.CreateExecutor;
35 import com.interrupt.bookkeeping.cc.executor.CreateHelper;
36 import com.interrupt.bookkeeping.cc.executor.LoadExecutor;
37 import com.interrupt.bookkeeping.cc.executor.LoadHelper;
38 import com.interrupt.bookkeeping.cc.executor.VisitorApplyRemove;
39 import com.interrupt.bookkeeping.cc.node.AAddCommand1;
40 import com.interrupt.bookkeeping.cc.node.AC1Command;
41 import com.interrupt.bookkeeping.cc.node.AC2Command;
42 import com.interrupt.bookkeeping.cc.node.AC3Command;
43 import com.interrupt.bookkeeping.cc.node.AC4Command;
44 import com.interrupt.bookkeeping.cc.node.AC5Command;
45 import com.interrupt.bookkeeping.cc.node.ACmdCommandInput;
46 import com.interrupt.bookkeeping.cc.node.ACmdExpr;
47 import com.interrupt.bookkeeping.cc.node.ACommitCommand7;
48 import com.interrupt.bookkeeping.cc.node.ACreateCommand3;
49 import com.interrupt.bookkeeping.cc.node.AExitCommand4;
50 import com.interrupt.bookkeeping.cc.node.AFindCommand2;
51 import com.interrupt.bookkeeping.cc.node.AIlist;
52 import com.interrupt.bookkeeping.cc.node.AIlistpart;
53 import com.interrupt.bookkeeping.cc.node.AListCommand2;
54 import com.interrupt.bookkeeping.cc.node.ALoadCommand3;
55 import com.interrupt.bookkeeping.cc.node.ALoginCommand3;
56 import com.interrupt.bookkeeping.cc.node.ALogoutCommand4;
57 import com.interrupt.bookkeeping.cc.node.AOptsCommandInput;
58 import com.interrupt.bookkeeping.cc.node.APrintCommand6;
59 import com.interrupt.bookkeeping.cc.node.ARemoveCommand1;
60 import com.interrupt.bookkeeping.cc.node.AReverseCommand5;
61 import com.interrupt.bookkeeping.cc.node.ATwohandexpr;
62 import com.interrupt.bookkeeping.cc.node.AUpdateCommand1;
63 import com.interrupt.bookkeeping.cc.node.AVarCommandInput;
64 import com.interrupt.bookkeeping.cc.node.AXmlCommandInput;
65 import com.interrupt.bookkeeping.cc.node.AXmlCommandInputRef;
66 import com.interrupt.bookkeeping.cc.node.Node;
67 import com.interrupt.bookkeeping.cc.node.PCommandInput;
68 import com.interrupt.bookkeeping.cc.node.PIlist;
69 import com.interrupt.bookkeeping.exception.AuthorisationException;
70 import com.interrupt.bookkeeping.journal.IEntries;
71 import com.interrupt.bookkeeping.system.BookkeepingSystem;
72 import com.interrupt.bookkeeping.system.BookkeepingSystemProperties;
73 import com.interrupt.bookkeeping.users.IUser;
74 import com.interrupt.bookkeeping.users.IUserSession;
75 import com.interrupt.bookkeeping.users.User;
76 import com.interrupt.bookkeeping.util.Util;
77 import com.interrupt.spittoon.Spittoon;
78 import com.interrupt.util.IdGenerator;
80 public class ExpressionVisitor extends DepthFirstAdapter implements Serializable {
83 private Logger logger = Logger.getLogger(ExpressionVisitor.class);
85 private IUserSession userSession = null;
86 private Aauthentication aauthentication = null;
87 private AXmlCommandInputRef previousCommandResult = null;
88 private Bkell _bkellEnv = null;
89 private boolean active = true;
90 private Spittoon spittoon = null;
91 private String contextUrl = null;
93 public ExpressionVisitor() {
95 public ExpressionVisitor(Spittoon spitt) {
96 spittoon = spitt;
100 public boolean isActive() { return active; }
101 public void setActive(boolean active) { this.active = active; }
104 public Bkell getBkellEnv() { return _bkellEnv; }
105 public void setBkellEnv(Bkell env) { _bkellEnv = env; }
107 public AXmlCommandInputRef getPreviousCommandResult() {
108 return previousCommandResult;
110 public void setPreviousCommandResult(AXmlCommandInputRef previousCommandResult) {
111 this.previousCommandResult = previousCommandResult;
114 public Aauthentication getAauthentication() { return aauthentication; }
115 public void setAauthentication(Aauthentication aauthentication) { this.aauthentication = aauthentication; }
117 public IUserSession getUserSession() { return userSession; }
118 public void setUserSession(IUserSession userSession) { this.userSession = userSession; }
120 public String getContextUrl() { return contextUrl; }
121 public void setContextUrl(String contextUrl) { this.contextUrl = contextUrl; }
124 /*********************
125 * COMMANDS
128 /* EXPR scenarios
129 * writing out a variable to memory
131 public void caseACmdExpr(ACmdExpr node) {
134 inACmdExpr(node);
136 // get variable name
137 String variableName = "previous";
138 IBob commandResult = null;
139 if(node.getCommand() != null) {
141 //** the 'node' should now be an 'AXmlCommandInput'
142 node.getCommand().apply(this);
144 // get result of command
145 if(this.getPreviousCommandResult() != null) {
146 commandResult = this.getPreviousCommandResult().getReference();
150 if(node.getSemicolon() != null) {
152 node.getSemicolon().apply(this);
156 // the 'previousCommandResult' has already been evaluated
157 // ...
159 // store in the bkell environments
160 IVariable variable = new Variable();
161 variable.setName(variableName);
162 variable.addChild(commandResult);
163 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(variableName);
164 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variable);
166 outACmdExpr(node);
170 public void caseATwohandexpr(ATwohandexpr node) {
173 inATwohandexpr(node);
175 String variableName = null;
176 IBob commandResult = null;
178 if(node.getVar() != null) {
180 node.getVar().apply(this);
182 if(node.getWord() != null) {
184 node.getWord().apply(this);
186 // get variable name
187 variableName = node.getWord().getText();
188 variableName.trim();
189 //logger.debug("putting variableName into memory["+variableName+"]");
192 if(node.getEquals() != null) {
194 node.getEquals().apply(this);
196 if(node.getCommand() != null) {
198 node.getCommand().apply(this);
200 // get result of command
201 commandResult = this._createBlock(this.getPreviousCommandResult().getXmlCommandInput());
205 // the 'previousCommandResult' has already been set
206 // ...
208 // store in the bkell environments
209 String previousVarName = "previous";
210 IVariable variablePrev = new Variable();
211 variablePrev.setName(previousVarName);
212 variablePrev.addChild(commandResult);
213 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(previousVarName);
214 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variablePrev);
216 IVariable variable = new Variable();
217 variable.setName(variableName);
218 variable.addChild(commandResult);
219 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).removeVariableByName(variableName);
220 ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).addVariable(variable);
222 outATwohandexpr(node);
227 /* reading a variable as input
229 public void caseAVarCommandInput(AVarCommandInput node) {
231 inAVarCommandInput(node);
233 String variableName = null;
234 if(node.getVarname() != null) {
236 node.getVarname().apply(this);
237 variableName = node.getVarname().toString();
239 // remove the '@' sign
240 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
241 variableName = variableName.trim();
246 // retrieve from the bkell environments
247 IBob commandResult = null;
248 IMemory memory = (IMemory)this.getBkellEnv().findMemoryById("main.memory");
249 if(variableName.equals("memory")) {
251 HashMap allPrefixes = new HashMap();
253 IBob eachbob = null;
254 ISystem system = BookkeepingSystem.instance().getMODEL();
255 while(system.canPull()) {
257 eachbob = system.pullNext();
258 allPrefixes.putAll(eachbob.getPrefixMappings());
260 memory.setPrefixMappings(allPrefixes);
261 commandResult = memory;
263 else {
265 IVariable variable = memory.findVariableByName(variableName);
266 commandResult = (IBob)variable.getChildren().get(0);
270 // setting the 'previousCommandResult'
271 AXmlCommandInput replacor = LoadHelper.reparse(commandResult.toXML(false));
272 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
273 replacorReference.setXmlCommandInput(replacor);
274 replacorReference.setReference(commandResult);
275 this.setPreviousCommandResult(replacorReference);
278 node.replaceBy(replacor);
280 outAVarCommandInput(node);
286 /* commit command
288 public void caseACommitCommand7(ACommitCommand7 node) {
290 inACommitCommand7(node);
292 String cxpath = null;
293 String inputXML = null;
295 if(this.userSession == null) {
296 throw new AuthorisationException("You are not logged in");
298 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
301 inACommitCommand7(node);
302 if(node.getCommit() != null)
304 node.getCommit().apply(this);
306 if(node.getLbdepth1() != null)
308 node.getLbdepth1().apply(this);
310 if(node.getLbdepth2() != null)
312 node.getLbdepth2().apply(this);
314 if(node.getInput1() != null) {
316 node.getInput1().apply(this);
317 cxpath = node.getInput1().toString();
318 cxpath = cxpath.replaceAll("`", "");
319 cxpath = cxpath.replaceAll(" ", "");
320 cxpath = cxpath.trim();
322 if(node.getRbdepth2() != null)
324 node.getRbdepth2().apply(this);
326 if(node.getInput2() != null) {
328 node.getInput2().apply(this);
330 logger.debug("caseACommitCommand7::getInput2 > class["+node.getInput2().getClass()+"] > data["+node.getInput2().toString()+"]");
332 if( node.getInput2().getClass() == AXmlCommandInput.class ) { // raw XML input
334 String cinput_s = node.getInput2().toString();
335 String input_3 = Util.filterSpacesFromXML(cinput_s);
336 logger.debug("XML input > BEFORE["+cinput_s+"] > AFTER["+input_3+"]");
338 IBob created = new Bob().load( input_3, BookkeepingSystemProperties.instance().getProperty("bob.def") );
339 inputXML = created.toXML(false);
341 //** add returnInput option here
342 /*if( node.getInput2() != null && ( node.getInput2(). ) ) {
344 if( ((AIlistpart)((AIlist)e).getIlistpart().get(0)).getCommandInput()
345 instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
347 /*PCommandInput cinput = ((AIlistpart)((AIlist)e).getIlistpart().get(0)).getCommandInput();
349 logger.debug("command option["+ cinput +"]");
351 CommandOptionVisitor covisitor = new CommandOptionVisitor();
352 covisitor.setCommand( createCommand );
353 cinput.apply( covisitor );
355 IOption option = covisitor.getCommand().getOption("returninput");
356 returnInput = Boolean.parseBoolean(option.getValue());
358 logger.debug("caseAAddCommand1 > input option["+option+"]");
364 else if( node.getInput2().getClass() == AVarCommandInput.class ) { // VARIABLE input
366 inputXML = node.getInput2().toString();
368 else { // result from PREVIOUS command
370 AXmlCommandInputRef cinput = this.getPreviousCommandResult();
371 String cinput_s = cinput.getXmlCommandInput().toString();
372 String input_3 = Util.filterSpacesFromXML(cinput_s);
374 IBob created = new Bob().load( input_3, BookkeepingSystemProperties.instance().getProperty("bob.def") );
375 inputXML = created.toXML(false);
379 IBob populateResult = Util.populateEmptyIDs(inputXML);
380 inputXML = populateResult.toXML(false);
383 logger.debug("caseACommitCommand7:: setContextXPath["+cxpath+"] > setInputXML["+inputXML+"]");
384 CommitCommand commitc = new CommitCommand(spittoon);
385 commitc.setAauthentication(this.getAauthentication());
386 commitc.setContextXPath(cxpath);
387 commitc.setContextUrl(this.getContextUrl());
388 commitc.setInputXML(inputXML);
390 commitc.execute(user);
393 if(node.getRbdepth1() != null)
395 node.getRbdepth1().apply(this);
397 outACommitCommand7(node);
402 /* print command
404 public void caseAPrintCommand6(APrintCommand6 node) {
406 inAPrintCommand6(node);
407 if(node.getPrint() != null) {
409 node.getPrint().apply(this);
411 if(node.getLbracket() != null) {
413 node.getLbracket().apply(this);
415 if(node.getCommandInput() != null) {
418 node.getCommandInput().apply(this);
420 if(this.userSession == null) {
421 throw new AuthorisationException("You are not logged in");
423 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
425 CreateCommand ccmd = new CreateCommand();
426 ccmd.setAauthentication(this.aauthentication);
428 /*IResult result = CreateHelper.execute(user, ccmd, this.getPreviousCommandResult().getXmlCommandInput());
429 if(result.allChildren().get(0) != null) {
430 IBob bobResult = (IBob)result.allChildren().get(0);
432 //logger.debug("");
433 logger.debug(bobResult.toXML(false));
434 logger.debug("\n");
437 IBob result = this.getPreviousCommandResult().getReference();
438 logger.debug(result.toXML(false));
441 if(node.getRbracket() != null) {
443 node.getRbracket().apply(this);
445 outAPrintCommand6(node);
450 /* bookkeeping structure manipulations - create, load, add, remove, reverse, find, list
452 public void caseACreateCommand3(ACreateCommand3 node) {
455 IResult result = null;
456 IBob bobReplacor = null;
458 inACreateCommand3(node);
460 //logger.debug("caseACreateCommand3["+node+"] CALLED");
461 if(node.getCreate() != null) {
463 node.getCreate().apply(this);
465 if(node.getLbracket() != null) {
467 node.getLbracket().apply(this);
469 if(node.getCommandInput() != null) {
471 node.getCommandInput().apply(this);
474 CreateExecutor cexecutor = new CreateExecutor();
475 cexecutor.setAauthenticationToInject(this.aauthentication);
477 if(this.userSession == null) {
478 throw new AuthorisationException("You are not logged in");
480 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
481 result = cexecutor.execute(user, node);
483 // replaceby XMLCommandInput
484 //logger.debug("1. "+ node.getClass());
485 //logger.debug("2. "+ node.parent().getClass());
486 //logger.debug("3. "+ node.parent().parent().getClass());
487 //logger.debug("4. "+ node.parent().parent().parent().getClass());
490 List children = result.getChildren();
491 bobReplacor = (IBob)children.get(0);
494 //if(node.parent().parent() instanceof ACmdCommandInput) {
496 // setting the 'previousCommandResult'
497 AXmlCommandInput replacor = LoadHelper.reparse(bobReplacor.toXML(false));
498 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
499 replacorReference.setXmlCommandInput(replacor);
500 replacorReference.setReference(bobReplacor);
501 this.setPreviousCommandResult(replacorReference);
503 System.out.println("1. caseACreateCommand3: setting the previous command result - : "+ result.toXML(false));
505 // for commands that use the result of create, we are replacing this node with the XML result
506 // - replaceby XMLCommandInput
507 //node.parent().parent().replaceBy(replacor);
512 if(node.getRbracket() != null) {
514 node.getRbracket().apply(this);
517 System.out.println("2. caseACreateCommand3: setting the previous command result: "+ result.toXML(false));
519 outACreateCommand3(node);
521 //logger.debug("Create THE END: ["+bobReplacor+"] CALLED");
525 public void caseALoadCommand3(ALoadCommand3 node) {
528 inALoadCommand3(node);
531 if(node.getLoad() != null) {
532 node.getLoad().apply(this);
534 if(node.getLbracket() != null) {
535 node.getLbracket().apply(this);
537 if(node.getCommandInput() != null) {
539 // collect tag & all attributes
540 // list all possible closest results
541 // return first one; warn user that there were other possibilities, and to isolate search
542 logger.debug("caseALoadCommand3 > CommandInput type ["+node.getCommandInput().getClass()+"]");
544 IResult result = null;
545 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
547 logger.debug("TODO - Re-Implement load via - AOptsCommandInput");
549 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput) {
551 String cxpath = node.getCommandInput().toString();
552 logger.debug("contextXPath BEFORE ["+ cxpath +"]");
554 cxpath = cxpath.replaceAll("`", "");
555 cxpath = cxpath.replaceAll(" ", "");
556 cxpath = cxpath.trim();
557 logger.debug("contextXPath AFTER ["+ cxpath +"]");
559 //**
560 node.getCommandInput().apply(this);
561 LoadExecutor lexecutor = new LoadExecutor();
562 if(this.userSession == null) {
563 throw new AuthorisationException("You are not logged in");
565 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
567 lexecutor.setAauthenticationToInject( this.getAauthentication() );
568 lexecutor.setSpittoon(spittoon);
569 lexecutor.setContextXPath( cxpath );
570 result = lexecutor.execute(user, node);
572 setContextUrl(lexecutor.getContextUrl());
575 //logger.debug("1. "+ node.getClass());
576 //logger.debug("2. "+ node.parent().getClass());
577 //logger.debug("3. "+ node.parent().parent().getClass());
578 //logger.debug("4. "+ node.parent().parent().parent().getClass());
580 List children = result.getChildren();
581 IBob bobReplacor = (IBob)children.get(0);
583 // replace by XMLCommandInput
584 Logger.getLogger("bobstate").debug(bobReplacor.toXML(false));
586 AXmlCommandInput replacor = LoadHelper.reparse(bobReplacor.toXML(false));
587 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
588 replacorReference.setXmlCommandInput(replacor);
589 replacorReference.setReference(bobReplacor);
591 // setting the 'previousCommandResult'
592 this.setPreviousCommandResult(replacorReference);
593 if(node.parent().parent() instanceof ACmdCommandInput) {
594 node.parent().parent().replaceBy(replacor);
598 if(node.getRbracket() != null) {
599 node.getRbracket().apply(this);
601 outALoadCommand3(node);
605 public void caseALoginCommand3(ALoginCommand3 node) {
608 inALoginCommand3(node);
609 if(node.getLogin() != null) {
610 node.getLogin().apply(this);
612 if(node.getLbracket() != null) {
613 node.getLbracket().apply(this);
615 if(node.getCommandInput() != null) {
618 node.getCommandInput().apply(this);
619 logger.debug("caseALoginCommand3 > CommandInput type ["+ node.getCommandInput().getClass() +"]");
621 IResult userResult = null;
622 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
624 PCommandInput cinput = node.getCommandInput();
625 LoginCommand lcommand = new LoginCommand(spittoon);
626 lcommand.setParent(this.getBkellEnv()); // ** TODO - a kludge to make searchTree work
629 CommandOptionVisitor covisitor = new CommandOptionVisitor();
630 covisitor.setCommand(lcommand);
631 cinput.apply(covisitor);
633 userResult = lcommand.execute(null); // null user entry b/c this is the command that will log the user in
634 if(userResult == null) {
635 throw new AuthorisationException("Incorrect username / password combination");
638 this.aauthentication = (Aauthentication)userResult.getChildren().get(0);
639 this.userSession = this.aauthentication.getUserSession();
640 logger.debug("caseALoginCommand3::userSession: "+ this.userSession.toXML(false));
642 AXmlCommandInput replacor = LoadHelper.reparse(this.userSession.toXML(false));
643 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
644 replacorReference.setXmlCommandInput(replacor);
645 replacorReference.setReference(this.userSession);
647 // setting the 'previousCommandResult'
648 this.setPreviousCommandResult(replacorReference);
651 if(node.getRbracket() != null) {
652 node.getRbracket().apply(this);
654 outALoginCommand3(node);
656 logger.debug("Login: userSession: " + this.userSession);
660 public void caseALogoutCommand4(ALogoutCommand4 node) {
662 inALogoutCommand4(node);
663 if(node.getLogout() != null) {
665 node.getLogout().apply(this);
667 //1. logout the user
668 LogoutCommand lcommand = new LogoutCommand(this.aauthentication);
669 lcommand.execute(this.aauthentication.findUser(this.userSession.getUserid())); // null user entry b/c this is the command that will log te user in
671 //2. set the userSession to null
672 if(this.userSession == null) {
673 throw new AuthorisationException("You are not logged in");
677 outALogoutCommand4(node);
681 public void caseAAddCommand1(AAddCommand1 node) {
684 IBob addee = null;
685 if(this.userSession == null) {
686 throw new AuthorisationException("You are not logged in");
688 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
689 String variableName = null;
690 String originalTagId = null;
691 boolean varInput = false;
692 AVarCommandInput ceeOne = null;
695 inAAddCommand1(node);
696 if(node.getAdd() != null) {
697 node.getAdd().apply(this);
699 if(node.getLbdepth1() != null) {
700 node.getLbdepth1().apply(this);
702 if(node.getLbdepth2() != null) {
703 node.getLbdepth2().apply(this);
705 if(node.getCommandInput() != null) {
708 if(node.getCommandInput() instanceof AVarCommandInput) {
709 varInput = true;
710 ceeOne = (AVarCommandInput)node.getCommandInput();
712 //ceeOne.getVarname().apply(this);
713 variableName = ceeOne.getVarname().toString();
715 // remove the '@' sign
716 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
717 variableName = variableName.trim();
720 /**
721 * The Token Acceptor
723 * IMPORTANT. XML, Options, or Command will be the input option
724 * [X] i. The Command will be processed in the visitor.
725 * [OK] ii. and the XML should be processed (not loaded)
726 * [OK] iii. We do want to process the Options though
728 node.getCommandInput().apply(this);
730 logger.debug("caseAAddCommand1 > XPath command input["+
731 node.getCommandInput().getClass() + "] > previous command result["+this.getPreviousCommandResult()+"]");
734 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput &&
735 this.getPreviousCommandResult() == null ) {
737 String cxpath = node.getCommandInput().toString();
738 logger.debug("contextXPath BEFORE ["+ cxpath +"]");
740 cxpath = cxpath.replaceAll("`", "");
741 cxpath = cxpath.replaceAll(" ", "");
742 cxpath = cxpath.trim();
743 logger.debug("contextXPath AFTER ["+ cxpath +"]");
745 //**
746 node.getCommandInput().apply(this);
747 LoadExecutor lexecutor = new LoadExecutor();
748 if(this.userSession == null) {
749 throw new AuthorisationException("You are not logged in");
752 lexecutor.setAauthenticationToInject( this.getAauthentication() );
753 lexecutor.setSpittoon(spittoon);
754 lexecutor.setContextXPath( cxpath );
755 addee = lexecutor.execute(user, node);
757 setContextUrl(lexecutor.getContextUrl());
759 else if(node.getCommandInput() instanceof AXmlCommandInput) {
761 // if the input was raw XML, reparse into Bob object
762 CreateCommand createCommand = new CreateCommand();
763 createCommand.setAauthentication(this.getAauthentication());
765 IResult result = CreateHelper.execute(user, createCommand, (AXmlCommandInput)node.getCommandInput());
766 addee = (IBob)result.getChild(0);
769 else {
770 addee = this.getPreviousCommandResult().getReference();
774 if(addee instanceof IResult) {
775 addee = (IBob)addee.allChildren().get(0);
777 logger.debug("caseAAddCommand1 addee: "+ addee.toXML(false));
779 originalTagId = addee.getAttributeValue("id");
782 if(node.getRbdepth2() != null) {
783 node.getRbdepth2().apply(this);
786 IBob input = null;
787 boolean returnInput = false;
790 //logger.debug( "caseAAddCommand1 addee: "+ ((ISystem)addee).findAauthenticationById("main.authentication") );
791 //** process list of inputs...
793 AddCommand addCommand = new AddCommand();
794 addCommand.setTokenReciever(addee);
796 List<PIlist> copy = new ArrayList<PIlist>(node.getIlist());
797 for(PIlist e : copy) {
799 e.apply(this);
800 logger.debug("caseAAddCommand1 each input["+e+"] / input class["+e.getClass()+"] / previous["+this.getPreviousCommandResult()+"]");
803 //** now add the gear
804 if( ((AIlist)e).getCommandInput() instanceof AXmlCommandInput ) {
806 CreateCommand createCommand = new CreateCommand();
807 createCommand.setAauthentication(this.getAauthentication());
809 IResult result = CreateHelper.execute(user, createCommand, (AXmlCommandInput)((AIlist)e).getCommandInput());
810 input = (IBob)result.allChildren().get(0);
812 addCommand.getTokenLiterals().addChild( input );
813 logger.debug("caseAAddCommand1 <AXmlCommandInput>: " + (IBob)result.allChildren().get(0));
814 //logger.debug("((AIlist)e).getIlistpart()["+ ((AIlist)e).getIlistpart() +"] / ["+
815 // ((AIlistpart)((AIlist)e).getIlistpart().get(0)).getCommandInput().getClass() +"]");
817 //** add returnInput option here
818 if( ((AIlist)e).getIlistpart() != null && !(((AIlist)e).getIlistpart()).isEmpty() ) {
820 if( ((AIlistpart)((AIlist)e).getIlistpart().get(0)).getCommandInput()
821 instanceof com.interrupt.bookkeeping.cc.node.AOptsCommandInput) {
823 PCommandInput cinput = ((AIlistpart)((AIlist)e).getIlistpart().get(0)).getCommandInput();
825 logger.debug("command option["+ cinput +"]");
827 CommandOptionVisitor covisitor = new CommandOptionVisitor();
828 covisitor.setCommand( createCommand );
829 cinput.apply( covisitor );
831 IOption option = covisitor.getCommand().getOption("returninput");
832 returnInput = Boolean.parseBoolean(option.getValue());
834 logger.debug("caseAAddCommand1 > input option["+option+"]");
838 else if(this.getPreviousCommandResult() != null) {
840 logger.debug("caseAAddCommand1 <previous command result>: "+ this.getPreviousCommandResult().getReference());
841 addCommand.getTokenLiterals().addChild(this.getPreviousCommandResult().getReference());
847 logger.debug("Add Command BEFORE ID population["+ addCommand +"]");
848 Util.populateEmptyIDs(addCommand);
849 logger.debug("Add Command AFTER ID population["+ addCommand +"]");
851 //logger.debug( "caseAAddCommand2 addee USERS: "+ ((Aauthentication)((ISystem)addee).findAauthenticationById("main.authentication")).getUsers() );
852 addCommand.setAauthentication(this.getAauthentication());
853 addCommand.execute(user); //**
857 if(node.getRbdepth1() != null) {
858 node.getRbdepth1().apply(this);
860 outAAddCommand1(node);
862 //logger.debug("Add: THE END ["+addee+"]");
863 if(varInput) {
865 logger.debug(">> main memory: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")) );
866 logger.debug(">> variable name ["+ variableName +"] / variable ["+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
867 .findVariableByName(variableName) +"]");
869 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
870 .findVariableByName(variableName).replace(addee.getTagName(), originalTagId, addee);
873 if(!returnInput)
874 input = addee;
875 logger.debug(">> returnInput["+returnInput+"] > ["+input+"]");
877 // setting the 'previousCommandResult'
878 AXmlCommandInput replacor = LoadHelper.reparse(input.toXML(false));
879 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
880 replacorReference.setXmlCommandInput(replacor);
881 replacorReference.setReference(input);
882 this.setPreviousCommandResult(replacorReference);
883 //logger.debug("Add / Previous Command "+ addee.toXML());
887 public void caseAUpdateCommand1(AUpdateCommand1 node) {
889 IBob updatee = null;
890 String originalTagId = null;
891 String variableName = null;
892 if(this.userSession == null) {
893 throw new AuthorisationException("You are not logged in");
895 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
897 logger.debug("c1 class["+node.getC1().getClass()+"]");
898 logger.debug(node.getC1() instanceof AXmlCommandInput);
899 logger.debug(node.getC1() instanceof com.interrupt.bookkeeping.cc.node.AVarCommandInput);
901 /**
902 * KLUDGE since 'node.getC1()' gets converted to an 'AXmlCommandInput' on first apply
904 boolean xmlInput = false;
905 boolean varInput = false;
906 AVarCommandInput ceeOne = null;
907 if(node.getC1() instanceof AXmlCommandInput) {
908 xmlInput = true;
910 else if(node.getC1() instanceof com.interrupt.bookkeeping.cc.node.AVarCommandInput) {
911 varInput = true;
912 ceeOne = (AVarCommandInput)node.getC1();
916 inAUpdateCommand1(node);
917 if(node.getUpdate() != null)
919 node.getUpdate().apply(this);
921 if(node.getLbdepth1() != null)
923 node.getLbdepth1().apply(this);
925 if(node.getLbdepth2() != null)
927 node.getLbdepth2().apply(this);
929 if(node.getC1() != null)
932 logger.debug("Grrr 1");
935 node.getC1().apply(this);
936 if(xmlInput) {
938 logger.debug("Grrr 2");
940 // 1. for raw XML
941 IResult result = CreateHelper.execute(user, new CreateCommand(), (AXmlCommandInput)node.getC1());
942 updatee = (IBob)result.getChild(0);
944 else if (varInput) {
946 logger.debug("Grrr 3");
948 // 2. for variable name
949 if( ceeOne != null) {
951 ceeOne.getVarname().apply(this);
952 variableName = ceeOne.getVarname().toString();
954 // remove the '@' sign
955 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
956 variableName = variableName.trim();
960 // retrieve from the bkell environments
961 IMemory memory = (IMemory)this.getBkellEnv().findMemoryById("main.memory");
962 if(variableName.equals("memory")) {
964 HashMap allPrefixes = new HashMap();
965 IBob eachbob = null;
966 ISystem system = BookkeepingSystem.instance().getMODEL();
967 while(system.canPull()) {
969 eachbob = system.pullNext();
970 allPrefixes.putAll(eachbob.getPrefixMappings());
972 memory.setPrefixMappings(allPrefixes);
973 updatee = memory;
975 else {
977 IVariable variable = memory.findVariableByName(variableName);
978 updatee = (IBob)variable.getChildren().get(0);
982 else {
984 logger.debug("Grrr 4");
986 // 3. for function result
987 //updatee = ((IResult)this.getPreviousCommandResult().getReference()).getChild(0);
988 updatee = this.getPreviousCommandResult().getReference();
991 logger.debug("caseAUpdateCommand1 updatee 1: "+ updatee.toXML(false));
992 if(updatee instanceof IResult) {
993 logger.debug("here 1");
994 updatee = updatee.getChild(0);
997 logger.debug("caseAUpdateCommand1 updatee 2: "+ updatee.toXML(false));
998 originalTagId = updatee.getAttributeValue("id");
1001 if(node.getRbdepth2() != null)
1003 node.getRbdepth2().apply(this);
1005 if(node.getC2() != null)
1008 logger.debug("Grrr 5");
1010 IBob updator = null;
1011 boolean xmlInput2 = false;
1012 boolean varInput2 = false;
1013 AVarCommandInput ceeTwo = null;
1014 if(node.getC2() instanceof AXmlCommandInput) {
1015 xmlInput2 = true;
1017 else if(node.getC2() instanceof AVarCommandInput) {
1018 varInput2 = true;
1019 ceeTwo = (AVarCommandInput)node.getC2();
1023 node.getC2().apply(this);
1024 if( xmlInput2 ) {
1026 CreateCommand ccommand = new CreateCommand();
1027 ccommand.setAauthentication(this.aauthentication);
1028 IResult result = CreateHelper.execute(user, ccommand, (AXmlCommandInput)node.getC2());
1030 updator = (IBob)result.allChildren().get(0);
1031 updatee = updator;
1033 logger.debug("caseAUpdateCommand1 ZING 2!!!! " + updatee.toXML(false));
1036 else if( varInput2 ) {
1038 logger.debug("caseAUpdateCommand1 ZING 3!!!!");
1039 updator = this.getPreviousCommandResult().getReference();
1040 updatee = updator;
1043 logger.debug("Grrr 6");
1045 // ** replace variable in mem if applicable
1046 if ( varInput ) {
1048 logger.debug("Grrr 7");
1049 logger.debug("caseAUpdateCommand1 ZING 4!!!! A. / "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1050 .findVariableByName(variableName).find(updatee.getTagName(), originalTagId) );
1052 logger.debug("caseAUpdateCommand1 ZING 4!!!! B. / updatee: "+ updatee);
1053 logger.debug("caseAUpdateCommand1 ZING 4!!!! D. / tagName["+updatee.getTagName()+"] / originalId["+originalTagId+"]");
1055 logger.debug("caseAUpdateCommand1 ZING 4!!!! E. / to replace: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")).findVariableByName(variableName));
1057 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1058 .findVariableByName(variableName).replace(updatee.getTagName(), originalTagId, updator);
1063 if(node.getRbdepth1() != null)
1065 node.getRbdepth1().apply(this);
1067 outAUpdateCommand1(node);
1069 // setting the 'previousCommandResult'
1070 AXmlCommandInput replacor = LoadHelper.reparse(updatee.toXML(false));
1071 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1072 replacorReference.setXmlCommandInput(replacor);
1073 replacorReference.setReference(updatee);
1074 this.setPreviousCommandResult(replacorReference);
1078 public void caseARemoveCommand1(ARemoveCommand1 node) {
1081 IBob removee = null;
1082 String variableName = null;
1083 boolean varInput = false;
1084 AVarCommandInput ceeOne = null;
1086 if(this.userSession == null) {
1087 throw new AuthorisationException("You are not logged in");
1089 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1090 String originalTagId = null;
1092 inARemoveCommand1(node);
1093 if(node.getRemove() != null) {
1094 node.getRemove().apply(this);
1096 if(node.getLbdepth1() != null) {
1097 node.getLbdepth1().apply(this);
1099 if(node.getLbdepth2() != null) {
1100 node.getLbdepth2().apply(this);
1103 String cxpath = null;
1104 if(node.getCommandInput() != null) {
1106 logger.debug(">> remove / varInput["+ (node.getCommandInput() instanceof AVarCommandInput) +"]");
1107 logger.debug(">> remove / class["+ node.getCommandInput().getClass() +"]");
1108 if(node.getCommandInput() instanceof AVarCommandInput) { //** @variable CONTEXT
1110 varInput = true;
1111 ceeOne = (AVarCommandInput)node.getCommandInput();
1113 //ceeOne.getVarname().apply(this);
1114 variableName = ceeOne.getVarname().toString();
1116 // remove the '@' sign
1117 variableName = variableName.substring(1); //** if this fails, then the user only put in the '@'
1118 variableName = variableName.trim();
1120 logger.debug(">> remove / varName["+ variableName +"]");
1123 if(node.getCommandInput() instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput) { //** XPATH CONTEXT
1126 //**
1127 node.getCommandInput().apply(this);
1128 LoadExecutor lexecutor = new LoadExecutor();
1130 lexecutor.setAauthenticationToInject( this.getAauthentication() );
1131 lexecutor.setSpittoon(spittoon);
1132 lexecutor.setContextXPath( cxpath );
1133 removee = lexecutor.execute(user, node);
1135 setContextUrl(lexecutor.getContextUrl());
1139 String ciString = node.getCommandInput().toString(); logger.debug("1["+ ciString +"]");
1140 ciString = ciString.substring(ciString.indexOf("`") + 1); logger.debug("2["+ ciString +"]");
1142 int i = 0; int j = ciString.lastIndexOf("`");
1143 logger.debug("3 > length["+ ciString.length() +"] > begin index["+ i +"] > end index["+ j +"]");
1145 ciString = ciString.substring(i, j);
1146 logger.debug("4["+ ciString +"]");
1149 cxpath = this._yankContextPath(ciString);
1150 logger.debug("Remove -1 > cxpath["+ cxpath +"]");
1153 //**
1154 node.getCommandInput().apply(this);
1156 logger.debug("Remove - 0 > contextPath["+ this.getContextUrl() +"]");
1158 /**
1159 * The Token Acceptor
1161 * IMPORTANT. XML, Options, or Command will be the input option
1162 * [X] i. The Command will be processed in the visitor.
1163 * [OK] ii. and the XML should be processed (not loaded)
1164 * [OK] iii. We do want to process the Options though
1166 node.getCommandInput().apply(this);
1167 if(node.getCommandInput() instanceof AXmlCommandInput) { //** XML CONTEXT
1169 // if the input was raw XML, reparse into Bob object
1170 CreateCommand ccommand = new CreateCommand();
1171 ccommand.setAauthentication(this.aauthentication);
1172 IResult result = CreateHelper.execute(user, ccommand, (AXmlCommandInput)node.getCommandInput());
1173 removee = (IBob)result.getChild(0);
1175 else {
1177 removee = this.getPreviousCommandResult().getReference();
1180 originalTagId = removee.getAttributeValue("id");
1183 if(node.getRbdepth2() != null) {
1184 node.getRbdepth2().apply(this);
1190 VisitorApplyRemove vremove = new VisitorApplyRemove();
1191 vremove.setUser(user);
1192 vremove.setRemovee(removee);
1193 vremove.setAauthentication(aauthentication);
1194 vremove.setSpittoon(spittoon);
1195 vremove.setContextXPath( cxpath );
1197 logger.debug("Remove - 1");
1199 //** process list of inputs...
1200 List<PIlist> copy = new ArrayList<PIlist>(node.getIlist());
1201 for(PIlist e : copy) {
1203 e.apply(this);
1205 //** now remove the gear
1206 e.apply(vremove);
1210 if(varInput) { //** if there's a variable, replace it
1212 //logger.debug(">> main memory: "+ ((IMemory)this.getBkellEnv().findMemoryById("main.memory")) );
1213 logger.debug(">> variable name ["+ variableName +"] / variable ["+
1214 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1215 .findVariableByName(variableName) +"]");
1217 ((IMemory)this.getBkellEnv().findMemoryById("main.memory"))
1218 .findVariableByName(variableName).replace(removee.getTagName(), originalTagId, removee);
1224 if(node.getRbdepth1() != null) {
1225 node.getRbdepth1().apply(this);
1227 outARemoveCommand1(node);
1229 //logger.debug("Remove: THE END ["+removee+"]");
1232 // setting the 'previousCommandResult'
1233 AXmlCommandInput replacor = LoadHelper.reparse(removee.toXML(false));
1234 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1235 replacorReference.setXmlCommandInput(replacor);
1236 replacorReference.setReference(removee);
1237 this.setPreviousCommandResult(replacorReference);
1243 public void caseAReverseCommand5(AReverseCommand5 node) {
1246 IBob parentReversee = null;
1247 IBob reversee = null;
1248 IBob reversor = null;
1250 IResult result = null;
1252 inAReverseCommand5(node);
1253 if(node.getReverse() != null) {
1255 node.getReverse().apply(this);
1257 if(node.getLbdepth1() != null) {
1259 node.getLbdepth1().apply(this);
1261 if(node.getLbdepth2() != null){
1263 node.getLbdepth2().apply(this);
1265 if(node.getCi1() != null){
1267 //**
1268 node.getCi1().apply(this);
1269 //parentReversee = this._addRemoveReverseLoadBlock(node.getCi1());
1270 parentReversee = this.getPreviousCommandResult().getReference();
1273 if(node.getRbdepth2() != null){
1275 node.getRbdepth2().apply(this);
1277 if(node.getLbdepth3() != null){
1279 node.getLbdepth3().apply(this);
1281 if(node.getCi2() != null){
1283 //**
1284 node.getCi2().apply(this);
1285 reversee = this._addRemoveReverseLoadBlock(node.getCi2());
1288 if(node.getRbdepth3() != null){
1290 node.getRbdepth3().apply(this);
1292 if(node.getCi3() != null){
1294 //**
1295 node.getCi3().apply(this);
1296 reversor = this._addRemoveReverseLoadBlock(node.getCi3());
1298 ITokenLiterals tliterals = new GTokenLiterals();
1299 tliterals.addChild(reversor);
1301 ReverseCommand rcommand = new ReverseCommand();
1302 rcommand.setTokenRecieverParent((IEntries)parentReversee);
1303 rcommand.setTokenReciever(reversee);
1304 rcommand.setTokenLiterals(tliterals);
1306 IUser user = new User();
1307 user.setId("root");
1308 user.setUsername("root");
1309 this.aauthentication.authenticate("webkell", user);
1310 result = rcommand.execute(user);
1313 if(node.getRbdepth1() != null){
1315 node.getRbdepth1().apply(this);
1317 outAReverseCommand5(node);
1319 IBob bobResult = (IBob)result.getChildren().get(0);
1320 //logger.debug("Reverse: THE END ["+ bobResult +"]");
1323 // setting the 'previousCommandResult'
1324 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1325 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1326 replacorReference.setXmlCommandInput(replacor);
1327 replacorReference.setReference(bobResult);
1328 this.setPreviousCommandResult(replacorReference);
1335 public void caseAFindCommand2(AFindCommand2 node) {
1338 IBob findContext = null;
1339 IBob bobResult = null;
1341 if(this.userSession == null) {
1342 throw new AuthorisationException("You are not logged in");
1344 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1346 inAFindCommand2(node);
1347 if(node.getFind() != null) {
1348 node.getFind().apply(this);
1350 if(node.getLbdepth1() != null) {
1351 node.getLbdepth1().apply(this);
1353 if(node.getLbdepth2() != null) {
1354 node.getLbdepth2().apply(this);
1356 if(node.getC1() != null) {
1358 //**
1359 node.getC1().apply(this);
1360 findContext = this.getPreviousCommandResult().getReference();
1363 if(node.getRbdepth2() != null) {
1364 node.getRbdepth2().apply(this);
1366 if(node.getC2() != null) {
1368 boolean isOptions = (node.getC2().getClass() == AOptsCommandInput.class);
1370 //**
1371 node.getC2().apply(this);
1373 ////////////
1374 if( isOptions ) {
1376 FindCommand fcommand = new FindCommand();
1377 fcommand.setTokenReciever(findContext);
1379 CommandOptionVisitor covisitor = new CommandOptionVisitor();
1380 covisitor.setCommand(fcommand);
1381 node.getC2().apply(covisitor);
1383 // execute command
1384 //Logger.getLogger("bobstate").debug(loadCommand);
1386 bobResult = fcommand.execute(user);
1389 else {
1391 // if we are dealing with XML
1393 IBob findor = this._addRemoveReverseLoadBlock(node.getC2());
1395 logger.debug("findee ["+findContext+"]");
1396 logger.debug("findor ["+findor+"]");
1398 //--> load this 'tliteral' xml from system
1399 FindVisitor fvisitor = new FindVisitor();
1400 fvisitor.setTagName(
1401 findor.getTagName()
1404 // go
1405 findContext.accept(fvisitor);
1407 // results
1408 List presults = fvisitor.getPossibleResults();
1409 List presults2 = new FindCommand().isolateSearchList( //** TODO - this is really bad, but I need the isolate function
1410 findor.getAttributes()
1411 , presults);
1413 //logger.debug("WARNING. These are possible results. Returning first one");
1414 //logger.debug(presults2);
1416 if(presults2.size() > 0) {
1418 bobResult = (IBob)presults2.get(0);
1421 ////////////
1424 if(node.getRbdepth1() != null) {
1425 node.getRbdepth1().apply(this);
1427 outAFindCommand2(node);
1429 //logger.debug("Find: THE END ["+ result +"]");
1432 // setting the 'previousCommandResult'
1433 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1434 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1435 replacorReference.setXmlCommandInput(replacor);
1436 replacorReference.setReference(bobResult);
1437 this.setPreviousCommandResult(replacorReference);
1442 public void caseAListCommand2(AListCommand2 node) {
1445 IBob listee = null;
1446 IResult result = new GResult();
1448 inAListCommand2(node);
1449 if(node.getList() != null) {
1450 node.getList().apply(this);
1452 if(node.getLbdepth1() != null) {
1453 node.getLbdepth1().apply(this);
1455 if(node.getLbdepth2() != null) {
1456 node.getLbdepth2().apply(this);
1458 if(node.getC1() != null) {
1460 //**
1461 node.getC1().apply(this);
1462 listee = this.getPreviousCommandResult().getReference();
1464 logger.debug("caseAListCommand2 > context["+ listee +"]");
1467 if(node.getRbdepth2() != null) {
1468 node.getRbdepth2().apply(this);
1470 if(node.getC2() != null) {
1472 //**
1473 node.getC2().apply(this);
1475 IBob listor = this._addRemoveReverseLoadBlock(node, node.getC2());
1476 logger.debug("caseAListCommand2 > input["+ listor +"]");
1478 //--> load this 'tliteral' xml from system
1479 FindVisitor fvisitor = new FindVisitor();
1480 fvisitor.setTagName( listor.getTagName() );
1481 listee.acceptFirst(fvisitor);
1483 // results
1484 List presults = fvisitor.getPossibleResults();
1485 if(listor.getAttributes().getLength() > 0) {
1487 presults = new FindCommand().isolateSearchList( //** this is really bad, but I need the isolate function
1488 listor.getAttributes()
1489 , presults);
1492 logger.debug("isolated results["+ presults +"]");
1494 if(presults.size() > 0) {
1495 result.addChildren(presults);
1499 if(node.getRbdepth1() != null) {
1500 node.getRbdepth1().apply(this);
1502 outAListCommand2(node);
1504 logger.debug("List: THE END ["+ result +"]");
1507 // setting the 'previousCommandResult'
1508 IBob bobResult = null;
1509 try {
1510 bobResult = (IBob)result.getChildren().get(0);
1512 catch(IndexOutOfBoundsException e) {
1513 logger.error("java.lang.IndexOutOfBoundsException["+e.getMessage()+"]");
1514 bobResult = new Bob();
1516 AXmlCommandInput replacor = LoadHelper.reparse(bobResult.toXML(false));
1517 AXmlCommandInputRef replacorReference = new AXmlCommandInputRef();
1518 replacorReference.setXmlCommandInput(replacor);
1519 replacorReference.setReference(bobResult);
1520 this.setPreviousCommandResult(replacorReference);
1525 public void caseAExitCommand4(AExitCommand4 node) {
1527 inAExitCommand4(node);
1528 if(node.getExit() != null) {
1529 node.getExit().apply(this);
1532 //** turn off this visitor's switch
1533 this.setActive(false);
1534 outAExitCommand4(node);
1538 private String yankContextPath( ALoadCommand3 node ) {
1539 return this._yankContextPath( node.getCommandInput().toString() );
1541 private String yankContextPath( ARemoveCommand1 node ) {
1542 return this._yankContextPath( node.getCommandInput().toString() );
1544 private String _yankContextPath( String inputString ) {
1546 String cxpath = inputString;
1547 logger.debug("contextXPath BEFORE ["+ cxpath +"]");
1549 cxpath = cxpath.replaceAll("`", "");
1550 cxpath = cxpath.replaceAll(" ", "");
1551 cxpath = cxpath.trim();
1552 logger.debug("contextXPath AFTER ["+ cxpath +"]");
1554 return cxpath;
1556 private IBob _createBlock(Node cinput) {
1559 IBob bobee = null;
1560 CreateCommand createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
1561 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
1563 if(this.userSession == null) {
1564 throw new AuthorisationException("You are not logged in");
1566 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1568 createCommand.setAauthentication(this.getAauthentication());
1569 IResult addee_r = CreateHelper.execute(user, createCommand, (AXmlCommandInput)cinput);
1570 List addeeList = addee_r.allChildren();
1571 bobee = (IBob)addeeList.get(0);
1573 return bobee;
1576 private IBob _addRemoveReverseLoadBlock( PCommandInput cinput ) {
1577 return this._addRemoveReverseLoadBlock(null, cinput);
1579 private IBob _addRemoveReverseLoadBlock( AListCommand2 node, PCommandInput cinput ) {
1582 IBob bobee = null;
1584 LoadCommand loadCommand = (com.interrupt.bookkeeping.cc.bkell.command.LoadCommand)
1585 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.LoadCommand" );
1586 CreateCommand createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
1587 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
1589 if( cinput instanceof com.interrupt.bookkeeping.cc.node.AXpathCommandInput ) {
1591 String cxpath = cinput.toString();
1592 logger.info("contextXPath BEFORE ["+ cxpath +"]");
1594 cxpath = cxpath.replaceAll("`", "");
1595 cxpath = cxpath.replaceAll(" ", "");
1596 cxpath = cxpath.trim();
1597 logger.info("contextXPath AFTER ["+ cxpath +"]");
1599 //**
1600 cinput.apply(this);
1601 LoadExecutor lexecutor = new LoadExecutor();
1602 if(this.userSession == null) {
1603 throw new AuthorisationException("You are not logged in");
1606 lexecutor.setAauthenticationToInject( this.getAauthentication() );
1607 lexecutor.setSpittoon(spittoon);
1608 lexecutor.setContextXPath( cxpath );
1609 IResult addee_r = lexecutor.execute(this.aauthentication.findUser(this.userSession.getUserid()), node);
1610 List addeeList = addee_r.allChildren();
1611 bobee = (IBob)addeeList.get(0);
1613 logger.debug("_addRemoveReverseLoadBlock > load executor result["+ bobee +"]");
1615 setContextUrl(lexecutor.getContextUrl());
1617 else if(cinput instanceof AXmlCommandInput) {
1619 if(this.userSession == null) {
1620 throw new AuthorisationException("You are not logged in");
1622 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1623 IResult addee_r = CreateHelper.execute(user, createCommand, (AXmlCommandInput)cinput);
1624 List addeeList = addee_r.allChildren();
1625 bobee = (IBob)addeeList.get(0);
1628 else if(cinput instanceof AOptsCommandInput) {
1630 if(this.userSession == null) {
1631 throw new AuthorisationException("You are not logged in");
1633 IUser user = this.aauthentication.findUser(this.userSession.getUserid());
1634 IResult addee_r = LoadHelper.execute(user, loadCommand, (AOptsCommandInput)cinput);
1635 List addeeList = addee_r.allChildren();
1636 bobee = (IBob)addeeList.get(0);
1640 return bobee;
1643 public static void main(String args[]) {
1646 // setup command
1647 Bob bob = new Bob();
1648 (System.getProperties()).setProperty("bob.gen", "gen/");
1649 (System.getProperties()).setProperty("bob.base", ".");
1652 //logger.debug("HERE 1");
1654 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 >";
1655 String input_1 = input_s.replaceAll("< ", "<");
1656 String input_2 = input_1.replaceAll("\\/ >", "/>");
1657 String input_x = input_2.replaceAll("< \\/", "</");
1658 String input_y = input_x.replaceAll("<\\/ ", "</");
1659 String input_xx = input_y.replaceAll(" \\/ ", "/");
1660 String input_3 = input_xx.replaceAll(" = ", "=");
1662 //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>";
1664 //logger.debug("HERE 2 ["+ input_3 +"]");
1666 IBob created = bob.load( input_3, BookkeepingSystemProperties.instance().getProperty("bob.def") );
1667 //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>",
1668 // "xml/bookkeeping.2.bookkeeping.xml xml/bookkeeping.2.transactions.xml xml/bookkeeping.2.users.xml" );
1672 //logger.debug("HERE 3");
1674 //created.toXML(System.out);
1680 /**
1681 * return XMLCommandInput from these commands
1683 public void caseAC1Command(AC1Command node) {
1685 inAC1Command(node);
1686 if(node.getCommand1() != null) {
1687 node.getCommand1().apply(this);
1689 outAC1Command(node);
1693 public void caseAC2Command(AC2Command node) {
1695 inAC2Command(node);
1696 if(node.getCommand2() != null) {
1697 node.getCommand2().apply(this);
1699 outAC2Command(node);
1703 public void caseAC5Command(AC5Command node) {
1705 inAC5Command(node);
1706 if(node.getCommand5() != null) {
1707 node.getCommand5().apply(this);
1709 outAC5Command(node);
1712 public void caseAC3Command(AC3Command node) {
1714 inAC3Command(node);
1715 if(node.getCommand3() != null) {
1716 node.getCommand3().apply(this);
1718 outAC3Command(node);
1721 public void caseAC4Command(AC4Command node) {
1723 inAC4Command(node);
1724 if(node.getCommand4() != null) {
1725 node.getCommand4().apply(this);
1727 outAC4Command(node);