Search in sources :

Example 1 with NullValueProvider

use of org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider in project camunda-bpm-platform by camunda.

the class BpmnParse method parseCallableElementProvider.

protected CallableElementParameter parseCallableElementProvider(Element parameterElement) {
    CallableElementParameter parameter = new CallableElementParameter();
    String variables = parameterElement.attribute("variables");
    if (ALL.equals(variables)) {
        parameter.setAllVariables(true);
    } else {
        boolean strictValidation = !Context.getProcessEngineConfiguration().getDisableStrictCallActivityValidation();
        ParameterValueProvider sourceValueProvider = new NullValueProvider();
        String source = parameterElement.attribute("source");
        if (source != null) {
            if (!source.isEmpty()) {
                sourceValueProvider = new ConstantValueProvider(source);
            } else {
                if (strictValidation) {
                    addError("Empty attribute 'source' when passing variables", parameterElement);
                } else {
                    source = null;
                }
            }
        }
        if (source == null) {
            source = parameterElement.attribute("sourceExpression");
            if (source != null) {
                if (!source.isEmpty()) {
                    Expression expression = expressionManager.createExpression(source);
                    sourceValueProvider = new ElValueProvider(expression);
                } else if (strictValidation) {
                    addError("Empty attribute 'sourceExpression' when passing variables", parameterElement);
                }
            }
        }
        if (strictValidation && source == null) {
            addError("Missing parameter 'source' or 'sourceExpression' when passing variables", parameterElement);
        }
        parameter.setSourceValueProvider(sourceValueProvider);
        String target = parameterElement.attribute("target");
        if ((strictValidation || source != null && !source.isEmpty()) && target == null) {
            addError("Missing attribute 'target' when attribute 'source' or 'sourceExpression' is set", parameterElement);
        } else if (strictValidation && target != null && target.isEmpty()) {
            addError("Empty attribute 'target' when attribute 'source' or 'sourceExpression' is set", parameterElement);
        }
        parameter.setTarget(target);
    }
    return parameter;
}
Also used : ParameterValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider) NullValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider) ConstantValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ConstantValueProvider)

Example 2 with NullValueProvider

use of org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider in project camunda-bpm-platform by camunda.

the class BpmnParseUtil method parseParamValueProvider.

/**
 * @throws BpmnParseException if the parameter is invalid
 */
protected static ParameterValueProvider parseParamValueProvider(Element parameterElement) {
    // LIST
    if ("list".equals(parameterElement.getTagName())) {
        List<ParameterValueProvider> providerList = new ArrayList<ParameterValueProvider>();
        for (Element element : parameterElement.elements()) {
            // parse nested provider
            providerList.add(parseParamValueProvider(element));
        }
        return new ListValueProvider(providerList);
    }
    // MAP
    if ("map".equals(parameterElement.getTagName())) {
        TreeMap<ParameterValueProvider, ParameterValueProvider> providerMap = new TreeMap<ParameterValueProvider, ParameterValueProvider>();
        for (Element entryElement : parameterElement.elements("entry")) {
            // entry must provide key
            String keyAttribute = entryElement.attribute("key");
            if (keyAttribute == null || keyAttribute.isEmpty()) {
                throw new BpmnParseException("Missing attribute 'key' for 'entry' element", entryElement);
            }
            // parse nested provider
            providerMap.put(new ElValueProvider(getExpressionManager().createExpression(keyAttribute)), parseNestedParamValueProvider(entryElement));
        }
        return new MapValueProvider(providerMap);
    }
    // SCRIPT
    if ("script".equals(parameterElement.getTagName())) {
        ExecutableScript executableScript = parseCamundaScript(parameterElement);
        if (executableScript != null) {
            return new ScriptValueProvider(executableScript);
        } else {
            return new NullValueProvider();
        }
    }
    String textContent = parameterElement.getText().trim();
    if (!textContent.isEmpty()) {
        // EL
        return new ElValueProvider(getExpressionManager().createExpression(textContent));
    } else {
        // NULL value
        return new NullValueProvider();
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ArrayList(java.util.ArrayList) ElValueProvider(org.camunda.bpm.engine.impl.el.ElValueProvider) ScriptValueProvider(org.camunda.bpm.engine.impl.scripting.ScriptValueProvider) TreeMap(java.util.TreeMap) MapValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.MapValueProvider) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) ParameterValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider) ListValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ListValueProvider) NullValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript)

Aggregations

NullValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider)2 ParameterValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider)2 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)1 ConstantValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ConstantValueProvider)1 ListValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ListValueProvider)1 MapValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.MapValueProvider)1 ElValueProvider (org.camunda.bpm.engine.impl.el.ElValueProvider)1 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)1 ScriptValueProvider (org.camunda.bpm.engine.impl.scripting.ScriptValueProvider)1 Element (org.camunda.bpm.engine.impl.util.xml.Element)1