Search in sources :

Example 6 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class CallActivityHandler method end.

@SuppressWarnings("unchecked")
@Override
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            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 orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // remove output collection data output of for each to avoid problems when running in variable strict mode
            if (orignalNode instanceof SubProcessNode) {
                ((SubProcessNode) orignalNode).adjustOutMapping(forEachNode.getOutputCollectionExpression());
            }
            Map<String, String> dataInputs = (Map<String, String>) orignalNode.getMetaData().remove("DataInputs");
            Map<String, String> dataOutputs = (Map<String, String>) orignalNode.getMetaData().remove("DataOutputs");
            orignalNode.setMetaData("MICollectionOutput", dataOutputs.get(((ForEachNode) node).getMetaData("MICollectionOutput")));
            orignalNode.setMetaData("MICollectionInput", dataInputs.get(((ForEachNode) node).getMetaData("MICollectionInput")));
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : Element(org.w3c.dom.Element) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) Node(org.jbpm.workflow.core.Node) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class IntermediateThrowEventHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    ActionNode node = (ActionNode) 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 ActionNode
            handleSignalNode(node, element, uri, localName, parser);
            break;
        } else if ("messageEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleMessageNode(node, element, uri, localName, parser);
            break;
        } else if ("escalationEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleEscalationNode(node, element, uri, localName, parser);
            break;
        } else if ("compensateEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleThrowCompensationEventNode(node, element, uri, localName, parser);
            break;
        } else if ("linkEventDefinition".equals(nodeName)) {
            ThrowLinkNode linkNode = new ThrowLinkNode();
            linkNode.setId(node.getId());
            handleLinkNode(element, linkNode, xmlNode, parser);
            NodeContainer nodeContainer = (NodeContainer) parser.getParent();
            nodeContainer.addNode(linkNode);
            ((ProcessBuildData) parser.getData()).addNode(node);
            // we break the while and stop the execution of this method.
            return linkNode;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // none event definition
    if (node.getAction() == null) {
        node.setAction(new DroolsConsequenceAction("mvel", ""));
        node.setMetaData("NodeType", "IntermediateThrowEvent-None");
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    return node;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) ThrowLinkNode(org.jbpm.workflow.core.node.ThrowLinkNode)

Example 8 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class IntermediateThrowEventHandler method handleEscalationNode.

@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode);
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                String faultName = escalation.getEscalationCode();
                String variable = (String) actionNode.getMetaData("MappingVariable");
                actionNode.setAction(new DroolsConsequenceAction("java", "org.jbpm.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.jbpm.process.instance.context.exception.ExceptionScopeInstance) ((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.jbpm.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"" + faultName + "\");" + EOL + "if (scopeInstance != null) {" + EOL + " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + "  tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + "  .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + "  scopeInstance.handleException(\"" + faultName + "\", tVariable);" + EOL + "} else {" + EOL + "    ((org.jbpm.process.instance.ProcessInstance) kcontext.getProcessInstance()).setState(org.jbpm.process.instance.ProcessInstance.STATE_ABORTED);" + EOL + "}"));
            } else {
                throw new IllegalArgumentException("General escalation is not yet supported");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Escalation(org.jbpm.bpmn2.core.Escalation) ActionNode(org.jbpm.workflow.core.node.ActionNode) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 9 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class MessageHandler method start.

@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 itemRef = attrs.getValue("itemRef");
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    if (itemDefinitions == null) {
        throw new IllegalArgumentException("No item definitions found");
    }
    ItemDefinition itemDefinition = itemDefinitions.get(itemRef);
    if (itemDefinition == null) {
        throw new IllegalArgumentException("Could not find itemDefinition " + itemRef);
    }
    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
    if (messages == null) {
        messages = new HashMap<String, Message>();
        buildData.setMetaData("Messages", messages);
    }
    Message message = new Message(id);
    message.setType(itemDefinition.getStructureRef());
    messages.put(id, message);
    return message;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class DefinitionsHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Element(org.w3c.dom.Element) Definitions(org.jbpm.bpmn2.core.Definitions) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) Map(java.util.Map) Interface(org.jbpm.bpmn2.core.Interface)

Aggregations

ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)28 Map (java.util.Map)12 Element (org.w3c.dom.Element)11 Node (org.jbpm.workflow.core.Node)8 NodeContainer (org.jbpm.workflow.core.NodeContainer)8 HashMap (java.util.HashMap)7 List (java.util.List)7 ArrayList (java.util.ArrayList)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)4 Error (org.jbpm.bpmn2.core.Error)3 Escalation (org.jbpm.bpmn2.core.Escalation)3 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)3 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)3 Message (org.jbpm.bpmn2.core.Message)2