Search in sources :

Example 11 with VariableScope

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);
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) MVELAction(org.jbpm.process.instance.impl.MVELAction) MVELCompilationUnit(org.drools.core.base.mvel.MVELCompilationUnit) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 12 with VariableScope

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);
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) MVELReturnValueEvaluator(org.jbpm.process.instance.impl.MVELReturnValueEvaluator) MVELCompilationUnit(org.drools.core.base.mvel.MVELCompilationUnit) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 13 with VariableScope

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;
}
Also used : DynamicNode(org.jbpm.workflow.core.node.DynamicNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 14 with VariableScope

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);
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 15 with VariableScope

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;
}
Also used : ContextContainer(org.jbpm.process.core.ContextContainer) Variable(org.jbpm.process.core.context.variable.Variable) SAXParseException(org.xml.sax.SAXParseException) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Aggregations

VariableScope (org.jbpm.process.core.context.variable.VariableScope)24 Variable (org.jbpm.process.core.context.variable.Variable)11 Map (java.util.Map)7 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)6 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ContextContainer (org.jbpm.process.core.ContextContainer)3 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)3 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)3 Node (org.jbpm.workflow.core.Node)3 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)3 HashSet (java.util.HashSet)2 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)2 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)2 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)2 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)2