1
2
3
4
5
6
7 package genie.commons.chain;
8
9 import java.util.Iterator;
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.apache.commons.chain.Catalog;
14 import org.apache.commons.chain.Command;
15 import org.apache.commons.chain.Context;
16 import org.apache.commons.collections.MapUtils;
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19
20 /***
21 *
22 *
23 * @author T. Kia Ntoni
24 *
25 * 27 déc. 2004
26 * CommandRunner @version
27 */
28 public abstract class CommandRunner implements Command {
29 private static Log log = LogFactory.getLog(CommandRunner.class);
30 protected Map<String, Context> contexts;
31
32 protected Catalog catalog;
33
34 /***
35 *
36 */
37 public CommandRunner() {
38 super();
39
40 }
41
42
43
44
45 public abstract boolean execute(Context context) throws Exception ;
46
47 /***
48 * @return Returns the catalog.
49 */
50 protected Catalog getCatalog() {
51 return catalog;
52 }
53 /***
54 * @param catalog The catalog to set.
55 */
56 protected void setCatalog(Catalog catalog) {
57 this.catalog = catalog;
58 }
59 /***
60 * @return Returns the contexts.
61 */
62 protected Map<String, Context> getContexts() {
63 return contexts;
64 }
65 /***
66 * @param contexts The contexts to set.
67 */
68 protected void setContexts(Map<String, Context> contexts) {
69 this.contexts = contexts;
70 }
71
72 protected static void verbosePrint(CommandRunner base) {
73
74
75 System.out.println("CommandRunner class = " + base.getClass().getName());
76 System.out.println("catalog class = " + base.getCatalog().getClass().getName());
77 System.out.println("contexts class = " + base.getContexts().getClass().getName());
78 MapUtils.verbosePrint(System.out, null, base.contexts);
79 for (Iterator<String> iter = base.getCatalog().getNames(); iter.hasNext();) {
80 String key = iter.next();
81 Command command = base.getCatalog().getCommand(key);
82 System.out.println("[");
83 System.out.println(" " + key + " = " + command);
84 System.out.println("]");
85 if (command instanceof CommandRunner) {
86 verbosePrint((CommandRunner) command);
87 }
88 }
89
90 }
91
92 }