org.springframework.beans.factory.support
Class PropertiesBeanDefinitionReader

java.lang.Object
  extended byorg.springframework.beans.factory.support.AbstractBeanDefinitionReader
      extended byorg.springframework.beans.factory.support.PropertiesBeanDefinitionReader

public class PropertiesBeanDefinitionReader
extends AbstractBeanDefinitionReader

Bean definition reader for a simple properties format. Provides bean definition registration methods for Map/Properties and ResourceBundle. Typically applied to a DefaultListableBeanFactory.

Since:
26.11.2003
Author:
Rod Johnson, Juergen Hoeller
See Also:
DefaultListableBeanFactory

Field Summary
static java.lang.String CLASS_KEY
          Prefix for the class property of a root bean definition.
static java.lang.String LAZY_INIT_KEY
          Special string added to distinguish owner.(lazy-init)=true Default is false.
protected  org.apache.commons.logging.Log logger
           
static java.lang.String PARENT_KEY
          Reserved "property" to indicate the parent of a child bean definition.
static java.lang.String REF_PREFIX
          Prefix before values referencing other beans.
static java.lang.String REF_SUFFIX
          Property suffix for references to other beans in the current BeanFactory: e.g.
static java.lang.String SEPARATOR
          Separator between bean name and property name.
static java.lang.String SINGLETON_KEY
          Special string added to distinguish owner.(singleton)=true Default is true.
static java.lang.String TRUE_VALUE
          Value of a T/F attribute that represents true.
 
Constructor Summary
PropertiesBeanDefinitionReader(BeanDefinitionRegistry beanFactory)
          Create new PropertiesBeanDefinitionReader for the given bean factory.
 
Method Summary
 java.lang.String getDefaultParentBean()
          Return the default parent bean for this bean factory.
 int loadBeanDefinitions(Resource resource)
          Load bean definitions from the specified properties file, using all property keys (i.e.
 int loadBeanDefinitions(Resource resource, java.lang.String prefix)
          Load bean definitions from the specified properties file.
protected  void registerBeanDefinition(java.lang.String beanName, java.util.Map m, java.lang.String prefix, java.lang.String resourceDescription)
          Get all property values, given a prefix (which will be stripped) and add the bean they define to the factory with the given name
 int registerBeanDefinitions(java.util.Map m)
          Register bean definitions contained in a Map, using all property keys (i.e.
 int registerBeanDefinitions(java.util.Map m, java.lang.String prefix)
          Register bean definitions contained in a Map.
 int registerBeanDefinitions(java.util.Map m, java.lang.String prefix, java.lang.String resourceDescription)
          Register bean definitions contained in a Map.
 int registerBeanDefinitions(java.util.ResourceBundle rb)
          Register bean definitions contained in a resource bundle, using all property keys (i.e.
 int registerBeanDefinitions(java.util.ResourceBundle rb, java.lang.String prefix)
          Register bean definitions contained in a ResourceBundle.
 void setDefaultParentBean(java.lang.String defaultParentBean)
          Set the default parent bean for this bean factory.
 
Methods inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionReader
getBeanClassLoader, getBeanFactory, setBeanClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE_VALUE

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

See Also:
Constant Field Values

SEPARATOR

public static final java.lang.String SEPARATOR
Separator between bean name and property name. We follow normal Java conventions.

See Also:
Constant Field Values

CLASS_KEY

public static final java.lang.String CLASS_KEY
Prefix for the class property of a root bean definition.

See Also:
Constant Field Values

SINGLETON_KEY

public static final java.lang.String SINGLETON_KEY
Special string added to distinguish owner.(singleton)=true Default is true.

See Also:
Constant Field Values

LAZY_INIT_KEY

public static final java.lang.String LAZY_INIT_KEY
Special string added to distinguish owner.(lazy-init)=true Default is false.

See Also:
Constant Field Values

PARENT_KEY

public static final java.lang.String PARENT_KEY
Reserved "property" to indicate the parent of a child bean definition.

See Also:
Constant Field Values

REF_SUFFIX

public static final java.lang.String REF_SUFFIX
Property suffix for references to other beans in the current BeanFactory: e.g. owner.dog(ref)=fido. Whether this is a reference to a singleton or a prototype will depend on the definition of the target bean.

See Also:
Constant Field Values

REF_PREFIX

public static final java.lang.String REF_PREFIX
Prefix before values referencing other beans.

See Also:
Constant Field Values

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

PropertiesBeanDefinitionReader

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

Method Detail

setDefaultParentBean

public void setDefaultParentBean(java.lang.String defaultParentBean)
Set the default parent bean for this bean factory. If a child bean definition (i.e. a definition without class attribute) handled by this factory doesn't provide a parent attribute, this default value gets used.

Can be used e.g. for view definition files, to define a parent with common attributes for all views.


getDefaultParentBean

public java.lang.String getDefaultParentBean()
Return the default parent bean for this bean factory.


loadBeanDefinitions

public int loadBeanDefinitions(Resource resource)
Load bean definitions from the specified properties file, using all property keys (i.e. not filtering by prefix).

Parameters:
resource - the resource descriptor for the properties file
Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors
See Also:
loadBeanDefinitions(org.springframework.core.io.Resource, String)

loadBeanDefinitions

public int loadBeanDefinitions(Resource resource,
                               java.lang.String prefix)
Load bean definitions from the specified properties file.

Parameters:
resource - the resource descriptor for the properties file
Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors

registerBeanDefinitions

public int registerBeanDefinitions(java.util.ResourceBundle rb)
                            throws BeanDefinitionStoreException
Register bean definitions contained in a resource bundle, using all property keys (i.e. not filtering by prefix).

Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors
BeanDefinitionStoreException
See Also:
registerBeanDefinitions(java.util.ResourceBundle, String)

registerBeanDefinitions

public int registerBeanDefinitions(java.util.ResourceBundle rb,
                                   java.lang.String prefix)
                            throws BeanDefinitionStoreException
Register bean definitions contained in a ResourceBundle.

Similar syntax as for a Map. This method is useful to enable standard Java internationalization support.

Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors
BeanDefinitionStoreException

registerBeanDefinitions

public int registerBeanDefinitions(java.util.Map m)
                            throws BeansException
Register bean definitions contained in a Map, using all property keys (i.e. not filtering by prefix).

Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors
See Also:
registerBeanDefinitions(java.util.Map, String, String)

registerBeanDefinitions

public int registerBeanDefinitions(java.util.Map m,
                                   java.lang.String prefix)
                            throws BeansException
Register bean definitions contained in a Map. Ignore ineligible properties.

Parameters:
m - Map name -> property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be strings. Class keys must be Strings. employee.class=MyClass // special property //employee.abstract=true // this prototype can't be instantiated directly employee.group=Insurance Services // real property employee.usesDialUp=false // default unless overriden employee.manager(ref)=tony // reference to another prototype defined in the same file // cyclic and unresolved references will be detected salesrep.parent=employee salesrep.department=Sales and Marketing techie.parent=employee techie.department=Software Engineering techie.usesDialUp=true // overridden property
prefix - The match or filter within the keys in the map: e.g. 'beans.'
Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors

registerBeanDefinitions

public int registerBeanDefinitions(java.util.Map m,
                                   java.lang.String prefix,
                                   java.lang.String resourceDescription)
                            throws BeansException
Register bean definitions contained in a Map. Ignore ineligible properties.

Parameters:
m - Map name -> property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be strings. Class keys must be Strings.
prefix - The match or filter within the keys in the map: e.g. 'beans.'
resourceDescription - description of the resource that the Map came from (for logging purposes)
Returns:
the number of bean definitions found
Throws:
BeansException - in case of loading or parsing errors
See Also:
registerBeanDefinitions(Map, String)

registerBeanDefinition

protected void registerBeanDefinition(java.lang.String beanName,
                                      java.util.Map m,
                                      java.lang.String prefix,
                                      java.lang.String resourceDescription)
                               throws BeansException
Get all property values, given a prefix (which will be stripped) and add the bean they define to the factory with the given name

Parameters:
beanName - name of the bean to define
m - Map containing string pairs
prefix - prefix of each entry, which will be stripped
resourceDescription - description of the resource that the Map came from (for logging purposes)
Throws:
BeansException - if the bean definition could not be parsed or registered


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