public void accept()

in jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DefaultAssignmentProducer.java [48:102]


    public void accept(String target, Object value) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, target);
        if (variableScopeInstance == null && nodeInstance != null) {
            nodeInstance.setVariable(target, value);
            return;
        }

        // proper information about the type
        Variable varDef = variableScopeInstance.getVariableScope().findVariable(target);
        DataType dataType = varDef.getType();

        // undefined or null we don't need to compute anything
        if (value == null || dataType instanceof UndefinedDataType) {
            variableScopeInstance.setVariable(nodeInstance, target, value);
            return;
        }

        // we try to convert with the converter
        // only if there is a TypeConverter registered for the data type
        if (value instanceof String) {
            value = dataType.readValue((String) value);
        }

        // the dataType is already the type
        if (dataType.verifyDataType(value)) {
            variableScopeInstance.setVariable(nodeInstance, target, value);
            return;
        }

        // if we use some strict variable this should not be needed but test require this.
        // this is some heuristics to try to transform stuff into the target type
        if (value != null && !(value instanceof Throwable)) {
            try {
                if (!dataType.getStringType().endsWith("java.lang.Object") && dataType instanceof ObjectDataType) {
                    value = typeTransformer.transform(value, ((ObjectDataType) dataType).getObjectClass());

                } else if (!(dataType instanceof StringDataType) && !(dataType instanceof ObjectDataType)) {
                    value = typeTransformer.transform(value, dataType.getStringType());
                }
            } catch (Exception e) {
                logger.debug("error trying to transform value {}", value, e);
            }
        }

        if (value != null && !dataType.verifyDataType(value)) {
            if (dataType instanceof StringDataType) {
                // last chance to put proper value
                value = value.toString();
            } else {
                throw new IllegalArgumentException("value " + value + " does not match " + dataType.getStringType());
            }
        }

        variableScopeInstance.setVariable(nodeInstance, target, value);
    }