package process;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.rmi.RemoteException;
import de.danet.an.workflow.omgcore.AlreadyRunningException;
import de.danet.an.workflow.omgcore.CannotStartException;
import de.danet.an.workflow.omgcore.InvalidStateException;
import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.omgcore.WfProcess;
/**
* Describe class <code>SmartWfProcess</code> here.
*
* @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
* @version 1.0
*/
public class SmartWfProcess extends SmartWfExecutionObject {
/**
* Describe variable <code>returnSmartActivities</code> here.
*
*/
protected boolean returnSmartActivities = true;
/**
* Creates a new <code>SmartWfProcess</code> instance.
*
* @param wfp a <code>WfProcess</code> value
* @param setStateDirectly a <code>boolean</code> value
* @param returnSmartActivities a <code>boolean</code> value
*/
public SmartWfProcess(WfProcess wfp,
boolean setStateDirectly,
boolean returnSmartActivities)
throws Exception {
super(wfp, setStateDirectly);
this.returnSmartActivities = returnSmartActivities;
}
/**
* Creates a new <code>SmartWfProcess</code> instance.
*
* @param wfp a <code>WfProcess</code> value
* @param setStateDirectly a <code>boolean</code> value
*/
public SmartWfProcess(WfProcess wfp,
boolean setStateDirectly)
throws Exception {
super(wfp, setStateDirectly);
}
/**
* Creates a new <code>SmartWfProcess</code> instance.
*
* @param wfp a <code>WfProcess</code> value
*/
public SmartWfProcess(WfProcess wfp) throws Exception {
super(wfp, false);
}
/**
* Sets the state of a WfProcess object by calling
* start() (setStateDirectly == false) or by calling
* setState() (setStateDirectly == true).
* The intended transition is from open.not_running.not_started to
* open.running.
* @exception RemoteException if an error occurs
* @exception CannotStartException if an error occurs
* @exception AlreadyRunningException if an error occurs
* @exception InvalidStateException if an error occurs
* @exception TransitionNotAllowedException if an error occurs
*/
public void start()
throws RemoteException, CannotStartException, AlreadyRunningException,
InvalidStateException, TransitionNotAllowedException {
boolean remoteExceptionCaught = false;
do {
remoteExceptionCaught = false;
try {
if (setStateDirectly) {
wfeo.changeState("open.running");
} else {
((WfProcess) wfeo).start();
}
} catch (RemoteException re) {
remoteExceptionCaught = true;
}
} while (remoteExceptionCaught);
}
/**
* Describe <code>activitiesInState</code> method here.
*
* @param state a <code>String</code> value
* @return a <code>Collection</code> value
* @exception Exception if an error occurs
*/
public Collection activitiesInState(String state)
throws Exception {
Collection activities = null;
boolean remoteExceptionCaught = false;
do {
remoteExceptionCaught = false;
try {
activities = ((WfProcess)wfeo).activitiesInState(state);
} catch (RemoteException re) {
remoteExceptionCaught = true;
}
} while (remoteExceptionCaught);
if (returnSmartActivities) {
activities = makeSmart(activities);
}
return activities;
}
/**
* Describe <code>steps</code> method here.
*
* @return a <code>Collection</code> value
* @exception Exception if an error occurs
*/
public Collection steps()
throws Exception {
Collection steps = null;
boolean remoteExceptionCaught = false;
do {
remoteExceptionCaught = false;
try {
steps = ((WfProcess)wfeo).steps();
} catch (RemoteException re) {
remoteExceptionCaught = true;
}
} while (remoteExceptionCaught);
if (returnSmartActivities) {
steps = makeSmart(steps);
}
return steps;
}
/**
* Describe <code>getWfProcess</code> method here.
*
* @return a <code>WfProcess</code> value
*/
public WfProcess getWfProcess() {
return (WfProcess)wfeo;
}
/**
* Describe <code>makeSmart</code> method here.
*
* @param activityCollection a <code>Collection</code> value
* @return a <code>Collection</code> value
*/
protected Collection makeSmart(Collection activityCollection)
throws Exception {
Collection newCollection = new ArrayList();
Iterator it = activityCollection.iterator();
while (it.hasNext()) {
WfActivity activity = (WfActivity)it.next();
newCollection.add(new SmartWfActivity(activity,
setStateDirectly));
}
return newCollection;
}
}