Class AbstractSpringPoweredDigesterFactory
java.lang.Object
org.apache.commons.digester3.AbstractObjectCreationFactory<Object>
org.frankframework.configuration.digester.AbstractSpringPoweredDigesterFactory
- All Implemented Interfaces:
org.apache.commons.digester3.ObjectCreationFactory<Object>
,IDigesterRuleAware
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
ConfigurationDigesterFactory
,GenericFactory
,JmsRealmsFactory
,MonitoringFactory
,SharedResourceFactory
public abstract class AbstractSpringPoweredDigesterFactory
extends org.apache.commons.digester3.AbstractObjectCreationFactory<Object>
implements org.springframework.context.ApplicationContextAware, IDigesterRuleAware
This is a factory for objects to be used with the 'factory-create-rule'
of the Apache Digester framework as a replacement for the 'object-create-rule'.
The intention is to have objects created by the Apache Digester be created
via the Spring Factory thus allowing for dependency injection; and if not
possible then create them ourselves but inject at least a reference to the
Spring Factory when supported by the object. When the object is created
directly by this factory, the Spring Factory is used for auto-wiring
and initialization.
The factory is abstract; subclasses will need to implement method
'getSuggestedBeanName()' to return the name of the default Bean to load from
the Spring Context.
All Beans defined in the Spring Context that can be loaded via this
Factory must be defined as Prototype beans (scope="prototype") because
the expected behaviour from an ObjectCreationFactory is to create new
instances with each call. The Apache Digester will normally set extra
properties for each instance. (See
isPrototypesOnly()
.)- Since:
- 4.8
- Author:
- Tim van der Leeuw
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopyAttrsToMap
(Attributes attrs) protected <T> T
createBeanAndAutoWire
(Class<T> beanClass) protected Object
createObject
(Map<String, String> attrs) Create Object from Spring factory, but using the attributes from the XML converted to a Map.createObject
(Attributes attrs) Create object using, if possible, the Spring BeanFactory.org.springframework.context.ApplicationContext
abstract String
Suggest the name of the bean which should be retrieved from the Spring BeanFactory.boolean
Returntrue
is only prototype beans from the Spring Context will be returned,false
is a Spring singleton bean might be returned.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) final void
setDigesterRule
(DigesterRule rule) Methods inherited from class org.apache.commons.digester3.AbstractObjectCreationFactory
getDigester, setDigester
-
Field Details
-
log
protected org.apache.logging.log4j.Logger log
-
-
Constructor Details
-
AbstractSpringPoweredDigesterFactory
protected AbstractSpringPoweredDigesterFactory()
-
-
Method Details
-
getSuggestedBeanName
Suggest the name of the bean which should be retrieved from the Spring BeanFactory. If a className attribute has also been specified in the XML, then that takes precedence over finding a bean with given suggestedBeanName. If for the className multiple bean-definitions are found in the factory, then a bean is selected from those with this given suggestedBeanName. If no such bean exists, an error is thrown because the factory can not select between multiple beans. -
isPrototypesOnly
public boolean isPrototypesOnly()Returntrue
is only prototype beans from the Spring Context will be returned,false
is a Spring singleton bean might be returned. This is hard-coded to returntrue
only in this class. If a subclass wishes to allow using singleton-beans, then this method should be overridden.- Returns:
true
-
createObject
Create object using, if possible, the Spring BeanFactory. An object is created according to the following rules:- If no attribute 'className' is given in the configuration file, then the bean named with method getSuggestedBeanName() is created from the Spring context.
- If exactly 1 bean of type given by 'className' attribute can be
found in the Spring context, an instance of that bean is created
from the Spring factory.
The value returned by method getSuggestedBeanName() is, in this case, not relevant. - If multiple beans of type given by 'className' attribute are defined in the Spring context, then an instance is created whose bean-name is the same as that returned by the method getSuggestedBeanName().
- If the Spring context contains no beans of type 'className', then
a new instance of this class is created without accessing the
Spring factory.
The Spring BeanFactory will then be invoked to attempt auto-wiring beans by name and initialization via any BeanFactory - callback methods. If the created class implements interfaceBeanFactoryAware
, the Spring factory will be made available as a property so that it can be accessed directly from the bean.
(NB:Objects created by the Spring Factory will also have a pointer to the creating BeanFactory when they implement this interface.)
- Specified by:
createObject
in interfaceorg.apache.commons.digester3.ObjectCreationFactory<Object>
- Specified by:
createObject
in classorg.apache.commons.digester3.AbstractObjectCreationFactory<Object>
- Throws:
Exception
- See Also:
-
org.apache.commons.digester.ObjectCreationFactory#createObject(org.xml.sax.Attributes)
-
createObject
Create Object from Spring factory, but using the attributes from the XML converted to a Map. This is so that sub-classes can override this method and change attributes in the map before creating the object from the Spring factory.- Throws:
ClassNotFoundException
-
createBeanAndAutoWire
-
copyAttrsToMap
-
setDigesterRule
- Specified by:
setDigesterRule
in interfaceIDigesterRuleAware
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext() -
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
-