sync
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / bkell / command / LoadCommand.java
blobb341eea9ef76c020660bc27171b14013cb2ea5db
1 package com.interrupt.bookkeeping.cc.bkell.command;
4 import java.io.File;
5 import java.lang.reflect.Method;
6 import java.lang.reflect.InvocationTargetException;
8 import java.util.List;
9 import java.util.Iterator;
11 import org.apache.log4j.Logger;
12 import org.xml.sax.Attributes;
13 import org.xml.sax.helpers.AttributesImpl;
15 import com.interrupt.bob.base.BobSystem;
17 import com.interrupt.bob.base.IBob;
18 import com.interrupt.bob.base.Bob;
19 import com.interrupt.bob.util.StringUtil;
20 import com.interrupt.bookkeeping.GSystem;
21 import com.interrupt.bookkeeping.ISystem;
22 import com.interrupt.bookkeeping.cc.bkell.IBkell;
23 import com.interrupt.bookkeeping.system.BookkeepingSystem;
24 import com.interrupt.bookkeeping.users.IUser;
25 import com.interrupt.spittoon.Spittoon;
27 public class LoadCommand extends AbstractCommand {
30 private Logger logger = Logger.getLogger(LoadCommand.class);
31 public LoadCommand() {
32 this(null);
34 public LoadCommand(Spittoon spitt) {
36 this.setName("load");
38 /**
39 * get the possible set of
40 * i. tokens for a command &
41 * ii. options for those tokens
43 */
44 ISystem bsystem = (GSystem)Bob.loadS( new File("xml/bookkeeping.system.xml") );
45 //logger.debug( "1 > "+ bsystem );
47 IBkell bkell = bsystem.findBkellById("bkell.main");
48 //logger.debug( "2 > "+ bkell );
50 ITokens tokens = bkell.findTokensById("tokens.def");
51 ICommands commands = bkell.findCommandsById("commands.def");
53 //logger.debug( "3 > "+ tokens );
54 //logger.debug( "4 > "+ commands );
57 ICommand command = commands.findCommandByName("load");
58 ITokens possibleTokens = (ITokens)command.allTokens().get(0);
61 // set the list of possible tokens
62 this.setTokens(possibleTokens);
64 spittoon = spitt;
68 public IResult execute(IUser user) {
70 logger.debug("LoadComand.execute:: command["+this+"] / user["+user+"]");
71 super.execute(user);
73 IResult result = new GResult();
75 //** TOKEN LITERAL - this should accept token literals as well as options
76 ITokenLiterals tliterals = this.getTokenLiterals();
77 logger.debug("token literals["+tliterals+"]");
79 List literalList = tliterals.allChildren();
80 IBob tliteral = null;
81 String txpath = null;
82 if(contextXPath != null) {
83 txpath = contextXPath;
85 else if( literalList.size() > 0 ) {
87 tliteral = (IBob)literalList.get(0);
88 txpath = tliteral.xpath(false);
91 String dbUrl = spittoon.getGroupsDbUrl();
92 logger.debug("LoadCommand::execute > dbUrl["+dbUrl+"] > txpath["+txpath+"]");
94 IBob resultBob = spittoon.retrieve(dbUrl, txpath, true);
96 result.addChild(resultBob);
97 return result;