站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

XmlBeanDefinitionReader (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.beans.factory.xml
Class XmlBeanDefinitionReader

java.lang.Object
  extended by org.springframework.beans.factory.support.AbstractBeanDefinitionReader
      extended by org.springframework.beans.factory.xml.XmlBeanDefinitionReader
All Implemented Interfaces:
BeanDefinitionReader

public class XmlBeanDefinitionReader
extends AbstractBeanDefinitionReader

Bean definition reader for XML bean definitions. Delegates the actual XML parsing to an implementation of the XmlBeanDefinitionParser interface. Typically applied to a DefaultListableBeanFactory.

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

Since:
26.11.2003
Author:
Juergen Hoeller
See Also:
setParserClass(java.lang.Class), XmlBeanDefinitionParser, DefaultXmlBeanDefinitionParser, BeanDefinitionRegistry, DefaultListableBeanFactory

Field Summary
 
Fields inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionReader
logger
 
Constructor Summary
XmlBeanDefinitionReader(BeanDefinitionRegistry beanFactory)
          Create new XmlBeanDefinitionReader for the given bean factory.
 
Method Summary
protected  DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
          Create a JAXP DocumentBuilder that this bean definition reader will use for parsing XML documents.
protected  DocumentBuilderFactory createDocumentBuilderFactory()
          Create a JAXP DocumentBuilderFactory that this bean definition reader will use for parsing XML documents.
protected  int doLoadBeanDefinitions(InputSource inputSource, Resource resource)
          Actually load bean definitions from the specified XML file.
 int loadBeanDefinitions(EncodedResource encodedResource)
          Load bean definitions from the specified XML file.
 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 registerBeanDefinitions(Document doc, Resource resource)
          Register the bean definitions contained in the given DOM 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 setNamespaceAware(boolean namespaceAware)
          Set whether or not the XML parser should be XML namespace aware.
 void setParserClass(Class parserClass)
          Set the XmlBeanDefinitionParser implementation to use, responsible for the actual parsing of XML bean definitions.
 void setValidating(boolean validating)
          Set if the XML parser should validate the document and thus enforce a DTD.
 
Methods inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionReader
getBeanClassLoader, getBeanFactory, getResourceLoader, loadBeanDefinitions, loadBeanDefinitions, loadBeanDefinitions, setBeanClassLoader, setResourceLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlBeanDefinitionReader

public XmlBeanDefinitionReader(BeanDefinitionRegistry beanFactory)
Create new XmlBeanDefinitionReader for the given bean factory.

Method Detail

setValidating

public void setValidating(boolean validating)
Set if the XML parser should validate the document and thus enforce a DTD. Default is "true".


setNamespaceAware

public void setNamespaceAware(boolean namespaceAware)
Set whether or not the XML parser should be XML namespace aware. Default is "false".


setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
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.

See Also:
SimpleSaxErrorHandler

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Set a SAX entity resolver to be used for parsing. By default, BeansDtdResolver will be used. Can be overridden for custom entity resolution, for example relative to some specific base path.

See Also:
BeansDtdResolver

setParserClass

public void setParserClass(Class parserClass)
Set the XmlBeanDefinitionParser implementation to use, responsible for the actual parsing of XML bean definitions. Default is DefaultXmlBeanDefinitionParser.

See Also:
XmlBeanDefinitionParser, DefaultXmlBeanDefinitionParser

loadBeanDefinitions

public int loadBeanDefinitions(Resource resource)
                        throws BeansException
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
BeansException

loadBeanDefinitions

public int loadBeanDefinitions(EncodedResource encodedResource)
                        throws BeansException
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
BeansException

loadBeanDefinitions

public int loadBeanDefinitions(InputSource inputSource)
                        throws BeansException
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
BeansException

loadBeanDefinitions

public int loadBeanDefinitions(InputSource inputSource,
                               String resourceDescription)
                        throws BeansException
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
BeansException

doLoadBeanDefinitions

protected int doLoadBeanDefinitions(InputSource inputSource,
                                    Resource resource)
                             throws BeansException
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
BeansException

createDocumentBuilderFactory

protected DocumentBuilderFactory createDocumentBuilderFactory()
                                                       throws ParserConfigurationException
Create a JAXP DocumentBuilderFactory that this bean definition reader will use for parsing XML documents. Can be overridden in subclasses, adding further initialization of the factory.

Returns:
the JAXP DocumentBuilderFactory
Throws:
ParserConfigurationException - if thrown by JAXP methods

createDocumentBuilder

protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
                                         throws ParserConfigurationException
Create a JAXP DocumentBuilder that this bean definition reader will use for parsing XML documents. Can be overridden in subclasses, adding further initialization of the builder.

Parameters:
factory - the JAXP DocumentBuilderFactory that the DocumentBuilder should be created with
Returns:
the JAXP DocumentBuilder
Throws:
ParserConfigurationException - if thrown by JAXP methods

registerBeanDefinitions

public int registerBeanDefinitions(Document doc,
                                   Resource resource)
                            throws BeansException
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:
BeansException - in case of parser instantiation failure
BeanDefinitionStoreException - in case of parsing errors
See Also:
loadBeanDefinitions(org.springframework.core.io.Resource), setParserClass(java.lang.Class), XmlBeanDefinitionParser.registerBeanDefinitions(org.springframework.beans.factory.support.BeanDefinitionReader, org.w3c.dom.Document, org.springframework.core.io.Resource)


Copyright (c) 2002-2007 The Spring Framework Project.