sync
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / bkell / command / AddCommand.java
blobebd5b312dc1649d73cafde73b2c7836517a8bc66
1 package com.interrupt.bookkeeping.cc.bkell.command;
4 import java.lang.reflect.InvocationTargetException;
5 import java.util.List;
6 import java.util.Iterator;
8 import org.apache.log4j.Logger;
10 import com.interrupt.bookkeeping.journal.Journal;
12 import com.interrupt.bob.base.IBob;
13 import com.interrupt.bob.util.Util;
14 import com.interrupt.bookkeeping.cc.ExpressionVisitor;
15 import com.interrupt.bookkeeping.cc.bkell.command.ITokenLiterals;
16 import com.interrupt.bookkeeping.cc.bkell.command.IResult;
17 import com.interrupt.bookkeeping.cc.bkell.command.GResult;
18 import com.interrupt.bookkeeping.exception.BkellException;
19 import com.interrupt.bookkeeping.exception.CommandException;
20 import com.interrupt.bookkeeping.journal.IEntry;
21 import com.interrupt.bookkeeping.journal.IJournal;
22 import com.interrupt.bookkeeping.users.IUser;
24 public class AddCommand extends AddRemoveReverseCommon {
27 private Logger logger = Logger.getLogger(AddCommand.class);
29 public AddCommand() {
31 super();
32 this.setName("add");
36 /* execute this command, add the 'token.literals' to the 'token.reciever'
38 public IResult execute(IUser user) {
40 logger.debug("AddCommand.execute: "+ this.toXML(false));
41 super.execute(user);
43 IBob treciever = this.getTokenReciever();
45 ITokenLiterals tliterals = this.getTokenLiterals();
46 List allLiterals = tliterals.allChildren();
47 Iterator titer = allLiterals.iterator();
48 IBob eachLiteral = null;
49 while( titer.hasNext() ) {
51 eachLiteral = (IBob)titer.next();
53 Class defParams[] = { eachLiteral.getClass() };
54 IBob methParams[] = { eachLiteral };
56 logger.debug("adding >> treceiver["+treciever.getClass()+" / "+treciever+"] / token["+eachLiteral.getClass()+" / "+eachLiteral.getTagName()
57 +"] / defParams["+defParams+"] / methParams["+methParams+"]");
59 try {
60 Util.evalReflectedAdd(treciever, eachLiteral.getTagName(), defParams, methParams);
62 catch(NoSuchMethodException e) {
63 BkellException bke = com.interrupt.bookkeeping.util.Util.generateBkellException(e);
64 throw bke;
66 catch(IllegalAccessException e) {
67 BkellException bke = com.interrupt.bookkeeping.util.Util.generateBkellException(e);
68 throw bke;
70 catch(InvocationTargetException e) {
71 BkellException bke = com.interrupt.bookkeeping.util.Util.generateBkellException(e);
72 throw bke;
78 //** TODO - update treciever into DB
81 IResult result = new GResult();
82 result.addChild(treciever);
84 return result;