KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Activities.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 {@link Activity}
21  * instances.
22  */

23 public class Activities extends XMLCollection {
24
25    /**
26     * Creates a new instance of the class.
27     * @param wpOrAs WorkflowProcess or ActivitySet that holds Activities class.
28     */

29    public Activities (XMLComplexElement wpOrAs) {
30       super (wpOrAs);
31    }
32
33    /**
34     * Generates a new element of the class which instances
35     * are members of collection of this class.
36     *
37     * return The generated instance of class that makes collection.
38     */

39    public XMLElement generateNewElement() {
40       WorkflowProcess wp;
41       if (myOwner instanceof WorkflowProcess) {
42          wp=(WorkflowProcess)myOwner;
43       } else {
44          wp=(WorkflowProcess)((ActivitySet)myOwner).getCollection().getOwner();
45       }
46       Activity a=new Activity(this,wp,0);
47       a.setRequired(true);
48       return a;
49    }
50
51    /**
52     * Returns an XMLActivity specified by given ID.
53     *
54     * @param ID The ID attribute of wanted XMLActivity.
55     * @return An instance of XMLActivity class that has specified ID.
56     * If collection of activities does not contain wanted
57     * Activity, the <tt>null</tt> is returned.
58     */

59    public Activity getActivity (String JavaDoc ID) {
60       return (Activity)super.getCollectionElement(ID);
61    }
62
63    /**
64     * Returns <tt>true</tt> if specified workflow process isn't referenced from
65     * any activity of subflow type.
66     */

67    protected boolean canRemoveWorkflow (WorkflowProcess toRemove) {
68       Activity a;
69       Iterator it=refCollectionElements.iterator();
70       while (it.hasNext()) {
71          a=(Activity)it.next();
72          if (a.getType()==3) {
73             if (((XMLComplexChoice)a.getSubflow().get("WorkflowProcess")).
74                 getChoosen()==toRemove) {
75                return false;
76             }
77          }
78       }
79       return true;
80    }
81
82    /**
83     * Returns <tt>true</tt> if specified participant isn't referenced to
84     * be a performer of activity.
85     */

86    protected boolean canRemoveParticipant (Participant toRemove) {
87       Activity a;
88       Iterator it=refCollectionElements.iterator();
89       while (it.hasNext()) {
90          a=(Activity)it.next();
91          if (a.get("Performer").toValue()==toRemove) {
92             return false;
93          }
94       }
95       return true;
96    }
97
98    /**
99     * Returns <tt>true</tt> if specified application isn't used as a tool
100     * of activity which type is Tool.
101     */

102    protected boolean canRemoveApplication (Application toRemove) {
103       Activity a;
104       Iterator it=refCollectionElements.iterator();
105       while (it.hasNext()) {
106          a=(Activity)it.next();
107          if (a.getType()==2) {
108             Tools ts=a.getTools();
109             Iterator itTools=ts.toCollection().iterator();
110             while (itTools.hasNext()) {
111                Tool t=(Tool)itTools.next();
112                if (((XMLComplexChoice)t.get("Application")).getChoosen()==toRemove) {
113                   return false;
114                }
115             }
116          }
117       }
118       return true;
119    }
120
121    /**
122     * Returns <tt>true</tt> if specified data field isn't used as
123     * actual parameter of activity which type is Tool or Subflow.
124     */

125    protected boolean canRemoveDataFieldOrFormalParameter (XMLCollectionElement toRemove) {
126       Activity a;
127       Iterator it=refCollectionElements.iterator();
128       while (it.hasNext()) {
129          a=(Activity)it.next();
130          if (a.getType()==2) {
131             Tools ts=a.getTools();
132             Iterator itTools=ts.toCollection().iterator();
133             while (itTools.hasNext()) {
134                Tool t=(Tool)itTools.next();
135                ActualParameters aps=(ActualParameters)t.get("ActualParameters");
136                Iterator itAPs=aps.toCollection().iterator();
137                while (itAPs.hasNext()) {
138                   ActualParameter ap=(ActualParameter)itAPs.next();
139                   if (ap.toValue()==toRemove) {
140                      return false;
141                   }
142                }
143             }
144          }
145          if (a.getType()==3) {
146             SubFlow sfw=a.getSubflow();
147             ActualParameters aps=(ActualParameters)sfw.get("ActualParameters");
148             Iterator itAPs=aps.toCollection().iterator();
149             while (itAPs.hasNext()) {
150                ActualParameter ap=(ActualParameter)itAPs.next();
151                if (ap.toValue()==toRemove) {
152                   return false;
153                }
154             }
155          }
156       }
157       return true;
158    }
159
160    /**
161     * Returns a set of Activity elements, which type is BlockActivity,
162     * contained within Activities object.
163     *
164     * @return A set of Activity object of BlockActivity type.
165     */

166    protected Set getBlockActivities () {
167       Set blockAs=new HashSet();
168       Activity a;
169       Iterator it=refCollectionElements.iterator();
170       while (it.hasNext()) {
171          a=(Activity)it.next();
172          if (a.getType()==4) {
173             blockAs.add(a);
174          }
175       }
176       return blockAs;
177    }
178
179    /**
180     * Called by owner object after importing of XML file to do neccessary
181     * things on activities after importing of XML.
182     */

183    protected void afterImporting () {
184       Iterator it=refCollectionElements.iterator();
185       while (it.hasNext()) {
186          Activity act=(Activity)it.next();
187          act.afterImporting();
188       }
189    }
190
191    /**
192     * Called by owner object after importing of XML file to do neccessary
193     * things on activities after "afterImporting" method is called both
194     * for activities and transitions
195     */

196    protected void fillOutgoingTransitions () {
197       Iterator it=refCollectionElements.iterator();
198       while (it.hasNext()) {
199          Activity act=(Activity)it.next();
200          act.fillOutgoingTransitions();
201       }
202    }
203
204    public int[] getInvisibleTableFieldOrdinals () {
205       int[] itfo=new int[12];
206       itfo[0]=2;
207       itfo[1]=3;
208       itfo[2]=4;
209       itfo[3]=6;
210       itfo[4]=7;
211       itfo[5]=8;
212       itfo[6]=9;
213       itfo[7]=10;
214       itfo[8]=11;
215       itfo[9]=12;
216       itfo[10]=13;
217       itfo[11]=14;
218       return itfo;
219    }
220
221    // First, the controlled panel must be created, and then the control panel
222
public XMLPanel getPanel () {
223       isReadOnly=true;
224       controlledPanel=new XMLTablePanel(this,"",false,false);
225       controlPanel=new XMLTableControlPanel(this,"",true,false);
226       return new XMLGroupPanel(this,new XMLPanel[]{
227                controlledPanel,controlPanel},toLabel(),XMLPanel.BOX_LAYOUT,
228                                false,true);
229    }
230
231    public WorkflowProcess getWorkflowProcess () {
232       Object JavaDoc own=getOwner();
233       if (own instanceof ActivitySet) {
234          return ((ActivitySet)own).getOwnerProcess();
235       } else {
236          return (WorkflowProcess)own;
237       }
238    }
239
240    public Object JavaDoc toValue () {
241       return String.valueOf(refCollectionElements.size());
242    }
243
244    /**
245     * Overrides parent method to handle the case when the activities
246     * from WorkflowProcess collection are copied to ActivitySet collection
247     * and vice-versa.
248     */

249    public void refreshCollection (Set elementsToAddOrRemove,boolean append) {
250       if (append) {
251          for (Iterator it=elementsToAddOrRemove.iterator(); it.hasNext();) {
252             Activity act=(Activity)it.next();
253             //HM: generate new ID because of possible different id-prefixes
254
if (act.getCollection() != this){
255                decrementID();
256                act.get("Id").setValue(this.generateID());
257             }
258             act.setCollection(this);
259             refCollectionElements.add(act);
260          }
261       } else {
262          refCollectionElements.removeAll(elementsToAddOrRemove);
263       }
264    }
265
266    /**
267     * Overrides parent method to be accessible within WorkflowManager.
268     */

269    public void decrementID () {
270       getWorkflowProcess().decrementActivityId();
271    }
272
273    public long getCurrentID () {
274       return getWorkflowProcess().getCurrentActivityId();
275    }
276
277    public String JavaDoc generateID () {
278       if (IDPrefix==null) IDPrefix="";
279       String JavaDoc ID;
280       do {
281          ID=IDPrefix+new Long JavaDoc(getWorkflowProcess().getNextActivityId()).toString();
282       } while (getWorkflowProcess().getActivity(ID)!=null);
283       return ID;
284    }
285
286    protected void resetID () {
287       getWorkflowProcess().resetActivityId();
288    }
289
290    protected void updateID (String JavaDoc someID) {
291       // try to get ID as if it is ours
292
try {
293          long val;
294          if (someID.startsWith(IDPrefix)) {
295             String JavaDoc ID=someID.substring(IDPrefix.length(),someID.length());
296             val=Long.parseLong(ID);
297             if (val>getWorkflowProcess().getCurrentActivityId()) {
298                getWorkflowProcess().setCurrentActivityId(val);
299             }
300          }
301          // then try to update someID as if it is only number
302
} catch (Exception JavaDoc ex) {
303          return;
304       }
305    }
306
307 }
308
Popular Tags