KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > loader > PaletteDescriptor


1 package com.opensymphony.workflow.loader;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.w3c.dom.Element JavaDoc;
8 import org.w3c.dom.NodeList JavaDoc;
9 import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle;
10 import com.opensymphony.workflow.designer.ResourceManager;
11
12 /**
13  * @author jackflit
14  * Date: 2003-11-21
15  */

16 public class PaletteDescriptor extends AbstractDescriptor
17 {
18   protected List JavaDoc statusList = new ArrayList JavaDoc();
19   protected List JavaDoc joinList = new ArrayList JavaDoc();
20   protected List JavaDoc preList = new ArrayList JavaDoc();
21   protected List JavaDoc permissionList = new ArrayList JavaDoc();
22   protected List JavaDoc resultList = new ArrayList JavaDoc();
23   protected String JavaDoc defaultOldStatus = null;
24   protected String JavaDoc defaultNextStatus = null;
25     private EnhancedResourceBundle bundle;
26
27     public PaletteDescriptor(Element JavaDoc root, EnhancedResourceBundle bundle)
28   {
29       this.bundle = bundle;
30     init(root);
31   }
32
33     public ConfigConditionDescriptor[] getJoinConditions()
34     {
35         ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[joinList.size()];
36         joinList.toArray(config);
37         return config;
38     }
39
40   public ConfigFunctionDescriptor[] getPreFunctions()
41   {
42       ConfigFunctionDescriptor[] array = new ConfigFunctionDescriptor[preList.size()];
43       preList.toArray(array);
44       return array;
45   }
46
47   public PermissionConditionDescriptor[] getPermissionConditions()
48   {
49       PermissionConditionDescriptor[] array = new PermissionConditionDescriptor[permissionList.size()];
50       permissionList.toArray(array);
51       return array;
52   }
53
54     public ConfigConditionDescriptor[] getResultConditions()
55     {
56         ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[resultList.size()];
57         resultList.toArray(config);
58         return config;
59     }
60
61   public String JavaDoc[] getStatusNames()
62   {
63     String JavaDoc[] names = new String JavaDoc[statusList.size()];
64
65     for(int i = 0; i < names.length; i++)
66     {
67       StatusDescriptor status = (StatusDescriptor)statusList.get(i);
68       names[i] = status.getName();
69     }
70     return names;
71   }
72
73   public ConfigConditionDescriptor getJoinCondition(String JavaDoc name)
74   {
75     if(name == null)
76     {
77       return null;
78     }
79     for(int i = 0; i < joinList.size(); i++)
80     {
81       ConfigConditionDescriptor join = (ConfigConditionDescriptor)joinList.get(i);
82       if(name.equals(join.getName()))
83       {
84         return join;
85       }
86     }
87     return null;
88   }
89
90   public ConfigFunctionDescriptor getPrefunction(String JavaDoc name)
91   {
92     if(name == null)
93     {
94       return null;
95     }
96     for(int i = 0; i < preList.size(); i++)
97     {
98       ConfigFunctionDescriptor pre = (ConfigFunctionDescriptor)preList.get(i);
99       if(name.equals(pre.getName()))
100       {
101         return pre;
102       }
103     }
104     return null;
105   }
106
107   public PermissionConditionDescriptor getPermissionCondition(String JavaDoc name)
108   {
109     if(name == null)
110     {
111       return null;
112     }
113     for(int i = 0; i < permissionList.size(); i++)
114     {
115       PermissionConditionDescriptor perm = (PermissionConditionDescriptor)permissionList.get(i);
116       if(name.equals(perm.getName()))
117       {
118         return perm;
119       }
120     }
121     return null;
122   }
123
124   public ConfigConditionDescriptor getResultCondition(String JavaDoc name)
125   {
126     if(name == null)
127     {
128       return null;
129     }
130     for(int i = 0; i < joinList.size(); i++)
131     {
132       ConfigConditionDescriptor result = (ConfigConditionDescriptor)resultList.get(i);
133       if(name.equals(result.getName()))
134       {
135         return result;
136       }
137     }
138     return null;
139   }
140
141   public String JavaDoc getDefaultOldStatus()
142   {
143     return defaultOldStatus;
144   }
145
146   public String JavaDoc getDefaultNextStatus()
147   {
148     return defaultNextStatus;
149   }
150
151   public void writeXML(PrintWriter JavaDoc writer, int indent)
152   {
153     throw new UnsupportedOperationException JavaDoc();
154   }
155
156   protected void init(Element JavaDoc root)
157   {
158     // joinconditions
159
Element JavaDoc s = XMLUtil.getChildElement(root, "statusvalues");
160     defaultNextStatus = s.getAttribute("default-next");
161     defaultOldStatus = s.getAttribute("default-old");
162     List JavaDoc l = XMLUtil.getChildElements(s, "status");
163     for(int i = 0; i < l.size(); i++)
164     {
165       Element JavaDoc status = (Element JavaDoc)l.get(i);
166       StatusDescriptor statusDescriptor = new StatusDescriptor(status);
167       statusDescriptor.setParent(this);
168       statusList.add(statusDescriptor);
169     }
170     Element JavaDoc j = XMLUtil.getChildElement(root, "joinconditions");
171     if(j != null)
172     {
173       List JavaDoc joins = XMLUtil.getChildElements(j, "condition");
174       for(int i = 0; i < joins.size(); i++)
175       {
176         Element JavaDoc condition = (Element JavaDoc)joins.get(i);
177         ConfigConditionDescriptor jcd = new ConfigConditionDescriptor(this, condition);
178           jcd.setDescription(bundle.getString(jcd.getName() + ".long"));
179           jcd.setDisplayName(bundle.getString(jcd.getName()));
180         jcd.setParent(this);
181         joinList.add(jcd);
182       }
183     }
184
185     // prefunctions
186
Element JavaDoc p = XMLUtil.getChildElement(root, "functions");
187     if(p != null)
188     {
189       List JavaDoc functions = XMLUtil.getChildElements(p, "function");
190       for(int i = 0; i < functions.size(); i++)
191       {
192         Element JavaDoc function = (Element JavaDoc)functions.get(i);
193         ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(this, function);
194           pd.setDescription(bundle.getString(pd.getName() + ".long"));
195           pd.setDisplayName(bundle.getString(pd.getName()));
196         pd.setParent(this);
197         preList.add(pd);
198       }
199     }
200
201     // permissionconditions
202
Element JavaDoc pm = XMLUtil.getChildElement(root, "permissionconditions");
203     if(pm != null)
204     {
205       List JavaDoc joins = XMLUtil.getChildElements(pm, "condition");
206       for(int i = 0; i < joins.size(); i++)
207       {
208         Element JavaDoc condition = (Element JavaDoc)joins.get(i);
209         PermissionConditionDescriptor pcd = new PermissionConditionDescriptor(this, condition);
210           pcd.setDescription(bundle.getString(pcd.getName() + ".long"));
211           pcd.setDisplayName(bundle.getString(pcd.getName()));
212         pcd.setParent(this);
213         permissionList.add(pcd);
214       }
215     }
216
217     // resultconditions
218
Element JavaDoc r = XMLUtil.getChildElement(root, "resultconditions");
219     if(j != null)
220     {
221       List JavaDoc conditions = XMLUtil.getChildElements(r, "condition");
222       for(int i = 0; i < conditions.size(); i++)
223       {
224         Element JavaDoc condition = (Element JavaDoc)conditions.get(i);
225         ConfigConditionDescriptor rcd = new ConfigConditionDescriptor(this, condition);
226           rcd.setDescription(bundle.getString(rcd.getName() + ".long"));
227           rcd.setDisplayName(bundle.getString(rcd.getName()));
228         rcd.setParent(this);
229         resultList.add(rcd);
230       }
231     }
232
233   }
234
235     public EnhancedResourceBundle getBundle()
236     {
237         return bundle;
238     }
239 }
240
Popular Tags