This sample's code is located in the package {@link org.otvl.sbxbsamp.abcref}.
<RootRef>
<Acontent>
<id>98</id>
<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="980"/>
</Acontent>
<Acontent>
<id>99</id>
<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="990"/>
</Acontent>
<Acontent>
<id>11</id>
<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="110"/>
</Acontent>
<AID clsName="org.otvl.sbxbsamp.abcref.ARefee" id="99"/>
<AID clsName="org.otvl.sbxbsamp.abcref.ARefee" id="100"/>
<Bcontent>
<sid>11</sid>
<CID clsName="org.otvl.sbxbsamp.abcref.CRefee" id="110"/>
</Bcontent>
</RootRef>
abcval.org.otvl.sbxbsamp.abcref.RootRef.0.aByValue=AContent(abcval)
abcval.org.otvl.sbxbsamp.abcref.RootRef.1.aByRef=AID(abcref)
abcval.org.otvl.sbxbsamp.abcref.RootRef.2.bByValue=BContent(abcval)
abcval.org.otvl.sbxbsamp.abcref.ARefee.0.id=id
abcval.org.otvl.sbxbsamp.abcref.ARefee.1.cByRef=CID(abcref)
abcval.org.otvl.sbxbsamp.abcref.BRefee.0.sid=sid
abcval.org.otvl.sbxbsamp.abcref.BRefee.1.cByRef=CID(abcref)
abcval.org.otvl.sbxbsamp.abcref.CRefee.0.cid=cid
abcref.org.otvl.sbxbsamp.abcref.ABCRef.0.clsName=@clsName
abcref.org.otvl.sbxbsamp.abcref.ABCRef.1.id=@id
abcref.org.otvl.sbxbsamp.abcref.CRefee.0.cid=cid
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");
bs.putReferencer(ARefee.class,ABCRef.class);
bs.putReferencer(BRefee.class,ABCRef.class);
bs.putReferencer(CRefee.class,ABCRef.class);
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.