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

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

Introduction

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

Prototype

public void setRootObject(@Nullable Object rootObject) 

Source Link

Usage

From source file:org.craftercms.commons.ebus.config.EBusBeanAutoConfiguration.java

private <T> T expression(String selector, Object bean) {
    if (selector == null) {
        return null;
    }/*from   w w  w. ja  v a  2 s.c  o  m*/

    StandardEvaluationContext evalCtx = new StandardEvaluationContext();
    evalCtx.setRootObject(bean);
    evalCtx.setBeanResolver(beanResolver);

    return (T) expressionParser.parseExpression(selector).getValue(evalCtx);
}

From source file:com.googlecode.fascinator.portal.security.FascinatorWebSecurityExpressionHandler.java

@Override
public EvaluationContext createEvaluationContext(Authentication authentication, FilterInvocation fi) {
    StandardEvaluationContext ctx = new StandardEvaluationContext();
    SecurityExpressionRoot root;/*from  w  w w.j av a 2 s  .  c  o  m*/
    root = new FascinatorWebSecurityExpressionRoot(authentication, fi, storage, accessControl);
    root.setTrustResolver(trustResolver);
    root.setRoleHierarchy(roleHierarchy);

    ctx.setRootObject(root);

    return ctx;
}

From source file:org.mule.module.spel.EvaluationContextFactory.java

public EvaluationContext create(MuleMessage message) {
    Assert.notNull(message, "Message cannot be null");

    StandardEvaluationContext simpleContext = new StandardEvaluationContext();

    simpleContext.setVariable(CONTEXT_VAR_NAME, muleContext);
    simpleContext.setVariable(REGISTRY_VAR_NAME, muleRegistry);
    simpleContext.setVariable(MESSAGE_VAR_NAME, message);
    simpleContext.setVariable(ORIGINAL_PAYLOAD_VAR_NAME, message.getOriginalPayload());
    simpleContext.setVariable(PAYLOAD_VAR_NAME, message.getPayload());
    simpleContext.setVariable(ID_VAR_NAME, message.getUniqueId());

    /* systemProperties and systemEnvironment are spring beans already registered
       in the mule registry, and thus available as @systemEnvironment and @systemProperties.
       But this is collateral, so to properly to mimic Spring framework behavior both beans will
       be added as variables. //www  .  j av  a  2s. c o m
    */

    if (muleRegistry != null) {
        simpleContext.setVariable(SYSTEM_PROPERTIES_VAR_NAME,
                muleRegistry.get(ConfigurableApplicationContext.SYSTEM_PROPERTIES_BEAN_NAME));
        simpleContext.setVariable(ENVIRONMENT_VAR_NAME,
                muleRegistry.get(ConfigurableApplicationContext.SYSTEM_ENVIRONMENT_BEAN_NAME));
    }

    simpleContext.setRootObject(message.getPayload());

    simpleContext.setBeanResolver(beanResolver);
    return simpleContext;
}

From source file:org.metaeffekt.dcc.commons.mapping.AbstractPropertyExpression.java

@SuppressWarnings("unchecked")
protected <T> T evaluateExpression(String originalExpression, String value, Class<T> type) {
    final ExpressionParser parser = new SpelExpressionParser();

    try {//  w  w  w.  j  a va2s  .c om
        final StandardEvaluationContext context = new StandardEvaluationContext();
        context.setRootObject(propertiesHolder);
        context.addPropertyAccessor(new EnvironmentAccessor());
        context.setVariable(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, STANDARD_ENVIRONMENT);
        context.setVariable(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, STANDARD_ENVIRONMENT);

        final Expression expression = parser.parseExpression(value, PARSER_CONTEXT);

        return expression.getValue(context, type);
    } catch (ParseException | EvaluationException e) {
        LOG.debug(String.format("Failed to evaluate expression %s, and with replaced properties %s",
                originalExpression, value), e);
    }

    if (type == String.class) {
        return (T) value;
    }

    return null;
}