org.springframework.beans.factory.xml

## Class AbstractSingleBeanDefinitionParser

- java.lang.Object
- - org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
  - - org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser

All Implemented Interfaces:
  BeanDefinitionParser

Direct Known Subclasses:
  AbstractSimpleBeanDefinitionParser, ExecutorBeanDefinitionParser, JtaTransactionManagerBeanDefinitionParser, ScheduledTasksBeanDefinitionParser, SchedulerBeanDefinitionParser

    public abstract class AbstractSingleBeanDefinitionParser
    extends 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 `BeanDefinitionRegistry`. Your job simply is to `parse` the custom XML `Element` into a single `BeanDefinition`.

Since:
  2.0
Author:
  Rob Harrop, Juergen Hoeller, Rick Evans
See Also:
  `getBeanClass(org.w3c.dom.Element)`, `getBeanClassName(org.w3c.dom.Element)`, `doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)`

### Field Summary

### Fields inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser

`ID_ATTRIBUTE, NAME_ATTRIBUTE`

### Constructor Summary

Constructors
Constructor and Description
`AbstractSingleBeanDefinitionParser()`

### Method Summary

Methods
`protected void` `doParse(Element element, BeanDefinitionBuilder builder)` Parse the supplied `Element` and populate the supplied `BeanDefinitionBuilder` as required.
`protected void` `doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)` Parse the supplied `Element` and populate the supplied `BeanDefinitionBuilder` as required.
`protected Class<?>` `getBeanClass(Element element)` Determine the bean class corresponding to the supplied `Element`.
`protected String` `getBeanClassName(Element element)` Determine the bean class name corresponding to the supplied `Element`.
`protected String` `getParentName(Element element)` Determine the name for the parent of the currently parsed bean, in case of the current bean being defined as a child bean.
`protected AbstractBeanDefinition` `parseInternal(Element element, ParserContext parserContext)` Creates a `BeanDefinitionBuilder` instance for the `bean Class` and passes it to the `doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)` strategy method.

### Methods inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser

`parse, postProcessComponentDefinition, registerBeanDefinition, resolveId, shouldFireEvents, shouldGenerateId, shouldGenerateIdAsFallback`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AbstractSingleBeanDefinitionParser

    public AbstractSingleBeanDefinitionParser()

### Method Detail

#### parseInternal

    protected final AbstractBeanDefinition parseInternal(Element element,
                                       ParserContext parserContext)

Creates a `BeanDefinitionBuilder` instance for the `bean Class` and passes it to the `doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)` strategy method.

Specified by:
  `parseInternal` in class `AbstractBeanDefinitionParser`
Parameters:
  `element` - the element that is to be parsed into a single BeanDefinition
  `parserContext` - the object encapsulating the current state of the parsing process
Returns:
  the BeanDefinition resulting from the parsing of the supplied `Element`
Throws:
  `IllegalStateException` - if the bean `Class` returned from `getBeanClass(org.w3c.dom.Element)` is `null`
See Also:
  `doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)`

#### getParentName

    protected String getParentName(Element element)

Determine the name for the parent of the currently parsed bean, in case of the current bean being defined as a child bean.

The default implementation returns `null`, indicating a root bean definition.

Parameters:
  `element` - the `Element` that is being parsed
Returns:
  the name of the parent bean for the currently parsed bean, or `null` if none

#### getBeanClass

    protected Class<?> getBeanClass(Element element)

Determine the bean class corresponding to the supplied `Element`.

Note that, for application classes, it is generally preferable to override `getBeanClassName(org.w3c.dom.Element)` instead, in order to avoid a direct dependence on the bean implementation class. The BeanDefinitionParser and its NamespaceHandler can be used within an IDE plugin then, even if the application classes are not available on the plugin's classpath.

Parameters:
  `element` - the `Element` that is being parsed
Returns:
  the `Class` of the bean that is being defined via parsing the supplied `Element`, or `null` if none
See Also:
  `getBeanClassName(org.w3c.dom.Element)`

#### getBeanClassName

    protected String getBeanClassName(Element element)

Determine the bean class name corresponding to the supplied `Element`.

Parameters:
  `element` - the `Element` that is being parsed
Returns:
  the class name of the bean that is being defined via parsing the supplied `Element`, or `null` if none
See Also:
  `getBeanClass(org.w3c.dom.Element)`

#### doParse

    protected void doParse(Element element,
               ParserContext parserContext,
               BeanDefinitionBuilder builder)

Parse the supplied `Element` and populate the supplied `BeanDefinitionBuilder` as required.

The default implementation delegates to the `doParse` version without ParserContext argument.

Parameters:
  `element` - the XML element being parsed
  `parserContext` - the object encapsulating the current state of the parsing process
  `builder` - used to define the `BeanDefinition`
See Also:
  `doParse(Element, BeanDefinitionBuilder)`

#### doParse

    protected void doParse(Element element,
               BeanDefinitionBuilder builder)

Parse the supplied `Element` and populate the supplied `BeanDefinitionBuilder` as required.

The default implementation does nothing.

Parameters:
  `element` - the XML element being parsed
  `builder` - used to define the `BeanDefinition`