KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > DataFields


1 /* DataFields.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe.xml.elements;
12
13 import org.enhydra.jawe.xml.*;
14 import org.enhydra.jawe.xml.panels.*;
15
16 import java.util.*;
17
18 /**
19 * Represents a WfMC DTD element that has the similar name.
20 * This class is a collection of class <b>DataField</b> instances.
21 *
22 * @see XML
23 */

24 public class DataFields extends XMLCollection {
25    /**
26    * Creates a new instance of the class.
27    *
28    * @param packageORWProcess The class instance which member is this class instance.
29    */

30    public DataFields (XMLComplexElement packageORWProcess) {
31       super(packageORWProcess);
32       coloringTable=true;
33    }
34
35    /**
36    * Generates a new element of the class which instances
37    * are members of collection of this class.
38    *
39    * return The generated instance of class that makes collection.
40    */

41    public XMLElement generateNewElement() {
42       Package JavaDoc p;
43       if (myOwner instanceof Package JavaDoc) {
44          p=(Package JavaDoc)myOwner;
45       }
46       else {
47          p=((WorkflowProcess)myOwner).getPackage();
48       }
49       DataField df=new DataField(this,p);
50       df.setRequired(true);
51       return df;
52    }
53
54    /**
55    * Returns all DataFields:
56    * <ul>
57    * <li> If DataFields instance is defined at the the process level,
58    * it gives all of it's data fields plus the ones defined at the package
59    * level.
60    * <li> If DataFields instance is defined at the the package level,
61    * it gives all of it's data fields.
62    * </ul>
63    */

64    public Collection getTableElements () {
65       ArrayList allDFs = new ArrayList();
66       if (myOwner instanceof Package JavaDoc) {
67          allDFs.addAll(refCollectionElements);
68       } else {
69          DataFields pdfs = (DataFields) (((WorkflowProcess) myOwner)
70             .getPackage()).get("DataFields");
71          allDFs.addAll(refCollectionElements);
72          allDFs.addAll(pdfs.refCollectionElements);
73       }
74       if (!getPackage().isReadOnly()) {
75          Iterator i = allDFs.iterator();
76          while (i.hasNext()) {
77             DataField df=(DataField)i.next();
78             boolean isMine=isMine(df);
79             df.setReadOnly(!isMine);
80             // Checks for it's own data field if it is used inside some
81
// transition condition expression, and if it isn't, set
82
// it's ID attribute not to be read only.
83
if (isMine && !isUsedWithinTransitionConditions(df)) {
84                df.get("Id").setReadOnly(false);
85             } else {
86                df.get("Id").setReadOnly(true);
87             }
88          }
89       }
90       return allDFs;
91    }
92
93    /**
94    * <ul>
95    * <li> If DataFields instance is defined at the the process level,
96    * it gives all of it's data fields plus the ones defined at the package
97    * level (except the ones that have the ID identical to some DataField at
98    * the process level), plus all formal parameters of process .
99    * <li> If DataFields instance is defined at the the package level,
100    * it gives all of it's data fields.
101    * </ul>
102    */

103    public Collection getChoosable() {
104       ArrayList chos = new ArrayList();
105       if (myOwner instanceof Package JavaDoc) {
106          chos.addAll(refCollectionElements);
107       } else {
108          DataFields pdfs = (DataFields) (((WorkflowProcess) myOwner)
109             .getPackage()).get("DataFields");
110          chos.addAll(refCollectionElements);
111          // adding the formal parameters of workflow process if this
112
// is at workflow process level
113
WorkflowProcess wp=(WorkflowProcess)myOwner;
114          FormalParameters fps=(FormalParameters)wp.get("FormalParameters");
115          Iterator i=fps.toCollection().iterator();
116          while (i.hasNext()) {
117             FormalParameter fp=(FormalParameter)i.next();
118             if (getCollectionElement(fp.getID())==null) {
119                chos.add(fp);
120             }
121          }
122          // adding data fields from package level
123
i=pdfs.getChoosable().iterator();
124          while (i.hasNext()) {
125             DataField df=(DataField)i.next();
126             if (getCollectionElement(df.getID())==null) {
127                chos.add(df);
128             }
129          }
130       }
131
132       if (!getPackage().isReadOnly()) {
133          Iterator i = chos.iterator();
134          while (i.hasNext()) {
135             XMLCollectionElement dfOrFP=(XMLCollectionElement)i.next();
136             if (dfOrFP instanceof DataField) {
137                DataField df=(DataField)dfOrFP;
138                boolean isMine=isMine(df);
139                dfOrFP.setReadOnly(!isMine);
140                // Checks for it's own data field if it is used inside some
141
// transition condition expression, and if it isn't, set
142
// it's ID attribute not to be read only.
143
if (isMine && !isUsedWithinTransitionConditions(df)) {
144                   dfOrFP.get("Id").setReadOnly(false);
145                } else {
146                   dfOrFP.get("Id").setReadOnly(true);
147                }
148             }
149          }
150       }
151       return chos;
152    }
153
154    /**
155    * Returns a data field with specified ID.
156    *
157    * @param ID The 'Id' attribute of wanted instance of
158    * DataField element defined within collection.
159    * @return The instance of DataField element that
160    * have the specified ID as an 'Id' attribute
161    * if it exist among all defined data fields within
162    * collection, if it doesn't exist, <tt>null</tt> is
163    * returned.
164    */

165    public DataField getDataField (String JavaDoc ID) {
166       DataField toReturn=(DataField)super.getCollectionElement(ID);
167
168       // if the data field haven't been found, and this is an instance of
169
// data fields at workflow process level, search the package level
170
if ((toReturn==null) && (myOwner instanceof WorkflowProcess)) {
171          toReturn=((DataFields)getPackage().get("DataFields")).getDataField(ID);
172       }
173
174       return toReturn;
175    }
176
177    /**
178    * Checks if specified data field can be removed. DataField can be
179    * removed only if it is not used anywhere.
180    */

181    public boolean canRemoveElement (XMLElement el) {
182       boolean remove=true;
183       DataField toRemove=(DataField)el;
184       // if this is data field from workflow process, check if it is
185
// used by any activity of subflow or generic type, or
186
// if it is used in transition condition expressions
187
// of any transition, but only within this workflow process
188
if (myOwner instanceof WorkflowProcess) {
189          Activities acts=(Activities)myOwner.get("Activities");
190          remove=acts.canRemoveDataFieldOrFormalParameter(toRemove);
191          // if it claims to be removed, check transitions
192
if (remove==true) {
193             Transitions ts=(Transitions)myOwner.get("Transitions");
194             remove=ts.canRemoveDataFieldOrFormalParameter(toRemove);
195          }
196
197          // if it claims to be removed, check activity sets
198
if (remove==true) {
199             ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets");
200             remove=actsts.canRemoveDataFieldOrFormalParameter(toRemove);
201          }
202       // else, check if it is used by any activity or transition within
203
// any workflow process within package
204
} else {
205          WorkflowProcesses wps=(WorkflowProcesses)myOwner.
206             get("WorkflowProcesses");
207          Iterator it=wps.toCollection().iterator();
208          while (it.hasNext()) {
209             WorkflowProcess wp=(WorkflowProcess)it.next();
210             Activities acts=(Activities)wp.get("Activities");
211             remove=acts.canRemoveDataFieldOrFormalParameter(toRemove);
212             if (!remove) {
213                break;
214             }
215             Transitions ts=(Transitions)wp.get("Transitions");
216             remove=ts.canRemoveDataFieldOrFormalParameter(toRemove);
217             if (!remove) {
218                break;
219             }
220             ActivitySets actsts=(ActivitySets)wp.get("ActivitySets");
221             remove=actsts.canRemoveDataFieldOrFormalParameter(toRemove);
222             if (!remove) {
223                break;
224             }
225          }
226       }
227       return remove;
228    }
229
230    protected boolean isUsedWithinTransitionConditions (DataField df) {
231       boolean inUse=false;
232       // if this is data field from workflow process, check all transitions
233
// within this workflow process
234
if (myOwner instanceof WorkflowProcess) {
235          Transitions ts=(Transitions)myOwner.get("Transitions");
236          inUse=!ts.canRemoveDataFieldOrFormalParameter(df);
237          // if it claims not to be used, check activity sets
238
if (inUse==false) {
239             ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets");
240             inUse=actsts.isDataFieldOrFormalParameterUsedWithinTransitionConditions(df);
241          }
242       // else, check if it is used by any transition within
243
// any workflow process within package
244
} else {
245          WorkflowProcesses wps=(WorkflowProcesses)myOwner.
246             get("WorkflowProcesses");
247          Iterator it=wps.toCollection().iterator();
248          while (it.hasNext()) {
249             WorkflowProcess wp=(WorkflowProcess)it.next();
250             Transitions ts=(Transitions)wp.get("Transitions");
251             inUse=!ts.canRemoveDataFieldOrFormalParameter(df);
252             if (inUse) {
253                break;
254             }
255             ActivitySets actsts=(ActivitySets)wp.get("ActivitySets");
256             inUse=actsts.isDataFieldOrFormalParameterUsedWithinTransitionConditions(df);
257             if (inUse) {
258                break;
259             }
260          }
261       }
262       return inUse;
263    }
264
265    public boolean isMine (DataField df) {
266       return refCollectionElements.contains(df);
267    }
268
269    public String JavaDoc getReadOnlyMessageName (XMLComplexElement el) {
270       return "WarningWorkflowRelevantDataDefinedAtPackageLevelCannotBeDeletedFromProcessLevel";
271    }
272
273    public String JavaDoc getInUseMessageName (XMLComplexElement el) {
274       return "WarningCannotDeleteWorkflowRelevantDataThatIsInUse";
275    }
276
277    /** Usefull to determine if some data field is from other package. */
278    public Package JavaDoc getPackage() {
279       Package JavaDoc p;
280       if (myOwner instanceof Package JavaDoc) {
281          p=(Package JavaDoc)myOwner;
282       }
283       else {
284          p=((WorkflowProcess)myOwner).getPackage();
285       }
286       return p;
287    }
288
289    public int[] getInvisibleTableFieldOrdinals () {
290       int[] itfo=new int[5];
291       itfo[0]=2;
292       itfo[1]=4;
293       itfo[2]=5;
294       itfo[3]=6;
295       itfo[4]=7;
296       return itfo;
297    }
298
299 }
300
Popular Tags