KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > UpdateChecker


1 package org.enhydra.shark;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.enhydra.shark.api.SharkTransaction;
7 import org.enhydra.shark.api.client.wfbase.BaseException;
8 import org.enhydra.shark.api.common.SharkConstants;
9 import org.enhydra.shark.api.internal.working.WfActivityInternal;
10 import org.enhydra.shark.xpdl.XMLCollectionElement;
11 import org.enhydra.shark.xpdl.XMLUtil;
12 import org.enhydra.shark.xpdl.elements.Activities;
13 import org.enhydra.shark.xpdl.elements.Activity;
14 import org.enhydra.shark.xpdl.elements.ActivitySet;
15 import org.enhydra.shark.xpdl.elements.WorkflowProcess;
16
17
18
19 /**
20  * The class that checks if updating of package is currently possible.
21  * Before calling this class, the processes from the package that is
22  * being checked must be suspended.
23  * <br>NOTE: This implementation only checks if definitions for all active
24  * activities exists in the new package.
25  * @author Sasa Bojanic
26  * @version 1.0
27  */

28 public class UpdateChecker {
29    private org.enhydra.shark.xpdl.elements.Package oldPackage;
30    private org.enhydra.shark.xpdl.elements.Package newPackage;
31    private List JavaDoc processesToRestore;
32    private List JavaDoc activitiesToRestore;
33
34    public UpdateChecker (org.enhydra.shark.xpdl.elements.Package oldPackage,
35                          org.enhydra.shark.xpdl.elements.Package newPackage,
36                          List JavaDoc processesToRestore,List JavaDoc activitiesToRestore) {
37       this.oldPackage=oldPackage;
38       this.newPackage=newPackage;
39       this.processesToRestore=processesToRestore;
40       this.activitiesToRestore=activitiesToRestore;
41    }
42
43    public boolean isUpdatePossible (SharkTransaction t) throws BaseException {
44       Iterator JavaDoc it=activitiesToRestore.iterator();
45       while (it.hasNext()) {
46          WfActivityInternal act=(WfActivityInternal)it.next();
47          // we don't check closed activities
48
try {
49             if (act.state(t).startsWith(SharkConstants.STATEPREFIX_CLOSED)) continue;
50          } catch (Exception JavaDoc ex) {}
51
52          Activity actDef=SharkUtilities.getActivityDefinition(t,act,
53                                                               SharkUtilities.getWorkflowProcess(act.container(t).package_id(t),
54                                                                                                 act.container(t).manager_version(t),
55                                                                                                 act.container(t).process_definition_id(t)),
56                                                               act.block_activity(t));
57
58          // search for the corresponding activity definition within new package
59
String JavaDoc processId=null;
60          String JavaDoc activitySetId=null;
61          // determine if activity definition is within the process
62
// or within processes activity set
63
XMLCollectionElement owner=(XMLCollectionElement)actDef.getParent().getParent();
64          if (owner instanceof WorkflowProcess) {
65             processId=owner.getId();
66          } else {
67             activitySetId=owner.getId();
68             processId=XMLUtil.getWorkflowProcess(actDef).getId();
69          }
70          WorkflowProcess wp=newPackage.getWorkflowProcess(processId);
71          // if process definition can't be found within the new package, return false
72
if (wp==null) {
73             return false;
74          }
75          // get all activity definitions from the process or from the set
76
Activities acts=null;
77          if (activitySetId!=null) {
78             ActivitySet as=wp.getActivitySet(activitySetId);
79             // if the set can't be found, return false
80
if (as==null) {
81                return false;
82             }
83             acts=as.getActivities();
84          } else {
85             acts=wp.getActivities();
86          }
87          // if activity definition can't be found, return false
88
if (acts.getActivity(actDef.getId())==null) {
89             return false;
90          }
91       }
92       return true;
93    }
94
95
96 }
97
Popular Tags