org.springframework.beans.factory.xml
Class DefaultXmlBeanDefinitionParser

java.lang.Object
  extended byorg.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser
All Implemented Interfaces:
XmlBeanDefinitionParser

public class DefaultXmlBeanDefinitionParser
extends Object
implements XmlBeanDefinitionParser

Default implementation of the XmlBeanDefinitionParser interface. Parses bean definitions according to the "spring-beans" DTD, i.e. 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" doesn't need to be the root element of the XML document: This class will parse all bean definition elements in the XML file.

Since:
18.12.2003
Author:
Rod Johnson, Juergen Hoeller

Field Summary
static String ABSTRACT_ATTRIBUTE
           
static String ARG_TYPE_ELEMENT
           
static String ARG_TYPE_MATCH_ATTRIBUTE
           
static String AUTOWIRE_ATTRIBUTE
           
static String AUTOWIRE_AUTODETECT_VALUE
           
static String AUTOWIRE_BY_NAME_VALUE
           
static String AUTOWIRE_BY_TYPE_VALUE
           
static String AUTOWIRE_CONSTRUCTOR_VALUE
           
static String BEAN_ELEMENT
           
static String BEAN_NAME_DELIMITERS
           
static String BEAN_REF_ATTRIBUTE
           
static String CLASS_ATTRIBUTE
           
static String CONSTRUCTOR_ARG_ELEMENT
           
static String DEFAULT_AUTOWIRE_ATTRIBUTE
           
static String DEFAULT_DEPENDENCY_CHECK_ATTRIBUTE
           
static String DEFAULT_LAZY_INIT_ATTRIBUTE
           
static String DEFAULT_VALUE
           
static String DEPENDENCY_CHECK_ALL_ATTRIBUTE_VALUE
           
static String DEPENDENCY_CHECK_ATTRIBUTE
           
static String DEPENDENCY_CHECK_OBJECTS_ATTRIBUTE_VALUE
           
static String DEPENDENCY_CHECK_SIMPLE_ATTRIBUTE_VALUE
           
static String DEPENDS_ON_ATTRIBUTE
           
static String DESCRIPTION_ELEMENT
           
static String DESTROY_METHOD_ATTRIBUTE
           
static String ENTRY_ELEMENT
           
static String FACTORY_BEAN_ATTRIBUTE
           
static String FACTORY_METHOD_ATTRIBUTE
           
static String ID_ATTRIBUTE
           
static String IDREF_ELEMENT
           
static String IMPORT_ELEMENT
           
static String INDEX_ATTRIBUTE
           
static String INIT_METHOD_ATTRIBUTE
           
static String KEY_ATTRIBUTE
           
static String LAZY_INIT_ATTRIBUTE
           
static String LIST_ELEMENT
           
static String LOCAL_REF_ATTRIBUTE
           
protected  Log logger
           
static String LOOKUP_METHOD_ELEMENT
           
static String MAP_ELEMENT
           
static String NAME_ATTRIBUTE
           
static String NULL_ELEMENT
           
static String PARENT_ATTRIBUTE
           
static String PARENT_REF_ATTRIBUTE
           
static String PROP_ELEMENT
           
static String PROPERTY_ELEMENT
           
static String PROPS_ELEMENT
           
static String REF_ELEMENT
           
static String REPLACED_METHOD_ELEMENT
           
static String REPLACER_ATTRIBUTE
           
static String RESOURCE_ATTRIBUTE
           
static String SET_ELEMENT
           
static String SINGLETON_ATTRIBUTE
           
static String TRUE_VALUE
          Value of a T/F attribute that represents true.
static String TYPE_ATTRIBUTE
           
static String VALUE_ELEMENT
           
 
Constructor Summary
DefaultXmlBeanDefinitionParser()
           
 
Method Summary
protected  int getAutowireMode(String att)
           
protected  BeanDefinitionReader getBeanDefinitionReader()
           
protected  List getChildElementsByTagName(Element mapEle, String elementName)
          Don't use the horrible DOM API to get child elements: Get an element's children with a given element name
protected  ConstructorArgumentValues getConstructorArgSubElements(Element beanEle, String beanName)
          Parse constructor argument subelements of the given bean element.
protected  String getDefaultAutowire()
           
protected  String getDefaultDependencyCheck()
           
protected  String getDefaultLazyInit()
           
protected  int getDependencyCheck(String att)
           
protected  List getList(Element collectionEle, String beanName)
           
protected  void getLookupOverrideSubElements(Element beanEle, String beanName, MethodOverrides overrides)
          Parse lookup-override sub elements.
protected  Map getMap(Element mapEle, String beanName)
           
protected  Object getPropertyValue(Element ele, String beanName, String propertyName)
          Get the value of a property element.
protected  MutablePropertyValues getPropertyValueSubElements(Element beanEle, String beanName)
          Parse property value subelements of the given bean element.
protected  Properties getProps(Element propsEle, String beanName)
           
protected  void getReplacedMethodSubElements(Element beanEle, String beanName, MethodOverrides overrides)
           
protected  Resource getResource()
           
protected  Set getSet(Element collectionEle, String beanName)
           
protected  String getTextValue(Element ele, String beanName)
          Make the horrible DOM API slightly more bearable: get the text value we know this element contains.
protected  void importBeanDefinitionResource(Element ele)
          Parse an "import" element and load the bean definitions from the given resource into the bean factory.
protected  BeanDefinitionHolder parseBeanDefinition(Element ele)
          Parse a standard bean definition into a BeanDefinitionHolder, including bean name and aliases.
protected  BeanDefinition parseBeanDefinition(Element ele, String beanName)
          Parse the BeanDefinition itself, without regard to name or aliases.
protected  void parseConstructorArgElement(Element ele, String beanName, ConstructorArgumentValues cargs)
          Parse a constructor-arg element.
protected  void parsePropertyElement(Element ele, String beanName, MutablePropertyValues pvs)
          Parse a property element.
protected  Object parsePropertySubelement(Element ele, String beanName)
          Parse a value, ref or collection subelement of a property element
 int registerBeanDefinitions(BeanDefinitionReader reader, Document doc, Resource resource)
          Parse bean definitions from the given DOM document, and register them with the given bean factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEAN_NAME_DELIMITERS

public static final String BEAN_NAME_DELIMITERS
See Also:
Constant Field Values

TRUE_VALUE

public static final String TRUE_VALUE
Value of a T/F attribute that represents true. Anything else represents false. Case seNsItive.

See Also:
Constant Field Values

DEFAULT_VALUE

public static final String DEFAULT_VALUE
See Also:
Constant Field Values

DESCRIPTION_ELEMENT

public static final String DESCRIPTION_ELEMENT
See Also:
Constant Field Values

AUTOWIRE_BY_NAME_VALUE

public static final String AUTOWIRE_BY_NAME_VALUE
See Also:
Constant Field Values

AUTOWIRE_BY_TYPE_VALUE

public static final String AUTOWIRE_BY_TYPE_VALUE
See Also:
Constant Field Values

AUTOWIRE_CONSTRUCTOR_VALUE

public static final String AUTOWIRE_CONSTRUCTOR_VALUE
See Also:
Constant Field Values

AUTOWIRE_AUTODETECT_VALUE

public static final String AUTOWIRE_AUTODETECT_VALUE
See Also:
Constant Field Values

DEPENDENCY_CHECK_ALL_ATTRIBUTE_VALUE

public static final String DEPENDENCY_CHECK_ALL_ATTRIBUTE_VALUE
See Also:
Constant Field Values

DEPENDENCY_CHECK_SIMPLE_ATTRIBUTE_VALUE

public static final String DEPENDENCY_CHECK_SIMPLE_ATTRIBUTE_VALUE
See Also:
Constant Field Values

DEPENDENCY_CHECK_OBJECTS_ATTRIBUTE_VALUE

public static final String DEPENDENCY_CHECK_OBJECTS_ATTRIBUTE_VALUE
See Also:
Constant Field Values

DEFAULT_LAZY_INIT_ATTRIBUTE

public static final String DEFAULT_LAZY_INIT_ATTRIBUTE
See Also:
Constant Field Values

DEFAULT_DEPENDENCY_CHECK_ATTRIBUTE

public static final String DEFAULT_DEPENDENCY_CHECK_ATTRIBUTE
See Also:
Constant Field Values

DEFAULT_AUTOWIRE_ATTRIBUTE

public static final String DEFAULT_AUTOWIRE_ATTRIBUTE
See Also:
Constant Field Values

IMPORT_ELEMENT

public static final String IMPORT_ELEMENT
See Also:
Constant Field Values

RESOURCE_ATTRIBUTE

public static final String RESOURCE_ATTRIBUTE
See Also:
Constant Field Values

BEAN_ELEMENT

public static final String BEAN_ELEMENT
See Also:
Constant Field Values

ID_ATTRIBUTE

public static final String ID_ATTRIBUTE
See Also:
Constant Field Values

NAME_ATTRIBUTE

public static final String NAME_ATTRIBUTE
See Also:
Constant Field Values

PARENT_ATTRIBUTE

public static final String PARENT_ATTRIBUTE
See Also:
Constant Field Values

CLASS_ATTRIBUTE

public static final String CLASS_ATTRIBUTE
See Also:
Constant Field Values

ABSTRACT_ATTRIBUTE

public static final String ABSTRACT_ATTRIBUTE
See Also:
Constant Field Values

SINGLETON_ATTRIBUTE

public static final String SINGLETON_ATTRIBUTE
See Also:
Constant Field Values

LAZY_INIT_ATTRIBUTE

public static final String LAZY_INIT_ATTRIBUTE
See Also:
Constant Field Values

AUTOWIRE_ATTRIBUTE

public static final String AUTOWIRE_ATTRIBUTE
See Also:
Constant Field Values

DEPENDENCY_CHECK_ATTRIBUTE

public static final String DEPENDENCY_CHECK_ATTRIBUTE
See Also:
Constant Field Values

DEPENDS_ON_ATTRIBUTE

public static final String DEPENDS_ON_ATTRIBUTE
See Also:
Constant Field Values

INIT_METHOD_ATTRIBUTE

public static final String INIT_METHOD_ATTRIBUTE
See Also:
Constant Field Values

DESTROY_METHOD_ATTRIBUTE

public static final String DESTROY_METHOD_ATTRIBUTE
See Also:
Constant Field Values

FACTORY_METHOD_ATTRIBUTE

public static final String FACTORY_METHOD_ATTRIBUTE
See Also:
Constant Field Values

FACTORY_BEAN_ATTRIBUTE

public static final String FACTORY_BEAN_ATTRIBUTE
See Also:
Constant Field Values

CONSTRUCTOR_ARG_ELEMENT

public static final String CONSTRUCTOR_ARG_ELEMENT
See Also:
Constant Field Values

INDEX_ATTRIBUTE

public static final String INDEX_ATTRIBUTE
See Also:
Constant Field Values

TYPE_ATTRIBUTE

public static final String TYPE_ATTRIBUTE
See Also:
Constant Field Values

PROPERTY_ELEMENT

public static final String PROPERTY_ELEMENT
See Also:
Constant Field Values

LOOKUP_METHOD_ELEMENT

public static final String LOOKUP_METHOD_ELEMENT
See Also:
Constant Field Values

REPLACED_METHOD_ELEMENT

public static final String REPLACED_METHOD_ELEMENT
See Also:
Constant Field Values

REPLACER_ATTRIBUTE

public static final String REPLACER_ATTRIBUTE
See Also:
Constant Field Values

ARG_TYPE_ELEMENT

public static final String ARG_TYPE_ELEMENT
See Also:
Constant Field Values

ARG_TYPE_MATCH_ATTRIBUTE

public static final String ARG_TYPE_MATCH_ATTRIBUTE
See Also:
Constant Field Values

REF_ELEMENT

public static final String REF_ELEMENT
See Also:
Constant Field Values

IDREF_ELEMENT

public static final String IDREF_ELEMENT
See Also:
Constant Field Values

BEAN_REF_ATTRIBUTE

public static final String BEAN_REF_ATTRIBUTE
See Also:
Constant Field Values

LOCAL_REF_ATTRIBUTE

public static final String LOCAL_REF_ATTRIBUTE
See Also:
Constant Field Values

PARENT_REF_ATTRIBUTE

public static final String PARENT_REF_ATTRIBUTE
See Also:
Constant Field Values

LIST_ELEMENT

public static final String LIST_ELEMENT
See Also:
Constant Field Values

SET_ELEMENT

public static final String SET_ELEMENT
See Also:
Constant Field Values

MAP_ELEMENT

public static final String MAP_ELEMENT
See Also:
Constant Field Values

ENTRY_ELEMENT

public static final String ENTRY_ELEMENT
See Also:
Constant Field Values

KEY_ATTRIBUTE

public static final String KEY_ATTRIBUTE
See Also:
Constant Field Values

PROPS_ELEMENT

public static final String PROPS_ELEMENT
See Also:
Constant Field Values

PROP_ELEMENT

public static final String PROP_ELEMENT
See Also:
Constant Field Values

VALUE_ELEMENT

public static final String VALUE_ELEMENT
See Also:
Constant Field Values

NULL_ELEMENT

public static final String NULL_ELEMENT
See Also:
Constant Field Values

logger

protected final Log logger
Constructor Detail

DefaultXmlBeanDefinitionParser

public DefaultXmlBeanDefinitionParser()
Method Detail

registerBeanDefinitions

public int registerBeanDefinitions(BeanDefinitionReader reader,
                                   Document doc,
                                   Resource resource)
                            throws BeansException
Description copied from interface: XmlBeanDefinitionParser
Parse bean definitions from the given DOM document, and register them with the given bean factory.

Specified by:
registerBeanDefinitions in interface XmlBeanDefinitionParser
Parameters:
reader - the bean definition reader, containing the bean factory to work on and the bean class loader to use. Can also be used to load further bean definition files referenced by the given document.
doc - the DOM document
resource - descriptor of the original XML resource (useful for displaying parse errors)
Throws:
BeansException - in case of parsing errors

getBeanDefinitionReader

protected BeanDefinitionReader getBeanDefinitionReader()

getDefaultLazyInit

protected String getDefaultLazyInit()

getDefaultDependencyCheck

protected String getDefaultDependencyCheck()

getDefaultAutowire

protected String getDefaultAutowire()

getResource

protected Resource getResource()

importBeanDefinitionResource

protected void importBeanDefinitionResource(Element ele)
Parse an "import" element and load the bean definitions from the given resource into the bean factory.


parseBeanDefinition

protected BeanDefinitionHolder parseBeanDefinition(Element ele)
Parse a standard bean definition into a BeanDefinitionHolder, including bean name and aliases.

Bean elements specify their canonical name as "id" attribute and their aliases as a delimited "name" attribute.

If no "id" specified, uses the first name in the "name" attribute as canonical name, registering all others as aliases.


parseBeanDefinition

protected BeanDefinition parseBeanDefinition(Element ele,
                                             String beanName)
Parse the BeanDefinition itself, without regard to name or aliases.


getConstructorArgSubElements

protected ConstructorArgumentValues getConstructorArgSubElements(Element beanEle,
                                                                 String beanName)
                                                          throws ClassNotFoundException
Parse constructor argument subelements of the given bean element.

Throws:
ClassNotFoundException

getPropertyValueSubElements

protected MutablePropertyValues getPropertyValueSubElements(Element beanEle,
                                                            String beanName)
Parse property value subelements of the given bean element.


getLookupOverrideSubElements

protected void getLookupOverrideSubElements(Element beanEle,
                                            String beanName,
                                            MethodOverrides overrides)
Parse lookup-override sub elements.


getReplacedMethodSubElements

protected void getReplacedMethodSubElements(Element beanEle,
                                            String beanName,
                                            MethodOverrides overrides)

parseConstructorArgElement

protected void parseConstructorArgElement(Element ele,
                                          String beanName,
                                          ConstructorArgumentValues cargs)
                                   throws DOMException,
                                          ClassNotFoundException
Parse a constructor-arg element.

Throws:
DOMException
ClassNotFoundException

parsePropertyElement

protected void parsePropertyElement(Element ele,
                                    String beanName,
                                    MutablePropertyValues pvs)
Parse a property element.


getPropertyValue

protected Object getPropertyValue(Element ele,
                                  String beanName,
                                  String propertyName)
Get the value of a property element. May be a list etc.


parsePropertySubelement

protected Object parsePropertySubelement(Element ele,
                                         String beanName)
Parse a value, ref or collection subelement of a property element

Parameters:
ele - subelement of property element; we don't know which yet

getList

protected List getList(Element collectionEle,
                       String beanName)

getSet

protected Set getSet(Element collectionEle,
                     String beanName)

getMap

protected Map getMap(Element mapEle,
                     String beanName)

getChildElementsByTagName

protected List getChildElementsByTagName(Element mapEle,
                                         String elementName)
Don't use the horrible DOM API to get child elements: Get an element's children with a given element name


getProps

protected Properties getProps(Element propsEle,
                              String beanName)

getTextValue

protected String getTextValue(Element ele,
                              String beanName)
Make the horrible DOM API slightly more bearable: get the text value we know this element contains.


getDependencyCheck

protected int getDependencyCheck(String att)

getAutowireMode

protected int getAutowireMode(String att)


Copyright (C) 2003-2004 The Spring Framework Project.