Package org.jbpm.graph.def

Examples of org.jbpm.graph.def.Transition


   * case that the completion of this task instances triggers a signal on the token. If this task
   * leads to a signal on the token, the given transition name will be used in the signal. If this
   * task completion does not trigger execution to move on, the transitionName is ignored.
   */
  public void end(String transitionName) {
    Transition leavingTransition = null;

    if (task != null) {
      Node node = task.getTaskNode();
      if (node == null) {
        node = (Node) task.getParent();
View Full Code Here


   * creates the transition object and configures it by the read attributes
   * @return the created <code>org.jbpm.graph.def.Transition</code> object (useful, if you want to override this method to read additional configuration properties)
   */
  public Transition resolveTransitionDestination(Element transitionElement, Node node)
  {
    Transition transition = new Transition();
    transition.setProcessDefinition(processDefinition);

    transition.setName(transitionElement.attributeValue("name"));
    transition.setDescription(transitionElement.elementTextTrim("description"));

    String condition = transitionElement.attributeValue("condition");
    if (condition == null)
    {
      Element conditionElement = transitionElement.element("condition");
      if (conditionElement != null)
      {
        condition = conditionElement.getTextTrim();
        // for backwards compatibility
        if ((condition == null) || (condition.length() == 0))
        {
          condition = conditionElement.attributeValue("expression");
        }
      }
    }
    transition.setCondition(condition);

    // add the transition to the node
    node.addLeavingTransition(transition);

    // set destinationNode of the transition
View Full Code Here

      decisionDelegation.read(decisionHandlerElement, jpdlReader);
    }
  }

  public void execute(ExecutionContext executionContext) {
    Transition transition = null;

    // set context class loader correctly for delegation class
    // (https://jira.jboss.org/jira/browse/JBPM-1448)
    Thread currentThread = Thread.currentThread();
    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    currentThread.setContextClassLoader(JbpmConfiguration.getProcessClassLoader(executionContext.getProcessDefinition()));

    try {
      if (decisionDelegation != null) {
        DecisionHandler decisionHandler = (DecisionHandler) decisionDelegation.getInstance();
        if (decisionHandler == null)
          decisionHandler = (DecisionHandler) decisionDelegation.instantiate();

        String transitionName = decisionHandler.decide(executionContext);
        transition = getLeavingTransition(transitionName);
        if (transition == null) {
          throw new JbpmException("decision '"
              + name
              + "' selected non existing transition '"
              + transitionName
              + "'");
        }
      }
      else if (decisionExpression != null) {
        Object result = JbpmExpressionEvaluator.evaluate(decisionExpression, executionContext);
        if (result == null) {
          throw new JbpmException("decision expression '" + decisionExpression + "' returned null");
        }
        String transitionName = result.toString();
        transition = getLeavingTransition(transitionName);
        if (transition == null) {
          throw new JbpmException("decision '"
              + name
              + "' selected non existing transition '"
              + transitionName
              + "'");
        }
      }
      else if (decisionConditions != null && !decisionConditions.isEmpty()) {
        // backwards compatible mode based on separate DecisionCondition's
        for (DecisionCondition decisionCondition : decisionConditions) {
          Object result = JbpmExpressionEvaluator.evaluate(decisionCondition.getExpression(),
              executionContext);
          if (Boolean.TRUE.equals(result)) {
            String transitionName = decisionCondition.getTransitionName();
            transition = getLeavingTransition(transitionName);
            if (transition != null) break;
          }
        }
      }
      else {
        // new mode based on conditions in the transition itself
        for (Transition candidate : leavingTransitions) {
          String conditionExpression = candidate.getCondition();
          if (conditionExpression != null) {
            Object result = JbpmExpressionEvaluator.evaluate(conditionExpression, executionContext);
            if (Boolean.TRUE.equals(result)) {
              transition = candidate;
              break;
            }
          }
        }
      }
    }
    catch (Exception exception) {
      raiseException(exception, executionContext);
      if (!equals(executionContext.getNode())) {
        return;
      }
    }
    finally {
      currentThread.setContextClassLoader(contextClassLoader);
    }

    if (transition == null) {
      transition = getDefaultLeavingTransition();

      if (transition == null)
        throw new JbpmException("decision cannot select transition: " + this);

      log.debug("decision did not select transition, taking default " + transition);
    }

    // since the decision node evaluates condition expressions, the condition of the
    // taken transition will always be met. therefore we can safely turn off
    // the standard condition enforcement in the transitions after a decision node.
    transition.removeConditionEnforcement();

    log.debug("decision '" + name + "' is taking " + transition);
    executionContext.leaveNode(transition);
  }
View Full Code Here

  public void signal(String transitionName)
  {
    if (node == null)
      throw new JbpmException("token '" + this + "' can't be signalled cause it is currently not positioned in a node");
   
    Transition leavingTransition = node.getLeavingTransition(transitionName);
   
    if (leavingTransition == null)
    {
      // Fall back to the name of the target node
      for (Transition auxTrans : node.getLeavingTransitions())
View Full Code Here

    for ( int i = 0; i < transitions.length; i++ ) {
      String[] parsedTransition = cutTransitionText( transitions[i] );
      Node from = pd.getNode( parsedTransition[0] );
      Node to = pd.getNode( parsedTransition[2] );
      Transition t = new Transition( parsedTransition[1] );
      from.addLeavingTransition(t);
      to.addArrivingTransition(t);
    }
  }
View Full Code Here

      "</process-definition>"
    );
   
    Node node = processDefinition.getNode("a");
    assertEquals( 1, node.getLeavingTransitionsMap().size() );
    Transition transition = node.getDefaultLeavingTransition();
    Event event = transition.getEvent(Event.EVENTTYPE_TRANSITION);
    Action action = (Action) event.getActions().iterator().next();
    Delegation instantiatableDelegate = action.getActionDelegation();
    assertEquals("org.foo.Burps", instantiatableDelegate.getClassName());
  }
View Full Code Here

      "  <action name='scratch' class='com.itch.Scratch' />" +
      "</process-definition>"
    );
   
    Node node = processDefinition.getNode("a");
    Transition transition = node.getDefaultLeavingTransition();
    Event event = transition.getEvent(Event.EVENTTYPE_TRANSITION);
    Action transitionAction = (Action) event.getActions().iterator().next();
   
    Action processAction = processDefinition.getAction("scratch");
    assertEquals("scratch", processAction.getName());
    assertSame(processAction, transitionAction.getReferencedAction());
View Full Code Here

      "    <transition to='b' />" +
      "  </state>" +
      "  <state name='b' />" +
      "</process-definition>"
    );
    Transition transition = processDefinition.getNode("a").getDefaultLeavingTransition();
   
    Delegation instantiatableDelegate = new Delegation();
    instantiatableDelegate.setClassName("com.foo.Fighting");
    transition.addEvent(new Event(Event.EVENTTYPE_TRANSITION)).addAction(new Action(instantiatableDelegate));
    Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/state/transition" );

    assertNotNull(element);
    assertEquals("transition", element.getName());
    assertEquals(1, element.elements("action").size());
View Full Code Here

    assertSame(processDefinition.getNode("t"), token.getNode());

    TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
    TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
   
    Transition messedTransition = processDefinition.getNode("t").getLeavingTransition("messed all over the floor");
    taskInstance.end(messedTransition);
   
    assertSame(processDefinition.getNode("b"), token.getNode());
  }
View Full Code Here

      "</process-definition>"
    );
   
    Node node = processDefinition.getNode("a");
    assertEquals( 1, node.getLeavingTransitionsMap().size() );
    Transition transition = node.getDefaultLeavingTransition();
    Event event = transition.getEvent(Event.EVENTTYPE_TRANSITION);
    Action action = (Action) event.getActions().iterator().next();
    Delegation instantiatableDelegate = action.getActionDelegation();
    assertEquals("org.foo.Burps", instantiatableDelegate.getClassName());
  }
View Full Code Here

TOP

Related Classes of org.jbpm.graph.def.Transition

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.