Java Code Examples for org.springframework.context.expression.BeanFactoryResolver

The following examples show how to use org.springframework.context.expression.BeanFactoryResolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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, Method targetMethod,
		@Nullable Object result, @Nullable BeanFactory beanFactory) {

	CacheExpressionRootObject rootObject = new CacheExpressionRootObject(
			caches, method, args, target, targetClass);
	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;
}
 
Example 2
/**
 * 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, Method targetMethod,
		@Nullable Object result, @Nullable BeanFactory beanFactory) {

	CacheExpressionRootObject rootObject = new CacheExpressionRootObject(
			caches, method, args, target, targetClass);
	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;
}
 
Example 3
Source Project: spring-cloud-gray   Source File: ConfigurationUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static Object getValue(SpelExpressionParser parser, BeanFactory beanFactory,
                               String entryValue) {
    Object value;
    String rawValue = entryValue;
    if (rawValue != null) {
        rawValue = rawValue.trim();
    }
    if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {
        // assume it's spel
        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setBeanResolver(new BeanFactoryResolver(beanFactory));
        Expression expression = parser.parseExpression(entryValue,
                new TemplateParserContext());
        context.lookupVariable("api");
        value = expression.getValue(context);
    } else {
        value = entryValue;
    }
    return value;
}
 
Example 4
Source Project: eclair   Source File: ExpressionEvaluatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void evaluateToString() {
    // given
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
    evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext);

    String string = "toString()";
    String string2 = "#this";
    String string3 = "#root";
    Argument argument = new Argument();
    // when
    Object result = expressionEvaluator.evaluate(string, argument);
    Object result2 = expressionEvaluator.evaluate(string2, argument);
    Object result3 = expressionEvaluator.evaluate(string3, argument);
    // then
    assertThat(result, is("!"));
    assertThat(result2, is(argument));
    assertThat(result3, is(argument));
}
 
Example 5
private List<MetricTagResult> getMetricTags(ExpressionParser expressionParser, 
		ConfigurableBeanFactory beanFactory,
		FilterConfiguration<R> filterConfig, 
		R servletRequest) {
	
	List<MetricTagResult> metricTagResults = filterConfig
		.getMetrics().getTags()
		.stream()
		.map( (metricMetaTag) -> {
			String expression = metricMetaTag.getExpression();
			if(StringUtils.isEmpty(expression)) {
				throw new MissingMetricTagExpressionException(metricMetaTag.getKey());
			}
			StandardEvaluationContext context = new StandardEvaluationContext();
			context.setBeanResolver(new BeanFactoryResolver(beanFactory));
			//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
			Expression expr = expressionParser.parseExpression(expression); 
			final String value = expr.getValue(context, servletRequest, String.class);
			
			return new MetricTagResult(metricMetaTag.getKey(), value, metricMetaTag.getTypes());
	}).collect(toList());
	if(metricTagResults == null) {
		metricTagResults = new ArrayList<>();
	}
	return metricTagResults;
}
 
Example 6
/**
 * Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
 * is the unique identifier like an IP address or a username.
 * 
 * @param url is used to generated a unique cache key
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
 */
public KeyFilter<R> getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	
	String expression = rateLimit.getExpression();
	if(StringUtils.isEmpty(expression)) {
		throw new MissingKeyFilterExpressionException();
	}
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	return  (request) -> {
		//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
		Expression expr = expressionParser.parseExpression(rateLimit.getExpression()); 
		final String value = expr.getValue(context, request, String.class);
		return url + "-" + value;
	};

	
}
 
Example 7
/**
 * 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;
}
 
Example 8
private QueryMethodEvaluationContextProvider delegateContextProvider(
		QueryMethodEvaluationContextProvider evaluationContextProvider) {
	return new QueryMethodEvaluationContextProvider() {
		@Override
		public <T extends Parameters<?, ?>> EvaluationContext getEvaluationContext(
				T parameters, Object[] parameterValues) {
			StandardEvaluationContext evaluationContext = (StandardEvaluationContext)
					evaluationContextProvider
					.getEvaluationContext(parameters, parameterValues);
			evaluationContext.setRootObject(
					DatastoreRepositoryFactory.this.applicationContext);
			evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());
			evaluationContext.setBeanResolver(new BeanFactoryResolver(
					DatastoreRepositoryFactory.this.applicationContext));
			return evaluationContext;
		}
	};
}
 
Example 9
Source Project: spring-cloud-gcp   Source File: SpannerRepositoryFactory.java    License: Apache License 2.0 6 votes vote down vote up
private QueryMethodEvaluationContextProvider delegateContextProvider(
		QueryMethodEvaluationContextProvider evaluationContextProvider) {
	return new QueryMethodEvaluationContextProvider() {
		@Override
		public <T extends Parameters<?, ?>> EvaluationContext getEvaluationContext(
				T parameters, Object[] parameterValues) {
			StandardEvaluationContext evaluationContext = (StandardEvaluationContext) evaluationContextProvider
					.getEvaluationContext(parameters, parameterValues);
			evaluationContext
					.setRootObject(SpannerRepositoryFactory.this.applicationContext);
			evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());
			evaluationContext.setBeanResolver(new BeanFactoryResolver(
					SpannerRepositoryFactory.this.applicationContext));
			return evaluationContext;
		}
	};
}
 
Example 10
Source Project: spring-cloud-gateway   Source File: ShortcutConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
static Object getValue(SpelExpressionParser parser, BeanFactory beanFactory,
		String entryValue) {
	Object value;
	String rawValue = entryValue;
	if (rawValue != null) {
		rawValue = rawValue.trim();
	}
	if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {
		// assume it's spel
		StandardEvaluationContext context = new StandardEvaluationContext();
		context.setBeanResolver(new BeanFactoryResolver(beanFactory));
		Expression expression = parser.parseExpression(entryValue,
				new TemplateParserContext());
		value = expression.getValue(context);
	}
	else {
		value = entryValue;
	}
	return value;
}
 
Example 11
/**
 * 创建SpEL执行上下文
 *
 * @param rootObject
 *            SpEL表达式根对象
 * @param context
 *            Beetl上下文对象
 * @return SpEL表达式执行上下文
 */
private EvaluationContext createEvaluationContext(Object rootObject, Context beetlContext) {
	StandardEvaluationContext context = new StandardEvaluationContext(rootObject);

	// 允许使用#context访问Beetl上下文
	context.setVariable("context", beetlContext);
	// 允许使用#global访问Beetl上下文的全局变量
	context.setVariable("global", beetlContext.globalVar);
	// 注册WebRender定义的全局变量
	context.setVariable("ctxPath", beetlContext.getGlobal("ctxPath"));
	context.setVariable("servlet", beetlContext.getGlobal("servlet"));
	context.setVariable("parameter", beetlContext.getGlobal("parameter"));
	context.setVariable("request", beetlContext.getGlobal("request"));
	context.setVariable("session", beetlContext.getGlobal("session"));
	// 允许使用属性格式访问Map
	context.addPropertyAccessor(new MapAccessor());
	// 允许访问Spring容器Bean
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));

	return context;
}
 
Example 12
/**
 * Create an {@link EvaluationContext}.
 *
 * @param method      the method
 * @param args        the method arguments
 * @param target      the target object
 * @param targetClass the target class
 * @return the evaluation context
 */
public EvaluationContext createContext(Method method, Object[] args, Object target, Class<?> targetClass, @Nullable BeanFactory beanFactory) {
	Method targetMethod = getTargetMethod(targetClass, method);
	MicaExpressionRootObject rootObject = new MicaExpressionRootObject(method, args, target, targetClass, targetMethod);
	MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(rootObject, targetMethod, args, getParameterNameDiscoverer());
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}
	return evaluationContext;
}
 
Example 13
Source Project: spring-analysis-note   Source File: EventExpressionEvaluator.java    License: MIT License 5 votes vote down vote up
/**
 * Determine if the condition defined by the specified expression evaluates
 * to {@code true}.
 */
public boolean condition(String conditionExpression, ApplicationEvent event, Method targetMethod,
		AnnotatedElementKey methodKey, Object[] args, @Nullable BeanFactory beanFactory) {

	EventExpressionRootObject root = new EventExpressionRootObject(event, args);
	MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(
			root, targetMethod, args, getParameterNameDiscoverer());
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}

	return (Boolean.TRUE.equals(getExpression(this.conditionCache, methodKey, conditionExpression).getValue(
			evaluationContext, Boolean.class)));
}
 
Example 14
Source Project: spring-analysis-note   Source File: EvalTag.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 15
/**
 * Create an {@link EvaluationContext}.
 *
 * @param method      the method
 * @param args        the method arguments
 * @param target      the target object
 * @param targetClass the target class
 * @return the evaluation context
 */
public EvaluationContext createContext(Method method, Object[] args, Object target, Class<?> targetClass, @Nullable BeanFactory beanFactory) {
	Method targetMethod = getTargetMethod(targetClass, method);
	ExpressionRootObject rootObject = new ExpressionRootObject(method, args, target, targetClass, targetMethod);
	MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(rootObject, targetMethod, args, getParameterNameDiscoverer());
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}
	return evaluationContext;
}
 
Example 16
/**
 * 包含方法上的参数的上下文
 *
 * @param secureExpressionHandler 上下文处理器
 * @param method                  方法
 * @param args                    参数
 * @return 上下文
 */
public static StandardEvaluationContext getEvaluationContext(SecureExpressionHandler secureExpressionHandler, Method method, Object[] args) {
	// 初始化Spel表达式上下文,并设置 处理函数
	StandardEvaluationContext context = new StandardEvaluationContext(secureExpressionHandler);
	// 设置表达式支持spring bean
	context.setBeanResolver(new BeanFactoryResolver(SpringUtil.getContext()));
	for (int i = 0; i < args.length; i++) {
		// 读取方法参数
		MethodParameter methodParam = ClassUtil.getMethodParameter(method, i);
		// 设置方法 参数名和值 为sp el变量
		context.setVariable(methodParam.getParameterName(), args[i]);
	}
	return context;
}
 
Example 17
/**
 * 设置 request/response 参数的上下文
 *
 * @param secureExpressionHandler 上下文处理器
 * @param request                 请求
 * @param response                响应
 * @return 上下文
 */
public static StandardEvaluationContext getEvaluationContext(SecureExpressionHandler secureExpressionHandler, HttpServletRequest request, HttpServletResponse response) {
	// 初始化Sp el表达式上下文,并设置 处理函数
	StandardEvaluationContext context = new StandardEvaluationContext(secureExpressionHandler);
	// 设置表达式支持spring bean
	context.setBeanResolver(new BeanFactoryResolver(SpringUtil.getContext()));
	context.setVariable(SecureConstants.REQUEST, request);
	context.setVariable(SecureConstants.RESPONSE, response);
	return context;
}
 
Example 18
Source Project: java-technology-stack   Source File: EventExpressionEvaluator.java    License: MIT License 5 votes vote down vote up
/**
 * Specify if the condition defined by the specified expression matches.
 */
public boolean condition(String conditionExpression, ApplicationEvent event, Method targetMethod,
		AnnotatedElementKey methodKey, Object[] args, @Nullable BeanFactory beanFactory) {

	EventExpressionRootObject root = new EventExpressionRootObject(event, args);
	MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(
			root, targetMethod, args, getParameterNameDiscoverer());
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}

	return (Boolean.TRUE.equals(getExpression(this.conditionCache, methodKey, conditionExpression).getValue(
			evaluationContext, Boolean.class)));
}
 
Example 19
Source Project: java-technology-stack   Source File: EvalTag.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 20
public EvaluationContext createEvaluationContext(Limiter limiter, Method method, Object[] args, Object target, Class<?> targetClass, Method targetMethod,
                                                 Map<String, Object> injectArgs, BeanFactory beanFactory) {

    LimiterExpressionRootObject rootObject = new LimiterExpressionRootObject(limiter, method, args, target, targetClass);
    MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(rootObject, targetMethod, args, this.parameterNameDiscoverer);
    for (String key : injectArgs.keySet()) {
        evaluationContext.setVariable(key, injectArgs.get(key));
    }

    if (beanFactory != null) {
        evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
    }
    return evaluationContext;
}
 
Example 21
Source Project: blade-tool   Source File: AuthAspect.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取方法上的参数
 *
 * @param method 方法
 * @param args   变量
 * @return {SimpleEvaluationContext}
 */
private StandardEvaluationContext getEvaluationContext(Method method, Object[] args) {
	// 初始化Sp el表达式上下文,并设置 AuthFun
	StandardEvaluationContext context = new StandardEvaluationContext(new AuthFun());
	// 设置表达式支持spring bean
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));
	for (int i = 0; i < args.length; i++) {
		// 读取方法参数
		MethodParameter methodParam = ClassUtil.getMethodParameter(method, i);
		// 设置方法 参数名和值 为sp el变量
		context.setVariable(methodParam.getParameterName(), args[i]);
	}
	return context;
}
 
Example 22
Source Project: eclair   Source File: EclairAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ExpressionEvaluator expressionEvaluator() {
    ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.MIXED, null));
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
    evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    return new ExpressionEvaluator(expressionParser, evaluationContext);
}
 
Example 23
Source Project: eclair   Source File: ExpressionEvaluatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void evaluateWithBeanReferencing() {
    // given
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
    evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext);

    String string = "@string.toString()";
    // when
    Object result = expressionEvaluator.evaluate(string);
    // then
    assertThat(result, is("bean string"));
}
 
Example 24
Source Project: eclair   Source File: ExpressionEvaluatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void evaluateWithArgumentAndBeanReferencing() {
    // given
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
    evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext);

    String string = "@string.toString()";
    Argument argument = new Argument();
    // when
    Object result = expressionEvaluator.evaluate(string, argument);
    // then
    assertThat(result, is("bean string"));
}
 
Example 25
Source Project: spring-data   Source File: ArangoTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
	context.setRootObject(applicationContext);
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));
	context.addPropertyAccessor(new BeanFactoryAccessor());
	eventPublisher = applicationContext;
	arango._setCursorInitializer(new ArangoCursorInitializer(converter, applicationContext));
}
 
Example 26
/**
 * Creates the lambda for the skip condition which will be evaluated on each request
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the skip expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition<R> skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getSkipCondition() != null) {
		return  (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
Example 27
/**
 * Creates the lambda for the execute condition which will be evaluated on each request.
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the execute condition string
 * @param expressionParser is used to evaluate the execution expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition<R> executeCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getExecuteCondition() != null) {
		return (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getExecuteCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
Example 28
Source Project: lams   Source File: EvalTag.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 29
/**
 * 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;
}
 
Example 30
Source Project: dubbox   Source File: SimpleSolrPersistentEntity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

	context.addPropertyAccessor(new BeanFactoryAccessor());
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));
	context.setRootObject(applicationContext);
}