Ejemplo n.º 1
0
 private void postProcessNodes(NodeContainer container) {
   for (Node node : container.getNodes()) {
     if (node instanceof StateNode) {
       StateNode stateNode = (StateNode) node;
       String condition = (String) stateNode.getMetaData().get("Condition");
       Constraint constraint = new ConstraintImpl();
       constraint.setConstraint(condition);
       constraint.setType("rule");
       for (org.drools.definition.process.Connection connection :
           stateNode.getDefaultOutgoingConnections()) {
         stateNode.setConstraint(connection, constraint);
       }
     } else if (node instanceof NodeContainer) {
       postProcessNodes((NodeContainer) node);
     }
   }
 }
Ejemplo n.º 2
0
 public static void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) {
   if (connections != null) {
     for (SequenceFlow connection : connections) {
       String sourceRef = connection.getSourceRef();
       String targetRef = connection.getTargetRef();
       Node source = null;
       Node target = null;
       try {
         // remove starting _
         sourceRef = sourceRef.substring(1);
         // remove ids of parent nodes
         sourceRef = sourceRef.substring(sourceRef.lastIndexOf("-") + 1);
         source = nodeContainer.getNode(new Integer(sourceRef));
       } catch (NumberFormatException e) {
         // try looking for a node with same "UniqueId" (in metadata)
         for (Node node : nodeContainer.getNodes()) {
           if (connection.getSourceRef().equals(node.getMetaData().get("UniqueId"))) {
             source = node;
             break;
           }
         }
         if (source == null) {
           throw new IllegalArgumentException(
               "Could not find source node for connection:" + connection.getSourceRef());
         }
       }
       try {
         // remove starting _
         targetRef = targetRef.substring(1);
         // remove ids of parent nodes
         targetRef = targetRef.substring(targetRef.lastIndexOf("-") + 1);
         target = nodeContainer.getNode(new Integer(targetRef));
       } catch (NumberFormatException e) {
         // try looking for a node with same "UniqueId" (in metadata)
         for (Node node : nodeContainer.getNodes()) {
           if (connection.getTargetRef().equals(node.getMetaData().get("UniqueId"))) {
             target = node;
             break;
           }
         }
         if (target == null) {
           throw new IllegalArgumentException(
               "Could not find target node for connection:" + connection.getTargetRef());
         }
       }
       Connection result =
           new ConnectionImpl(
               source, NodeImpl.CONNECTION_DEFAULT_TYPE,
               target, NodeImpl.CONNECTION_DEFAULT_TYPE);
       result.setMetaData("bendpoints", connection.getBendpoints());
       if (source instanceof Split) {
         Split split = (Split) source;
         Constraint constraint = new ConstraintImpl();
         String defaultConnection = (String) split.getMetaData("Default");
         if (defaultConnection != null && defaultConnection.equals(connection.getId())) {
           constraint.setDefault(true);
         }
         if (connection.getName() != null) {
           constraint.setName(connection.getName());
         } else {
           constraint.setName("");
         }
         if (connection.getType() != null) {
           constraint.setType(connection.getType());
         } else {
           constraint.setType("code");
         }
         if (connection.getLanguage() != null) {
           constraint.setDialect(connection.getLanguage());
         }
         if (connection.getExpression() != null) {
           constraint.setConstraint(connection.getExpression());
         }
         split.addConstraint(
             new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
       }
     }
   }
 }