Search in sources :

Example 21 with ProcessBuildData

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

the class ItemDefinitionHandler 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 type = attrs.getValue("structureRef");
    if (type == null || type.trim().length() == 0) {
        type = "java.lang.Object";
    }
    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) buildData.getMetaData("ItemDefinitions");
    if (itemDefinitions == null) {
        itemDefinitions = new HashMap<String, ItemDefinition>();
        buildData.setMetaData("ItemDefinitions", itemDefinitions);
    }
    ItemDefinition itemDefinition = new ItemDefinition(id);
    itemDefinition.setStructureRef(type);
    itemDefinitions.put(id, itemDefinition);
    return itemDefinition;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with ProcessBuildData

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

the class InterfaceHandler 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 name = attrs.getValue("name");
    String implRef = attrs.getValue("implementationRef");
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("Interface name is required attribute");
    }
    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;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with ProcessBuildData

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

the class AbstractNodeHandler method readMultiInstanceLoopCharacteristics.

@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");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            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");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            if (variableName != null && variableName.trim().length() > 0) {
                forEachNode.setOutputVariable(variableName, dataType);
            }
        } else if ("loopDataOutputRef".equals(nodeName)) {
            String outputDataRef = ((Element) subNode).getTextContent();
            if (outputDataRef != null && outputDataRef.trim().length() > 0) {
                String collectionName = outputAssociation.get(outputDataRef);
                if (collectionName == null) {
                    collectionName = dataOutputs.get(outputDataRef);
                }
                forEachNode.setOutputCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionOutput", outputDataRef);
        } else if ("loopDataInputRef".equals(nodeName)) {
            String inputDataRef = ((Element) subNode).getTextContent();
            if (inputDataRef != null && inputDataRef.trim().length() > 0) {
                String collectionName = inputAssociation.get(inputDataRef);
                if (collectionName == null) {
                    collectionName = dataInputs.get(inputDataRef);
                }
                forEachNode.setCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionInput", inputDataRef);
        } else if ("completionCondition".equals(nodeName)) {
            String expression = subNode.getTextContent();
            forEachNode.setCompletionConditionExpression(expression);
        }
        subNode = subNode.getNextSibling();
    }
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with ProcessBuildData

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

the class StartEventHandler method handleNode.

@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to true
    // The spec says that Escalation start events should default to not interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode, startNode);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these elements)
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            type = checkSignalAndConvertToRealSignalNam(parser, type);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
        } 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);
            }
            startNode.setMetaData("MessageType", message.getType());
            addTriggerWithInMappings(startNode, "Message-" + messageRef);
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
        // following event definitions are only for event sub process and will be validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            if (!startNode.isInterrupting()) {
                // BPMN2 spec (p.245-246, (2011-01-03)) implies that
                // - a <startEvent> in an Event Sub-Process
                // - *without* the 'isInterupting' attribute always interrupts (containing process)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
            }
        } 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);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, element, xmlNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Message(org.jbpm.bpmn2.core.Message) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 25 with ProcessBuildData

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

the class SubProcessHandler 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
    boolean found = false;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            Boolean isAsync = Boolean.parseBoolean((String) node.getMetaData().get("customAsync"));
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            forEachNode.setName(node.getName());
            forEachNode.setAutoComplete(((CompositeContextNode) node).isAutoComplete());
            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, isAsync);
            found = true;
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (!found) {
        handleCompositeContextNode(node, element, uri, localName, parser);
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Element(org.w3c.dom.Element) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

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