use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class CompositeNodeHandler method createNode.
protected Node createNode() {
CompositeContextNode result = new CompositeContextNode();
VariableScope variableScope = new VariableScope();
result.addContext(variableScope);
result.setDefaultContext(variableScope);
return result;
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class ActivityTest method testMinimalProcessMetaData.
@Test
public void testMinimalProcessMetaData() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MinimalProcessMetaData.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
final List<String> list3 = new ArrayList<String>();
final List<String> list4 = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.debug("before node");
Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTag");
if (customTag != null) {
list1.add(customTag);
}
String customTag2 = (String) metaData.get("customTag2");
if (customTag2 != null) {
list2.add(customTag2);
}
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
logger.debug("after variable");
VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
if (variableScope == null) {
return;
}
Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagVar");
if (customTag != null) {
list3.add(customTag);
}
}
public void afterProcessStarted(ProcessStartedEvent event) {
logger.debug("after process");
Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagProcess");
if (customTag != null) {
list4.add(customTag);
}
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "krisv");
ProcessInstance processInstance = ksession.startProcess("Minimal", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(3, list1.size());
assertEquals(2, list2.size());
assertEquals(1, list3.size());
assertEquals(1, list4.size());
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class SubProcessHandler method createNode.
protected Node createNode(Attributes attrs) {
CompositeContextNode subProcessNode = new CompositeContextNode();
String eventSubprocessAttribute = attrs.getValue("triggeredByEvent");
if (eventSubprocessAttribute != null && Boolean.parseBoolean(eventSubprocessAttribute)) {
subProcessNode = new EventSubProcessNode();
}
VariableScope variableScope = new VariableScope();
subProcessNode.addContext(variableScope);
subProcessNode.setDefaultContext(variableScope);
String compensation = attrs.getValue("isForCompensation");
if (compensation != null) {
boolean isForCompensation = Boolean.parseBoolean(compensation);
if (isForCompensation) {
subProcessNode.setMetaData("isForCompensation", isForCompensation);
}
}
subProcessNode.setAutoComplete(true);
return subProcessNode;
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class PropertyHandler 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);
final String id = attrs.getValue("id");
final String name = attrs.getValue("name");
final String itemSubjectRef = attrs.getValue("itemSubjectRef");
Object parent = parser.getParent();
if (parent instanceof ContextContainer) {
ContextContainer contextContainer = (ContextContainer) parent;
VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
List variables = variableScope.getVariables();
Variable variable = new Variable();
// if name is given use it as variable name instead of id
if (name != null && name.length() > 0) {
variable.setName(name);
} else {
variable.setName(id);
}
variable.setMetaData("ItemSubjectRef", itemSubjectRef);
variables.add(variable);
((ProcessBuildData) parser.getData()).setMetaData("Variable", variable);
return variable;
}
return new Variable();
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class DataObjectHandler 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);
final String id = attrs.getValue("id");
final String itemSubjectRef = attrs.getValue("itemSubjectRef");
Object parent = parser.getParent();
if (parent instanceof ContextContainer) {
ContextContainer contextContainer = (ContextContainer) parent;
VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
List variables = variableScope.getVariables();
Variable variable = new Variable();
variable.setMetaData("DataObject", "true");
variable.setName(id);
// retrieve type from item definition
DataType dataType = new ObjectDataType();
Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
if (itemDefinitions != null) {
ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
if (itemDefinition != null) {
String structureRef = itemDefinition.getStructureRef();
if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
dataType = new BooleanDataType();
} else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
dataType = new IntegerDataType();
} else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
dataType = new FloatDataType();
} else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
dataType = new StringDataType();
} else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
// use FQCN of Object
dataType = new ObjectDataType("java.lang.Object");
} else {
dataType = new ObjectDataType(structureRef, parser.getClassLoader());
}
}
}
variable.setType(dataType);
variables.add(variable);
return variable;
}
return new Variable();
}
Aggregations