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.CannotCompleteException;
010: import de.danet.an.workflow.omgcore.InvalidStateException;
011: import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
012: import de.danet.an.workflow.omgcore.WfActivity;
013: import de.danet.an.workflow.omgcore.WfProcess;
014:
015: /**
016: * Describe class <code>SmartWfActivity</code> here.
017: *
018: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
019: * @version 1.0
020: */
021: public class SmartWfActivity extends SmartWfExecutionObject {
022: /**
023: * Describe variable <code>returnSmartProcesses</code> here.
024: *
025: */
026: protected boolean returnSmartProcesses = true;
027:
028: /**
029: * Creates a new <code>SmartWfActivity</code> instance.
030: *
031: * @param wfa a <code>WfActivity</code> value
032: * @param setStateDirectly a <code>boolean</code> value
033: */
034: public SmartWfActivity(WfActivity wfa, boolean setStateDirectly)
035: throws Exception {
036: super (wfa, setStateDirectly);
037: }
038:
039: /**
040: * Creates a new <code>SmartWfActivity</code> instance.
041: *
042: * @param wfa a <code>WfActivity</code> value
043: */
044: public SmartWfActivity(WfActivity wfa) throws Exception {
045: super (wfa, false);
046: }
047:
048: /**
049: * Sets the state of a Wfeoctivity object by calling
050: * complete() (setStateDirectly == false) or by calling
051: * setState() (setStateDirectly == true).
052: * The intended transition is from open.not_running.not_started to
053: * open.running.
054: * @exception RemoteException if an error occurs
055: * @exception CannotCompleteException if an error occurs
056: * @exception InvalidStateException if an error occurs
057: * @exception TransitionNotAllowedException if an error occurs
058: */
059: protected void complete() throws RemoteException,
060: CannotCompleteException, InvalidStateException,
061: TransitionNotAllowedException {
062: boolean remoteExceptionCaught = false;
063: do {
064: remoteExceptionCaught = false;
065: try {
066: if (setStateDirectly) {
067: wfeo.changeState("closed.completed");
068: } else {
069: ((WfActivity) wfeo).complete();
070: }
071: } catch (RemoteException re) {
072: remoteExceptionCaught = true;
073: }
074: } while (remoteExceptionCaught);
075: }
076:
077: /**
078: * return the performers of this activity, i.e. processes.
079: */
080: public Collection performers() throws Exception {
081: Collection performers = null;
082: boolean remoteExceptionCaught = false;
083: do {
084: remoteExceptionCaught = false;
085: try {
086: performers = ((WfActivity) wfeo).performers();
087: } catch (RemoteException re) {
088: remoteExceptionCaught = true;
089: }
090: } while (remoteExceptionCaught);
091: if (returnSmartProcesses) {
092: performers = makeSmart(performers);
093: }
094: return performers;
095: }
096:
097: /**
098: * Describe <code>makeSmart</code> method here.
099: *
100: * @param activityCollection a <code>Collection</code> value
101: * @return a <code>Collection</code> value
102: */
103: protected Collection makeSmart(Collection performerCollection)
104: throws Exception {
105: Collection newCollection = new ArrayList();
106: Iterator it = performerCollection.iterator();
107: while (it.hasNext()) {
108: WfProcess process = (WfProcess) it.next();
109: newCollection.add(new SmartWfProcess(process,
110: setStateDirectly));
111: }
112: return newCollection;
113: }
114: }
|