Search in sources :

Example 1 with BeanFactoryResolver

use of org.springframework.context.expression.BeanFactoryResolver in project camel by apache.

the class JpaRouteSharedEntityManagerTest method getBrokerCount.

private int getBrokerCount() {
    LocalEntityManagerFactoryBean entityManagerFactory = applicationContext.getBean("&entityManagerFactory", LocalEntityManagerFactoryBean.class);
    //uses Spring EL so we don't need to reference the classes
    StandardEvaluationContext context = new StandardEvaluationContext(entityManagerFactory);
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("nativeEntityManagerFactory.brokerFactory.openBrokers");
    List<?> brokers = expression.getValue(context, List.class);
    return brokers.size();
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) LocalEntityManagerFactoryBean(org.springframework.orm.jpa.LocalEntityManagerFactoryBean)

Example 2 with BeanFactoryResolver

use of org.springframework.context.expression.BeanFactoryResolver in project camel by apache.

the class SpelExpression method createEvaluationContext.

private EvaluationContext createEvaluationContext(Exchange exchange) {
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new RootObject(exchange));
    if (exchange.getContext() instanceof SpringCamelContext) {
        // Support references (like @foo) in expressions to beans defined in the Registry/ApplicationContext
        ApplicationContext applicationContext = ((SpringCamelContext) exchange.getContext()).getApplicationContext();
        evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    }
    return evaluationContext;
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) ApplicationContext(org.springframework.context.ApplicationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 3 with BeanFactoryResolver

use of org.springframework.context.expression.BeanFactoryResolver in project spring-framework by spring-projects.

the class EvalTag method createEvaluationContext.

private EvaluationContext createEvaluationContext(PageContext pageContext) {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
    context.addPropertyAccessor(new MapAccessor());
    context.addPropertyAccessor(new EnvironmentAccessor());
    context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
    ConversionService conversionService = getConversionService(pageContext);
    if (conversionService != null) {
        context.setTypeConverter(new StandardTypeConverter(conversionService));
    }
    return context;
}
Also used : StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ConversionService(org.springframework.core.convert.ConversionService) MapAccessor(org.springframework.context.expression.MapAccessor) EnvironmentAccessor(org.springframework.context.expression.EnvironmentAccessor)

Example 4 with BeanFactoryResolver

use of org.springframework.context.expression.BeanFactoryResolver in project spring-framework by spring-projects.

the class CacheOperationExpressionEvaluator method createEvaluationContext.

/**
	 * Create an {@link EvaluationContext}.
	 * @param caches the current caches
	 * @param method the method
	 * @param args the method arguments
	 * @param target the target object
	 * @param targetClass the target class
	 * @param result the return value (can be {@code null}) or
	 * {@link #NO_RESULT} if there is no return at this time
	 * @return the evaluation context
	 */
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches, Method method, Object[] args, Object target, Class<?> targetClass, Object result, BeanFactory beanFactory) {
    CacheExpressionRootObject rootObject = new CacheExpressionRootObject(caches, method, args, target, targetClass);
    Method targetMethod = getTargetMethod(targetClass, method);
    CacheEvaluationContext evaluationContext = new CacheEvaluationContext(rootObject, targetMethod, args, getParameterNameDiscoverer());
    if (result == RESULT_UNAVAILABLE) {
        evaluationContext.addUnavailableVariable(RESULT_VARIABLE);
    } else if (result != NO_RESULT) {
        evaluationContext.setVariable(RESULT_VARIABLE, result);
    }
    if (beanFactory != null) {
        evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
    }
    return evaluationContext;
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Method(java.lang.reflect.Method)

Example 5 with BeanFactoryResolver

use of org.springframework.context.expression.BeanFactoryResolver in project spring-framework by spring-projects.

the class EventExpressionEvaluator method createEvaluationContext.

/**
	 * Create the suitable {@link EvaluationContext} for the specified event handling
	 * on the specified method.
	 */
public EvaluationContext createEvaluationContext(ApplicationEvent event, Class<?> targetClass, Method method, Object[] args, BeanFactory beanFactory) {
    Method targetMethod = getTargetMethod(targetClass, method);
    EventExpressionRootObject root = new EventExpressionRootObject(event, args);
    MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(root, targetMethod, args, getParameterNameDiscoverer());
    if (beanFactory != null) {
        evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
    }
    return evaluationContext;
}
Also used : MethodBasedEvaluationContext(org.springframework.context.expression.MethodBasedEvaluationContext) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Method(java.lang.reflect.Method)

Aggregations

BeanFactoryResolver (org.springframework.context.expression.BeanFactoryResolver)5 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)3 Method (java.lang.reflect.Method)2 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1 ApplicationContext (org.springframework.context.ApplicationContext)1 EnvironmentAccessor (org.springframework.context.expression.EnvironmentAccessor)1 MapAccessor (org.springframework.context.expression.MapAccessor)1 MethodBasedEvaluationContext (org.springframework.context.expression.MethodBasedEvaluationContext)1 ConversionService (org.springframework.core.convert.ConversionService)1 Expression (org.springframework.expression.Expression)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 StandardTypeConverter (org.springframework.expression.spel.support.StandardTypeConverter)1 LocalEntityManagerFactoryBean (org.springframework.orm.jpa.LocalEntityManagerFactoryBean)1