Class CombinedBeanDeclaration
- java.lang.Object
-
- org.apache.commons.configuration2.beanutils.CombinedBeanDeclaration
-
- All Implemented Interfaces:
BeanDeclaration
public class CombinedBeanDeclaration extends java.lang.Object implements BeanDeclaration
A special implementation of the
BeanDeclaration
interface which allows combining multipleBeanDeclaration
objects.An instance of this class can be used if a bean is defined using multiple sources. For instance, there can be one definition with default values and one with actual values; if actual values are provided, they are used; otherwise, the default values apply.
When constructing an instance an arbitrary number of child
BeanDeclaration
objects can be specified. The implementations of theBeanDeclaration
methods implement a logical combination of the data returned by these child declarations. The order in which child declarations are added is relevant; first entries take precedence over later ones. The comments of the single methods explain in which way a combination of the child declarations is built.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description CombinedBeanDeclaration(BeanDeclaration... decl)
Creates a new instance ofCombinedBeanDeclaration
and initializes it with the given child declarations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getBeanClassName()
Returns the name of the bean class, from which an instance is to be created.java.lang.String
getBeanFactoryName()
Returns the name of theBeanFactory
that should be used for creating the bean instance.java.lang.Object
getBeanFactoryParameter()
Here an arbitrary object can be returned that will be passed to the bean factory.java.util.Map<java.lang.String,java.lang.Object>
getBeanProperties()
Returns a map with properties that should be initialized on the newly created bean.java.util.Collection<ConstructorArg>
getConstructorArgs()
Returns a collection with constructor arguments.java.util.Map<java.lang.String,java.lang.Object>
getNestedBeanDeclarations()
Returns a map with declarations for beans that should be set as properties of the newly created bean.
-
-
-
Constructor Detail
-
CombinedBeanDeclaration
public CombinedBeanDeclaration(BeanDeclaration... decl)
Creates a new instance ofCombinedBeanDeclaration
and initializes it with the given child declarations.- Parameters:
decl
- the child declarations- Throws:
java.lang.NullPointerException
- if the array with child declarations is null
-
-
Method Detail
-
getBeanFactoryName
public java.lang.String getBeanFactoryName()
Returns the name of theBeanFactory
that should be used for creating the bean instance. This can be null, then a default factory will be used. This implementation iterates over the list of child declarations and asks them for a bean factory name. The first non-null value is returned. If none of the child declarations have a defined bean factory name, result is null.- Specified by:
getBeanFactoryName
in interfaceBeanDeclaration
- Returns:
- the name of the bean factory
-
getBeanFactoryParameter
public java.lang.Object getBeanFactoryParameter()
Here an arbitrary object can be returned that will be passed to the bean factory. Its meaning is not further specified. The purpose of this additional parameter is to support a further configuration of the bean factory that can be placed directly at the bean declaration. This implementation iterates over the list of child declarations and asks them for a bean factory parameter. The first non-null value is returned. If none of the child declarations have a defined bean factory parameter, result is null.- Specified by:
getBeanFactoryParameter
in interfaceBeanDeclaration
- Returns:
- a parameter for the bean factory
-
getBeanClassName
public java.lang.String getBeanClassName()
Returns the name of the bean class, from which an instance is to be created. This value must be defined unless a default class is provided for the bean creation operation. This implementation iterates over the list of child declarations and asks them for the bean class name. The first non-null value is returned. If none of the child declarations have a defined bean class, result is null.- Specified by:
getBeanClassName
in interfaceBeanDeclaration
- Returns:
- the name of the bean class
-
getBeanProperties
public java.util.Map<java.lang.String,java.lang.Object> getBeanProperties()
Returns a map with properties that should be initialized on the newly created bean. The map's keys are the names of the properties; the corresponding values are the properties' values. The return value can be null if no properties should be set. This implementation creates a union of the properties returned by all child declarations. If a property is defined in multiple child declarations, the declaration that comes before in the list of children takes precedence.- Specified by:
getBeanProperties
in interfaceBeanDeclaration
- Returns:
- a map with properties to be initialized
-
getNestedBeanDeclarations
public java.util.Map<java.lang.String,java.lang.Object> getNestedBeanDeclarations()
Returns a map with declarations for beans that should be set as properties of the newly created bean. This allows for complex initialization scenarios: a bean for a bean that contains complex properties (e.g. other beans) can have nested declarations for defining these complex properties. The returned map's key are the names of the properties to initialize. The values are eitherBeanDeclaration
implementations or collections thereof. They will be treated like this declaration (in a recursive manner), and the resulting beans are assigned to the corresponding properties. This implementation creates a union of the nested bean declarations returned by all child declarations. If a complex property is defined in multiple child declarations, the declaration that comes before in the list of children takes precedence.- Specified by:
getNestedBeanDeclarations
in interfaceBeanDeclaration
- Returns:
- a map with nested bean declarations
-
getConstructorArgs
public java.util.Collection<ConstructorArg> getConstructorArgs()
Returns a collection with constructor arguments. This data is used to determine the constructor of the bean class to be invoked. The values of the arguments are passed to the constructor. An implementation can return null or an empty collection; then the standard constructor of the bean class is called. This implementation iterates over the list of child declarations and asks them for constructor arguments. The first non-null and non empty collection is returned. If none of the child declarations provide constructor arguments, result is an empty collection.- Specified by:
getConstructorArgs
in interfaceBeanDeclaration
- Returns:
- a collection with the arguments to be passed to the bean class's constructor
-
-