Package org.jbpm.workflow.core.node

Examples of org.jbpm.workflow.core.node.Split


    }
    private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
        for ( int i = 0; i < nodes.length; i++ ) {
            if ( nodes[i] instanceof Split ) {
                Split split = (Split) nodes[i];
                if ( split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR ) {
                    for ( Connection connection : split.getDefaultOutgoingConnections() ) {
                        Constraint constraint = split.getConstraint( connection );
                        if ( "rule".equals( constraint.getType() ) ) {
                            builder.append( createSplitRule( process,
                                                             connection,
                                                             split.getConstraint( connection ).getConstraint() ) );
                        }
                    }
                }
            } else if ( nodes[i] instanceof MilestoneNode ) {
                MilestoneNode milestone = (MilestoneNode) nodes[i];
View Full Code Here


            if (bendpoints != null) {
                xmlDump.append("g:bendpoints=\"" + bendpoints + "\" ");
            }
        }
        if (connection.getFrom() instanceof Split) {
          Split split = (Split) connection.getFrom();
          if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
            Constraint constraint = split.getConstraint(connection);
            if (constraint == null) {
                xmlDump.append(">" + EOL +
              "      <conditionExpression xsi:type=\"tFormalExpression\" />");
            } else {
                    if (constraint.getName() != null && constraint.getName().trim().length() > 0) {
View Full Code Here

public class EventBasedGatewayHandler extends AbstractNodeHandler {
   
    protected Node createNode(Attributes attrs) {
        final String type = attrs.getValue("gatewayDirection");
        if ("Diverging".equals(type)) {
          Split split = new Split();
          split.setType(Split.TYPE_XAND);
          split.setMetaData("EventBased", "true");
          return split;
        } else {
          throw new IllegalArgumentException(
          "Unknown gateway direction: " + type);
        }
View Full Code Here

        if ("Converging".equals(type)) {
          Join join = new Join();
          join.setType(Join.TYPE_UNDEFINED);
          return join;
        } else if ("Diverging".equals(type)) {
          Split split = new Split();
          split.setType(Split.TYPE_UNDEFINED);
          return split;
        } else {
          throw new IllegalArgumentException(
          "Unknown gateway direction: " + type);
        }
View Full Code Here

  public Class generateNodeFor() {
        return Split.class;
    }

  public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    Split split = (Split) node;
    switch (split.getType()) {
      case Split.TYPE_AND:
        writeNode("parallelGateway", node, xmlDump, metaDataType);
        break;
      case Split.TYPE_XOR:
        writeNode("exclusiveGateway", node, xmlDump, metaDataType);
        for (Map.Entry<ConnectionRef, Constraint> entry: split.getConstraints().entrySet()) {
          if (entry.getValue().isDefault()) {
            xmlDump.append("default=\"" +
              XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" +
              XmlBPMNProcessDumper.getUniqueNodeId(node.getNodeContainer().getNode(entry.getKey().getNodeId())) +
              "\" ");
            break;
          }
        }
        break;
      case Split.TYPE_OR:
                writeNode("inclusiveGateway", node, xmlDump, metaDataType);
        for (Map.Entry<ConnectionRef, Constraint> entry: split.getConstraints().entrySet()) {
          if (entry.getValue().isDefault()) {
            xmlDump.append("default=\"" +
              XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" +
              XmlBPMNProcessDumper.getUniqueNodeId(node.getNodeContainer().getNode(entry.getKey().getNodeId())) +
              "\" ");
View Full Code Here

    public SplitFactory(RuleFlowNodeContainerFactory nodeContainerFactory, NodeContainer nodeContainer, long id) {
        super(nodeContainerFactory, nodeContainer, id);
    }

    protected Node createNode() {
        return new Split();
    }
View Full Code Here

                  for (Timer timer: ruleSetNode.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                  }
                }
            } else if (node instanceof Split) {
                final Split split = (Split) node;
                if (split.getType() == Split.TYPE_UNDEFINED) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] has no type."));
                }
                if (split.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (split.getDefaultOutgoingConnections().size() < 2) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] does not have more than one outgoing connection: " + split.getOutgoingConnections().size() + "."));
                }
                if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR ) {
                    for ( final Iterator<Connection> it = split.getDefaultOutgoingConnections().iterator(); it.hasNext(); ) {
                        final Connection connection = it.next();
                        if (split.getConstraint(connection) == null && !split.getConstraint(connection).isDefault() && (split.getConstraint(connection).getConstraint() == null || split.getConstraint(connection).getConstraint().trim().length() == 0)) {
                            errors.add(new ProcessValidationErrorImpl(process,
                                "Split node '" + node.getName() + "' [" + node.getId() + "] does not have a constraint for " + connection.toString() + "."));
                        }
                    }
                }
View Full Code Here

    public void internalTrigger(final NodeInstance from, String type) {
        if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
            throw new IllegalArgumentException(
                "A Split only accepts default incoming connections!");
        }
        final Split split = getSplit();
        // TODO make different strategies for each type
        switch ( split.getType() ) {
            case Split.TYPE_AND :
                triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, true);
                break;
            case Split.TYPE_XOR :
                List<Connection> outgoing = split.getDefaultOutgoingConnections();
                int priority = Integer.MAX_VALUE;
                Connection selected = null;
                for ( final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint( connection );
                    if ( constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
                        try {
                          if ( constraint.evaluate( this,
                                                      connection,
                                                      constraint ) ) {
                            selected = connection;
                            priority = constraint.getPriority();
                          }
                        } catch (RuntimeException e) {
                          throw new RuntimeException(
                          "Exception when trying to evaluate constraint "
                              + constraint.getName() + " in split "
                              + split.getName(), e);
                        }
                    }
                }
                ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                if ( selected == null ) {
                  for ( final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                        final Connection connection = (Connection) iterator.next();
                        ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint( connection );
                        if ( constraint.isDefault() ) {
                            selected = connection;
                            break;
                        }
                    }
                }
                if ( selected == null ) {
                  throw new IllegalArgumentException( "XOR split could not find at least one valid outgoing connection for split " + getSplit().getName() );
                }
                triggerConnection(selected);
                break;
            case Split.TYPE_OR :
              ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                outgoing = split.getDefaultOutgoingConnections();
                boolean found = false;
                List<Connection> outgoingCopy = new ArrayList<Connection>(outgoing);
                while (!outgoingCopy.isEmpty()) {
                    priority = Integer.MAX_VALUE;
                    Connection selectedConnection = null;
                    ConstraintEvaluator selectedConstraint = null;
                    for ( final Iterator<Connection> iterator = outgoingCopy.iterator(); iterator.hasNext(); ) {
                        final Connection connection = (Connection) iterator.next();
                        ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint( connection );
   
                        if ( constraint != null 
                                && constraint.getPriority() < priority
                                && !constraint.isDefault() ) {
                            priority = constraint.getPriority();
                            selectedConnection = connection;
                            selectedConstraint = constraint;
                        }
                    }
                    if (selectedConstraint == null) {
                      break;
                    }
                    if (selectedConstraint.evaluate( this,
                                                     selectedConnection,
                                                     selectedConstraint ) ) {
                        triggerConnection(selectedConnection);
                        found = true;
                    }
                    outgoingCopy.remove(selectedConnection);
                }
                if ( !found ) {
                  for ( final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                        final Connection connection = (Connection) iterator.next();
                        ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint( connection );
                        if ( constraint.isDefault() ) {
                          triggerConnection(connection);
                          found = true;
                            break;
                        }
                    }
                }
                if ( !found ) {
                    throw new IllegalArgumentException( "OR split could not find at least one valid outgoing connection for split " + getSplit().getName() );
                }               
                break;
            case Split.TYPE_XAND :
              ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                Node node = getNode();
                List<Connection> connections = null;
                if (node != null) {
                  connections = node.getOutgoingConnections(type);
                }
                if (connections == null || connections.isEmpty()) {
                  ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer())
                    .nodeInstanceCompleted(this, type);
                } else {
                  ExclusiveGroupInstance groupInstance = new ExclusiveGroupInstance();
                org.drools.runtime.process.NodeInstanceContainer parent = getNodeInstanceContainer();
                  if (parent instanceof ContextInstanceContainer) {
                    ((ContextInstanceContainer) parent).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, groupInstance);
                  } else {
                    throw new IllegalArgumentException(
                    "An Exclusive AND is only possible if the parent is a context instance container");
                  }
                  Map<NodeInstance, String> nodeInstances = new HashMap<NodeInstance, String>();
                  for (Connection connection: connections) {
                    nodeInstances.put(
                      ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer())
                          .getNodeInstance(connection.getTo()),
                      connection.getToType());
                  }
                  for (NodeInstance nodeInstance: nodeInstances.keySet()) {
                    groupInstance.addNodeInstance(nodeInstance);
                  }
                  for (Map.Entry<NodeInstance, String> entry: nodeInstances.entrySet()) {
                    // stop if this process instance has been aborted / completed
                    if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
                      return;
                    }
                    boolean hidden = false;
                    if (getNode().getMetaData().get("hidden") != null) {
                      hidden = true;
                    }
                    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
                    if (!hidden) {
                      ((InternalProcessRuntime) kruntime.getProcessRuntime())
                        .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
                    }
                      ((org.jbpm.workflow.instance.NodeInstance) entry.getKey())
                      .trigger(this, entry.getValue());
                      if (!hidden) {
                        ((InternalProcessRuntime) kruntime.getProcessRuntime())
                          .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
                      }
                  }
                }
                break;
            default :
                throw new IllegalArgumentException( "Illegal split type " + split.getType() );
        }
    }
View Full Code Here

        log.debug( "Processing " + process.getId() );
        result = new HashMap<String, String[]>();
        StartNode start = process.getStart();
        Node target = start.getTo().getTo();
        if ( target instanceof Split ) {
            Split split = (Split) target;
            for ( Connection connection : split.getDefaultOutgoingConnections() ) {
                Constraint constraint = split.getConstraint( connection );
                if ( constraint != null ) {
                    System.out.println( "Found constraint to node " + connection.getTo().getName() + " [" + connection.getTo().getId() + "]: " + constraint.getConstraint() );
                    result.put( XmlBPMNProcessDumper.getUniqueNodeId( connection.getTo() ),
                                new String[]{connection.getTo().getName(), constraint.getConstraint()} );
                }
View Full Code Here

        } else {
            log.debug( "Processing " + process.getId() );
            StartNode start = process.getStart();
            Node target = start.getTo().getTo();
            if ( target instanceof Split ) {
                Split split = (Split) target;
                for ( Connection connection : split.getDefaultOutgoingConnections() ) {
                    String s = constraints.get( XmlBPMNProcessDumper.getUniqueNodeId( connection.getTo() ) );
                    if ( s != null ) {
                        System.out.println( "Found constraint to node " + connection.getTo().getName() + ": " + s );
                        Constraint constraint = split.getConstraint( connection );
                        if ( constraint == null ) {
                            constraint = new ConstraintImpl();
                            split.setConstraint( connection,
                                                 constraint );
                        }
                        constraint.setConstraint( s );
                    }
                }
View Full Code Here

TOP

Related Classes of org.jbpm.workflow.core.node.Split

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.