spring-framework / org.springframework.beans.factory.xml / AbstractSingleBeanDefinitionParser

AbstractSingleBeanDefinitionParser

abstract class AbstractSingleBeanDefinitionParser : AbstractBeanDefinitionParser

Base class for those BeanDefinitionParser implementations that need to parse and define just a single BeanDefinition.

Extend this parser class when you want to create a single bean definition from an arbitrarily complex XML element. You may wish to consider extending the AbstractSimpleBeanDefinitionParser when you want to create a single bean definition from a relatively simple custom XML element.

The resulting BeanDefinition will be automatically registered with the org.springframework.beans.factory.support.BeanDefinitionRegistry. Your job simply is to parse the custom XML Element into a single BeanDefinition.

Author
Rob Harrop

Author
Juergen Hoeller

Author
Rick Evans

Since
2.0

See Also
#getBeanClass#getBeanClassName#doParse

Constructors

<init>

AbstractSingleBeanDefinitionParser()

Base class for those BeanDefinitionParser implementations that need to parse and define just a single BeanDefinition.

Extend this parser class when you want to create a single bean definition from an arbitrarily complex XML element. You may wish to consider extending the AbstractSimpleBeanDefinitionParser when you want to create a single bean definition from a relatively simple custom XML element.

The resulting BeanDefinition will be automatically registered with the org.springframework.beans.factory.support.BeanDefinitionRegistry. Your job simply is to parse the custom XML Element into a single BeanDefinition.

Inherited Properties

ID_ATTRIBUTE

static val ID_ATTRIBUTE: String

Constant for the "id" attribute

NAME_ATTRIBUTE

static val NAME_ATTRIBUTE: String

Constant for the "name" attribute

Inherited Functions

parse

fun parse(element: Element, parserContext: ParserContext): BeanDefinition

Inheritors

AbstractSimpleBeanDefinitionParser

abstract class AbstractSimpleBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Convenient base class for when there exists a one-to-one mapping between attribute names on the element that is to be parsed and the property names on the Class being configured.

Extend this parser class when you want to create a single bean definition from a relatively simple custom XML element. The resulting BeanDefinition will be automatically registered with the relevant org.springframework.beans.factory.support.BeanDefinitionRegistry.

An example will hopefully make the use of this particular parser class immediately clear. Consider the following class definition:

public class SimpleCache implements Cache { public void setName(String name) {...} public void setTimeout(int timeout) {...} public void setEvictionPolicy(EvictionPolicy policy) {...} // remaining class definition elided for clarity... }

Then let us assume the following XML tag has been defined to permit the easy configuration of instances of the above class;

<caching:cache name="..." timeout="..." eviction-policy="..."/>

All that is required of the Java developer tasked with writing the parser to parse the above XML tag into an actual SimpleCache bean definition is the following:

public class SimpleCacheBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser { protected Class getBeanClass(Element element) { return SimpleCache.class; } }

Please note that the AbstractSimpleBeanDefinitionParser is limited to populating the created bean definition with property values. if you want to parse constructor arguments and nested elements from the supplied XML element, then you will have to implement the #postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.w3c.dom.Element) method and do such parsing yourself, or (more likely) subclass the AbstractSingleBeanDefinitionParser or AbstractBeanDefinitionParser classes directly.

The process of actually registering the SimpleCacheBeanDefinitionParser with the Spring XML parsing infrastructure is described in the Spring Framework reference documentation (in one of the appendices).

For an example of this parser in action (so to speak), do look at the source code for the org.springframework.beans.factory.xml.UtilNamespaceHandler.PropertiesBeanDefinitionParser; the observant (and even not so observant) reader will immediately notice that there is next to no code in the implementation. The PropertiesBeanDefinitionParser populates a org.springframework.beans.factory.config.PropertiesFactoryBean from an XML element that looks like this:

<util:properties location="jdbc.properties"/>

The observant reader will notice that the sole attribute on the <util:properties/> element matches the org.springframework.beans.factory.config.PropertiesFactoryBean#setLocation(org.springframework.core.io.Resource) method name on the PropertiesFactoryBean (the general usage thus illustrated holds true for any number of attributes). All that the PropertiesBeanDefinitionParser needs actually do is supply an implementation of the #getBeanClass(org.w3c.dom.Element) method to return the PropertiesFactoryBean type.

ExecutorBeanDefinitionParser

open class ExecutorBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parser for the 'executor' element of the 'task' namespace.

FreeMarkerConfigurerBeanDefinitionParser

open class FreeMarkerConfigurerBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parse the MVC namespace element and register FreeMarkerConfigurer bean

JtaTransactionManagerBeanDefinitionParser

open class JtaTransactionManagerBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parser for the <tx:jta-transaction-manager/> XML configuration element, autodetecting WebLogic and WebSphere servers and exposing the corresponding org.springframework.transaction.jta.JtaTransactionManager subclass.

ScheduledTasksBeanDefinitionParser

open class ScheduledTasksBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parser for the 'scheduled-tasks' element of the scheduling namespace.

SchedulerBeanDefinitionParser

open class SchedulerBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parser for the 'scheduler' element of the 'task' namespace.

TilesConfigurerBeanDefinitionParser

open class TilesConfigurerBeanDefinitionParser : AbstractSingleBeanDefinitionParser

Parse the MVC namespace element and register a corresponding TilesConfigurer bean.