Package org.apache.commons.configuration2.beanutils

## Class CombinedBeanDeclaration

- java.lang.Object
- - org.apache.commons.configuration2.beanutils.CombinedBeanDeclaration

- All Implemented Interfaces:
    `BeanDeclaration`

      public class CombinedBeanDeclaration
      extends Object
      implements BeanDeclaration

  A special implementation of the `BeanDeclaration` interface which allows combining multiple `BeanDeclaration` 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 the `BeanDeclaration` 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)` | Constructs a new instance of `CombinedBeanDeclaration` and initializes it with the given child declarations.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `String` | `getBeanClassName()` | Gets the name of the bean class, from which an instance is to be created.
    `String` | `getBeanFactoryName()` | Gets the name of the `BeanFactory` that should be used for creating the bean instance.
    `Object` | `getBeanFactoryParameter()` | Gets an arbitrary object that will be passed to the bean factory.
    `Map<String,​Object>` | `getBeanProperties()` | Gets a map with properties that should be initialized on the newly created bean.
    `Collection<ConstructorArg>` | `getConstructorArgs()` | Gets a collection with constructor arguments.
    `Map<String,​Object>` | `getNestedBeanDeclarations()` | Gets a map with declarations for beans that should be set as properties of the newly created bean.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CombinedBeanDeclaration

          public CombinedBeanDeclaration​(BeanDeclaration... decl)

      Constructs a new instance of `CombinedBeanDeclaration` and initializes it with the given child declarations.
      Parameters:
        `decl` - the child declarations
      Throws:
        `NullPointerException` - if the array with child declarations is null

  - ### Method Detail

    - #### getBeanFactoryName

          public String getBeanFactoryName()

      Gets the name of the `BeanFactory` 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 interface `BeanDeclaration`
      Returns:
        the name of the bean factory

    - #### getBeanFactoryParameter

          public Object getBeanFactoryParameter()

      Gets an arbitrary object 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 interface `BeanDeclaration`
      Returns:
        a parameter for the bean factory

    - #### getBeanClassName

          public String getBeanClassName()

      Gets 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 interface `BeanDeclaration`
      Returns:
        the name of the bean class

    - #### getBeanProperties

          public Map<String,​Object> getBeanProperties()

      Gets 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 interface `BeanDeclaration`
      Returns:
        a map with properties to be initialized

    - #### getNestedBeanDeclarations

          public Map<String,​Object> getNestedBeanDeclarations()

      Gets 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 either `BeanDeclaration` 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 interface `BeanDeclaration`
      Returns:
        a map with nested bean declarations

    - #### getConstructorArgs

          public Collection<ConstructorArg> getConstructorArgs()

      Gets 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 interface `BeanDeclaration`
      Returns:
        a collection with the arguments to be passed to the bean class's constructor