Site Navigation:


Support for references

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

The SoftBean object model

The sample's object model is provided here:

The target XML format




<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="980"/>




<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="990"/>




<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="110"/>


<AID clsName="org.otvl.sbxbsamp.abcref.ARefee" id="99"/>

<AID clsName="org.otvl.sbxbsamp.abcref.ARefee" id="100"/>



<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="110"/>



The binding specification

Reference handling

It is quite easy to handle references.

First, you must provide a class that encapsulates the references and that will be serialized in XML just as any other SoftBean. In the sample, this is ABCRef. It is used to handle any reference in the sample. This class must handle equals/hashcode correctly.

Secondly, you must register each referenced class to the binding specification. In the sample, the following code is used:

BindingSpec bs = BindingSpec.getInstance("abcref");




Lastly, each referenced class must realize the XmlReferencee interface.

Now each time the XML rendering process handles an object of one of those three referenced classes with the binding specification named in the sample “abcref”, it substitutes the object with a referencer instance from the class ABCRef thanks to getSbxbReference.

When analyzing a XML document, any references are substituted back to real instances. Only one object with a given reference value will be instantiated (however two objects of two different classes may share the same reference value). Moreover, once the reference has been successfully analyzed, the parser calls the XmlReferencee method named setSbxbReference: if the referencee has just been instantiated, it can take the chance to initialize its state. At the end of parsing, all objects pointing to the same referenced one (in the sense of “equals”) will share the same instance.