Site Navigation:


A complex binding example

This sample's code is located in the package {@link org.otvl.sbxbsamp.complex}.

The SoftBean object model

The sample's object model is provided here:

This sample uses the classic SoftBean's patterns for simple, indexed and mapped properties.

The target XML format

Here is a sample of a XML document to be mapped to the collection of SoftBean objects.

<A a1="xa1">


<a3 a4="xa4">xa3</a3>


<a5 a6="xa6">xa5</a5>

<B b1="xb1">xBa




<xB b1="xxb1">xxBa



<xB b1="xyb1">xyBa



<c c1="xc1">



<c3 c4="xc4">xc3</c3>

<yB b1="yxb1">yxBa



<yB b1="yyb1">yyBa







<xD d1="typeE" d2="xxd2">xxD



<xD d1="typeF" d2="xyd2">xyD



<xD d1="typeU" d2="xzd2">xzD















The binding specification

The binding specification can be written as following:[2]a3@a4[4]x/a5[5]x/a5@a6[4]x/B(mapx),attC1)\


Specialized rules for writing a binding specification

In the previous sample you can see that it is sometimes necessary to add and additional XML level, which is not directly linked to an object's element. To handle this case, we use "start element references" with the syntax "__ser[index]", where index references the rule where the element referenced has been defined. It is also possible to create any "start element" you want with the syntax "__sed" for "start element definition". This element may be later referenced like any other "start element" with the "__ser[index]" notation.

Indexed simple properties

It is also possible to handle properties implemented with arrays of simple values as XML sub-elements such as int[] or String[]. Just declare them in the binding specification as you would for simple properties, the corresponding XML sub-element will be rendered for each item in the array. When parsing the document, the indexed property will be built with one item for each bound sub-element. It should be generalized for collections of simple values, but it is not the case currently.