use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class MVELActionBuilder method buildAction.
protected void buildAction(final PackageBuildContext context, final DroolsAction action, final ActionDescr actionDescr, final ContextResolver contextResolver, final MVELDialect dialect, final MVELAnalysisResult analysis, final String text, Map<String, Class<?>> variables) throws Exception {
Set<String> variableNames = analysis.getNotBoundedIdentifiers();
if (contextResolver != null) {
for (String variableName : variableNames) {
if (analysis.getMvelVariables().keySet().contains(variableName) || variableName.equals("kcontext") || variableName.equals("context")) {
continue;
}
VariableScope variableScope = (VariableScope) contextResolver.resolveContext(VariableScope.VARIABLE_SCOPE, variableName);
if (variableScope == null) {
context.getErrors().add(new DescrBuildError(context.getParentDescr(), actionDescr, null, "Could not find variable '" + variableName + "' " + "for action '" + actionDescr.getText() + "'"));
} else {
variables.put(variableName, context.getDialect().getTypeResolver().resolveType(variableScope.findVariable(variableName).getType().getStringType()));
}
}
}
MVELCompilationUnit unit = dialect.getMVELCompilationUnit(text, analysis, null, null, variables, context, "context", org.kie.api.runtime.process.ProcessContext.class, false, MVELCompilationUnit.Scope.EXPRESSION);
MVELAction expr = new MVELAction(unit, context.getDialect().getId());
action.setMetaData("Action", expr);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData(dialect.getId());
data.addCompileable(action, expr);
expr.compile(data);
collectTypes("MVELDialect", analysis, (ProcessBuildContext) context);
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class MVELReturnValueEvaluatorBuilder method buildReturnValueEvaluator.
public void buildReturnValueEvaluator(final PackageBuildContext context, final ReturnValueConstraintEvaluator constraintNode, final ReturnValueDescr descr, final ContextResolver contextResolver, final MVELDialect dialect, final MVELAnalysisResult analysis, final String text, Map<String, Class<?>> variables) throws Exception {
Set<String> variableNames = analysis.getNotBoundedIdentifiers();
if (contextResolver != null) {
for (String variableName : variableNames) {
if (analysis.getMvelVariables().keySet().contains(variableName) || variableName.equals("kcontext") || variableName.equals("context")) {
continue;
}
VariableScope variableScope = (VariableScope) contextResolver.resolveContext(VariableScope.VARIABLE_SCOPE, variableName);
if (variableScope == null) {
context.getErrors().add(new DescrBuildError(context.getParentDescr(), descr, null, "Could not find variable '" + variableName + "' for action '" + descr.getText() + "'"));
} else {
variables.put(variableName, context.getDialect().getTypeResolver().resolveType(variableScope.findVariable(variableName).getType().getStringType()));
}
}
}
MVELCompilationUnit unit = dialect.getMVELCompilationUnit(text, analysis, null, null, variables, context, "context", org.kie.api.runtime.process.ProcessContext.class, false, MVELCompilationUnit.Scope.EXPRESSION);
// MVELReturnValueExpression expr = new MVELReturnValueExpression( unit, context.getDialect().getId() );
MVELReturnValueEvaluator expr = new MVELReturnValueEvaluator(unit, dialect.getId());
// expr.setVariableNames(variableNames);
constraintNode.setEvaluator(expr);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData(dialect.getId());
data.addCompileable(constraintNode, expr);
expr.compile(data);
collectTypes("MVELReturnValue", analysis, (ProcessBuildContext) context);
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class AdHocSubProcessHandler method createNode.
protected Node createNode(Attributes attrs) {
DynamicNode result = new DynamicNode();
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 CompositeContextNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
CompositeContextNode compositeNode = (CompositeContextNode) node;
String nodeType = "subProcess";
if (node.getMetaData().get("Transaction") != null) {
nodeType = "transaction";
}
writeNode(nodeType, compositeNode, xmlDump, metaDataType);
if (compositeNode instanceof EventSubProcessNode) {
xmlDump.append(" triggeredByEvent=\"true\" ");
}
Object isForCompensationObject = compositeNode.getMetaData("isForCompensation");
if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
xmlDump.append("isForCompensation=\"true\" ");
}
xmlDump.append(">" + EOL);
writeExtensionElements(compositeNode, xmlDump);
// variables
VariableScope variableScope = (VariableScope) compositeNode.getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null && !variableScope.getVariables().isEmpty()) {
xmlDump.append(" <!-- variables -->" + EOL);
for (Variable variable : variableScope.getVariables()) {
xmlDump.append(" <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
if (variable.getType() != null) {
xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(compositeNode) + "-" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "Item\"");
}
// TODO: value
xmlDump.append("/>" + EOL);
}
}
// nodes
List<Node> subNodes = getSubNodes(compositeNode);
XmlBPMNProcessDumper.INSTANCE.visitNodes(subNodes, xmlDump, metaDataType);
// connections
visitConnectionsAndAssociations(compositeNode, xmlDump, metaDataType);
endNode(nodeType, xmlDump);
}
use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.
the class VariableHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
ContextContainer contextContainer = (ContextContainer) parser.getParent();
final String name = attrs.getValue("name");
emptyAttributeCheck(localName, "name", name, parser);
VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
Variable variable = new Variable();
if (variableScope != null) {
variable.setName(name);
List<Variable> variables = variableScope.getVariables();
if (variables == null) {
variables = new ArrayList<Variable>();
variableScope.setVariables(variables);
}
variables.add(variable);
} else {
throw new SAXParseException("Could not find default variable scope.", parser.getLocator());
}
return variable;
}
Aggregations