public class

DefaultBeanDefinitionDocumentReader

extends Object
implements BeanDefinitionDocumentReader
java.lang.Object
   ↳ org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader

Class Overview

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). <beans> 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.

Summary

Constants
String ALIAS_ATTRIBUTE
String ALIAS_ELEMENT
String BEAN_ELEMENT
String IMPORT_ELEMENT
String NAME_ATTRIBUTE
String NESTED_BEANS_ELEMENT
String PROFILE_ATTRIBUTE
String RESOURCE_ATTRIBUTE
Fields
protected final Log logger
Public Constructors
DefaultBeanDefinitionDocumentReader()
Public Methods
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).

void setEnvironment(Environment environment)
Set the Environment to use when reading bean definitions.

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

Protected Methods
BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)
void doRegisterBeanDefinitions(Element root)
Register each bean definition within the given root <beans/> element.
Object extractSource(Element ele)
Invoke the SourceExtractor to pull the source metadata from the supplied Element.
final XmlReaderContext getReaderContext()
Return the descriptor for the XML resource that this parser works on.
void importBeanDefinitionResource(Element ele)
Parse an "import" element and load the bean definitions from the given resource into the bean factory.
void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate)
Parse the elements at the root level in the document: "import", "alias", "bean".
void postProcessXml(Element root)
Allow the XML to be extensible by processing any custom element types last, after we finished processing the bean definitions.
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.
void processAliasRegistration(Element ele)
Process the given alias element, registering the alias with the registry.
void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate)
Process the given bean element, parsing the bean definition and registering it with the registry.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.xml.BeanDefinitionDocumentReader

Constants

public static final String ALIAS_ATTRIBUTE

Also: SpringBeans

Constant Value: "alias"

public static final String ALIAS_ELEMENT

Also: SpringBeans

Constant Value: "alias"

public static final String BEAN_ELEMENT

Also: SpringBeans

Constant Value: "bean"

public static final String IMPORT_ELEMENT

Also: SpringBeans

Constant Value: "import"

public static final String NAME_ATTRIBUTE

Also: SpringBeans

Constant Value: "name"

public static final String NESTED_BEANS_ELEMENT

Also: SpringBeans

Constant Value: "beans"

public static final String PROFILE_ATTRIBUTE

Also: SpringBeans

See Also
Constant Value: "profile"

public static final String RESOURCE_ATTRIBUTE

Also: SpringBeans

Constant Value: "resource"

Fields

protected final Log logger

Also: SpringBeans

Public Constructors

public DefaultBeanDefinitionDocumentReader ()

Also: SpringBeans

Public Methods

public void registerBeanDefinitions (Document doc, XmlReaderContext readerContext)

Also: SpringBeans

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.

Parameters
doc the DOM document
readerContext the current context of the reader. Includes the resource being parsed

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.

Protected Methods

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

Also: SpringBeans

protected void doRegisterBeanDefinitions (Element root)

Also: SpringBeans

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

protected Object extractSource (Element ele)

Also: SpringBeans

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

protected final XmlReaderContext getReaderContext ()

Also: SpringBeans

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

protected void importBeanDefinitionResource (Element ele)

Also: SpringBeans

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

protected void parseBeanDefinitions (Element root, BeanDefinitionParserDelegate delegate)

Also: SpringBeans

Parse the elements at the root level in the document: "import", "alias", "bean".

Parameters
root the DOM root element of the document

protected void postProcessXml (Element root)

Also: SpringBeans

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.

protected void preProcessXml (Element root)

Also: SpringBeans

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.

protected void processAliasRegistration (Element ele)

Also: SpringBeans

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

protected void processBeanDefinition (Element ele, BeanDefinitionParserDelegate delegate)

Also: SpringBeans

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