* @param mustExist If true the method will throw an exception if the specified socket does not exist.
* @return The socket
*/
private NodeSocket determineResumptionPosition(TokenContext context, NodeSocket currentSocket, String ref, Engine engine, boolean mustExist)
{
NodeSocket startSocket = null;
// Relative execution request, the current process of the context should be continued with the specified entry name.
if (currentSocket == null)
{
// No current position we can search the relative entry from.
// The user either tries to access the application using a relative request
// or the session context has timed out.
// Log and create an exception
String msg = LogUtil.error(getClass(), "Session does not have a current position or session has expired for socket reference $0. [{1}]", ref, context);
throw new EngineException("NoCurrentPosition", msg);
}
// Try to determine the socket to start with using the usual socket search strategy
if (ref != null)
{
Node currentNode = currentSocket.getNode();
String socketName;
int index = ref.indexOf(ModelQualifier.OBJECT_DELIMITER_CHAR);
if (index >= 0)
{
// "Node.Socket"
String nodeName = ref.substring (0, index);
socketName = ref.substring(index + 1);
currentNode = currentSocket.getProcess().getNodeByName(nodeName);
if (currentNode == null)
{
String msg = LogUtil.error(getClass(), "Initial node $0 not found (position reference: $1). [{2}]", nodeName, ref, context);
throw new ModelException("NodeNotFound", msg);
}
if (! (currentNode instanceof InitialNode))
{
String msg = LogUtil.error(getClass(), "Node $0 is not an initial node (position reference: $1). [{2}]", currentNode.getQualifier(), ref, context);
throw new ModelException("NoInitialNode", msg);
}
}
else if (index == 0)
{
// ".Socket"
socketName = ref.substring(1);
}
else
{
// "Socket"
socketName = ref;
}
startSocket = currentNode.getSocketByName(socketName);
if (startSocket == null)
{
if (mustExist)
{
String msg = LogUtil.error(getClass(), "Exit socket $0 not found. [{1}]", socketName, context);
throw new EngineException("NoExitSocket", msg);
}
}
}
else
{
// Resuming at an entry socket of a wait state node would lead to an endless loop.
if (currentSocket.isExitSocket())
{
startSocket = currentSocket;
}
else
{
startSocket = currentSocket.getNode().getDefaultExitSocket();
}
}
if (startSocket != null && ! mustExist)
{
if (! startSocket.hasControlLinks())
{
// Accept connected sockets only when looking for an optional socket
startSocket = null;
}
}