public class

XmlBeanDefinitionReader

extends AbstractBeanDefinitionReader
java.lang.Object
   ↳ org.springframework.beans.factory.support.AbstractBeanDefinitionReader
     ↳ org.springframework.beans.factory.xml.XmlBeanDefinitionReader

Class Overview

Bean definition reader for XML bean definitions. Delegates the actual XML document reading to an implementation of the BeanDefinitionDocumentReader interface.

Typically applied to a DefaultListableBeanFactory or a GenericApplicationContext.

This class loads a DOM document and applies the BeanDefinitionDocumentReader to it. The document reader will register each bean definition with the given bean factory, talking to the latter's implementation of the BeanDefinitionRegistry interface.

Summary

Constants
int VALIDATION_AUTO Indicates that the validation mode should be detected automatically.
int VALIDATION_DTD Indicates that DTD validation should be used.
int VALIDATION_NONE Indicates that the validation should be disabled.
int VALIDATION_XSD Indicates that XSD validation should be used.
[Expand]
Inherited Fields
From class org.springframework.beans.factory.support.AbstractBeanDefinitionReader
Public Constructors
XmlBeanDefinitionReader(BeanDefinitionRegistry registry)
Create new XmlBeanDefinitionReader for the given bean factory.
Public Methods
int getValidationMode()
Return the validation mode to use.
boolean isNamespaceAware()
Return whether or not the XML parser should be XML namespace aware.
int loadBeanDefinitions(InputSource inputSource)
Load bean definitions from the specified XML file.
int loadBeanDefinitions(InputSource inputSource, String resourceDescription)
Load bean definitions from the specified XML file.
int loadBeanDefinitions(Resource resource)
Load bean definitions from the specified XML file.
int loadBeanDefinitions(EncodedResource encodedResource)
Load bean definitions from the specified XML file.
int registerBeanDefinitions(Document doc, Resource resource)
Register the bean definitions contained in the given DOM document.
void setDocumentLoader(DocumentLoader documentLoader)
Specify the DocumentLoader to use.
void setDocumentReaderClass(Class<?> documentReaderClass)
Specify the BeanDefinitionDocumentReader implementation to use, responsible for the actual reading of the XML bean definition document.
void setEntityResolver(EntityResolver entityResolver)
Set a SAX entity resolver to be used for parsing.
void setErrorHandler(ErrorHandler errorHandler)
Set an implementation of the org.xml.sax.ErrorHandler interface for custom handling of XML parsing errors and warnings.
void setEventListener(ReaderEventListener eventListener)
Specify which ReaderEventListener to use.
void setNamespaceAware(boolean namespaceAware)
Set whether or not the XML parser should be XML namespace aware.
void setNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver)
Specify the NamespaceHandlerResolver to use.
void setProblemReporter(ProblemReporter problemReporter)
Specify which ProblemReporter to use.
void setSourceExtractor(SourceExtractor sourceExtractor)
Specify the SourceExtractor to use.
void setValidating(boolean validating)
Set whether to use XML validation.
void setValidationMode(int validationMode)
Set the validation mode to use.
void setValidationModeName(String validationModeName)
Set the validation mode to use by name.
Protected Methods
BeanDefinitionDocumentReader createBeanDefinitionDocumentReader()
Create the BeanDefinitionDocumentReader to use for actually reading bean definitions from an XML document.
NamespaceHandlerResolver createDefaultNamespaceHandlerResolver()
Create the default implementation of NamespaceHandlerResolver used if none is specified.
XmlReaderContext createReaderContext(Resource resource)
Create the XmlReaderContext to pass over to the document reader.
int detectValidationMode(Resource resource)
Detects which kind of validation to perform on the XML file identified by the supplied Resource.
int doLoadBeanDefinitions(InputSource inputSource, Resource resource)
Actually load bean definitions from the specified XML file.
EntityResolver getEntityResolver()
Return the EntityResolver to use, building a default resolver if none specified.
int getValidationModeForResource(Resource resource)
Gets the validation mode for the specified Resource.
[Expand]
Inherited Methods
From class org.springframework.beans.factory.support.AbstractBeanDefinitionReader
From class java.lang.Object
From interface org.springframework.beans.factory.support.BeanDefinitionReader
From interface org.springframework.core.env.EnvironmentCapable

Constants

public static final int VALIDATION_AUTO

Also: SpringBeans

Indicates that the validation mode should be detected automatically.

Constant Value: 1 (0x00000001)

public static final int VALIDATION_DTD

Also: SpringBeans

Indicates that DTD validation should be used.

Constant Value: 2 (0x00000002)

public static final int VALIDATION_NONE

Also: SpringBeans

Indicates that the validation should be disabled.

Constant Value: 0 (0x00000000)

public static final int VALIDATION_XSD

Also: SpringBeans

Indicates that XSD validation should be used.

Constant Value: 3 (0x00000003)

Public Constructors

public XmlBeanDefinitionReader (BeanDefinitionRegistry registry)

Also: SpringBeans

Create new XmlBeanDefinitionReader for the given bean factory.

Parameters
registry the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry

Public Methods

public int getValidationMode ()

Also: SpringBeans

Return the validation mode to use.

public boolean isNamespaceAware ()

Also: SpringBeans

Return whether or not the XML parser should be XML namespace aware.

public int loadBeanDefinitions (InputSource inputSource)

Load bean definitions from the specified XML file.

Parameters
inputSource the SAX InputSource to read from
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

public int loadBeanDefinitions (InputSource inputSource, String resourceDescription)

Also: SpringBeans

Load bean definitions from the specified XML file.

Parameters
inputSource the SAX InputSource to read from
resourceDescription a description of the resource (can be null or empty)
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

public int loadBeanDefinitions (Resource resource)

Load bean definitions from the specified XML file.

Parameters
resource the resource descriptor for the XML file
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

public int loadBeanDefinitions (EncodedResource encodedResource)

Load bean definitions from the specified XML file.

Parameters
encodedResource the resource descriptor for the XML file, allowing to specify an encoding to use for parsing the file
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

public int registerBeanDefinitions (Document doc, Resource resource)

Register the bean definitions contained in the given DOM document. Called by loadBeanDefinitions.

Creates a new instance of the parser class and invokes registerBeanDefinitions on it.

Parameters
doc the DOM document
resource the resource descriptor (for context information)
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of parsing errors

public void setDocumentLoader (DocumentLoader documentLoader)

Also: SpringBeans

Specify the DocumentLoader to use.

The default implementation is DefaultDocumentLoader which loads Document instances using JAXP.

public void setDocumentReaderClass (Class<?> documentReaderClass)

Also: SpringBeans

Specify the BeanDefinitionDocumentReader implementation to use, responsible for the actual reading of the XML bean definition document.

The default is DefaultBeanDefinitionDocumentReader.

Parameters
documentReaderClass the desired BeanDefinitionDocumentReader implementation class

public void setEntityResolver (EntityResolver entityResolver)

Also: SpringBeans

Set a SAX entity resolver to be used for parsing.

By default, ResourceEntityResolver will be used. Can be overridden for custom entity resolution, for example relative to some specific base path.

public void setErrorHandler (ErrorHandler errorHandler)

Also: SpringBeans

Set an implementation of the org.xml.sax.ErrorHandler interface for custom handling of XML parsing errors and warnings.

If not set, a default SimpleSaxErrorHandler is used that simply logs warnings using the logger instance of the view class, and rethrows errors to discontinue the XML transformation.

public void setEventListener (ReaderEventListener eventListener)

Also: SpringBeans

Specify which ReaderEventListener to use.

The default implementation is EmptyReaderEventListener which discards every event notification. External tools can provide an alternative implementation to monitor the components being registered in the BeanFactory.

public void setNamespaceAware (boolean namespaceAware)

Also: SpringBeans

Set whether or not the XML parser should be XML namespace aware. Default is "false".

This is typically not needed when schema validation is active. However, without validation, this has to be switched to "true" in order to properly process schema namespaces.

public void setNamespaceHandlerResolver (NamespaceHandlerResolver namespaceHandlerResolver)

Also: SpringBeans

Specify the NamespaceHandlerResolver to use.

If none is specified, a default instance will be created through createDefaultNamespaceHandlerResolver().

public void setProblemReporter (ProblemReporter problemReporter)

Also: SpringBeans

Specify which ProblemReporter to use.

The default implementation is FailFastProblemReporter which exhibits fail fast behaviour. External tools can provide an alternative implementation that collates errors and warnings for display in the tool UI.

public void setSourceExtractor (SourceExtractor sourceExtractor)

Also: SpringBeans

Specify the SourceExtractor to use.

The default implementation is NullSourceExtractor which simply returns null as the source object. This means that - during normal runtime execution - no additional source metadata is attached to the bean configuration metadata.

public void setValidating (boolean validating)

Also: SpringBeans

Set whether to use XML validation. Default is true.

This method switches namespace awareness on if validation is turned off, in order to still process schema namespaces properly in such a scenario.

public void setValidationMode (int validationMode)

Also: SpringBeans

Set the validation mode to use. Defaults to VALIDATION_AUTO.

Note that this only activates or deactivates validation itself. If you are switching validation off for schema files, you might need to activate schema namespace support explicitly: see setNamespaceAware(boolean).

public void setValidationModeName (String validationModeName)

Also: SpringBeans

Set the validation mode to use by name. Defaults to VALIDATION_AUTO.

Protected Methods

protected BeanDefinitionDocumentReader createBeanDefinitionDocumentReader ()

Also: SpringBeans

Create the BeanDefinitionDocumentReader to use for actually reading bean definitions from an XML document.

The default implementation instantiates the specified "documentReaderClass".

protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver ()

Also: SpringBeans

Create the default implementation of NamespaceHandlerResolver used if none is specified. Default implementation returns an instance of DefaultNamespaceHandlerResolver.

protected XmlReaderContext createReaderContext (Resource resource)

Create the XmlReaderContext to pass over to the document reader.

protected int detectValidationMode (Resource resource)

Detects which kind of validation to perform on the XML file identified by the supplied Resource. If the file has a DOCTYPE definition then DTD validation is used otherwise XSD validation is assumed.

Override this method if you would like to customize resolution of the VALIDATION_AUTO mode.

protected int doLoadBeanDefinitions (InputSource inputSource, Resource resource)

Actually load bean definitions from the specified XML file.

Parameters
inputSource the SAX InputSource to read from
resource the resource descriptor for the XML file
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

protected EntityResolver getEntityResolver ()

Also: SpringBeans

Return the EntityResolver to use, building a default resolver if none specified.

protected int getValidationModeForResource (Resource resource)

Gets the validation mode for the specified Resource. If no explicit validation mode has been configured then the validation mode is detected.

Override this method if you would like full control over the validation mode, even when something other than VALIDATION_AUTO was set.