List of usage examples for org.springframework.expression EvaluationContext lookupVariable
@Nullable Object lookupVariable(String name);
From source file:net.abhinavsarkar.spelhelper.ImplicitMethodResolver.java
private static Method lookupMethod(final EvaluationContext context, final Class<?> type, final String name) { for (Class<?> clazz : InheritenceUtil.getInheritance(type)) { Object variable = ((SpelHelper) context.lookupVariable(SpelHelper.CONTEXT_LOOKUP_KEY)) .lookupImplicitMethod(clazz.getName() + "." + name); if (variable instanceof Method) { return (Method) variable; }/*from w ww . j av a2 s . co m*/ } return null; }
From source file:io.dyn.el.ScopedEvaluationContext.java
@Override public Object lookupVariable(String name) { Object o = super.lookupVariable(name); if (null == o) { for (EvaluationContext ec : parentContexts) { o = ec.lookupVariable(name); if (null != o) { break; }/*ww w. ja v a2 s .c o m*/ } } return o; }
From source file:org.mule.module.spel.EvaluationContextFactoryTest.java
public void testCreate() { MuleRegistry muleRegistry = mock(MuleRegistry.class); MuleContext context = mock(MuleContext.class); when(context.getRegistry()).thenReturn(muleRegistry); MuleMessage message = new DefaultMuleMessage(null, context); message.setPayload("a payload"); EvaluationContextFactory contextFactory = new EvaluationContextFactory(context); EvaluationContext evaluationContext = contextFactory.create(message); Object resultMuleContext = evaluationContext.lookupVariable("context"); assertNotNull(resultMuleContext);/*from w w w . j a v a 2 s . c o m*/ assertTrue(resultMuleContext instanceof MuleContext); assertEquals(context, resultMuleContext); Object resultMuleRegistry = evaluationContext.lookupVariable("registry"); assertNotNull(resultMuleRegistry); assertTrue(resultMuleRegistry instanceof MuleRegistry); assertEquals(muleRegistry, resultMuleRegistry); Object resultMuleMessage = evaluationContext.lookupVariable("message"); assertNotNull(resultMuleMessage); assertTrue(resultMuleMessage instanceof MuleMessage); Object resultOriginalPayload = evaluationContext.lookupVariable("originalPayload"); assertNull(resultOriginalPayload); Object resultPayload = evaluationContext.lookupVariable("payload"); assertNotNull(resultPayload); assertEquals("a payload", resultPayload); Object resultId = evaluationContext.lookupVariable("id"); assertNotNull(resultId); }
From source file:net.abhinavsarkar.spelhelper.ImplicitConstructorResolver.java
@Override public ConstructorExecutor resolve(final EvaluationContext context, final String typeName, final List<TypeDescriptor> argumentTypes) throws AccessException { try {//from w w w . j av a 2s. c o m return delegate.resolve(context, typeName, argumentTypes); } catch (AccessException ex) { Object variable = ((SpelHelper) context.lookupVariable(SpelHelper.CONTEXT_LOOKUP_KEY)) .lookupImplicitConstructor(typeName + argumentTypes.toString()); if (variable instanceof Constructor<?>) { Constructor<?> constructor = (Constructor<?>) variable; return delegate.resolve(context, constructor.getDeclaringClass().getName(), argumentTypes); } return null; } }
From source file:cz.jirutka.validator.spring.SpELAssertValidator.java
private String inspectFunctions(EvaluationContext context) { StringBuilder message = new StringBuilder(); Set<String> names = new HashSet<>(functions.size()); message.append("Registered functions: \n"); for (Method function : functions) { names.add(function.getName());//from w w w .j ava2 s.c o m } for (String name : names) { Object obj = context.lookupVariable(name); if (obj instanceof Method) { message.append(" #").append(name).append(" -> ").append(obj).append("\n"); } } return message.toString(); }