Package org.openbp.server.handler

Examples of org.openbp.server.handler.HandlerContext


  public HandlerContext executeHandler(final HandlerDefinition handlerDef, final String eventType,
    final TokenContext context, NodeSocket currentSocket, NodeSocket nextSocket)
  {
    if (handlerDef != null && handlerDef.canHandle(eventType))
    {
      HandlerContext hc = new HandlerContext(this, eventType, context);
      if (currentSocket == null)
        currentSocket = context.getCurrentSocket();
      if (currentSocket == null)
      {
        String msg = LogUtil.error(getClass(), "Cannot call handler w/o a current socket. [{0}]", context);
        throw new OpenBPException("HandlerExecutionFailed", msg);
      }
      hc.setCurrentSocket(currentSocket);
      if (nextSocket == null && currentSocket != null)
        nextSocket = currentSocket.getNode().getDefaultExitSocket();
      hc.setNextSocket(nextSocket);

      // Execute the handler
      if (handlerDef.getHandlerClassName() != null)
      {
        Object handlerInstanceObject = handlerDef.obtainHandlerInstance();
        if (! (handlerInstanceObject instanceof Handler))
        {
          String msg = LogUtil.error(getClass(),
            "Handler object class $0 does not implement the handler interface $1. [{2}]", handlerInstanceObject
              .getClass().getName(), Handler.class.getName(), context);
          throw new OpenBPException("HandlerExecutionFailed", msg);
        }

        Handler handlerInstance = (Handler) handlerInstanceObject;
        LogUtil.trace(getClass(), "Executing handler on node $0 (class $1) as {2} handler. [{3}]",
          currentSocket.getNode().getQualifier().toString(), handlerInstance.getClass().getName(), eventType, context);

        // Execute the Java implementation of this handler
        try
        {
          handlerInstance.execute(hc);
        }
        catch (OpenBPException ee)
        {
          // Engine exceptions can be rethrown.
          throw ee;
        }
        catch (Throwable t)
        {
          // Catch any exceptions, so the server won't be confused by errors in handlers
          String msg = LogUtil.error(getClass(), "Error executing handler of $0. [{1}]", currentSocket.getNode()
            .getQualifier().toString(), t);
          throw new OpenBPException("HandlerExecutionFailed", msg, t);
        }
      }
      else if (handlerDef.getScript() != null)
      {
        LogUtil.trace(getClass(), "Executing script on node $0 as {1} handler. [{2}]",
          currentSocket.getNode().getQualifier().toString(), eventType, context);

        // Execute the script associated with this handler
        ScriptEngine scriptEngine = getScriptEngineFactory().obtainScriptEngine(hc.getTokenContext());
        try
        {
          scriptEngine.prepareHandlerExecution(hc);
          String script = handlerDef.getScript();
          scriptEngine.executeScript(script, "handler script", currentSocket.getNode().getQualifier().toString());
View Full Code Here


    JavaActivityItem activity = (JavaActivityItem) mo;

    NodeSocket nextSocket = null;

    TokenContext oldContext = context;
    HandlerContext hc = getEngine().executeHandler(activity.getHandlerDefinition(), HandlerTypes.ACTIVITY, context, context.getCurrentSocket(), nextSocket);
    if (hc != null)
    {
      context = hc.getTokenContext();
      if (context != oldContext)
      {
        // Token context instance has changed due to rollback
        ee.setTokenContext(context);
        return;
      }

      nextSocket = hc.getNextSocket();
      if (nextSocket == null)
      {
        String msg = LogUtil.error(getClass(), "Handler of activity $0 did not provide a a socket to continue with. [{1}]", activity.getQualifier(), context);
        throw new EngineException("MissingNextSocket", msg);
      }
View Full Code Here

          String nodeType = currentNode.getModelObjectSymbolName();
          LogUtil.trace(getClass(), "Executing {0}Node $1. [{2}]", nodeType, currentNode.getQualifier(), context);
        }

        // Execute the NodeEntry handler, if any
        HandlerContext hc = engine.executeHandler(currentNode.getEventHandlerDefinition(), HandlerTypes.NODE_ENTRY, context, entrySocket,
          currentNode.getDefaultExitSocket());
        if (hc != null && hc.hasNextSocketChanged())
        {
          // Handler changed the flow of control...
          if (hc.getNextSocket() == null)
            throw new EngineException("MissingNextSocket", "Handler of node  '" + currentNode.getQualifier()
              + "' has set a null next socket.\nThe process cannot be continued.");
          context.setCurrentSocket(hc.getNextSocket());
          return;
        }

        // *** Execute the node ***
        ModelObjectExecutor executor = engine.getModelObjectExecutorMgr().getExecutor(currentNode);
        executor.executeModelObject(currentNode, this);
      }
      else
      {
        // We have an exit socket; Node has been executed already, process is being continued now.
      }

      // *** Handle any lifecycle state requests and perform the transaction handling ***
      handleLifecycleRequest();

      if (context.getLifecycleState() == LifecycleState.RUNNING)
      {
        NodeSocket nextSocket = context.getCurrentSocket();
        if (nextSocket != null)
        {
          // Execute the node exit handler, if any and if not executing an error socket
          if (! nextSocket.getName().equals(CoreConstants.ERROR_SOCKET_NAME))
          {
            HandlerContext hc2 = engine.executeHandler(currentNode.getEventHandlerDefinition(), HandlerTypes.NODE_EXIT, context, entrySocket, nextSocket);
            if (hc2 != null && hc2.hasNextSocketChanged())
            {
              // Handler changed the flow of control...
              nextSocket = hc2.getNextSocket();
              context.setCurrentSocket(nextSocket);
            }
          }

          if (nextSocket != null)
View Full Code Here

    NodeSocket nextSocket = node.getDefaultExitSocket();

    // Activity reference missing, try the node's handler
    TokenContext oldContext = context;
    HandlerContext hc = getEngine().executeHandler(node.getActivityHandlerDefinition(), HandlerTypes.ACTIVITY, context, context.getCurrentSocket(), nextSocket);
    if (hc != null)
    {
      context = hc.getTokenContext();
      if (context != oldContext)
      {
        // Token context instance has changed due to rollback
        ee.setTokenContext(context);
      }

      nextSocket = hc.getNextSocket();
      if (nextSocket == null)
      {
        String msg = LogUtil.error(getClass(), "Handler of node $0 has set a null next socket. [{1}]", node.getQualifier(), context);
        throw new EngineException("MissingNextSocket", msg);
      }
View Full Code Here

TOP

Related Classes of org.openbp.server.handler.HandlerContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.