* @throws OpenBPException On error
*/
public void executeModelObject(ModelObject mo, EngineExecutor ee)
{
TokenContext context = ee.getTokenContext();
NodeSocket entrySocket = context.getCurrentSocket();
ForkNode node = (ForkNode) entrySocket.getNode();
NodeSocket defaultOutSocket = node.getDefaultExitSocket();
if (defaultOutSocket == null)
{
String msg = LogUtil.error(getClass(), "No default exit socket present for fork node $0. [{1}]", node.getQualifier(), context);
throw new EngineException("NoDefaultExitSocket", msg);
}
Object collectionParamValue = TokenContextUtil.getParamValue(context, entrySocket, CoreConstants.FORK_COLLECTION_PARAM);
if (collectionParamValue != null)
{
// Automatic fork node based on input collection
if (defaultOutSocket.getParamByName(CoreConstants.FORK_COLLECTION_ELEMENT_PARAM) == null)
{
String msg = LogUtil.error(getClass(), "Fork node having a $0 input parameter requires a $1 output parameter. [{2}]", CoreConstants.FORK_COLLECTION_PARAM, CoreConstants.FORK_COLLECTION_ELEMENT_PARAM, context);
throw new EngineException("NoCollectionElementForFork", msg);
}
Iterator it = CollectionUtil.iterator(collectionParamValue);
while (it.hasNext())
{
Object collectionElement = it.next();
// Create a new child context
TokenContext childContext = getEngine().getTokenContextService().createChildContext(context);
// Provide the collection element to it
Param outParam = defaultOutSocket.getParamByName(CoreConstants.FORK_COLLECTION_ELEMENT_PARAM);
if (outParam != null)
{
// If the exit socket contains a 'WorkflowTask' parameter, set it
TokenContextUtil.setParamValue(childContext, outParam, collectionElement);
}
// Copy the data of the node entry socket in the current context
// to the exit socket in the child context.
EngineUtil.copySocketData(entrySocket, context, defaultOutSocket, childContext);
childContext.setCurrentSocket(defaultOutSocket);
getEngine().resumeToken(childContext);
}
}
else
{
// Iterate all exit sockets
for (Iterator itOutSockets = node.getSockets(false); itOutSockets.hasNext();)
{
final NodeSocket outSocket = (NodeSocket) itOutSockets.next();
if (outSocket.getName().equals(CoreConstants.FORK_RESUME))
continue;
// Create a new child context
TokenContext childContext = getEngine().getTokenContextService().createChildContext(context);
// Copy the data of the node entry socket in the current context
// to the exit socket in the child context.
EngineUtil.copySocketData(entrySocket, context, outSocket, childContext);
childContext.setCurrentSocket(outSocket);
getEngine().resumeToken(childContext);
}
}
// When there is a 'Resume' exit socket, let's continue there; otherwise simply end
NodeSocket nextSocket = getEngine().resolveSocketRef(CoreConstants.FORK_RESUME, entrySocket, context, false);
if (nextSocket != null)
{
context.setCurrentSocket(nextSocket);
}
else