1
2
3
4
5
6
7 package genie.core;
8
9
10 import org.apache.commons.digester.CallMethodRule;
11 import org.apache.commons.digester.CallParamRule;
12 import org.apache.commons.digester.Digester;
13 import org.apache.commons.digester.ObjectCreateRule;
14 import org.apache.commons.digester.Rules;
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18 /***
19 *
20 *
21 * @author T. Kia Ntoni
22 *
23 * 3 janv. 2005
24 * ConfigRuleSet @version
25 */
26 public class CommandRuleSet extends AbstractRuleSet {
27 /***
28 * Logger for this class
29 */
30 private static final Log log = LogFactory.getLog(CommandRuleSet.class);
31
32 protected String cmdName = null;
33 protected boolean nestedCmd = true;
34 protected boolean handler = false;
35 /***
36 *
37 */
38 public CommandRuleSet() {
39 super();
40
41 }
42
43
44
45
46 public void addRuleInstances(Digester digester) {
47 if (log.isDebugEnabled()) {
48 log.debug("addRuleInstances(Digester) - start");
49 }
50
51
52 if (cmdName != null && cmdName.trim().length() > 0) {
53 super.addRuleInstances(digester);
54 Rules rules = digester.getRules();
55
56 String mgrPath = nestedCmd ? "!*/" + cmdName : cmdName;
57
58 rules.add(mgrPath, new ObjectCreateRule("className", Manager.class));
59
60 rules.add(mgrPath, new CallMethodRule(1, "addCommand", 2, addCommandParams ));
61 rules.add(mgrPath, new CallParamRule(0, "id"));
62 rules.add(mgrPath, new CallParamRule(1, true));
63 if (log.isDebugEnabled()) {
64 log.debug("mgrPath = " + mgrPath);
65 }
66
67 if (! handler) {
68
69 String contextPath = mgrPath + "/context";
70
71 rules.add(contextPath, new CallMethodRule(1 , "addContext", 2, addContextParams));
72 rules.add(contextPath, new CallParamRule(0, "id"));
73 rules.add(contextPath, new CallParamRule(1, true));
74 if (log.isDebugEnabled()) {
75 log.debug("contextPath = " + contextPath);
76 }
77
78 }
79
80
81
82 }else {
83 RuntimeException re = new RuntimeException(getClass().getName() + " : cmdName should be neither null nor empty.");
84 log.error("addRuleInstances(Digester)", re);
85 throw re;
86 }
87 if (log.isDebugEnabled()) {
88 log.debug("addRuleInstances(Digester) - end");
89 }
90 }
91
92 /***
93 * @return Returns the cmdName.
94 */
95 public String getCmdName() {
96 if (log.isDebugEnabled()) {
97 log.debug("getMgrName() - start");
98 }
99
100 if (log.isDebugEnabled()) {
101 log.debug("getMgrName() - end");
102 }
103 return cmdName;
104 }
105 /***
106 * @param cmdName The cmdName to set.
107 */
108 public void setCmdName(String mgrName) {
109 if (log.isDebugEnabled()) {
110 log.debug("setMgrName(String) - start");
111 }
112
113 this.cmdName = mgrName;
114
115 if (log.isDebugEnabled()) {
116 log.debug("setMgrName(String) - end");
117 }
118 }
119 /***
120 * @return Returns the nestedCmd.
121 */
122 public boolean isNestedCmd() {
123 if (log.isDebugEnabled()) {
124 log.debug("isNestedMgr() - start");
125 }
126
127 if (log.isDebugEnabled()) {
128 log.debug("isNestedMgr() - end");
129 }
130 return nestedCmd;
131 }
132 /***
133 * @param nestedCmd The nestedCmd to set.
134 */
135 public void setNestedCmd(boolean nestedMgr) {
136 if (log.isDebugEnabled()) {
137 log.debug("setNestedMgr(boolean) - start");
138 }
139
140 this.nestedCmd = nestedMgr;
141
142 if (log.isDebugEnabled()) {
143 log.debug("setNestedMgr(boolean) - end");
144 }
145 }
146 /***
147 * @return Returns the handler.
148 */
149 public boolean isHandler() {
150 return handler;
151 }
152 /***
153 * @param handler The handler to set.
154 */
155 public void setHandler(boolean handler) {
156 this.handler = handler;
157 }
158 }