org.springframework.beans.factory.xml

Class DefaultBeanDefinitionDocumentReader

  • java.lang.Object
    • org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader
  • All Implemented Interfaces:
    BeanDefinitionDocumentReader


    public class DefaultBeanDefinitionDocumentReader
    extends java.lang.Object
    implements BeanDefinitionDocumentReader
    Default implementation of the BeanDefinitionDocumentReader interface that 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> does not need to be the root element of the XML document: this class will parse all bean definition elements in the XML file, regardless of the actual root element.

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

      • DefaultBeanDefinitionDocumentReader

        public DefaultBeanDefinitionDocumentReader()
    • Method Detail

      • registerBeanDefinitions

        public void registerBeanDefinitions(org.w3c.dom.Document doc,
                                            XmlReaderContext readerContext)
        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 target registry and the resource being parsed)
      • getReaderContext

        protected final XmlReaderContext getReaderContext()
        Return the descriptor for the XML resource that this parser works on.
      • extractSource

        @Nullable
        protected java.lang.Object extractSource(org.w3c.dom.Element ele)
        Invoke the SourceExtractor to pull the source metadata from the supplied Element.
      • doRegisterBeanDefinitions

        protected void doRegisterBeanDefinitions(org.w3c.dom.Element root)
        Register each bean definition within the given root <beans/> element.
      • parseBeanDefinitions

        protected void parseBeanDefinitions(org.w3c.dom.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(org.w3c.dom.Element ele)
        Parse an "import" element and load the bean definitions from the given resource into the bean factory.
      • processAliasRegistration

        protected void processAliasRegistration(org.w3c.dom.Element ele)
        Process the given alias element, registering the alias with the registry.
      • processBeanDefinition

        protected void processBeanDefinition(org.w3c.dom.Element ele,
                                             BeanDefinitionParserDelegate delegate)
        Process the given bean element, parsing the bean definition and registering it with the registry.
      • preProcessXml

        protected void preProcessXml(org.w3c.dom.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(org.w3c.dom.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()