Example usage for org.springframework.beans.factory.config BeanPostProcessor getClass

List of usage examples for org.springframework.beans.factory.config BeanPostProcessor getClass

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config BeanPostProcessor getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.springframework.batch.core.configuration.support.AbstractApplicationContextFactory.java

/**
 * Extension point for special subclasses that want to do more complex things with the bean factory prior to
 * refresh. The default implementation copies all configuration from the parent according to the
 * {@link #setCopyConfiguration(boolean) flag} set.
 *
 * @param parent the parent bean factory for the new context (will never be null)
 * @param beanFactory the new bean factory before bean definitions are loaded
 *
 * @see AbstractApplicationContextFactory#setCopyConfiguration(boolean)
 * @see DefaultListableBeanFactory#copyConfigurationFrom(ConfigurableBeanFactory)
 *//*from w  w  w. ja  v  a  2 s  . c  o  m*/
protected void prepareBeanFactory(ConfigurableListableBeanFactory parent,
        ConfigurableListableBeanFactory beanFactory) {
    if (copyConfiguration && parent != null) {
        List<BeanPostProcessor> parentPostProcessors = new ArrayList<BeanPostProcessor>();
        List<BeanPostProcessor> childPostProcessors = new ArrayList<BeanPostProcessor>();

        childPostProcessors.addAll(beanFactory instanceof AbstractBeanFactory
                ? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors()
                : new ArrayList<BeanPostProcessor>());
        parentPostProcessors.addAll(
                parent instanceof AbstractBeanFactory ? ((AbstractBeanFactory) parent).getBeanPostProcessors()
                        : new ArrayList<BeanPostProcessor>());

        try {
            Class<?> applicationContextAwareProcessorClass = ClassUtils.forName(
                    "org.springframework.context.support.ApplicationContextAwareProcessor",
                    parent.getBeanClassLoader());

            for (BeanPostProcessor beanPostProcessor : new ArrayList<BeanPostProcessor>(parentPostProcessors)) {
                if (applicationContextAwareProcessorClass.isAssignableFrom(beanPostProcessor.getClass())) {
                    logger.debug("Removing parent ApplicationContextAwareProcessor");
                    parentPostProcessors.remove(beanPostProcessor);
                }
            }
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException(e);
        }

        List<BeanPostProcessor> aggregatedPostProcessors = new ArrayList<BeanPostProcessor>();
        aggregatedPostProcessors.addAll(childPostProcessors);
        aggregatedPostProcessors.addAll(parentPostProcessors);

        for (BeanPostProcessor beanPostProcessor : new ArrayList<BeanPostProcessor>(aggregatedPostProcessors)) {
            for (Class<?> cls : beanPostProcessorExcludeClasses) {
                if (cls.isAssignableFrom(beanPostProcessor.getClass())) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Removing bean post processor: " + beanPostProcessor + " of type " + cls);
                    }
                    aggregatedPostProcessors.remove(beanPostProcessor);
                }
            }
        }

        beanFactory.copyConfigurationFrom(parent);

        List<BeanPostProcessor> beanPostProcessors = beanFactory instanceof AbstractBeanFactory
                ? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors()
                : new ArrayList<BeanPostProcessor>();

        beanPostProcessors.clear();
        beanPostProcessors.addAll(aggregatedPostProcessors);
    }
}

From source file:org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextFactory.java

/**
 * Extension point for special subclasses that want to do more complex
 * things with the bean factory prior to refresh. The default implementation
 * copies all configuration from the parent according to the
 * {@link #setCopyConfiguration(boolean) flag} set.
 * //from  w  w  w .j  a  va2  s. c  o m
 * @param parent the parent bean factory for the new context (will never be
 * null)
 * @param beanFactory the new bean factory before bean definitions are
 * loaded
 * 
 * @see ClassPathXmlApplicationContextFactory#setCopyConfiguration(boolean)
 * @see DefaultListableBeanFactory#copyConfigurationFrom(ConfigurableBeanFactory)
 */
protected void prepareBeanFactory(DefaultListableBeanFactory parent, DefaultListableBeanFactory beanFactory) {
    if (copyConfiguration && parent != null) {
        beanFactory.copyConfigurationFrom(parent);
        @SuppressWarnings("unchecked")
        List<BeanPostProcessor> beanPostProcessors = beanFactory.getBeanPostProcessors();
        for (BeanPostProcessor beanPostProcessor : new ArrayList<BeanPostProcessor>(beanPostProcessors)) {
            for (Class<?> cls : beanPostProcessorExcludeClasses) {
                if (cls.isAssignableFrom(beanPostProcessor.getClass())) {
                    logger.debug("Removing bean post processor: " + beanPostProcessor + " of type " + cls);
                    beanPostProcessors.remove(beanPostProcessor);
                }
            }
        }
    }
}

From source file:org.springframework.data.hadoop.admin.workflow.support.FileSystemApplicationContextFactory.java

/**
 * Extension point for special subclasses that want to do more complex
 * things with the bean factory prior to refresh. The default implementation
 * copies all configuration from the parent according to the
 * {@link #setCopyConfiguration(boolean) flag} set.
 * /*from  ww  w .  j a  va  2s .  c  o  m*/
 * @param parent the parent bean factory for the new context (will never be
 * null)
 * @param beanFactory the new bean factory before bean definitions are
 * loaded
 * 
 * @see ClassPathXmlApplicationContextFactory#setCopyConfiguration(boolean)
 * @see DefaultListableBeanFactory#copyConfigurationFrom(ConfigurableBeanFactory)
 */
protected void prepareBeanFactory(DefaultListableBeanFactory parent, DefaultListableBeanFactory beanFactory) {
    if (copyConfiguration && parent != null) {
        beanFactory.copyConfigurationFrom(parent);
        List<BeanPostProcessor> beanPostProcessors = beanFactory.getBeanPostProcessors();
        for (BeanPostProcessor beanPostProcessor : new ArrayList<BeanPostProcessor>(beanPostProcessors)) {
            for (Class<?> cls : beanPostProcessorExcludeClasses) {
                if (cls.isAssignableFrom(beanPostProcessor.getClass())) {
                    logger.debug("Removing bean post processor: " + beanPostProcessor + " of type " + cls);
                    beanPostProcessors.remove(beanPostProcessor);
                }
            }
        }
    }
}