Example usage for org.springframework.expression Expression setValue

List of usage examples for org.springframework.expression Expression setValue

Introduction

In this page you can find the example usage for org.springframework.expression Expression setValue.

Prototype

void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException;

Source Link

Document

Set this expression in the provided context to the value provided.

Usage

From source file:com.google.code.activetemplates.impl.CompileContext.java

public void setExpressionValue(String expression, Object value) {
    Expression expr = expressionParser.parseExpression(expression);
    expr.setValue(getEvaluationContext(), value);
}

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

/**
  * {@inheritDoc}/*www  .  j a va  2s . c  om*/
  */
public void evaluateAndSet(Object target, Object value) {
    Expression expression = getParsedExpression();
    StandardEvaluationContext context = m_context;

    context.setRootObject(target);
    try {
        expression.setValue(context, value);
    } catch (EvaluationException e) {
        throw new RuntimeException(e);
    }
}

From source file:it.geosolutions.opensdi2.workflow.transform.spel.SpelTransformer.java

@Override
public DESTTYPE transform(SOURCETYPE source) throws IllegalArgumentException {

    //create the output object
    DESTTYPE output = null;//  w w w . j  a  va 2  s  .c o m
    if (outputObject == null && outputPreBuilder != null) {
        output = outputPreBuilder.build(rules);
    } else if (outputPreBuilder != null) {
        output = outputPreBuilder.build(outputObject, rules);
    } else if (outputObject != null) {
        output = outputObject;
    } else {
        throw new IllegalArgumentException("no outputObject or outPrebuilder provided");
    }

    //create evaluation Context
    StandardEvaluationContext inputEvaluationContext = new StandardEvaluationContext(source);
    StandardEvaluationContext outputevaluationContext = new StandardEvaluationContext(output);
    //set property accessors for input and output
    inputEvaluationContext.setPropertyAccessors(inputaccessors);
    outputevaluationContext.setPropertyAccessors(outputaccessors);
    if (rules != null) {
        Set<String> attributes = rules.keySet();

        //parse rules to create output
        for (String attribute : attributes) {
            String expression = rules.get(attribute);
            //create expressions for in and out
            Expression conversionExpression = expressionParser.parseExpression(expression);
            Expression outputAttribute = expressionParser.parseExpression(attribute);
            //evaluate input value
            Object value = conversionExpression.getValue(inputEvaluationContext); //TODO create a second evaulationContext for output
            //set the attribute value using the output context
            outputAttribute.setValue(outputevaluationContext, value);
        }
    }
    return output;

}