Class XmlBeanDefinitionReader
- All Implemented Interfaces:
- BeanDefinitionReader,- EnvironmentCapable
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.
- Since:
- 26.11.2003
- Author:
- Juergen Hoeller, Rob Harrop, Chris Beams
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intIndicates that the validation mode should be detected automatically.static final intIndicates that DTD validation should be used.static final intIndicates that the validation should be disabled.static final intIndicates that XSD validation should be used.Fields inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionReaderlogger
- 
Constructor SummaryConstructorsConstructorDescriptionCreate new XmlBeanDefinitionReader for the given bean factory.
- 
Method SummaryModifier and TypeMethodDescriptionprotected BeanDefinitionDocumentReaderCreate theBeanDefinitionDocumentReaderto use for actually reading bean definitions from an XML document.protected NamespaceHandlerResolverCreate the default implementation ofNamespaceHandlerResolverused if none is specified.createReaderContext(Resource resource) Create theXmlReaderContextto pass over to the document reader.protected intdetectValidationMode(Resource resource) Detect which kind of validation to perform on the XML file identified by the suppliedResource.protected intdoLoadBeanDefinitions(InputSource inputSource, Resource resource) Actually load bean definitions from the specified XML file.protected DocumentdoLoadDocument(InputSource inputSource, Resource resource) Actually load the specified document using the configured DocumentLoader.protected EntityResolverReturn the EntityResolver to use, building a default resolver if none specified.Lazily create a default NamespaceHandlerResolver, if not set before.intReturn the validation mode to use.protected intgetValidationModeForResource(Resource resource) Determine the validation mode for the specifiedResource.booleanReturn whether the XML parser should be XML namespace aware.intloadBeanDefinitions(Resource resource) Load bean definitions from the specified XML file.intloadBeanDefinitions(EncodedResource encodedResource) Load bean definitions from the specified XML file.intloadBeanDefinitions(InputSource inputSource) Load bean definitions from the specified XML file.intloadBeanDefinitions(InputSource inputSource, String resourceDescription) Load bean definitions from the specified XML file.intregisterBeanDefinitions(Document doc, Resource resource) Register the bean definitions contained in the given DOM document.voidsetDocumentLoader(DocumentLoader documentLoader) Specify theDocumentLoaderto use.voidsetDocumentReaderClass(Class<? extends BeanDefinitionDocumentReader> documentReaderClass) Specify theBeanDefinitionDocumentReaderimplementation to use, responsible for the actual reading of the XML bean definition document.voidsetEntityResolver(EntityResolver entityResolver) Set a SAX entity resolver to be used for parsing.voidsetErrorHandler(ErrorHandler errorHandler) Set an implementation of theorg.xml.sax.ErrorHandlerinterface for custom handling of XML parsing errors and warnings.voidsetEventListener(ReaderEventListener eventListener) Specify whichReaderEventListenerto use.voidsetNamespaceAware(boolean namespaceAware) Set whether the XML parser should be XML namespace aware.voidsetNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver) Specify theNamespaceHandlerResolverto use.voidsetProblemReporter(ProblemReporter problemReporter) Specify whichProblemReporterto use.voidsetSourceExtractor(SourceExtractor sourceExtractor) Specify theSourceExtractorto use.voidsetValidating(boolean validating) Set whether to use XML validation.voidsetValidationMode(int validationMode) Set the validation mode to use.voidsetValidationModeName(String validationModeName) Set the validation mode to use by name.Methods inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionReadergetBeanClassLoader, getBeanNameGenerator, getEnvironment, getRegistry, getResourceLoader, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, setBeanClassLoader, setBeanNameGenerator, setEnvironment, setResourceLoader
- 
Field Details- 
VALIDATION_NONEpublic static final int VALIDATION_NONEIndicates that the validation should be disabled.- See Also:
 
- 
VALIDATION_AUTOpublic static final int VALIDATION_AUTOIndicates that the validation mode should be detected automatically.- See Also:
 
- 
VALIDATION_DTDpublic static final int VALIDATION_DTDIndicates that DTD validation should be used.- See Also:
 
- 
VALIDATION_XSDpublic static final int VALIDATION_XSDIndicates that XSD validation should be used.- See Also:
 
 
- 
- 
Constructor Details- 
XmlBeanDefinitionReaderCreate new XmlBeanDefinitionReader for the given bean factory.- Parameters:
- registry- the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
 
 
- 
- 
Method Details- 
setValidatingpublic void setValidating(boolean validating) Set whether to use XML validation. Default istrue.This method switches namespace awareness on if validation is turned off, in order to still process schema namespaces properly in such a scenario. 
- 
setValidationModeNameSet the validation mode to use by name. Defaults toVALIDATION_AUTO.- See Also:
 
- 
setValidationModepublic void setValidationMode(int validationMode) Set the validation mode to use. Defaults toVALIDATION_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).
- 
getValidationModepublic int getValidationMode()Return the validation mode to use.
- 
setNamespaceAwarepublic void setNamespaceAware(boolean namespaceAware) Set whether 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. 
- 
isNamespaceAwarepublic boolean isNamespaceAware()Return whether the XML parser should be XML namespace aware.
- 
setProblemReporterSpecify whichProblemReporterto use.The default implementation is FailFastProblemReporterwhich exhibits fail fast behaviour. External tools can provide an alternative implementation that collates errors and warnings for display in the tool UI.
- 
setEventListenerSpecify whichReaderEventListenerto 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. 
- 
setSourceExtractorSpecify theSourceExtractorto use.The default implementation is NullSourceExtractorwhich simply returnsnullas the source object. This means that - during normal runtime execution - no additional source metadata is attached to the bean configuration metadata.
- 
setNamespaceHandlerResolverpublic void setNamespaceHandlerResolver(@Nullable NamespaceHandlerResolver namespaceHandlerResolver) Specify theNamespaceHandlerResolverto use.If none is specified, a default instance will be created through createDefaultNamespaceHandlerResolver().
- 
setDocumentLoaderSpecify theDocumentLoaderto use.The default implementation is DefaultDocumentLoaderwhich loadsDocumentinstances using JAXP.
- 
setEntityResolverSet a SAX entity resolver to be used for parsing.By default, ResourceEntityResolverwill be used. Can be overridden for custom entity resolution, for example relative to some specific base path.
- 
getEntityResolverReturn the EntityResolver to use, building a default resolver if none specified.
- 
setErrorHandlerSet an implementation of theorg.xml.sax.ErrorHandlerinterface 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. - See Also:
 
- 
setDocumentReaderClasspublic void setDocumentReaderClass(Class<? extends BeanDefinitionDocumentReader> documentReaderClass) Specify theBeanDefinitionDocumentReaderimplementation to use, responsible for the actual reading of the XML bean definition document.The default is DefaultBeanDefinitionDocumentReader.- Parameters:
- documentReaderClass- the desired BeanDefinitionDocumentReader implementation class
 
- 
loadBeanDefinitionsLoad 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
 
- 
loadBeanDefinitionsLoad 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
 
- 
loadBeanDefinitionsLoad 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
 
- 
loadBeanDefinitionspublic int loadBeanDefinitions(InputSource inputSource, @Nullable String resourceDescription) throws BeanDefinitionStoreException Load bean definitions from the specified XML file.- Parameters:
- inputSource- the SAX InputSource to read from
- resourceDescription- a description of the resource (can be- nullor empty)
- Returns:
- the number of bean definitions found
- Throws:
- BeanDefinitionStoreException- in case of loading or parsing errors
 
- 
doLoadBeanDefinitionsprotected int doLoadBeanDefinitions(InputSource inputSource, Resource resource) throws BeanDefinitionStoreException 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
- See Also:
 
- 
doLoadDocumentActually load the specified document using the configured DocumentLoader.- Parameters:
- inputSource- the SAX InputSource to read from
- resource- the resource descriptor for the XML file
- Returns:
- the DOM Document
- Throws:
- Exception- when thrown from the DocumentLoader
- See Also:
 
- 
getValidationModeForResourceDetermine the validation mode for the specifiedResource. If no explicit validation mode has been configured, then the validation mode getsdetectedfrom the given resource.Override this method if you would like full control over the validation mode, even when something other than VALIDATION_AUTOwas set.
- 
detectValidationModeDetect which kind of validation to perform on the XML file identified by the suppliedResource. If the file has aDOCTYPEdefinition then DTD validation is used otherwise XSD validation is assumed.Override this method if you would like to customize resolution of the VALIDATION_AUTOmode.
- 
registerBeanDefinitionspublic int registerBeanDefinitions(Document doc, Resource resource) throws BeanDefinitionStoreException Register the bean definitions contained in the given DOM document. Called byloadBeanDefinitions.Creates a new instance of the parser class and invokes registerBeanDefinitionson 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
- See Also:
- 
- loadBeanDefinitions(org.springframework.core.io.Resource)
- setDocumentReaderClass(java.lang.Class<? extends org.springframework.beans.factory.xml.BeanDefinitionDocumentReader>)
- BeanDefinitionDocumentReader.registerBeanDefinitions(org.w3c.dom.Document, org.springframework.beans.factory.xml.XmlReaderContext)
 
 
- 
createBeanDefinitionDocumentReaderCreate theBeanDefinitionDocumentReaderto use for actually reading bean definitions from an XML document.The default implementation instantiates the specified "documentReaderClass". 
- 
createReaderContextCreate theXmlReaderContextto pass over to the document reader.
- 
getNamespaceHandlerResolverLazily create a default NamespaceHandlerResolver, if not set before.- See Also:
 
- 
createDefaultNamespaceHandlerResolverCreate the default implementation ofNamespaceHandlerResolverused if none is specified.The default implementation returns an instance of DefaultNamespaceHandlerResolver.
 
-