001: package com.opensymphony.workflow.loader;
002:
003: import java.io.PrintWriter;
004: import java.util.ArrayList;
005: import java.util.List;
006:
007: import org.w3c.dom.Element;
008: import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle;
009:
010: /**
011: * @author jackflit
012: * Date: 2003-11-21
013: */
014: public class PaletteDescriptor extends AbstractDescriptor {
015: protected List statusList = new ArrayList();
016: protected List joinList = new ArrayList();
017: protected List preList = new ArrayList();
018: protected List permissionList = new ArrayList();
019: protected List resultList = new ArrayList();
020: protected List validatorList = new ArrayList();
021: protected List registerList = new ArrayList();
022: protected List triggerList = new ArrayList();
023: protected List argtypeList = new ArrayList();
024: protected String defaultOldStatus = null;
025: protected String defaultNextStatus = null;
026: private EnhancedResourceBundle bundle;
027:
028: public PaletteDescriptor(Element root, EnhancedResourceBundle bundle) {
029: this .bundle = bundle;
030: init(root);
031: }
032:
033: public ConfigConditionDescriptor[] getJoinConditions() {
034: ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[joinList
035: .size()];
036: joinList.toArray(config);
037: return config;
038: }
039:
040: public ConfigFunctionDescriptor[] getPreFunctions() {
041: ConfigFunctionDescriptor[] array = new ConfigFunctionDescriptor[preList
042: .size()];
043: preList.toArray(array);
044: return array;
045: }
046:
047: public PermissionConditionDescriptor[] getPermissionConditions() {
048: PermissionConditionDescriptor[] array = new PermissionConditionDescriptor[permissionList
049: .size()];
050: permissionList.toArray(array);
051: return array;
052: }
053:
054: public ConfigConditionDescriptor[] getResultConditions() {
055: ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[resultList
056: .size()];
057: resultList.toArray(config);
058: return config;
059: }
060:
061: public ConfigRegisterDescriptor[] getRegisters() {
062: // workflow registers
063: ConfigRegisterDescriptor[] config = new ConfigRegisterDescriptor[registerList
064: .size()];
065: registerList.toArray(config);
066: return config;
067: }
068:
069: public ConfigValidatorDescriptor[] getValidators() {
070: ConfigValidatorDescriptor[] config = new ConfigValidatorDescriptor[validatorList
071: .size()];
072: validatorList.toArray(config);
073: return config;
074: }
075:
076: public ConfigFunctionDescriptor[] getTriggerFunctions() {
077: ConfigFunctionDescriptor[] config = new ConfigFunctionDescriptor[triggerList
078: .size()];
079: triggerList.toArray(config);
080: return config;
081: }
082:
083: public String[] getStatusNames() {
084: String[] names = new String[statusList.size()];
085:
086: for (int i = 0; i < names.length; i++) {
087: StatusDescriptor status = (StatusDescriptor) statusList
088: .get(i);
089: names[i] = status.getName();
090: }
091: return names;
092: }
093:
094: public ConfigConditionDescriptor getJoinCondition(String name) {
095: if (name == null) {
096: return null;
097: }
098: for (int i = 0; i < joinList.size(); i++) {
099: ConfigConditionDescriptor join = (ConfigConditionDescriptor) joinList
100: .get(i);
101: if (name.equals(join.getName())) {
102: return join;
103: }
104: }
105: return null;
106: }
107:
108: public ConfigFunctionDescriptor getPrefunction(String name) {
109: if (name == null) {
110: return null;
111: }
112: for (int i = 0; i < preList.size(); i++) {
113: ConfigFunctionDescriptor pre = (ConfigFunctionDescriptor) preList
114: .get(i);
115: if (name.equals(pre.getName())) {
116: return pre;
117: }
118: }
119: return null;
120: }
121:
122: public PermissionConditionDescriptor getPermissionCondition(
123: String name) {
124: if (name == null) {
125: return null;
126: }
127: for (int i = 0; i < permissionList.size(); i++) {
128: PermissionConditionDescriptor perm = (PermissionConditionDescriptor) permissionList
129: .get(i);
130: if (name.equals(perm.getName())) {
131: return perm;
132: }
133: }
134: return null;
135: }
136:
137: public ConfigConditionDescriptor getResultCondition(String name) {
138: if (name == null) {
139: return null;
140: }
141: for (int i = 0; i < joinList.size(); i++) {
142: ConfigConditionDescriptor result = (ConfigConditionDescriptor) resultList
143: .get(i);
144: if (name.equals(result.getName())) {
145: return result;
146: }
147: }
148: return null;
149: }
150:
151: public ConfigFunctionDescriptor getTriggerFunction(String name) {
152: if (name == null)
153: return null;
154: for (int i = 0; i < triggerList.size(); i++) {
155: ConfigFunctionDescriptor function = (ConfigFunctionDescriptor) triggerList
156: .get(i);
157: if (name.equals(function.getName()))
158: return function;
159: }
160: return null;
161: }
162:
163: public ConfigRegisterDescriptor getRegister(String name) {
164: if (name == null)
165: return null;
166: for (int i = 0; i < registerList.size(); i++) {
167: ConfigRegisterDescriptor reg = (ConfigRegisterDescriptor) registerList
168: .get(i);
169: if (name.equals(reg.getVariableName()))
170: return reg;
171: }
172: return null;
173: }
174:
175: public ArgType getArgType(String name) {
176: if (name == null)
177: return null;
178: for (int i = 0; i < argtypeList.size(); i++) {
179: ArgType type = (ArgType) argtypeList.get(i);
180: if (name.equals(type.getName()))
181: return type;
182: }
183: return null;
184: }
185:
186: public String getDefaultOldStatus() {
187: return defaultOldStatus;
188: }
189:
190: public String getDefaultNextStatus() {
191: return defaultNextStatus;
192: }
193:
194: public void writeXML(PrintWriter writer, int indent) {
195: throw new UnsupportedOperationException();
196: }
197:
198: protected void init(Element root) {
199: // argtypes
200: Element a = XMLUtil.getChildElement(root, "argtypes");
201: if (a != null) {
202: List types = XMLUtil.getChildElements(a, "argtype");
203: for (int i = 0; i < types.size(); i++) {
204: Element argtype = (Element) types.get(i);
205: String sClass = argtype.getAttribute("class");
206: if (sClass != null) {
207: ArgType argImpl = null;
208: try {
209: argImpl = (ArgType) Class.forName(sClass)
210: .newInstance();
211: if ((argImpl != null)
212: && (argImpl.init(argtype))) {
213: argtypeList.add(argImpl);
214: }
215: } catch (Exception e) {
216: e.printStackTrace();
217: }
218: }
219: }
220: }
221:
222: // joinconditions
223: Element s = XMLUtil.getChildElement(root, "statusvalues");
224: defaultNextStatus = s.getAttribute("default-next");
225: defaultOldStatus = s.getAttribute("default-old");
226: List l = XMLUtil.getChildElements(s, "status");
227: for (int i = 0; i < l.size(); i++) {
228: Element status = (Element) l.get(i);
229: StatusDescriptor statusDescriptor = new StatusDescriptor(
230: status);
231: statusDescriptor.setParent(this );
232: statusList.add(statusDescriptor);
233: }
234: Element j = XMLUtil.getChildElement(root, "joinconditions");
235: if (j != null) {
236: List joins = XMLUtil.getChildElements(j, "condition");
237: for (int i = 0; i < joins.size(); i++) {
238: Element condition = (Element) joins.get(i);
239: ConfigConditionDescriptor jcd = new ConfigConditionDescriptor(
240: this , condition);
241: jcd.setDescription(bundle.getString(jcd.getName()
242: + ".long"));
243: jcd.setDisplayName(bundle.getString(jcd.getName()));
244: jcd.setParent(this );
245: joinList.add(jcd);
246: }
247: }
248:
249: // prefunctions
250: Element p = XMLUtil.getChildElement(root, "functions");
251: if (p != null) {
252: List functions = XMLUtil.getChildElements(p, "function");
253: for (int i = 0; i < functions.size(); i++) {
254: Element function = (Element) functions.get(i);
255: ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(
256: this , function);
257: pd.setDescription(bundle.getString(pd.getName()
258: + ".long"));
259: pd.setDisplayName(bundle.getString(pd.getName()));
260: pd.setParent(this );
261: preList.add(pd);
262: }
263: }
264:
265: // permissionconditions
266: Element pm = XMLUtil.getChildElement(root,
267: "permissionconditions");
268: if (pm != null) {
269: List joins = XMLUtil.getChildElements(pm, "condition");
270: for (int i = 0; i < joins.size(); i++) {
271: Element condition = (Element) joins.get(i);
272: PermissionConditionDescriptor pcd = new PermissionConditionDescriptor(
273: this , condition);
274: pcd.setDescription(bundle.getString(pcd.getName()
275: + ".long"));
276: pcd.setDisplayName(bundle.getString(pcd.getName()));
277: pcd.setParent(this );
278: permissionList.add(pcd);
279: }
280: }
281:
282: // resultconditions
283: Element r = XMLUtil.getChildElement(root, "resultconditions");
284: if (r != null) {
285: List conditions = XMLUtil.getChildElements(r, "condition");
286: for (int i = 0; i < conditions.size(); i++) {
287: Element condition = (Element) conditions.get(i);
288: ConfigConditionDescriptor rcd = new ConfigConditionDescriptor(
289: this , condition);
290: rcd.setDescription(bundle.getString(rcd.getName()
291: + ".long"));
292: rcd.setDisplayName(bundle.getString(rcd.getName()));
293: rcd.setParent(this );
294: resultList.add(rcd);
295: }
296: }
297:
298: // registers
299: Element rr = XMLUtil.getChildElement(root, "registers");
300: if (rr != null) {
301: List registers = XMLUtil.getChildElements(rr, "register");
302: for (int i = 0; i < registers.size(); i++) {
303: Element register = (Element) registers.get(i);
304: ConfigRegisterDescriptor rd = new ConfigRegisterDescriptor(
305: this , register);
306: rd.setDescription(bundle.getString(rd.getName()
307: + ".long"));
308: rd.setVariableName(bundle.getString(rd.getName()));
309: rd.setParent(this );
310: registerList.add(rd);
311: }
312: }
313:
314: // trigger-functions
315: Element tf = XMLUtil.getChildElement(root, "triggerfunctions");
316: if (tf != null) {
317: List functions = XMLUtil.getChildElements(tf, "function");
318: for (int i = 0; i < functions.size(); i++) {
319: Element function = (Element) functions.get(i);
320: ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(
321: this , function);
322: pd.setDescription(bundle.getString(pd.getName()
323: + ".long"));
324: pd.setDisplayName(bundle.getString(pd.getName()));
325: pd.setParent(this );
326: triggerList.add(pd);
327: }
328: }
329:
330: // validators
331: Element vl = XMLUtil.getChildElement(root, "validators");
332: if (vl != null) {
333: List validators = XMLUtil.getChildElements(vl, "validator");
334: for (int i = 0; i < validators.size(); i++) {
335: Element validator = (Element) validators.get(i);
336: ConfigValidatorDescriptor vd = new ConfigValidatorDescriptor(
337: this , validator);
338: vd.setDescription(bundle.getString(vd.getName()
339: + ".long"));
340: vd.setName(bundle.getString(vd.getName()));
341: vd.setParent(this );
342: validatorList.add(vd);
343: }
344: }
345:
346: }
347:
348: public EnhancedResourceBundle getBundle() {
349: return bundle;
350: }
351: }
|