Hi,This question combines structure mapping with abstract mapping, so it makes me confuse. However, I still not sure on how to separate the issue so maybe you guys could help me here.
This is a sample XML data:
<person>
<name>Jack</name>
<equipment>
<phone>
<phone-name>Siemens S45</name>
<phone-quantity>5</quantity>
</phone>
<pda>
<pda-name>O2 XDA mini</name>
<pda-quantity>2</quantity>
</pda>
</equipment>
</person>
A person has a set of equipment line items, equipments can be
categorized into 2 categories - phone and pda. Each line item is
composed of name of the equipment and quantity. Please note that the tag
that describe each line item is different by the type of equipment it
contains.
The following are the classes which shows only parts that are relevant to the mapping:
class Person {
private Set<EquipmentLineItem> lineItems;
}
class EquipmentLineItem {
private Equipment equipment;
private int quantity;
}
abstract class Equipment {
private String name;
}
class Phone extends Equipment {
}
class Pda extends Equipment {
}
I have also attached an image file which is the class diagram for the
preceding classes.
The question is how to map this class structure to the above XML format. There is several issue (for me).
- the structure is not symmetric. While in java class it is a collection of equipments, in XML the tag is up to the specific equipment type.
- In java class quantity attribute resides in EquipmentLineItem, whereas in XML they are all in the same level.
- sub element in each equipment has different element name depends on equipment type
Is it possible to do this type of mapping? Please suggest me. If it is not possible, I could adjust the class structure to which can be map better.
Regards, Vairoj
<<attachment: diagram.jpg>>
