Example usage for org.springframework.context.expression MapAccessor MapAccessor

List of usage examples for org.springframework.context.expression MapAccessor MapAccessor

Introduction

In this page you can find the example usage for org.springframework.context.expression MapAccessor MapAccessor.

Prototype

MapAccessor

Source Link

Usage

From source file:org.cloudfoundry.identity.app.web.MapWrapper.java

public MapWrapper(Object target) throws Exception {
    this.target = target;
    context = new StandardEvaluationContext();
    context.addPropertyAccessor(new MapAccessor());
    parser = new SpelExpressionParser();
}

From source file:org.springframework.batch.admin.web.JsonWrapper.java

@SuppressWarnings("unchecked")
public JsonWrapper(String content) throws Exception {
    this.content = content;
    try {//from  w w  w .ja v a2s.c  o m
        target = new MappingJsonFactory().createJsonParser(content.replace("\\", "/")).readValueAs(Map.class);
    } catch (JsonParseException e) {
        throw new JsonMappingException("Cannot create wrapper for:\n" + content, e);
    }
    context = new StandardEvaluationContext();
    context.addPropertyAccessor(new MapAccessor());
    parser = new SpelExpressionParser();
}

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 w  w  w .j  a va2s .  com
        aContext.addPropertyAccessor(new MapAccessor());
    }
    aContext.setVariable(sName, sValue);
    return aContext;
}

From source file:cz.jirutka.spring.exhandler.interpolators.SpelMessageInterpolator.java

/**
 * Creates a new instance with {@link StandardEvaluationContext} including
 * {@link org.springframework.expression.spel.support.ReflectivePropertyAccessor ReflectivePropertyAccessor}
 * and {@link MapAccessor}.//w  w  w  .  j a v  a2  s.c om
 */
public SpelMessageInterpolator() {
    StandardEvaluationContext ctx = new StandardEvaluationContext();
    ctx.addPropertyAccessor(new MapAccessor());
    this.evalContext = ctx;
}

From source file:org.develspot.data.orientdb.convert.MappingOrientConverter.java

public MappingOrientConverter(
        MappingContext<? extends OrientPersistentEntity<?>, OrientPersistentProperty> mappingContext) {
    super(new DefaultConversionService());
    Assert.notNull(mappingContext, "MappingContext should not be null!");
    this.mappingContext = mappingContext;
    this.spELContext = new SpELContext(new MapAccessor());
    this.fieldAccessOnly = true;
}

From source file:net.asfun.jangod.interpret.FloorBindings.java

public Object get(String key, int level) {
    checkKey(key);//w ww  .j  a v  a2  s . c  o  m
    Map<String, Object> bindings = getBindings(level);
    try {
        StandardEvaluationContext context = new StandardEvaluationContext();
        context.addPropertyAccessor(new ReflectivePropertyAccessor());
        context.addPropertyAccessor(new MapAccessor());
        context.setRootObject(bindings);
        return parser.parseExpression(key).getValue(context);
    } catch (Exception e) {
        return bindings.get(key);
    }
}

From source file:net.asfun.jangod.base.Context.java

public Object getAttribute(String expression) {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.addPropertyAccessor(new ReflectivePropertyAccessor());
    context.addPropertyAccessor(new BeanFactoryAccessor());
    context.addPropertyAccessor(new MapAccessor());
    Expression parseExpression = null;
    try {/*from www .ja  v  a  2 s  .  c  o m*/
        parseExpression = parser.parseExpression(expression);
    } catch (ParseException e) {
        // ignore parsing problem, might be jangod token
        return null;
    }
    try {
        return parseExpression.getValue(context, sessionBindings);
    } catch (EvaluationException e) {
        // ignore. try global application global bindings
    }
    try {
        return parseExpression.getValue(context, application.globalBindings);
    } catch (EvaluationException e) {
        return null;
    }
}

From source file:org.springjutsu.validation.spel.NamedScopeEvaluationContext.java

/**
 * Creates an empty instance, on which scopes can be registered.
 * By ensuring a @see{MapAccessor} is registered, we allow the
 * hack that is the @see{ContextScope} class to work.
 *//*  w  w w  . ja v a  2 s  .  c o m*/
public NamedScopeEvaluationContext() {
    contextScope = new ContextScope();
    this.setRootObject(contextScope);
    this.addPropertyAccessor(new MapAccessor());
}

From source file:org.jasig.portlet.widget.service.SpringELProcessor.java

/**
 * @{inheritDoc}/*  w ww.j a va  2  s .  c o m*/
 */
@Override
public String process(String value, PortletRequest request) {
    Map<String, Object> context = getContext(request);

    StandardEvaluationContext sec = new StandardEvaluationContext(context);
    sec.addPropertyAccessor(new MapAccessor());
    sec.addPropertyAccessor(new ReflectivePropertyAccessor());
    sec.addPropertyAccessor(new DefaultPropertyAccessor(PARSER_CONTEXT.getExpressionPrefix(),
            PARSER_CONTEXT.getExpressionSuffix()));
    sec.setBeanResolver(beanResolver);
    SpelExpressionParser parser = new SpelExpressionParser();

    String processed = parser.parseExpression(value, PARSER_CONTEXT).getValue(sec, String.class);

    return processed;
}

From source file:org.jasig.portlet.spring.SpringELProcessor.java

@Override
public String process(String value, PortletRequest request) {
    Map<String, Object> context = getContext(request);

    StandardEvaluationContext sec = new StandardEvaluationContext(context);
    sec.addPropertyAccessor(new MapAccessor());
    sec.addPropertyAccessor(new ReflectivePropertyAccessor());
    sec.addPropertyAccessor(new DefaultPropertyAccessor(PARSER_CONTEXT.getExpressionPrefix(),
            PARSER_CONTEXT.getExpressionSuffix()));
    if (beanResolver != null) {
        sec.setBeanResolver(beanResolver);
    }//w  ww.j  a  va2  s.com
    SpelExpressionParser parser = new SpelExpressionParser();

    try {
        String processed = parser.parseExpression(value, PARSER_CONTEXT).getValue(sec, String.class);
        return processed;
    } catch (SpelEvaluationException e) {
        throw new EvaluationException("Failed to process string '" + value
                + "'. See nested error message and check your SpEL tokens in your string", e);
    }
}