How to handle composition?

Announcements and support of XMT, the XStream Migration Tool

How to handle composition?

Postby sproket » Wed May 12, 2010 6:58 pm

Suppose the class I'm serializing has other objects inside that are created by my application. How can I version those?

Code: Select all
<testObject version="1">
  <field1>1</field1>
  <date>1255492800000</date>
  <subObject>   ---> This does not have version info?
    <whatever>1</whatever>
  </subObject>
</testObject>
sproket
 
Posts: 5
Joined: Tue May 11, 2010 1:30 pm

Re: How to handle composition?

Postby robinshen » Wed May 12, 2010 11:55 pm

Unfortunately XMT does not handle composition. You will need to handle data migration in the root class for all embedded classes.
robinshen
Site Admin
 
Posts: 6169
Joined: Thu Jul 24, 2003 9:53 pm

Re: How to handle composition?

Postby zedkil » Sun Sep 05, 2010 11:50 am

meaning ?

Could someone give an example of composition class please ?

Thank you in advance,
zedkil
 
Posts: 1
Joined: Sun Sep 05, 2010 11:48 am

Re: How to handle composition?

Postby Larkin65 » Thu Jan 05, 2012 12:35 pm

I have two abstract classes, lets call them Car's and Wheel's. I am handling different types of cars using some inheritance. So lets say there are two derivations MonsterTruckCar and ToyCar. Additionally there are different types of wheels that correspond to the Cars, say TreadedWheel's and PlasticWheel's (the mapping does not necessarily need to be one-to-one from types of cars to types of wheels). Further Car's are composed of Wheel's.
The way I thought I would be able to do this in Java is by using an attribute of Car's to be type ArrayList<Wheel>. The issue I am having is that now when I want to use polymorphism on the Wheel's I cannot because whenever I deal with a Wheel it is through an ArrayList which is not a derived class of Wheel's.
I thought I might be able to use bounded wildcards, or just a lot of switch statements to handle different combinations but I dont think either of those would be the greatest solutions. How can I handle such a structure?
Larkin65
 
Posts: 3
Joined: Thu Jan 05, 2012 12:21 pm

Re: How to handle composition?

Postby robinshen » Fri Jan 06, 2012 2:12 am

A switch structure will be necessary in this case as XMT does not support to composite another XMT structure inside.
robinshen
Site Admin
 
Posts: 6169
Joined: Thu Jul 24, 2003 9:53 pm

Re: How to handle composition?

Postby atsteffen » Wed Nov 14, 2012 3:28 pm

So, what are the theoretical limits of compositional migration?

I was able to add recursive behavior to XMT and got some basic compositional unit tests cases to work. That was easy enough. I simply passed the node to the MigrationHelper.migrate method instead of the Document object. After migrating all fields in the top level node, I recursively call migrate on all of the non-primitive, non-reference, children elements that are remaining, passing the element node in place of the root node.

The only down side I see right now is that you will always have to traverse the entire document tree. But since you, on average, do very little work during this traversal, I don't think it adding much to the time complexity relative to reading and writing the xml in the first place.

Again, I've only tried a couple happy path unit tests. I wanted to make sure this idea had not already been tried and discarded for reasons I've not yet encountered.
atsteffen
 
Posts: 1
Joined: Wed Nov 14, 2012 3:08 pm

Re: How to handle composition?

Postby robinshen » Thu Nov 15, 2012 2:04 am

We did not tried the approach as we are careful to avoid the composition problem in our product. Just go ahead with your approach and I believe this should work.
robinshen
Site Admin
 
Posts: 6169
Joined: Thu Jul 24, 2003 9:53 pm


Return to XMT

Who is online

Users browsing this forum: No registered users and 1 guest

cron