Hello Ladies and Gents,
I have a question on wrapping a jaxb created class and would really like to hear your inputs.
My xsd looks a bit like:
<ComplexService>
<ComplexObject1>
<Element1></Element1>
<Parameter></Parameter>
</ComplexObject1>
<ComplexObject2>
<Element2> </Element2>
<Parameter> </Parameter>
</ComplexObject2>
...
<ComplexObject10>
<Element10> </Element10>
<Parameter> </Parameter>
</ComplexObjec10>
The class created after running the above xsd through xjc looks a bit like :
public class ComplexService{
ComplexObject1 object1;
ComplexObject2 object2;
...
ComplexObject10 object10;
public static class ComplexObject1{
//Accessors and mutators on ComplexObject1
}
public static class ComplexObject2{
//Accessors and mutators on ComplexObject1
}
...
public static class ComplexObject10{
//Accessors and mutators on ComplexObject1
}
}
Now I want to create a wrapper around these CompleObjects as well the ComplexService class.
public class WrappedComplexObject1{
private final ComplexObject1;
public WrappedComplexObject1(){
complexObject1 = new ComplexObject1();
}
//Delegate calls to the underlying ComplexObject1
public String getServiceName(){
return complexObject1.getServiceName();
}
}
My questions are these:
Would the above way be the preferred way to wrap the class? My objectives are to not mess with the underlying classes created by xjc; to provide a better named api (Class as well as method names).
I also want to validate the data in these objects. Therefore I am thinking of using the decorator pattern to further wrap WrappedComplexObject1. Would this be a recommended approach?
Lastly, the xsd contains the element "Parameter" which is structurally the same (just contains one value field). However, when xjc created the ComplexService class, for every ComplexObject a new Parameter class was created.
Should I worry about just having one wrapper class for "Parameter" or should I simply create one Parameter wrapper classes per ComplexObject.
Any suggestions, ideas, code samples would be most helpful.
Thanks