001: package process;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006:
007: import java.rmi.RemoteException;
008:
009: import de.danet.an.workflow.omgcore.AlreadyRunningException;
010: import de.danet.an.workflow.omgcore.CannotStartException;
011: import de.danet.an.workflow.omgcore.InvalidStateException;
012: import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
013: import de.danet.an.workflow.omgcore.WfActivity;
014: import de.danet.an.workflow.omgcore.WfProcess;
015:
016: /**
017: * Describe class <code>SmartWfProcess</code> here.
018: *
019: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
020: * @version 1.0
021: */
022: public class SmartWfProcess extends SmartWfExecutionObject {
023:
024: /**
025: * Describe variable <code>returnSmartActivities</code> here.
026: *
027: */
028: protected boolean returnSmartActivities = true;
029:
030: /**
031: * Creates a new <code>SmartWfProcess</code> instance.
032: *
033: * @param wfp a <code>WfProcess</code> value
034: * @param setStateDirectly a <code>boolean</code> value
035: * @param returnSmartActivities a <code>boolean</code> value
036: */
037: public SmartWfProcess(WfProcess wfp, boolean setStateDirectly,
038: boolean returnSmartActivities) throws Exception {
039: super (wfp, setStateDirectly);
040: this .returnSmartActivities = returnSmartActivities;
041: }
042:
043: /**
044: * Creates a new <code>SmartWfProcess</code> instance.
045: *
046: * @param wfp a <code>WfProcess</code> value
047: * @param setStateDirectly a <code>boolean</code> value
048: */
049: public SmartWfProcess(WfProcess wfp, boolean setStateDirectly)
050: throws Exception {
051: super (wfp, setStateDirectly);
052: }
053:
054: /**
055: * Creates a new <code>SmartWfProcess</code> instance.
056: *
057: * @param wfp a <code>WfProcess</code> value
058: */
059: public SmartWfProcess(WfProcess wfp) throws Exception {
060: super (wfp, false);
061: }
062:
063: /**
064: * Sets the state of a WfProcess object by calling
065: * start() (setStateDirectly == false) or by calling
066: * setState() (setStateDirectly == true).
067: * The intended transition is from open.not_running.not_started to
068: * open.running.
069: * @exception RemoteException if an error occurs
070: * @exception CannotStartException if an error occurs
071: * @exception AlreadyRunningException if an error occurs
072: * @exception InvalidStateException if an error occurs
073: * @exception TransitionNotAllowedException if an error occurs
074: */
075: public void start() throws RemoteException, CannotStartException,
076: AlreadyRunningException, InvalidStateException,
077: TransitionNotAllowedException {
078: boolean remoteExceptionCaught = false;
079: do {
080: remoteExceptionCaught = false;
081: try {
082: if (setStateDirectly) {
083: wfeo.changeState("open.running");
084: } else {
085: ((WfProcess) wfeo).start();
086: }
087: } catch (RemoteException re) {
088: remoteExceptionCaught = true;
089: }
090: } while (remoteExceptionCaught);
091: }
092:
093: /**
094: * Describe <code>activitiesInState</code> method here.
095: *
096: * @param state a <code>String</code> value
097: * @return a <code>Collection</code> value
098: * @exception Exception if an error occurs
099: */
100: public Collection activitiesInState(String state) throws Exception {
101: Collection activities = null;
102: boolean remoteExceptionCaught = false;
103: do {
104: remoteExceptionCaught = false;
105: try {
106: activities = ((WfProcess) wfeo)
107: .activitiesInState(state);
108: } catch (RemoteException re) {
109: remoteExceptionCaught = true;
110: }
111: } while (remoteExceptionCaught);
112: if (returnSmartActivities) {
113: activities = makeSmart(activities);
114: }
115: return activities;
116: }
117:
118: /**
119: * Describe <code>steps</code> method here.
120: *
121: * @return a <code>Collection</code> value
122: * @exception Exception if an error occurs
123: */
124: public Collection steps() throws Exception {
125: Collection steps = null;
126: boolean remoteExceptionCaught = false;
127: do {
128: remoteExceptionCaught = false;
129: try {
130: steps = ((WfProcess) wfeo).steps();
131: } catch (RemoteException re) {
132: remoteExceptionCaught = true;
133: }
134: } while (remoteExceptionCaught);
135: if (returnSmartActivities) {
136: steps = makeSmart(steps);
137: }
138: return steps;
139: }
140:
141: /**
142: * Describe <code>getWfProcess</code> method here.
143: *
144: * @return a <code>WfProcess</code> value
145: */
146: public WfProcess getWfProcess() {
147: return (WfProcess) wfeo;
148: }
149:
150: /**
151: * Describe <code>makeSmart</code> method here.
152: *
153: * @param activityCollection a <code>Collection</code> value
154: * @return a <code>Collection</code> value
155: */
156: protected Collection makeSmart(Collection activityCollection)
157: throws Exception {
158: Collection newCollection = new ArrayList();
159: Iterator it = activityCollection.iterator();
160: while (it.hasNext()) {
161: WfActivity activity = (WfActivity) it.next();
162: newCollection.add(new SmartWfActivity(activity,
163: setStateDirectly));
164: }
165: return newCollection;
166: }
167: }
|