KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Applications.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 import org.w3c.dom.*;
18
19 /**
20 * Represents a WfMC DTD element that has the similar name.
21 * This class is a collection of class <b>Application</b> instances.
22 *
23 * @see XML
24 */

25 public class Applications extends XMLCollection {
26    private ArrayList externalApplications=new ArrayList();
27
28    /**
29    * Creates a new instance of the class.
30    *
31    * @param packageORWProcess The class instance which member
32    * is this class instance.
33    */

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

45    public XMLElement generateNewElement() {
46       Package JavaDoc p=getPackage();
47       Application ap=new Application(this,p);
48       ap.setRequired(true);
49       return ap;
50    }
51
52    /**
53    * It is overriden to give the caller all Applications:
54    * <ul>
55    * <li> If Applications instance is defined at the the workflow process level,
56    * it gives all of it's applications plus the ones defined at the package
57    * level (including all applications from externaly referenced packages).
58    * <li> If Applications instance is defined at the the package level,
59    * it gives all of it's applications plus the ones from externaly
60    * referenced packages).
61    * </ul>
62    */

63    public Collection getTableElements () {
64       ArrayList allApps = new ArrayList();
65       if (myOwner instanceof Package JavaDoc) {
66          allApps.addAll(refCollectionElements);
67          allApps.addAll(externalApplications);
68       } else {
69          Applications apps = (Applications)(((WorkflowProcess)myOwner)
70             .getPackage()).get("Applications");
71          allApps.addAll(refCollectionElements);
72          allApps.addAll(apps.refCollectionElements);
73          allApps.addAll(apps.externalApplications);
74       }
75
76       // if this is collection within the package that is not external,
77
// remove read-only attribute for all applications that belong
78
// to the collection, and set to others
79
if (!getPackage().isReadOnly()) {
80          Iterator i=allApps.iterator();
81          while (i.hasNext()) {
82             Application app = (Application) i.next();
83             app.setReadOnly(!isMine(app));
84          }
85       }
86       return allApps;
87    }
88
89    /**
90    * It is overriden to give the caller all Applications except the ones
91    * with same Ids as applications on lower level:
92    * <ul>
93    * <li> If Applications instance is defined at the the workflow process level,
94    * it gives all of it's applications plus the ones defined at the package
95    * level (including all applications from externaly referenced packages).
96    * <li> If Applications instance is defined at the the package level,
97    * it gives all of it's applications plus the ones from externaly
98    * referenced packages).
99    * </ul>
100    */

101    public Collection getChoosable() {
102       ArrayList chos = new ArrayList();
103       if (myOwner instanceof Package JavaDoc) {
104          chos.addAll(refCollectionElements);
105          Iterator i=externalApplications.iterator();
106          while (i.hasNext()) {
107             Application app=(Application)i.next();
108             if (getCollectionElement(app.getID())==null) {
109                chos.add(app);
110             }
111          }
112       } else {
113          Applications apps = (Applications)(((WorkflowProcess)myOwner)
114             .getPackage()).get("Applications");
115          chos.addAll(refCollectionElements);
116          Collection eaps=apps.getChoosable();
117          Iterator i=eaps.iterator();
118          while (i.hasNext()) {
119             Application app=(Application)i.next();
120             if (getCollectionElement(app.getID())==null) {
121                chos.add(app);
122             }
123          }
124       }
125
126       // if this is collection within the package that is not external,
127
// remove read-only attribute for all applications that belong
128
// to the collection, and set to others
129
if (!getPackage().isReadOnly()) {
130          Iterator i=chos.iterator();
131          while (i.hasNext()) {
132             Application app = (Application) i.next();
133             app.setReadOnly(!isMine(app));
134          }
135       }
136       return chos;
137    }
138
139    public Application getApplication (String JavaDoc ID) {
140       Application toReturn=(Application)super.getCollectionElement(ID);
141
142       // if the application haven't been found, and this is an instance of
143
// applications at workflow process level, search the package level
144
if ((toReturn==null) && (myOwner instanceof WorkflowProcess)) {
145          toReturn=((Applications)getPackage().get("Applications")).getApplication(ID);
146       }
147
148       // if the application haven't been found, search external applications
149
if (toReturn==null) {
150          String JavaDoc extID;
151          Iterator it=externalApplications.iterator();
152          while (it.hasNext()) {
153             Application atmp=(Application)it.next();
154             extID=atmp.getID();
155             if (extID.equals(ID)) {
156                toReturn=atmp;
157                break;
158             }
159          }
160       }
161
162       return toReturn;
163    }
164
165    /**
166    * Checks if specified application can be removed. Application can be
167    * removed only if it is not used anywhere.
168    */

169    public boolean canRemoveElement (XMLElement el) {
170       if (!isMine((Application)el)) return false;
171       Application toRemove=(Application)el;
172
173       return canRemoveApplication(toRemove);
174    }
175
176    public boolean canRemoveApplication (Application toRemove) {
177       boolean remove=true;
178       // if this is application from workflow process, check if it is
179
// used by any activity only within this workflow process
180
if (myOwner instanceof WorkflowProcess) {
181          Activities acts=(Activities)myOwner.get("Activities");
182          remove=acts.canRemoveApplication(toRemove);
183          // if it claims to be removed, check activity sets
184
if (remove==true) {
185             ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets");
186             remove=actsts.canRemoveApplication(toRemove);
187          }
188       // else, check if it is used by any activity within
189
// any workflow process within package
190
} else {
191          WorkflowProcesses wps=(WorkflowProcesses)myOwner.get("WorkflowProcesses");
192          Iterator it=wps.toCollection().iterator();
193          while (it.hasNext()) {
194             WorkflowProcess wp=(WorkflowProcess)it.next();
195             Activities acts=(Activities)wp.get("Activities");
196             remove=acts.canRemoveApplication(toRemove);
197             if (!remove) {
198                break;
199             }
200             ActivitySets actsts=(ActivitySets)wp.get("ActivitySets");
201             remove=actsts.canRemoveApplication(toRemove);
202             if (!remove) {
203                break;
204             }
205          }
206       }
207       return remove;
208    }
209
210    public boolean isMine (Application a) {
211       return refCollectionElements.contains(a);
212    }
213
214    public String JavaDoc getReadOnlyMessageName (XMLComplexElement el) {
215       if (!refCollectionElements.contains(el)) {
216          if (myOwner instanceof Package JavaDoc) {
217             return "WarningCannotDeleteExternalApplication";
218          } else {
219             return "WarningApplicationDefinedAtPackageLevelCannotBeDeletedFromProcessLevel";
220          }
221       }
222       return "";
223    }
224
225    public String JavaDoc getInUseMessageName (XMLComplexElement el) {
226       return "WarningCannotDeleteApplicationThatIsInUse";
227    }
228
229    /** Usefull to determine if some application is from other package. */
230    public Package JavaDoc getPackage() {
231       Package JavaDoc p;
232       if (myOwner instanceof Package JavaDoc) {
233          p=(Package JavaDoc)myOwner;
234       }
235       else {
236          p=((WorkflowProcess)myOwner).getPackage();
237       }
238       return p;
239    }
240
241    /**
242     *
243     */

244    protected void insertFromExternal(Package JavaDoc ep) {
245       Applications externalApps=(Applications)ep.get("Applications");
246       // insert only the aps that owns package 'ep'
247
// and are not referenced from some ext. pack. of 'ep'
248
Iterator it=externalApps.refCollectionElements.iterator();
249       while (it.hasNext()) {
250          Application app=(Application)it.next();
251          if (!externalApplications.contains(app)) {
252             externalApplications.add(app);
253          }
254       }
255    }
256
257    /**
258     *
259     */

260    protected void removeFromExternal(Package JavaDoc ep) {
261       Applications externalApps=(Applications)ep.get("Applications");
262       Iterator it=externalApps.toCollection().iterator();
263       while (it.hasNext()) {
264          Application app=(Application)it.next();
265          // removes only applications that directly belong to specified package
266
externalApplications.remove(app);
267       }
268    }
269
270    public int[] getInvisibleTableFieldOrdinals () {
271       int[] itfo=new int[3];
272       itfo[0]=2;
273       itfo[1]=3;
274       itfo[2]=4;
275       return itfo;
276    }
277
278    /**
279    * Overrides parent method to be accessible within application.
280    */

281    protected void updateID (String JavaDoc someID) {
282       super.updateID(someID);
283    }
284
285 }
286
Popular Tags