DefaultBeanDefinitionDocumentReader (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.beans.factory.xml

## Class DefaultBeanDefinitionDocumentReader

- java.lang.Object
- - org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader

- All Implemented Interfaces:
    BeanDefinitionDocumentReader

      public class DefaultBeanDefinitionDocumentReader
      extends Object
      implements BeanDefinitionDocumentReader

  Default implementation of the `BeanDefinitionDocumentReader` interface. Reads bean definitions according to the "spring-beans" DTD and XSD format (Spring's default XML bean definition format).

  The structure, elements and attribute names of the required XML document are hard-coded in this class. (Of course a transform could be run if necessary to produce this format). `&lt;beans&gt;` doesn't need to be the root element of the XML document: This class will parse all bean definition elements in the XML file, not regarding the actual root element.

  Since:
    18.12.2003
  Author:
    Rod Johnson, Juergen Hoeller, Rob Harrop, Erik Wiersma

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ALIAS_ATTRIBUTE`
    `static String` | `ALIAS_ELEMENT`
    `static String` | `BEAN_ELEMENT`
    `static String` | `IMPORT_ELEMENT`
    `protected Log` | `logger`
    `static String` | `NAME_ATTRIBUTE`
    `static String` | `NESTED_BEANS_ELEMENT`
    `static String` | `PROFILE_ATTRIBUTE`
    `static String` | `RESOURCE_ATTRIBUTE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultBeanDefinitionDocumentReader()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected BeanDefinitionParserDelegate` | `createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)`
    `protected void` | `doRegisterBeanDefinitions(Element root)` Register each bean definition within the given root `<beans/>` element.
    `protected Object` | `extractSource(Element ele)` Invoke the `SourceExtractor` to pull the source metadata from the supplied `Element`.
    `protected XmlReaderContext` | `getReaderContext()` Return the descriptor for the XML resource that this parser works on.
    `protected void` | `importBeanDefinitionResource(Element ele)` Parse an "import" element and load the bean definitions from the given resource into the bean factory.
    `protected void` | `parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate)` Parse the elements at the root level in the document: "import", "alias", "bean".
    `protected void` | `postProcessXml(Element root)` Allow the XML to be extensible by processing any custom element types last, after we finished processing the bean definitions.
    `protected void` | `preProcessXml(Element root)` Allow the XML to be extensible by processing any custom element types first, before we start to process the bean definitions.
    `protected void` | `processAliasRegistration(Element ele)` Process the given alias element, registering the alias with the registry.
    `protected void` | `processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate)` Process the given bean element, parsing the bean definition and registering it with the registry.
    `void` | `registerBeanDefinitions(Document doc, XmlReaderContext readerContext)` Read bean definitions from the given DOM document, and register them with the given bean factory.
    `void` | `setEnvironment(Environment environment)` Set the Environment to use when reading bean definitions.

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

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

- - ### Field Detail

    - #### BEAN_ELEMENT

          public static final String BEAN_ELEMENT

      See Also:
        Constant Field Values

    - #### NESTED_BEANS_ELEMENT

          public static final String NESTED_BEANS_ELEMENT

      See Also:
        Constant Field Values

    - #### ALIAS_ELEMENT

          public static final String ALIAS_ELEMENT

      See Also:
        Constant Field Values

    - #### NAME_ATTRIBUTE

          public static final String NAME_ATTRIBUTE

      See Also:
        Constant Field Values

    - #### ALIAS_ATTRIBUTE

          public static final String ALIAS_ATTRIBUTE

      See Also:
        Constant Field Values

    - #### IMPORT_ELEMENT

          public static final String IMPORT_ELEMENT

      See Also:
        Constant Field Values

    - #### RESOURCE_ATTRIBUTE

          public static final String RESOURCE_ATTRIBUTE

      See Also:
        Constant Field Values

    - #### PROFILE_ATTRIBUTE

          public static final String PROFILE_ATTRIBUTE

      See Also:
        `Profile`, Constant Field Values

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### DefaultBeanDefinitionDocumentReader

          public DefaultBeanDefinitionDocumentReader()

  - ### Method Detail

    - #### setEnvironment

          public void setEnvironment(Environment environment)

      Set the Environment to use when reading bean definitions. Used for evaluating profile information to determine whether a `<beans/>` document/element should be included or omitted.

      Default value is `null`; property is required for parsing any `<beans/>` element with a `profile` attribute present.

      Specified by:
        `setEnvironment` in interface `BeanDefinitionDocumentReader`
      See Also:
        `doRegisterBeanDefinitions(org.w3c.dom.Element)`

    - #### registerBeanDefinitions

          public void registerBeanDefinitions(Document doc,
                                     XmlReaderContext readerContext)

      Read bean definitions from the given DOM document, and register them with the given bean factory.

      This implementation parses bean definitions according to the "spring-beans" XSD (or DTD, historically).

      Opens a DOM Document; then initializes the default settings specified at the `<beans/>` level; then parses the contained bean definitions.

      Specified by:
        `registerBeanDefinitions` in interface `BeanDefinitionDocumentReader`
      Parameters:
        `doc` - the DOM document
        `readerContext` - the current context of the reader. Includes the resource being parsed

    - #### doRegisterBeanDefinitions

          protected void doRegisterBeanDefinitions(Element root)

      Register each bean definition within the given root `<beans/>` element.
      Throws:
        `IllegalStateException` - if `<beans profile="..."` attribute is present and Environment property has not been set
      See Also:
        `setEnvironment(org.springframework.core.env.Environment)`

    - #### createHelper

          protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext,
                                                  Element root,
                                                  BeanDefinitionParserDelegate parentDelegate)

    - #### getReaderContext

          protected final XmlReaderContext getReaderContext()

      Return the descriptor for the XML resource that this parser works on.

    - #### extractSource

          protected Object extractSource(Element ele)

      Invoke the `SourceExtractor` to pull the source metadata from the supplied `Element`.

    - #### parseBeanDefinitions

          protected void parseBeanDefinitions(Element root,
                                  BeanDefinitionParserDelegate delegate)

      Parse the elements at the root level in the document: "import", "alias", "bean".
      Parameters:
        `root` - the DOM root element of the document

    - #### importBeanDefinitionResource

          protected void importBeanDefinitionResource(Element ele)

      Parse an "import" element and load the bean definitions from the given resource into the bean factory.

    - #### processAliasRegistration

          protected void processAliasRegistration(Element ele)

      Process the given alias element, registering the alias with the registry.

    - #### processBeanDefinition

          protected void processBeanDefinition(Element ele,
                                   BeanDefinitionParserDelegate delegate)

      Process the given bean element, parsing the bean definition and registering it with the registry.

    - #### preProcessXml

          protected void preProcessXml(Element root)

      Allow the XML to be extensible by processing any custom element types first, before we start to process the bean definitions. This method is a natural extension point for any other custom pre-processing of the XML.

      The default implementation is empty. Subclasses can override this method to convert custom elements into standard Spring bean definitions, for example. Implementors have access to the parser's bean definition reader and the underlying XML resource, through the corresponding accessors.

      See Also:
        `getReaderContext()`

    - #### postProcessXml

          protected void postProcessXml(Element root)

      Allow the XML to be extensible by processing any custom element types last, after we finished processing the bean definitions. This method is a natural extension point for any other custom post-processing of the XML.

      The default implementation is empty. Subclasses can override this method to convert custom elements into standard Spring bean definitions, for example. Implementors have access to the parser's bean definition reader and the underlying XML resource, through the corresponding accessors.

      See Also:
        `getReaderContext()`