org.springframework.batch.core.configuration.support
Class ClassPathXmlApplicationContextFactory

java.lang.Object
  extended by org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextFactory
All Implemented Interfaces:
ApplicationContextFactory, ApplicationContextAware

public class ClassPathXmlApplicationContextFactory
extends Object
implements ApplicationContextFactory, ApplicationContextAware

ApplicationContextFactory implementation that takes a parent context and a path to the context to create. When createApplicationContext method is called, the child ApplicationContext will be returned. The child context is not re-created every time it is requested, it is lazily initialized and cached. Clients should ensure that it is closed when it is no longer needed. If a path is not set, the parent will always be returned.


Constructor Summary
ClassPathXmlApplicationContextFactory()
          Convenient constructor for configuration purposes.
ClassPathXmlApplicationContextFactory(Resource resource)
          Create a factory instance with the resource specified.
 
Method Summary
 ConfigurableApplicationContext createApplicationContext()
          Creates an ApplicationContext from the provided path.
 boolean equals(Object obj)
           
protected  Collection<Class<? extends BeanFactoryPostProcessor>> getBeanFactoryPostProcessorClasses()
          Protected access to the list of bean factory post processor classes that should be copied over to the context from the parent.
 int hashCode()
           
protected  boolean isCopyConfiguration()
          Protected access for subclasses to the flag determining whether configuration should be copied from parent context.
protected  void prepareBeanFactory(DefaultListableBeanFactory parent, DefaultListableBeanFactory beanFactory)
          Extension point for special subclasses that want to do more complex things with the bean factory prior to refresh.
protected  void prepareContext(ConfigurableApplicationContext parent, ConfigurableApplicationContext context)
          Extension point for special subclasses that want to do more complex things with the context prior to refresh.
 void setApplicationContext(ApplicationContext applicationContext)
          Setter for the parent application context.
 void setBeanFactoryPostProcessorClasses(Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses)
          Determines which bean factory post processors (like property placeholders) should be copied from the parent context.
 void setBeanPostProcessorExcludeClasses(Class<?>[] beanPostProcessorExcludeClasses)
          Determines by exclusion which bean post processors should be copied from the parent context.
 void setCopyConfiguration(boolean copyConfiguration)
          Flag to indicate that configuration such as bean post processors and custom editors should be copied from the parent context.
 void setResource(Resource resource)
          Setter for the path to the xml to load to create an ApplicationContext.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassPathXmlApplicationContextFactory

public ClassPathXmlApplicationContextFactory()
Convenient constructor for configuration purposes.


ClassPathXmlApplicationContextFactory

public ClassPathXmlApplicationContextFactory(Resource resource)
Create a factory instance with the resource specified. The resource is a Spring XML configuration file.

Method Detail

setResource

public void setResource(Resource resource)
Setter for the path to the xml to load to create an ApplicationContext. Use imports to centralise the configuration in one file.

Parameters:
resource - the resource path to the xml to load for the child context.

setCopyConfiguration

public void setCopyConfiguration(boolean copyConfiguration)
Flag to indicate that configuration such as bean post processors and custom editors should be copied from the parent context. Defaults to true.

Parameters:
copyConfiguration - the flag value to set

isCopyConfiguration

protected final boolean isCopyConfiguration()
Protected access for subclasses to the flag determining whether configuration should be copied from parent context.

Returns:
the flag value

setBeanFactoryPostProcessorClasses

public void setBeanFactoryPostProcessorClasses(Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses)
Determines which bean factory post processors (like property placeholders) should be copied from the parent context. Defaults to PropertyPlaceholderConfigurer and CustomEditorConfigurer.

Parameters:
copyBeanFactoryPostProcessors - the flag value to set

setBeanPostProcessorExcludeClasses

public void setBeanPostProcessorExcludeClasses(Class<?>[] beanPostProcessorExcludeClasses)
Determines by exclusion which bean post processors should be copied from the parent context. Defaults to BeanFactoryAware (so any post processors that have a reference to the parent bean factory are not copied into the child). Note that these classes do not themselves have to be BeanPostProcessor implementations or sub-interfaces.

Parameters:
beanPostProcessorExcludeClasses - the classes to set

getBeanFactoryPostProcessorClasses

protected final Collection<Class<? extends BeanFactoryPostProcessor>> getBeanFactoryPostProcessorClasses()
Protected access to the list of bean factory post processor classes that should be copied over to the context from the parent.

Returns:
the classes for post processors that were nominated for copying

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Setter for the parent application context.

Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException
See Also:
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

createApplicationContext

public ConfigurableApplicationContext createApplicationContext()
Creates an ApplicationContext from the provided path.

Specified by:
createApplicationContext in interface ApplicationContextFactory
See Also:
ApplicationContextFactory.createApplicationContext()

prepareContext

protected void prepareContext(ConfigurableApplicationContext parent,
                              ConfigurableApplicationContext context)
Extension point for special subclasses that want to do more complex things with the context prior to refresh. The default implementation does nothing.

Parameters:
parent - the parent for the new application context
context - the new application context before it is refreshed, but after bean factory is initialized
See Also:
setBeanFactoryPostProcessorClasses(Class[])

prepareBeanFactory

protected void prepareBeanFactory(DefaultListableBeanFactory parent,
                                  DefaultListableBeanFactory beanFactory)
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 flag set.

Parameters:
parent - the parent bean factory for the new context (will never be null)
beanFactory - the new bean factory before bean definitions are loaded
See Also:
setCopyConfiguration(boolean), DefaultListableBeanFactory.copyConfigurationFrom(ConfigurableBeanFactory)

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2013 SpringSource. All Rights Reserved.