Search in sources :

Example 11 with NodeContainer

use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.

the class IntermediateCatchEventHandler method end.

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);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) TimerNode(org.jbpm.workflow.core.node.TimerNode) StateNode(org.jbpm.workflow.core.node.StateNode) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.jbpm.workflow.core.Node) StateNode(org.jbpm.workflow.core.node.StateNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) TimerNode(org.jbpm.workflow.core.node.TimerNode)

Example 12 with NodeContainer

use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.

the class IntermediateThrowEventHandler method handleLinkNode.

protected void handleLinkNode(Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
    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();
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    IntermediateLink aLink = new IntermediateLink();
    aLink.setName(name);
    aLink.setUniqueId(id);
    while (null != xmlNode) {
        String nodeName = xmlNode.getNodeName();
        if (LINK_TARGET.equals(nodeName)) {
            String target = xmlNode.getTextContent();
            node.setMetaData(LINK_TARGET, target);
        }
        if (LINK_SOURCE.equals(nodeName)) {
            String source = xmlNode.getTextContent();
            ArrayList<String> sources = (ArrayList<String>) node.getMetaData().get(LINK_SOURCE);
            // if there is no list, create one
            if (null == sources) {
                sources = new ArrayList<String>();
            }
            // to connect nodes.
            aLink.addSource(source);
            // to do the xml dump
            sources.add(source);
            node.setMetaData(LINK_SOURCE, sources);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    aLink.configureThrow();
    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);
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NamedNodeMap(org.w3c.dom.NamedNodeMap) ArrayList(java.util.ArrayList) NodeContainer(org.jbpm.workflow.core.NodeContainer) IntermediateLink(org.jbpm.bpmn2.core.IntermediateLink) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with NodeContainer

use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.

the class AbstractNodeHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final Node node = createNode(attrs);
    String id = attrs.getValue("id");
    node.setMetaData("UniqueId", id);
    final String name = attrs.getValue("name");
    node.setName(name);
    if ("true".equalsIgnoreCase(System.getProperty("jbpm.v5.id.strategy"))) {
        try {
            // remove starting _
            id = id.substring(1);
            // remove ids of parent nodes
            id = id.substring(id.lastIndexOf("-") + 1);
            node.setId(Integer.parseInt(id));
        } catch (NumberFormatException e) {
            // id is not in the expected format, generating a new one
            long newId = 0;
            NodeContainer nodeContainer = (NodeContainer) parser.getParent();
            for (org.kie.api.definition.process.Node n : nodeContainer.getNodes()) {
                if (n.getId() > newId) {
                    newId = n.getId();
                }
            }
            ((org.jbpm.workflow.core.Node) node).setId(++newId);
        }
    } else {
        AtomicInteger idGen = (AtomicInteger) parser.getMetaData().get("idGen");
        node.setId(idGen.getAndIncrement());
    }
    return node;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 14 with NodeContainer

use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.

the class AbstractNodeHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    final Node node = createNode();
    final String id = attrs.getValue("id");
    node.setId(new Long(id));
    final String name = attrs.getValue("name");
    node.setName(name);
    nodeContainer.addNode(node);
    return node;
}
Also used : Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 15 with NodeContainer

use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.

the class ConnectionHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String fromId = attrs.getValue("from");
    emptyAttributeCheck(localName, "from", fromId, parser);
    String toId = attrs.getValue("to");
    emptyAttributeCheck(localName, "to", toId, parser);
    String bendpoints = attrs.getValue("bendpoints");
    String fromType = attrs.getValue("fromType");
    if (fromType == null || fromType.trim().length() == 0) {
        fromType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    String toType = attrs.getValue("toType");
    if (toType == null || toType.trim().length() == 0) {
        toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    Node fromNode = nodeContainer.getNode(new Long(fromId));
    Node toNode = nodeContainer.getNode(new Long(toId));
    if (fromNode == null) {
        throw new SAXParseException("Node '" + fromId + "'cannot be found", parser.getLocator());
    }
    if (toNode == null) {
        throw new SAXParseException("Node '" + toId + "' cannot be found", parser.getLocator());
    }
    ConnectionImpl connection = new ConnectionImpl(fromNode, fromType, toNode, toType);
    connection.setMetaData("bendpoints", bendpoints);
    return connection;
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Node(org.kie.api.definition.process.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Aggregations

NodeContainer (org.jbpm.workflow.core.NodeContainer)17 Node (org.jbpm.workflow.core.Node)9 Element (org.w3c.dom.Element)9 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)8 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)6 ArrayList (java.util.ArrayList)5 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)5 List (java.util.List)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 EndNode (org.jbpm.workflow.core.node.EndNode)3 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)3 IntermediateLink (org.jbpm.bpmn2.core.IntermediateLink)2 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)2 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)2 Node (org.kie.api.definition.process.Node)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1