use of org.jbpm.workflow.core.Node 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;
}
use of org.jbpm.workflow.core.Node 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;
}
use of org.jbpm.workflow.core.Node 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;
}
use of org.jbpm.workflow.core.Node in project jbpm by kiegroup.
the class EndNodeInstanceTest method testEndNode.
@Test
public void testEndNode() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
MockNode mockNode = new MockNode();
MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), factory);
WorkflowProcessImpl process = new WorkflowProcessImpl();
Node endNode = new EndNode();
endNode.setId(1);
endNode.setName("end node");
mockNode.setId(2);
new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
process.addNode(mockNode);
process.addNode(endNode);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setState(ProcessInstance.STATE_ACTIVE);
processInstance.setProcess(process);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
mockNodeInstance.triggerCompleted();
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.workflow.core.Node in project jbpm by kiegroup.
the class CompensationTest method findNode.
private Node findNode(RuleFlowProcess process, String nodeName) {
Node found = null;
Queue<org.kie.api.definition.process.Node> nodes = new LinkedList<org.kie.api.definition.process.Node>();
nodes.addAll(Arrays.asList(process.getNodes()));
while (!nodes.isEmpty()) {
org.kie.api.definition.process.Node node = nodes.poll();
if (node.getName().equals(nodeName)) {
found = (Node) node;
}
if (node instanceof NodeContainer) {
nodes.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
}
}
assertNotNull("Could not find node (" + nodeName + ").", found);
return found;
}
Aggregations