List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext setRootObject
public void setRootObject(@Nullable Object rootObject)
From source file:app.commons.SpELUtils.java
public static Object parseExpression(String expression, Object rootObject) { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); // ctx.setBeanResolver(); ctx.setRootObject(rootObject); // ctx.setVariable("root", rootObject); return parser.parseExpression(expression).getValue(ctx); }
From source file:com.fitbur.core.el.spring.SpringExpressionService.java
@Override public <T> T eval(String name, Reader template, Object context, Class<T> resultType) { Expression expression = compile(name, template); StandardEvaluationContext ctx = contextProvider.get(); ctx.setRootObject(context); return expression.getValue(ctx, resultType); }
From source file:com.seovic.core.expression.SpelExpression.java
/** * {@inheritDoc}//ww w .jav a 2 s .c o m */ 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:com.seovic.core.expression.SpelExpression.java
/** * {@inheritDoc}/*from www . ja va 2 s .com*/ */ 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:com.fitbur.core.el.spring.SpringExpressionService.java
@Override public <T> T eval(String name, Reader template, Map<String, Object> context, Class<T> resultType) { Expression expression = compile(name, template); StandardEvaluationContext ctx = contextProvider.get(); ctx.addPropertyAccessor(mapAccessor); ctx.setRootObject(context); return expression.getValue(ctx, resultType); }
From source file:cz.jirutka.validator.spring.SpELAssertValidator.java
private StandardEvaluationContext createEvaluationContext(Object rootObject) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setRootObject(rootObject); context.setTypeConverter(TYPE_CONVERTER); if (beanFactory != null) { context.setBeanResolver(new BeanFactoryResolver(beanFactory)); }//ww w . j ava2s. c o m if (!functions.isEmpty()) { for (Method helper : functions) { context.registerFunction(helper.getName(), helper); } LOG.trace(inspectFunctions(context)); } return context; }
From source file:net.asfun.jangod.interpret.FloorBindings.java
public Object get(String key, int level) { checkKey(key);/*from w ww .j av a 2 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:com.oneops.controller.cms.ExpressionEvaluator.java
private EvaluationContext getEvaluationContext(CmsWorkOrderBase woBase) { StandardEvaluationContext context = new StandardEvaluationContext(); if (woBase instanceof CmsWorkOrder) { CmsRfcCISimple rfcSimple = cmsUtil.custRfcCI2RfcCISimple(((CmsWorkOrder) woBase).getRfcCi()); context.setRootObject(rfcSimple); } else if (woBase instanceof CmsActionOrder) { CmsCISimple ciSimple = cmsUtil.custCI2CISimple(((CmsActionOrder) woBase).getCi(), CmsConstants.ATTR_VALUE_TYPE_DF, true); context.setRootObject(ciSimple); }//from w w w .j a v a2s . co m return context; }
From source file:reactor.spring.context.ConsumerBeanPostProcessor.java
@Override public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException { ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() { @Override/* w w w . j av a 2 s .com*/ public void doWith(final Method method) throws IllegalArgumentException, IllegalAccessException { Annotation anno = AnnotationUtils.findAnnotation(method, On.class); if (null == anno) { return; } StandardEvaluationContext evalCtx = new StandardEvaluationContext(); evalCtx.setRootObject(bean); evalCtx.setBeanResolver(beanResolver); evalCtx.setMethodResolvers(METHOD_RESOLVERS); On onAnno = (On) anno; Object reactorObj = null; if (StringUtils.hasText(onAnno.reactor())) { Expression reactorExpr = expressionParser.parseExpression(onAnno.reactor()); reactorObj = reactorExpr.getValue(evalCtx); } Object selObj; if (StringUtils.hasText(onAnno.selector())) { try { Expression selectorExpr = expressionParser.parseExpression(onAnno.selector()); selObj = selectorExpr.getValue(evalCtx); } catch (EvaluationException e) { selObj = Fn.$(onAnno.selector()); } } else { selObj = Fn.$(method.getName()); } Consumer<Event<Object>> handler = new Consumer<Event<Object>>() { Class<?>[] argTypes = method.getParameterTypes(); @Override public void accept(Event<Object> ev) { if (argTypes.length == 0) { ReflectionUtils.invokeMethod(method, bean); return; } if (!argTypes[0].isAssignableFrom(ev.getClass()) && conversionService.canConvert(ev.getClass(), argTypes[0])) { ReflectionUtils.invokeMethod(method, bean, conversionService.convert(ev, argTypes[0])); } else { ReflectionUtils.invokeMethod(method, bean, ev); return; } if (null == ev.getData() || argTypes[0].isAssignableFrom(ev.getData().getClass())) { ReflectionUtils.invokeMethod(method, bean, ev.getData()); return; } if (conversionService.canConvert(ev.getData().getClass(), argTypes[0])) { ReflectionUtils.invokeMethod(method, bean, conversionService.convert(ev.getData(), argTypes[0])); return; } throw new IllegalArgumentException( "Cannot invoke method " + method + " passing parameter " + ev.getData()); } }; if (!(selObj instanceof Selector)) { throw new IllegalArgumentException(selObj + ", referred to by the expression '" + onAnno.selector() + "', is not a Selector"); } if (null == reactorObj) { throw new IllegalStateException("Cannot register handler with null Reactor"); } else { ((Reactor) reactorObj).on((Selector) selObj, handler); } } }); return bean; }
From source file:org.icescrum.core.security.WebScrumExpressionHandler.java
public EvaluationContext createEvaluationContext(Authentication authentication, FilterInvocation fi) { StandardEvaluationContext ctx = new StandardEvaluationContext(); WebScrumExpressionRoot root = new WebScrumExpressionRoot(authentication, fi); root.setTrustResolver(trustResolver); root.setRoleHierarchy(roleHierarchy); root.setSecurityService(securityService); ctx.setRootObject(root); return ctx;/*from ww w . j av a 2 s .c om*/ }