Type converters and the Blueprint Container
During injection, the Blueprint Container converts the XML value elements into value objects that are injected into the manager components. The elements are converted based on the type of the injected property.
-
- String values can be converted to all primitive types, wrapper types, or any types that have a public constructor that takes a String value.
- Array elements can be converted to collection objects with compatible member types.
- List or set elements can be converted to array objects with compatible member types.
The Blueprint Container also supports generics. If the generics information is available, the Blueprint Container uses that information for the conversions. For example, in the following Blueprint XML example code, the list element is converted into a list of java.util.Long objects.
public class AccountManager {
...
public void setAccountNumbers(List<Long> accounts) {
...
}
}
<bean id="accountManagerFour" class="org.apache.aries.AccountManager">
<property name="accountNumbers">
<list>
<value>123</value>
<value>456</value>
<value>789</value>
</list>
</property>
</bean>
A Blueprint bundle can also provide its own converters. The custom converters are bean managers that provide an object that implements the Blueprint Converter interface. Specify the custom converters in the type-converters element under the Blueprint element. When the Blueprint Container is initialized, the type converters are initialized first, so that other managers can use the custom converters. For further details, see the Blueprint Container specification.