use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.
the class DefinitionsHandler method postProcessInterfaces.
private void postProcessInterfaces(NodeContainer nodeContainer, List<Interface> interfaces) {
for (Node node : nodeContainer.getNodes()) {
if (node instanceof NodeContainer) {
postProcessInterfaces((NodeContainer) node, interfaces);
}
if (node instanceof WorkItemNode && "Service Task".equals(((WorkItemNode) node).getMetaData("Type"))) {
WorkItemNode workItemNode = (WorkItemNode) node;
if (interfaces == null) {
throw new IllegalArgumentException("No interfaces found");
}
String operationRef = (String) workItemNode.getMetaData("OperationRef");
String implementation = (String) workItemNode.getMetaData("Implementation");
Operation operation = null;
for (Interface i : interfaces) {
operation = i.getOperation(operationRef);
if (operation != null) {
break;
}
}
if (operation == null) {
throw new IllegalArgumentException("Could not find operation " + operationRef);
}
// avoid overriding parameters set by data input associations
if (workItemNode.getWork().getParameter("Interface") == null) {
workItemNode.getWork().setParameter("Interface", operation.getInterface().getName());
}
if (workItemNode.getWork().getParameter("Operation") == null) {
workItemNode.getWork().setParameter("Operation", operation.getName());
}
if (workItemNode.getWork().getParameter("ParameterType") == null) {
workItemNode.getWork().setParameter("ParameterType", operation.getMessage().getType());
}
// parameters to support web service invocation
if (implementation != null) {
workItemNode.getWork().setParameter("interfaceImplementationRef", operation.getInterface().getImplementationRef());
workItemNode.getWork().setParameter("operationImplementationRef", operation.getImplementationRef());
workItemNode.getWork().setParameter("implementation", implementation);
}
}
}
}
use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.
the class AbstractNodeHandler 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();
handleNode(node, element, uri, localName, parser);
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.
the class AssociationHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
Association association = new Association();
association.setId(attrs.getValue("id"));
association.setSourceRef(attrs.getValue("sourceRef"));
association.setTargetRef(attrs.getValue("targetRef"));
String direction = attrs.getValue("associationDirection");
if (direction != null) {
boolean acceptableDirection = false;
direction = direction.toLowerCase();
String[] possibleDirections = { "none", "one", "both" };
for (String acceptable : possibleDirections) {
if (acceptable.equals(direction)) {
acceptableDirection = true;
break;
}
}
if (!acceptableDirection) {
throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
}
}
association.setDirection(direction);
/**
* BPMN2 spec, p. 66:
* "At this point, BPMN provides three standard Artifacts: Associations,
* Groups, and Text Annotations.
* ...
* When an Artifact is defined it is contained within a Collaboration
* or a FlowElementsContainer (a Process or Choreography)."
*
* (In other words: associations must be defined within a process, not outside)
*/
List<Association> associations = null;
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
if (nodeContainer instanceof Process) {
RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
if (associations == null) {
associations = new ArrayList<Association>();
process.setMetaData(ASSOCIATIONS, associations);
}
} else if (nodeContainer instanceof CompositeNode) {
CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
if (associations == null) {
associations = new ArrayList<Association>();
compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
}
}
associations.add(association);
return association;
}
use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.
the class BoundaryEventHandler method handleCompensationNode.
protected void handleCompensationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
BoundaryEventNode eventNode = (BoundaryEventNode) parser.getCurrent();
super.handleNode(node, element, uri, localName, parser);
NodeList childs = element.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
if (childs.item(i) instanceof Element) {
Element el = (Element) childs.item(i);
if ("compensateEventDefinition".equalsIgnoreCase(el.getNodeName())) {
String activityRef = el.getAttribute("activityRef");
if (activityRef != null && activityRef.length() > 0) {
logger.warn("activityRef value [" + activityRef + "] on Boundary Event '" + eventNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
}
}
}
}
eventNode.setMetaData("AttachedTo", attachedTo);
eventNode.setAttachedToNodeId(attachedTo);
// 1. Find the parent (sub-)process
NodeContainer parentContainer = (NodeContainer) parser.getParent();
// 2. Add the event filter (never fires, purely for dumping purposes)
EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
eventFilter.setType("Compensation");
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
eventNode.setEventFilters(eventFilters);
eventFilters.add(eventFilter);
// 3. Add compensation scope (with key/id: attachedTo)
ProcessHandler.addCompensationScope((RuleFlowProcess) parser.getParent(RuleFlowProcess.class), eventNode, parentContainer, attachedTo);
}
use of org.jbpm.workflow.core.NodeContainer in project jbpm by kiegroup.
the class EndEventHandler 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
super.handleNode(node, element, uri, localName, parser);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("terminateEventDefinition".equals(nodeName)) {
// reuse already created EndNode
handleTerminateNode(node, element, uri, localName, parser);
break;
} else if ("signalEventDefinition".equals(nodeName)) {
handleSignalNode(node, element, uri, localName, parser);
} else if ("messageEventDefinition".equals(nodeName)) {
handleMessageNode(node, element, uri, localName, parser);
} else if ("errorEventDefinition".equals(nodeName)) {
// create new faultNode
FaultNode faultNode = new FaultNode();
faultNode.setId(node.getId());
faultNode.setName(node.getName());
faultNode.setTerminateParent(true);
faultNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = faultNode;
super.handleNode(node, element, uri, localName, parser);
handleErrorNode(node, element, uri, localName, parser);
break;
} else if ("escalationEventDefinition".equals(nodeName)) {
// create new faultNode
FaultNode faultNode = new FaultNode();
faultNode.setId(node.getId());
faultNode.setName(node.getName());
faultNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = faultNode;
super.handleNode(node, element, uri, localName, parser);
handleEscalationNode(node, element, uri, localName, parser);
break;
} else if ("compensateEventDefinition".equals(nodeName)) {
// reuse already created ActionNode
handleThrowCompensationEventNode(node, element, uri, localName, parser);
break;
}
xmlNode = xmlNode.getNextSibling();
}
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
Aggregations