use of org.jbpm.bpmn2.core.Definitions in project jbpm by kiegroup.
the class DataTest method testDataStore.
@Test
public void testDataStore() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2");
ksession = createKnowledgeSession(kbase);
ProcessInstance processInstance = ksession.startProcess("Evaluation");
Definitions def = (Definitions) processInstance.getProcess().getMetaData().get("Definitions");
assertNotNull(def.getDataStores());
assertTrue(def.getDataStores().size() == 1);
DataStore dataStore = def.getDataStores().get(0);
assertEquals("employee", dataStore.getId());
assertEquals("employeeStore", dataStore.getName());
assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName());
}
use of org.jbpm.bpmn2.core.Definitions in project jbpm by kiegroup.
the class SubProcessHandler method handleForEachNode.
@SuppressWarnings("unchecked")
protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, boolean isAsync) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
ForEachNode forEachNode = (ForEachNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("ioSpecification".equals(nodeName)) {
readIoSpecification(xmlNode, dataInputs, dataOutputs);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, inputAssociation);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, outputAssociation);
} else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
}
xmlNode = xmlNode.getNextSibling();
}
handleScript(forEachNode, element, "onEntry");
handleScript(forEachNode, element, "onExit");
List<SequenceFlow> connections = (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS);
ProcessHandler.linkConnections(forEachNode, connections);
ProcessHandler.linkBoundaryEvents(forEachNode);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) forEachNode.getMetaData(ProcessHandler.ASSOCIATIONS);
ProcessHandler.linkAssociations((Definitions) forEachNode.getMetaData("Definitions"), forEachNode, associations);
applyAsync(node, isAsync);
}
use of org.jbpm.bpmn2.core.Definitions in project jbpm by kiegroup.
the class SubProcessHandler method handleCompositeContextNode.
@SuppressWarnings("unchecked")
protected void handleCompositeContextNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
CompositeContextNode compositeNode = (CompositeContextNode) node;
List<SequenceFlow> connections = (List<SequenceFlow>) compositeNode.getMetaData(ProcessHandler.CONNECTIONS);
handleScript(compositeNode, element, "onEntry");
handleScript(compositeNode, element, "onExit");
List<IntermediateLink> throwLinks = (List<IntermediateLink>) compositeNode.getMetaData(ProcessHandler.LINKS);
ProcessHandler.linkIntermediateLinks(compositeNode, throwLinks);
ProcessHandler.linkConnections(compositeNode, connections);
ProcessHandler.linkBoundaryEvents(compositeNode);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) compositeNode.getMetaData(ProcessHandler.ASSOCIATIONS);
ProcessHandler.linkAssociations((Definitions) compositeNode.getMetaData("Definitions"), compositeNode, associations);
// TODO: do we fully support interruping ESP's?
/**
* for( org.kie.api.definition.process.Node subNode : compositeNode.getNodes() ) {
* if( subNode instanceof StartNode ) {
* if( ! ((StartNode) subNode).isInterrupting() ) {
* throw new IllegalArgumentException("Non-interrupting event subprocesses are not yet fully supported." );
* }
* }
* }
*/
}
use of org.jbpm.bpmn2.core.Definitions in project jbpm by kiegroup.
the class ProcessHandler method linkAssociations.
public static void linkAssociations(Definitions definitions, NodeContainer nodeContainer, List<Association> associations) {
if (associations != null) {
for (Association association : associations) {
String sourceRef = association.getSourceRef();
Object source = null;
try {
source = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, sourceRef, "Could not find source [" + sourceRef + "] for association " + association.getId() + "]");
} catch (IllegalArgumentException e) {
// source not found
}
String targetRef = association.getTargetRef();
Object target = null;
try {
target = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, targetRef, "Could not find target [" + targetRef + "] for association [" + association.getId() + "]");
} catch (IllegalArgumentException e) {
// target not found
}
if (source == null || target == null) {
// TODO: ignoring this association for now
} else if (target instanceof DataStore || source instanceof DataStore) {
// TODO: ignoring data store associations for now
} else if (source instanceof EventNode) {
EventNode sourceNode = (EventNode) source;
Node targetNode = (Node) target;
checkBoundaryEventCompensationHandler(association, sourceNode, targetNode);
// make sure IsForCompensation is set to true on target
NodeImpl targetNodeImpl = (NodeImpl) target;
String isForCompensation = "isForCompensation";
Object compensationObject = targetNodeImpl.getMetaData(isForCompensation);
if (compensationObject == null) {
targetNodeImpl.setMetaData(isForCompensation, true);
logger.warn("Setting {} attribute to true for node {}", isForCompensation, targetRef);
} else if (!Boolean.parseBoolean(compensationObject.toString())) {
throw new IllegalArgumentException(isForCompensation + " attribute [" + compensationObject + "] should be true for Compensation Activity [" + targetRef + "]");
}
// put Compensation Handler in CompensationHandlerNode
NodeContainer sourceParent = sourceNode.getNodeContainer();
NodeContainer targetParent = targetNode.getNodeContainer();
if (!sourceParent.equals(targetParent)) {
throw new IllegalArgumentException("Compensation Associations may not cross (sub-)process boundaries,");
}
// connect boundary event to compensation activity
ConnectionImpl connection = new ConnectionImpl(sourceNode, NodeImpl.CONNECTION_DEFAULT_TYPE, targetNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
connection.setMetaData("UniqueId", null);
connection.setMetaData("hidden", true);
connection.setMetaData("association", true);
// Compensation use cases:
// - boundary event --associated-> activity
// - implicit sub process compensation handler + recursive?
/**
* BPMN2 spec, p.442:
* "A Compensation Event Sub-process becomes enabled when its parent Activity transitions into state
* Completed. At that time, a snapshot of the data associated with the parent Acitivity is taken and kept for
* later usage by the Compensation Event Sub-Process."
*/
}
}
}
}
use of org.jbpm.bpmn2.core.Definitions 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;
}
Aggregations