Search in sources :

Example 1 with SpelPropertyAccessorRegistrar

use of org.springframework.integration.expression.SpelPropertyAccessorRegistrar in project spring-integration by spring-projects.

the class AbstractEvaluationContextFactoryBean method initialize.

protected void initialize(String beanName) throws Exception {
    if (this.applicationContext != null) {
        ConversionService conversionService = IntegrationUtils.getConversionService(getApplicationContext());
        if (conversionService != null) {
            this.typeConverter = new StandardTypeConverter(conversionService);
        }
        Map<String, SpelFunctionFactoryBean> functionFactoryBeanMap = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.applicationContext, SpelFunctionFactoryBean.class);
        for (SpelFunctionFactoryBean spelFunctionFactoryBean : functionFactoryBeanMap.values()) {
            if (!getFunctions().containsKey(spelFunctionFactoryBean.getFunctionName())) {
                getFunctions().put(spelFunctionFactoryBean.getFunctionName(), spelFunctionFactoryBean.getObject());
            }
        }
        try {
            SpelPropertyAccessorRegistrar propertyAccessorRegistrar = this.applicationContext.getBean(SpelPropertyAccessorRegistrar.class);
            for (Entry<String, PropertyAccessor> entry : propertyAccessorRegistrar.getPropertyAccessors().entrySet()) {
                if (!getPropertyAccessors().containsKey(entry.getKey())) {
                    getPropertyAccessors().put(entry.getKey(), entry.getValue());
                }
            }
        } catch (NoSuchBeanDefinitionException e) {
        // There is no 'SpelPropertyAccessorRegistrar' bean in the application context.
        }
        ApplicationContext parent = this.applicationContext.getParent();
        if (parent != null && parent.containsBean(beanName)) {
            AbstractEvaluationContextFactoryBean parentFactoryBean = parent.getBean("&" + beanName, getClass());
            for (Entry<String, PropertyAccessor> entry : parentFactoryBean.getPropertyAccessors().entrySet()) {
                if (!getPropertyAccessors().containsKey(entry.getKey())) {
                    getPropertyAccessors().put(entry.getKey(), entry.getValue());
                }
            }
            for (Entry<String, Method> entry : parentFactoryBean.getFunctions().entrySet()) {
                if (!getFunctions().containsKey(entry.getKey())) {
                    getFunctions().put(entry.getKey(), entry.getValue());
                }
            }
        }
    }
    this.initialized = true;
}
Also used : SpelPropertyAccessorRegistrar(org.springframework.integration.expression.SpelPropertyAccessorRegistrar) PropertyAccessor(org.springframework.expression.PropertyAccessor) Method(java.lang.reflect.Method) StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) ApplicationContext(org.springframework.context.ApplicationContext) ConversionService(org.springframework.core.convert.ConversionService) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Aggregations

Method (java.lang.reflect.Method)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConversionService (org.springframework.core.convert.ConversionService)1 PropertyAccessor (org.springframework.expression.PropertyAccessor)1 StandardTypeConverter (org.springframework.expression.spel.support.StandardTypeConverter)1 SpelPropertyAccessorRegistrar (org.springframework.integration.expression.SpelPropertyAccessorRegistrar)1