Search in sources :

Example 1 with AttributesBeanConfigurer

use of com.revolsys.spring.config.AttributesBeanConfigurer in project com.revolsys.open by revolsys.

the class SpringUtil method getApplicationContext.

public static GenericApplicationContext getApplicationContext(final ClassLoader classLoader, final Resource... resources) {
    final GenericApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.setClassLoader(classLoader);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(applicationContext, null);
    final AttributesBeanConfigurer attributesConfig = new AttributesBeanConfigurer(applicationContext);
    applicationContext.addBeanFactoryPostProcessor(attributesConfig);
    final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(applicationContext);
    beanReader.setBeanClassLoader(classLoader);
    beanReader.loadBeanDefinitions(resources);
    applicationContext.refresh();
    return applicationContext;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AttributesBeanConfigurer(com.revolsys.spring.config.AttributesBeanConfigurer) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Example 2 with AttributesBeanConfigurer

use of com.revolsys.spring.config.AttributesBeanConfigurer in project com.revolsys.open by revolsys.

the class ModuleImport method getApplicationContext.

protected GenericApplicationContext getApplicationContext(final BeanDefinitionRegistry parentRegistry) {
    if (this.applicationContext == null) {
        this.applicationContext = new GenericApplicationContext();
        if (parentRegistry instanceof ResourceLoader) {
            final ResourceLoader resourceLoader = (ResourceLoader) parentRegistry;
            final ClassLoader classLoader = resourceLoader.getClassLoader();
            this.applicationContext.setClassLoader(classLoader);
        }
        AnnotationConfigUtils.registerAnnotationConfigProcessors(this.applicationContext, null);
        final DefaultListableBeanFactory beanFactory = this.applicationContext.getDefaultListableBeanFactory();
        final BeanFactory parentBeanFactory = (BeanFactory) parentRegistry;
        for (final String beanName : parentRegistry.getBeanDefinitionNames()) {
            final BeanDefinition beanDefinition = parentRegistry.getBeanDefinition(beanName);
            final String beanClassName = beanDefinition.getBeanClassName();
            if (beanClassName != null) {
                if (beanClassName.equals(AttributeMap.class.getName())) {
                    registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
                    this.beanNamesNotToExport.add(beanName);
                } else if (beanClassName.equals(MapFactoryBean.class.getName())) {
                    final PropertyValue targetMapClass = beanDefinition.getPropertyValues().getPropertyValue("targetMapClass");
                    if (targetMapClass != null) {
                        final Object mapClass = targetMapClass.getValue();
                        if (AttributeMap.class.getName().equals(mapClass)) {
                            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
                            this.beanNamesNotToExport.add(beanName);
                        }
                    }
                }
            }
        }
        beanFactory.addPropertyEditorRegistrar(this.resourceEditorRegistrar);
        final AttributesBeanConfigurer attributesConfig = new AttributesBeanConfigurer(this.applicationContext, this.parameters);
        this.applicationContext.addBeanFactoryPostProcessor(attributesConfig);
        for (final String beanName : this.importBeanNames) {
            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
            this.beanNamesNotToExport.add(beanName);
        }
        for (final Entry<String, String> entry : this.importBeanAliases.entrySet()) {
            final String beanName = entry.getKey();
            final String aliasName = entry.getValue();
            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, aliasName);
            this.beanNamesNotToExport.add(aliasName);
        }
        final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(this.applicationContext);
        for (final Resource resource : this.resources) {
            beanReader.loadBeanDefinitions(resource);
        }
        this.applicationContext.refresh();
    }
    return this.applicationContext;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) AttributesBeanConfigurer(com.revolsys.spring.config.AttributesBeanConfigurer) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Resource(com.revolsys.spring.resource.Resource) PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AttributeMap(com.revolsys.collection.map.AttributeMap) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory)

Aggregations

AttributesBeanConfigurer (com.revolsys.spring.config.AttributesBeanConfigurer)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 AttributeMap (com.revolsys.collection.map.AttributeMap)1 Resource (com.revolsys.spring.resource.Resource)1 PropertyValue (org.springframework.beans.PropertyValue)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1