An implementation of the {@code BeanDeclaration} interface that issuitable for XML configuration files.
This class defines the standard layout of a bean declaration in an XML configuration file. Such a declaration must look like the following example fragment:
... <personBean config-class="my.model.PersonBean" lastName="Doe" firstName="John"> <config-constrarg config-value="ID03493" config-type="java.lang.String"/> <address config-class="my.model.AddressBean" street="21st street 11" zip="1234" city="TestCity"/> </personBean>
The bean declaration can be contained in an arbitrary element. Here it is the {@code personBean} element. In the attributes of this elementthere can occur some reserved attributes, which have the following meaning:
- {@code config-class}
- Here the full qualified name of the bean's class can be specified. An instance of this class will be created. If this attribute is not specified, the bean class must be provided in another way, e.g. as the {@code defaultClass} passed to the {@code BeanHelper} class.
- {@code config-factory}
- This attribute can contain the name of the {@link BeanFactory} that should be used for creating the bean.If it is defined, a factory with this name must have been registered at the {@code BeanHelper} class. If this attribute is missing, the defaultbean factory will be used.
- {@code config-factoryParam}
- With this attribute a parameter can be specified that will be passed to the bean factory. This may be useful for custom bean factories.
All further attributes starting with the {@code config-} prefix areconsidered as meta data and will be ignored. All other attributes are treated as properties of the bean to be created, i.e. corresponding setter methods of the bean will be invoked with the values specified here.
If the bean to be created has also some complex properties (which are itself beans), their values cannot be initialized from attributes. For this purpose nested elements can be used. The example listing shows how an address bean can be initialized. This is done in a nested element whose name must match the name of a property of the enclosing bean declaration. The format of this nested element is exactly the same as for the bean declaration itself, i.e. it can have attributes defining meta data or bean properties and even further nested elements for complex bean properties.
If the bean should be created using a specific constructor, the constructor arguments have to be specified. This is done by an arbitrary number of nested {@code } elements. Each element can either have the{@code config-value} attribute - then it defines a simple value - or must beagain a bean declaration (conforming to the format defined here) defining the complex value of this constructor argument.
A {@code XMLBeanDeclaration} object is usually created from a{@code HierarchicalConfiguration}. From this it will derive a {@code SubnodeConfiguration}, which is used to access the needed properties. This subnode configuration can be obtained using the {@link #getConfiguration()} method. All of its properties canbe accessed in the usual way. To ensure that the property keys used by this class are understood by the configuration, the default expression engine will be set.
@since 1.3
@version $Id: XMLBeanDeclaration.java 1624601 2014-09-12 18:04:36Z oheger $