Beispiel #1
0
  public Object start(
      final String uri,
      final String localName,
      final Attributes attrs,
      final ExtensibleXmlParser xmlPackageReader)
      throws SAXException {
    xmlPackageReader.startElementBuilder(localName, attrs);

    WorkflowProcessImpl process = (WorkflowProcessImpl) xmlPackageReader.getParent();

    ActionNode actionNode = new ActionNode();

    final String name = attrs.getValue("name");
    emptyAttributeCheck(localName, "name", name, xmlPackageReader);
    actionNode.setName(name);

    final String id = attrs.getValue("id");
    emptyAttributeCheck(localName, "id", name, xmlPackageReader);
    actionNode.setId(new Long(id));

    process.addNode(actionNode);
    ((ProcessBuildData) xmlPackageReader.getData()).addNode(actionNode);

    return actionNode;
  }
Beispiel #2
0
 public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
     throws SAXException {
   final Element element = parser.endElementBuilder();
   Node node = (Node) parser.getCurrent();
   // determine type of event definition, so the correct type of node
   // can be generated
   handleNode(node, element, uri, localName, parser);
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
       // create new timerNode
       ForEachNode forEachNode = new ForEachNode();
       forEachNode.setId(node.getId());
       forEachNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
       node.setMetaData("UniqueId", null);
       node.setMetaData("hidden", true);
       forEachNode.addNode(node);
       forEachNode.linkIncomingConnections(
           NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
       forEachNode.linkOutgoingConnections(
           node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
       node = forEachNode;
       handleForEachNode(node, element, uri, localName, parser);
       break;
     }
     xmlNode = xmlNode.getNextSibling();
   }
   NodeContainer nodeContainer = (NodeContainer) parser.getParent();
   nodeContainer.addNode(node);
   return node;
 }
Beispiel #3
0
  @SuppressWarnings("unchecked")
  public Object start(
      final String uri,
      final String localName,
      final Attributes attrs,
      final ExtensibleXmlParser parser)
      throws SAXException {
    parser.startElementBuilder(localName, attrs);

    String id = attrs.getValue("id");
    String name = attrs.getValue("name");
    String implRef = attrs.getValue("implementationRef");

    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    List<Interface> interfaces = (List<Interface>) buildData.getMetaData("Interfaces");
    if (interfaces == null) {
      interfaces = new ArrayList<Interface>();
      buildData.setMetaData("Interfaces", interfaces);
    }
    Interface i = new Interface(id, name);
    if (implRef != null) {
      i.setImplementationRef(implRef);
    }
    interfaces.add(i);
    return i;
  }
Beispiel #4
0
  @SuppressWarnings("unchecked")
  protected void readMultiInstanceLoopCharacteristics(
      org.w3c.dom.Node xmlNode, ForEachNode forEachNode, ExtensibleXmlParser parser) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    while (subNode != null) {
      String nodeName = subNode.getNodeName();
      if ("inputDataItem".equals(nodeName)) {
        String variableName = ((Element) subNode).getAttribute("id");
        String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
        DataType dataType = null;
        Map<String, ItemDefinition> itemDefinitions =
            (Map<String, ItemDefinition>)
                ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
          ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
          if (itemDefinition != null) {
            dataType = new ObjectDataType(itemDefinition.getStructureRef());
          }
        }
        if (dataType == null) {
          dataType = new ObjectDataType("java.lang.Object");
        }
        if (variableName != null && variableName.trim().length() > 0) {
          forEachNode.setVariable(variableName, dataType);
        }
      } else if ("outputDataItem".equals(nodeName)) {
        String variableName = ((Element) subNode).getAttribute("id");
        String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
        DataType dataType = null;
        Map<String, ItemDefinition> itemDefinitions =
            (Map<String, ItemDefinition>)
                ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
          ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
          if (itemDefinition != null) {
            dataType = new ObjectDataType(itemDefinition.getStructureRef());
          }
        }
        if (dataType == null) {
          dataType = new ObjectDataType("java.lang.Object");
        }
        if (variableName != null && variableName.trim().length() > 0) {
          forEachNode.setOutputVariable(variableName, dataType);
        }
      } else if ("loopDataOutputRef".equals(nodeName)) {

        String outputDataRef = ((Element) subNode).getTextContent();

        String outputDataName = dataOutputs.get(outputDataRef);
        if (outputDataName != null && outputDataName.trim().length() > 0) {
          forEachNode.setOutputCollectionExpression(outputDataName);
        }
      }
      subNode = subNode.getNextSibling();
    }
  }
Beispiel #5
0
 public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
     throws SAXException {
   final Element element = parser.endElementBuilder();
   ValueObject valueObject = (ValueObject) parser.getParent();
   String text = ((Text) element.getChildNodes().item(0)).getWholeText();
   if (text != null) {
     text = text.trim();
     if ("".equals(text)) {
       text = null;
     }
   }
   Object value = restoreValue(text, valueObject.getType(), parser);
   valueObject.setValue(value);
   return null;
 }
 public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
     throws SAXException {
   final Element element = parser.endElementBuilder();
   Node node = (Node) parser.getCurrent();
   // determine type of event definition, so the correct type of node
   // can be generated
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("signalEventDefinition".equals(nodeName)) {
       // reuse already created EventNode
       handleSignalNode(node, element, uri, localName, parser);
       break;
     } else if ("messageEventDefinition".equals(nodeName)) {
       // reuse already created EventNode
       handleMessageNode(node, element, uri, localName, parser);
       break;
     } else if ("timerEventDefinition".equals(nodeName)) {
       // create new timerNode
       TimerNode timerNode = new TimerNode();
       timerNode.setId(node.getId());
       timerNode.setName(node.getName());
       timerNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
       node = timerNode;
       handleTimerNode(node, element, uri, localName, parser);
       break;
     } else if ("conditionalEventDefinition".equals(nodeName)) {
       // create new stateNode
       StateNode stateNode = new StateNode();
       stateNode.setId(node.getId());
       stateNode.setName(node.getName());
       stateNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
       node = stateNode;
       handleStateNode(node, element, uri, localName, parser);
       break;
     } else if ("linkEventDefinition".equals(nodeName)) {
       CatchLinkNode linkNode = new CatchLinkNode();
       linkNode.setId(node.getId());
       node = linkNode;
       handleLinkNode(element, node, xmlNode, parser);
       break;
     }
     xmlNode = xmlNode.getNextSibling();
   }
   NodeContainer nodeContainer = (NodeContainer) parser.getParent();
   nodeContainer.addNode(node);
   return node;
 }
Beispiel #7
0
  public Object end(
      final String uri, final String localName, final ExtensibleXmlParser xmlPackageReader)
      throws SAXException {
    final Element element = xmlPackageReader.endElementBuilder();

    ActionNode actionNode = (ActionNode) xmlPackageReader.getCurrent();

    String text = ((org.w3c.dom.Text) element.getChildNodes().item(0)).getWholeText();

    DroolsConsequenceAction actionText =
        new DroolsConsequenceAction("mvel", "list.add(\"" + text + "\")");

    actionNode.setAction(actionText);

    return actionNode;
  }
Beispiel #8
0
 public Object start(
     final String uri,
     final String localName,
     final Attributes attrs,
     final ExtensibleXmlParser parser)
     throws SAXException {
   parser.startElementBuilder(localName, attrs);
   return null;
 }
Beispiel #9
0
  public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
      throws SAXException {
    final Element element = parser.endElementBuilder();

    final FromDescr fromDescr = (FromDescr) parser.getCurrent();

    Object parent = parser.getParent();

    final PatternDescr patternDescr = (PatternDescr) parent;

    final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent(1);

    if (element.getElementsByTagName("expression").getLength() > 0) {
      patternDescr.setSource(fromDescr);
    }

    return fromDescr;
  }
Beispiel #10
0
 public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
     throws SAXException {
   final Element element = parser.endElementBuilder();
   Node node = (Node) parser.getCurrent();
   // determine type of event definition, so the correct type of node
   // can be generated
   boolean found = false;
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
       // create new timerNode
       ForEachNode forEachNode = new ForEachNode();
       forEachNode.setId(node.getId());
       forEachNode.setName(node.getName());
       for (org.kie.api.definition.process.Node subNode :
           ((CompositeContextNode) node).getNodes()) {
         forEachNode.addNode(subNode);
       }
       forEachNode.setMetaData("UniqueId", ((CompositeContextNode) node).getMetaData("UniqueId"));
       forEachNode.setMetaData(
           ProcessHandler.CONNECTIONS,
           ((CompositeContextNode) node).getMetaData(ProcessHandler.CONNECTIONS));
       VariableScope v =
           (VariableScope)
               ((CompositeContextNode) node).getDefaultContext(VariableScope.VARIABLE_SCOPE);
       ((VariableScope)
               ((CompositeContextNode) forEachNode.internalGetNode(2))
                   .getDefaultContext(VariableScope.VARIABLE_SCOPE))
           .setVariables(v.getVariables());
       node = forEachNode;
       handleForEachNode(node, element, uri, localName, parser);
       found = true;
       break;
     }
     xmlNode = xmlNode.getNextSibling();
   }
   if (!found) {
     handleCompositeContextNode(node, element, uri, localName, parser);
   }
   NodeContainer nodeContainer = (NodeContainer) parser.getParent();
   nodeContainer.addNode(node);
   return node;
 }
Beispiel #11
0
  public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
      throws SAXException {

    final Element element = parser.endElementBuilder();
    final AccumulateDescr accumulateDescr = (AccumulateDescr) parser.getCurrent();

    final Object parent = parser.getParent();

    if (parent.getClass().getName().equals(FromDescr.class.getName())) {
      final PatternDescr result = (PatternDescr) parser.getParent(1);
      result.setSource(accumulateDescr);

    } else if (parent instanceof ConditionalElementDescr) {
      final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
      parentDescr.addDescr(accumulateDescr);
    }

    return accumulateDescr;
  }
Beispiel #12
0
 public Object start(
     final String uri,
     final String localName,
     final Attributes attrs,
     final ExtensibleXmlParser parser)
     throws SAXException {
   parser.startElementBuilder(localName, attrs);
   final FromDescr fromDesctiptor = new FromDescr();
   return fromDesctiptor;
 }
Beispiel #13
0
 private Object restoreValue(String text, DataType dataType, ExtensibleXmlParser parser)
     throws SAXException {
   if (text == null || "".equals(text)) {
     return null;
   }
   if (dataType == null) {
     throw new SAXParseException("Null datatype", parser.getLocator());
   }
   return dataType.readValue(text);
 }
  protected void handleLinkNode(
      Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();

    node.setName(element.getAttribute("name"));

    NamedNodeMap linkAttr = xmlLinkNode.getAttributes();
    String name = linkAttr.getNamedItem("name").getNodeValue();
    String id = element.getAttribute("id");

    node.setMetaData("UniqueId", id);
    node.setMetaData(LINK_NAME, name);

    org.w3c.dom.Node xmlNode = xmlLinkNode.getFirstChild();

    IntermediateLink aLink = new IntermediateLink();
    aLink.setName(name);
    aLink.setUniqueId(id);

    while (null != xmlNode) {
      String nodeName = xmlNode.getNodeName();
      if ("target".equals(nodeName)) {
        String target = xmlNode.getTextContent();
        node.setMetaData("target", target);
        aLink.setTarget(target);
      }
      if ("source".equals(nodeName)) {
        String source = xmlNode.getTextContent();
        node.setMetaData("source", source);
        aLink.addSource(source);
      }
      xmlNode = xmlNode.getNextSibling();
    }

    if (nodeContainer instanceof RuleFlowProcess) {
      RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
      List<IntermediateLink> links =
          (List<IntermediateLink>) process.getMetaData().get(ProcessHandler.LINKS);
      if (null == links) {
        links = new ArrayList<IntermediateLink>();
      }
      links.add(aLink);
      process.setMetaData(ProcessHandler.LINKS, links);
    } else if (nodeContainer instanceof CompositeNode) {
      CompositeNode subprocess = (CompositeNode) nodeContainer;
      List<IntermediateLink> links =
          (List<IntermediateLink>) subprocess.getMetaData().get(ProcessHandler.LINKS);
      if (null == links) {
        links = new ArrayList<IntermediateLink>();
      }
      links.add(aLink);
      subprocess.setMetaData(ProcessHandler.LINKS, links);
    }
  }
Beispiel #15
0
  public Object start(
      final String uri,
      final String localName,
      final Attributes attrs,
      final ExtensibleXmlParser parser)
      throws SAXException {

    parser.startElementBuilder(localName, attrs);
    final AccumulateDescr accumulateDesrc = new AccumulateDescr();
    return accumulateDesrc;
  }
Beispiel #16
0
 public Object start(
     final String uri,
     final String localName,
     final Attributes attrs,
     final ExtensibleXmlParser parser)
     throws SAXException {
   parser.startElementBuilder(localName, attrs);
   Mappable mappable = (Mappable) parser.getParent();
   final String type = attrs.getValue("type");
   emptyAttributeCheck(localName, "type", type, parser);
   final String fromName = attrs.getValue("from");
   emptyAttributeCheck(localName, "from", fromName, parser);
   final String toName = attrs.getValue("to");
   emptyAttributeCheck(localName, "to", toName, parser);
   if ("in".equals(type)) {
     mappable.addInMapping(toName, fromName);
   } else if ("out".equals(type)) {
     mappable.addOutMapping(fromName, toName);
   } else {
     throw new SAXParseException("Unknown mapping type " + type, parser.getLocator());
   }
   return null;
 }
 @SuppressWarnings("unchecked")
 protected void handleMessageNode(
     final Node node,
     final Element element,
     final String uri,
     final String localName,
     final ExtensibleXmlParser parser)
     throws SAXException {
   super.handleNode(node, element, uri, localName, parser);
   EventNode eventNode = (EventNode) node;
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("dataOutputAssociation".equals(nodeName)) {
       readDataOutputAssociation(xmlNode, eventNode);
     } else if ("messageEventDefinition".equals(nodeName)) {
       String messageRef = ((Element) xmlNode).getAttribute("messageRef");
       Map<String, Message> messages =
           (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
       if (messages == null) {
         throw new IllegalArgumentException("No messages found");
       }
       Message message = messages.get(messageRef);
       if (message == null) {
         throw new IllegalArgumentException("Could not find message " + messageRef);
       }
       eventNode.setMetaData("MessageType", message.getType());
       List<EventFilter> eventFilters = new ArrayList<EventFilter>();
       EventTypeFilter eventFilter = new EventTypeFilter();
       eventFilter.setType("Message-" + messageRef);
       eventFilters.add(eventFilter);
       eventNode.setEventFilters(eventFilters);
     }
     xmlNode = xmlNode.getNextSibling();
   }
 }
Beispiel #18
0
 public Object end(final String uri, final String localName, final ExtensibleXmlParser parser)
     throws SAXException {
   parser.endElementBuilder();
   return parser.getCurrent();
 }