Hi,

Sorry for a separate post. After posted the message, I managed to find a way to provide flatten mapping for Equipment using serializer and deserializer.

So now I have the binding defined as follow:

<mapping name="lineitem"
          class="com.waveman.poc.EquipmentLineItem">
      <value name="name"
              field="equipment"
              serializer="com.waveman.poc.BindingUtils.equipmentToString"
deserializer="com.waveman.poc.BindingUtils.stringToEquipment"
      />
      <value name="quantity" field="quantity" />
</mapping>

However, I still could not figure out how to have different element name based on Equipment subclasses. The current binding always map Equipment to <name> tag under <lineItem> here is the example (which is not the correct one).

<equipment>
  <lineitem>
      <name>Siemens S45</name>
      <quantity>10</name>
  </lineitem>
  <lineitem>
     <name>O2 XDA</name>
     <quantity>5</quantity>
</equipment>

So now, the revised (and hopefully, final) question is, how to define the binding to have element name different, based on subclasses of Equipment (like the example XML file in my previous post)?

Regards,

Vairoj

Vairoj A. wrote:
Hi,

After my previous post with suggestion from Dennis, I have re-evaluate the structure of both domain object and XML with other application requirements. It is confirm the the domain object has to remain unchanged. However, the XML structure can be changed.

So the same object model:

class Person {
 private Set<EquipmentLineItem> lineItems;
}

class EquipmentLineItem {
 private Equipment equipment;
 private int quantity;
}

abstract class Equipment {
 private String name;
}

class Phone extends Equipment {
   private int someOtherAttrib;
}

class Pda extends Equipment {
   private String someOtherAttrib;
}

Now, the XML will be look like what Dennis suggested in his reply to my previous post:

<equipment>
  <item>
     <phone>Siemens S45</phone>
     <quantity>5</quantity>
  </item>     <item>
     <pda>O2 XDA</pda>
     <quantity>2</quantity>
  </item>
</equipment>

Point to note is that, the binding will not construct Equipment subclass itself this time. As you can see from the class declaration, there are some other attributes specific to each subclass. So I would like to delegate the instantiation of Equipment subclass to a factory method instead. The factory method returns correct instance (fully initialized) based on String between <phone> tag or <pda> tag (i.e. Siemens S45, O2 XDA)

public static Equipment getEquipment(String equipmentName)

Based on the above requirements, I am having 2 issues regarding binding:

1. How can I define the mapping for equipment so that different subclass map to different element name?

2. I don't seems to make use of factory attribute correctly. While it use the factory method to create new instance, it still override values of the instance with one from the XML, which I do not want.

Could you give me a binding example for the situation? I am kind of stuck now. Thank you very much, I know that the question is not a short one.

Regards,

Vairoj





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to