posted 21 years ago
Hi Java Gurus,
I was given the task of creating a java code generator/w GUI that will
mapped attributes from 1 object to another object and generate the source of
that said mapping.
For example
Class A{
String a;
String b;
String c;
getter/setter are provided
}
Class B{
String b1;
String b2;
getter/setter are provided
}
From the wizard, just think of it a object tree in 2 panels with drag n drop capability, wherein the developer, will drag and attribute
to corresponding attribute of the other object. When finish, the genereted code will look something like this : supposing i drag, a and b attribute
of A class to b1 attribute and b2 attribute of B class correspondingly
AtoB.java
public class AtoB{
public B assign( A a){
B b = new B();
b.setB1 (a.getA());
b.setB2( a.getB());
}
}
This is pretty straight forward isn't it? Thats what i thought also,
But when i consider the different constraints like
1. What if A as a subclass C which has a subclass and so on and so forth
2. What if B as a subclass C which has a subclass and so on and so forth
3. What if A has an attribute which is an array?
4. What if A has an attribute which has a subclass and also an array.
and so on and so forth.
I just opened a pandora's box!
My question is, is there any utility /tools (both open source and commercial) that works in similar fashion available? Or perhaps
an approach to dealing with this kind of dilemma.
Any help will be greatly appreciated
Ajing