类 XmlBeanDefinitionReader
- java.lang.Object
- org.springframework.beans.factory.support.AbstractBeanDefinitionReader
- org.springframework.beans.factory.xml.XmlBeanDefinitionReader
- 所有已实现的接口:
BeanDefinitionReader,EnvironmentCapable
public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader
Bean definition reader for XML bean definitions. Delegates the actual XML document reading to an implementation of theBeanDefinitionDocumentReaderinterface.Typically applied to a
DefaultListableBeanFactoryor aGenericApplicationContext.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
BeanDefinitionRegistryinterface.- 从以下版本开始:
- 26.11.2003
- 作者:
- Juergen Hoeller, Rob Harrop, Chris Beams
- 另请参阅:
setDocumentReaderClass(java.lang.Class<?>),BeanDefinitionDocumentReader,DefaultBeanDefinitionDocumentReader,BeanDefinitionRegistry,DefaultListableBeanFactory,GenericApplicationContext
字段概要
字段 修饰符和类型 字段 说明 static intVALIDATION_AUTOIndicates that the validation mode should be detected automatically.static intVALIDATION_DTDIndicates that DTD validation should be used.static intVALIDATION_NONEIndicates that the validation should be disabled.static intVALIDATION_XSDIndicates that XSD validation should be used.从类继承的字段 org.springframework.beans.factory.support.AbstractBeanDefinitionReader
logger
构造器概要
构造器 构造器 说明 XmlBeanDefinitionReader(BeanDefinitionRegistry registry)Create new XmlBeanDefinitionReader for the given bean factory.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected BeanDefinitionDocumentReadercreateBeanDefinitionDocumentReader()Create theBeanDefinitionDocumentReaderto use for actually reading bean definitions from an XML document.protected NamespaceHandlerResolvercreateDefaultNamespaceHandlerResolver()Create the default implementation ofNamespaceHandlerResolverused if none is specified.XmlReaderContextcreateReaderContext(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 EntityResolvergetEntityResolver()Return the EntityResolver to use, building a default resolver if none specified.NamespaceHandlerResolvergetNamespaceHandlerResolver()Lazily create a default NamespaceHandlerResolver, if not set before.intgetValidationMode()Return the validation mode to use.protected intgetValidationModeForResource(Resource resource)Determine the validation mode for the specifiedResource.booleanisNamespaceAware()Return whether or not 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<?> 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 or not 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.从类继承的方法 org.springframework.beans.factory.support.AbstractBeanDefinitionReader
getBeanClassLoader, getBeanFactory, getBeanNameGenerator, getEnvironment, getRegistry, getResourceLoader, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, setBeanClassLoader, setBeanNameGenerator, setEnvironment, setResourceLoader
字段详细资料
VALIDATION_NONE
public static final int VALIDATION_NONE
Indicates that the validation should be disabled.- 另请参阅:
- 常量字段值
VALIDATION_AUTO
public static final int VALIDATION_AUTO
Indicates that the validation mode should be detected automatically.- 另请参阅:
- 常量字段值
VALIDATION_DTD
public static final int VALIDATION_DTD
Indicates that DTD validation should be used.- 另请参阅:
- 常量字段值
VALIDATION_XSD
public static final int VALIDATION_XSD
Indicates that XSD validation should be used.- 另请参阅:
- 常量字段值
构造器详细资料
XmlBeanDefinitionReader
public XmlBeanDefinitionReader(BeanDefinitionRegistry registry)
Create new XmlBeanDefinitionReader for the given bean factory.- 参数:
registry- the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
方法详细资料
setValidating
public 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.
setValidationModeName
public void setValidationModeName(String validationModeName)
Set the validation mode to use by name. Defaults toVALIDATION_AUTO.
setValidationMode
public 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).
getValidationMode
public int getValidationMode()
Return the validation mode to use.
setNamespaceAware
public void setNamespaceAware(boolean namespaceAware)
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.
isNamespaceAware
public boolean isNamespaceAware()
Return whether or not the XML parser should be XML namespace aware.
setProblemReporter
public void setProblemReporter(ProblemReporter problemReporter)
Specify 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.
setEventListener
public void setEventListener(ReaderEventListener eventListener)
Specify 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.
setSourceExtractor
public void setSourceExtractor(SourceExtractor sourceExtractor)
Specify 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.
setNamespaceHandlerResolver
public void setNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver)
Specify theNamespaceHandlerResolverto use.If none is specified, a default instance will be created through
createDefaultNamespaceHandlerResolver().
setDocumentLoader
public void setDocumentLoader(DocumentLoader documentLoader)
Specify theDocumentLoaderto use.The default implementation is
DefaultDocumentLoaderwhich loadsDocumentinstances using JAXP.
setEntityResolver
public void setEntityResolver(EntityResolver entityResolver)
Set 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.
getEntityResolver
protected EntityResolver getEntityResolver()
Return the EntityResolver to use, building a default resolver if none specified.
setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
Set 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.
setDocumentReaderClass
public void setDocumentReaderClass(Class<?> documentReaderClass)
Specify theBeanDefinitionDocumentReaderimplementation to use, responsible for the actual reading of the XML bean definition document.The default is
DefaultBeanDefinitionDocumentReader.- 参数:
documentReaderClass- the desired BeanDefinitionDocumentReader implementation class
loadBeanDefinitions
public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException
Load bean definitions from the specified XML file.- 参数:
resource- the resource descriptor for the XML file- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of loading or parsing errors
loadBeanDefinitions
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException
Load bean definitions from the specified XML file.- 参数:
encodedResource- the resource descriptor for the XML file, allowing to specify an encoding to use for parsing the file- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of loading or parsing errors
loadBeanDefinitions
public int loadBeanDefinitions(InputSource inputSource) throws BeanDefinitionStoreException
Load bean definitions from the specified XML file.- 参数:
inputSource- the SAX InputSource to read from- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of loading or parsing errors
loadBeanDefinitions
public int loadBeanDefinitions(InputSource inputSource, String resourceDescription) throws BeanDefinitionStoreException
Load bean definitions from the specified XML file.- 参数:
inputSource- the SAX InputSource to read fromresourceDescription- a description of the resource (can benullor empty)- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of loading or parsing errors
doLoadBeanDefinitions
protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource) throws BeanDefinitionStoreException
Actually load bean definitions from the specified XML file.- 参数:
inputSource- the SAX InputSource to read fromresource- the resource descriptor for the XML file- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of loading or parsing errors- 另请参阅:
doLoadDocument(org.xml.sax.InputSource, org.springframework.core.io.Resource),registerBeanDefinitions(org.w3c.dom.Document, org.springframework.core.io.Resource)
doLoadDocument
protected Document doLoadDocument(InputSource inputSource, Resource resource) throws Exception
Actually load the specified document using the configured DocumentLoader.- 参数:
inputSource- the SAX InputSource to read fromresource- the resource descriptor for the XML file- 返回:
- the DOM Document
- 抛出:
Exception- when thrown from the DocumentLoader- 另请参阅:
setDocumentLoader(org.springframework.beans.factory.xml.DocumentLoader),DocumentLoader.loadDocument(org.xml.sax.InputSource, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, int, boolean)
getValidationModeForResource
protected int getValidationModeForResource(Resource resource)
Determine 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.
detectValidationMode
protected int detectValidationMode(Resource resource)
Detect 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.
registerBeanDefinitions
public 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.- 参数:
doc- the DOM documentresource- the resource descriptor (for context information)- 返回:
- the number of bean definitions found
- 抛出:
BeanDefinitionStoreException- in case of parsing errors- 另请参阅:
loadBeanDefinitions(org.springframework.core.io.Resource),setDocumentReaderClass(java.lang.Class<?>),BeanDefinitionDocumentReader.registerBeanDefinitions(org.w3c.dom.Document, org.springframework.beans.factory.xml.XmlReaderContext)
createBeanDefinitionDocumentReader
protected BeanDefinitionDocumentReader createBeanDefinitionDocumentReader()
Create theBeanDefinitionDocumentReaderto use for actually reading bean definitions from an XML document.The default implementation instantiates the specified "documentReaderClass".
createReaderContext
public XmlReaderContext createReaderContext(Resource resource)
Create theXmlReaderContextto pass over to the document reader.
getNamespaceHandlerResolver
public NamespaceHandlerResolver getNamespaceHandlerResolver()
Lazily create a default NamespaceHandlerResolver, if not set before.
createDefaultNamespaceHandlerResolver
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver()
Create the default implementation ofNamespaceHandlerResolverused if none is specified.The default implementation returns an instance of
DefaultNamespaceHandlerResolver.