Example usage for org.springframework.expression.spel.support StandardEvaluationContext setVariables

List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext setVariables

Introduction

In this page you can find the example usage for org.springframework.expression.spel.support StandardEvaluationContext setVariables.

Prototype

public void setVariables(Map<String, Object> variables) 

Source Link

Usage

From source file:org.arrow.model.gateway.impl.ExclusiveGateway.java

@Override
public List<EventMessage> fork(Execution execution, ExecutionService service) {

    ExpressionParser parser = new SpelExpressionParser();

    for (Flow flow : getOutgoingFlows()) {

        // handle multiple outgoing flows
        ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression();

        if (ce == null) {
            continue;
        }//ww  w. j a v a2s . c o  m

        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariables(execution.getVariables());

        Expression expr = parser.parseExpression(ce.getCondition());
        Boolean result = expr.getValue(context, Boolean.class);

        if ((result != null) && (result)) {
            flow.enableRelation(execution);
            break;
        }
    }

    // mark gateway as finished
    execution.setState(State.SUCCESS);
    finish(execution, service);

    return Arrays.asList();
}

From source file:org.arrow.model.gateway.impl.InclusiveGateway.java

/**
 * {@inheritDoc}//from   w  ww. j  a  va 2  s.c  o m
 */
@Override
public List<EventMessage> fork(Execution execution, ExecutionService service) {

    ExpressionParser parser = new SpelExpressionParser();

    for (Flow flow : getOutgoingFlows()) {

        // handle multiple outgoing flows
        ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression();
        notNull(ce, "no condition detected on flow " + flow.getId());

        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariables(execution.getVariables());

        Expression expression = parser.parseExpression(ce.getCondition());
        Boolean result = expression.getValue(context, Boolean.class);

        if ((result != null) && result) {
            flow.enableRelation(execution);
        }
    }

    // mark gateway as finished
    execution.setState(State.SUCCESS);
    finish(execution, service);

    return Arrays.asList();
}

From source file:com.seovic.core.expression.SpelExpression.java

/**
  * {@inheritDoc}/* w ww .j av a2s.c o m*/
  */
public T evaluate(Object target, Map variables) {
    Expression expression = getParsedExpression();
    StandardEvaluationContext context = m_context;

    context.setRootObject(target);
    if (variables != null) {
        context.setVariables(variables);
    }
    try {
        return (T) expression.getValue(context);
    } catch (EvaluationException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.acxio.tools.agia.expression.StandardEvaluationContextFactory.java

@Override
public StandardEvaluationContext createContext(String sName, Object sValue,
        StandardEvaluationContext sContext) {
    StandardEvaluationContext aContext = sContext;
    if (sContext == null) {
        aContext = new StandardEvaluationContext();
        if (commonObjects != null) {
            aContext.setVariables(commonObjects);
        }/*from   ww w .jav a  2s. c  o m*/
        aContext.addPropertyAccessor(new MapAccessor());
    }
    aContext.setVariable(sName, sValue);
    return aContext;
}

From source file:com.googlecode.starflow.core.script.spel.SpelScriptEngine.java

private StandardEvaluationContext getStandardEvaluationContext(ScriptContext scriptContext) {
    StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext(
            scriptContext.getAttribute(ROOT_OBJECT));
    standardEvaluationContext.setVariables(getVariables(scriptContext));
    return standardEvaluationContext;
}

From source file:com.oembedler.moon.graphql.engine.execute.GraphQLAbstractRxExecutionStrategy.java

protected Observable<Double> calculateFieldComplexity(ExecutionContext executionContext,
        GraphQLObjectType parentType, List<Field> fields, Observable<Double> childScore) {
    return childScore.flatMap(aDouble -> {
        Observable<Double> result = Observable.just(aDouble + NODE_SCORE);
        GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType,
                fields.get(0));/*from   w  w  w  . j  a v a2s  .c  om*/
        if (fieldDef != null) {
            GraphQLFieldDefinitionWrapper graphQLFieldDefinitionWrapper = getGraphQLFieldDefinitionWrapper(
                    fieldDef);
            if (graphQLFieldDefinitionWrapper != null) {
                Expression expression = graphQLFieldDefinitionWrapper.getComplexitySpelExpression();
                if (expression != null) {
                    Map<String, Object> argumentValues = valuesResolver.getArgumentValues(
                            fieldDef.getArguments(), fields.get(0).getArguments(),
                            executionContext.getVariables());
                    StandardEvaluationContext context = new StandardEvaluationContext();
                    context.setVariable(GraphQLConstants.EXECUTION_COMPLEXITY_CHILD_SCORE, aDouble);
                    if (argumentValues != null)
                        context.setVariables(argumentValues);
                    result = Observable.just(expression.getValue(context, Double.class));
                }
            }
        }
        return addComplexityCheckObservable(executionContext, result);
    });
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpressionTemplate(java.lang.Object,
 *      java.util.Map, java.lang.String)
 *///from   w  ww .j a v  a  2 s.c  o m
public String evaluateExpressionTemplate(Object contextObject, Map<String, Object> evaluationParameters,
        String expressionTemplate) {
    StandardEvaluationContext context = new StandardEvaluationContext(contextObject);
    context.setVariables(evaluationParameters);
    addCustomFunctions(context);

    ExpressionParser parser = new SpelExpressionParser();

    String result = null;
    try {
        Expression expression = null;
        if (StringUtils.contains(expressionTemplate, UifConstants.EL_PLACEHOLDER_PREFIX)) {
            expression = parser.parseExpression(expressionTemplate, new TemplateParserContext(
                    UifConstants.EL_PLACEHOLDER_PREFIX, UifConstants.EL_PLACEHOLDER_SUFFIX));
        } else {
            expression = parser.parseExpression(expressionTemplate);
        }

        result = expression.getValue(context, String.class);
    } catch (Exception e) {
        LOG.error("Exception evaluating expression: " + expressionTemplate);
        throw new RuntimeException("Exception evaluating expression: " + expressionTemplate, e);
    }

    return result;
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpression(java.lang.Object,
 *      java.util.Map, java.lang.String)
 *//*  www  .  ja  v  a2 s .  c  o  m*/
public Object evaluateExpression(Object contextObject, Map<String, Object> evaluationParameters,
        String expressionStr) {
    StandardEvaluationContext context = new StandardEvaluationContext(contextObject);
    context.setVariables(evaluationParameters);
    addCustomFunctions(context);

    // if expression contains placeholders remove before evaluating
    if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX)
            && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) {
        expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX);
        expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX);
    }

    ExpressionParser parser = new SpelExpressionParser();
    Object result = null;
    try {
        Expression expression = parser.parseExpression(expressionStr);

        result = expression.getValue(context);
    } catch (Exception e) {
        LOG.error("Exception evaluating expression: " + expressionStr);
        throw new RuntimeException("Exception evaluating expression: " + expressionStr, e);
    }

    return result;
}