When you scatter the components of an object in this way the current code will create a new instance of the object each time you get to one. A workaround is to use a factory-method with a signature like: public static ObjectClass childFactory(Object obj) It'll be called with the containing object, so you can cast to the appropriate type and either return the existing object or create a new instance. Assuming your elements are actually ordered, you could even just use the factory-method in a second <structure> reference so you know the object will always exist:

 <mapping name="FindBeneficiaryResponse" 
class="com.caremark.psd.infrastructure.model.Beneficiary">

<structure field="beneficiaryKey">
<value style="element" name="externalID" field="externalID"/>
<value style="element" name="personCodeNumber" field="personCode"/>
</structure>


   <value style="element" name="lastname" get-method="getLastName"
set-method="setLastName"/>
   <value style="element" name="firstname" get-method="getFirstName"
set-method="setFirstName"/>
   <value style="element" name="middlename" get-method="getMiddleName"
set-method="setMiddleName"/>

   <structure field="beneficiaryKey"
factory-method="com.caremark...Beneficiary.childFactory">
     <value style="element" name="carrierID" field="carrierID"/>
     <value style="element" name="groupID" field="groupID"/>
   </structure>

</mapping>

 - Dennis

Arora, Yogesh wrote:

We have following xml

        <ecs:FindBeneficiaryResponse>
                        <ecs:externalID>9999999999</ecs:externalID>
                        <ecs:personCodeNumber>00</ecs:personCodeNumber>
                        <ecs:lastname>XXXXX</ecs:lastname>
                        <ecs:firstname>YYYYY</ecs:firstname>
                        <ecs:middlename>X</ecs:middlename>
                        <ecs:carrierID>9999</ecs:carrierID>
                        <ecs:groupID>1111</ecs:groupID>
        </ecs:FindBeneficiaryResponse>

We are trying to bind externalID,personCodeNumber,carrierID and groupID
(i.e. 1st,2nd,6th and 7th) elements to one Java object which is contained
inside the main java object. Elements 3rd ,4th and 5th are part of container
class. We have found that we are only getting last two elements i.e. 6th and
7th populated in the contained Java object. We have tried using test-method
attribute in the structure for contained class but that did not make any
difference.

Is there any way we can avoid creating the new instance of contained class
if it has already been initialized and set in the container object?

This is the part of binding xml.

 <mapping name="FindBeneficiaryResponse"
class="com.caremark.psd.infrastructure.model.Beneficiary" ordered="false">
   <structure field="beneficiaryKey"
test-method="isBeneficiaryKeyInitialised" ordered="false" usage="optional">

<value style="element" name="externalID" field="externalID"
usage="optional"/>
<value style="element" name="personCodeNumber" field="personCode"
usage="optional"/>
<value style="element" name="carrierID" field="carrierID"
usage="optional"/>
<value style="element" name="groupID" field="groupID"
usage="optional"/>
</structure>


   <value style="element" name="lastname" get-method="getLastName"
set-method="setLastName" usage="optional"/>
   <value style="element" name="firstname" get-method="getFirstName"
set-method="setFirstName" usage="optional"/>
   <value style="element" name="middlename" get-method="getMiddleName"
set-method="setMiddleName" usage="optional"/>
</mapping>


Thanks,

Yogesh Arora



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to