Friday, December 29, 2006

XBean list of Strings

If you use XBean you probably encounter common (in my opinion) problem - XBean documentation sucks. I like short and concrete documentation but XBean exaggerates this idea ;) For example it is not explained how to fill collection of primitives e.g. String. If your bean consists of such construct:

private Collection<String> strings;

public Collection<String> getStrings() {
return strings;
}

public void setStrings(Collection<String> strings) {
this.strings = strings;
}

you will have problems in writing appropriate XML file with this bean definition.

In bare Spring you will do simple thing:

<property name="strings">
<list>
<value>Bob</value>
<value>Julia</value>
<value>Steven</value>
</list>
</property>


In XBean you cannot use <list> tag because it is unknown... What you can do is to add following entry to your schema definition (META-INF/services/org/apache/xbean/spring/$namespace):

string = java.lang.String
java.lang.String(java.lang.String).propertyNames = value

and then you will be able to use such notation in your bean defining XML:

<strings>
<string value="Bob" />
<string value="Julia" />
<string value="steve" />
</strings>


Please refer to this document spring-forward-2006-xbean-spring.pdf in order to find out more about XBean capabilities (note that this document does not explain my problem also).

No comments: