List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext setTypeLocator
public void setTypeLocator(TypeLocator typeLocator)
From source file:org.craftercms.core.util.template.impl.spel.SpELStringTemplateCompiler.java
@PostConstruct public void init() { if (evalContext == null) { evalContext = new StandardEvaluationContext(); }//from ww w . j av a2 s . c om if (evalContext instanceof StandardEvaluationContext) { StandardEvaluationContext standardEvalContext = (StandardEvaluationContext) evalContext; // PropertyAccessor used when the model is a BeanFactory. standardEvalContext.addPropertyAccessor(new BeanFactoryAccessor()); if (beanFactory != null) { if (standardEvalContext.getBeanResolver() == null) { standardEvalContext.setBeanResolver(new BeanFactoryResolver(beanFactory)); } if (standardEvalContext.getTypeLocator() == null) { standardEvalContext.setTypeLocator(new StandardTypeLocator(beanFactory.getBeanClassLoader())); } if (standardEvalContext.getTypeConverter() == null) { ConversionService conversionService = beanFactory.getConversionService(); if (conversionService != null) { standardEvalContext.setTypeConverter(new StandardTypeConverter(conversionService)); } } } } }
From source file:org.springframework.cloud.function.deployer.ApplicationRunner.java
public Object evaluate(String expression, Object root, Object... attrs) { Expression parsed = new SpelExpressionParser(this.config).parseExpression(expression); StandardEvaluationContext context = new StandardEvaluationContext(root); context.setTypeLocator(this.typeLocator); if (attrs.length % 2 != 0) { throw new IllegalArgumentException("Context attributes must be name, value pairs"); }/*from w ww . j av a 2s .co m*/ for (int i = 0; i < attrs.length / 2; i++) { String name = (String) attrs[2 * i]; Object value = attrs[2 * i + 1]; context.setVariable(name, value); } return parsed.getValue(context); }
From source file:org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.java
/** * Constructs, configures and initializes a new instance of an {@link EvaluationContext}. * * @param beanFactory reference to the Spring {@link BeanFactory}. * @return a new {@link EvaluationContext}. * @see org.springframework.beans.factory.BeanFactory * @see org.springframework.expression.EvaluationContext * @see #getBeanFactory()/* w w w . j a v a 2s . c o m*/ */ protected EvaluationContext newEvaluationContext(BeanFactory beanFactory) { StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); evaluationContext.addPropertyAccessor(new BeanFactoryAccessor()); evaluationContext.addPropertyAccessor(new EnvironmentAccessor()); evaluationContext.addPropertyAccessor(new MapAccessor()); evaluationContext.setTypeLocator(new StandardTypeLocator(getBeanClassLoader())); configureTypeConverter(evaluationContext, beanFactory); return evaluationContext; }