我有一个关于包装jaxb创建类的问题,并且很想听听你的输入。评论我的JAXB对象封装器
我的XSD看起来有点像:
<ComplexService>
<ComplexObject1>
<Element1></Element1>
<Parameter></Parameter>
</ComplexObject1>
<ComplexObject2>
<Element2> </Element2>
<Parameter> </Parameter>
</ComplexObject2>
...
<ComplexObject10>
<Element10> </Element10>
<Parameter> </Parameter>
</ComplexObjec10>
通过XJC运行上面的XSD后创建的类看起来有点像:
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
}
}
现在我想创建一个封装这些CompleObjects以及ComplexService类。
public class WrappedComplexObject1{
private final ComplexObject1;
public WrappedComplexObject1(){
complexObject1 = new ComplexObject1();
}
//Delegate calls to the underlying ComplexObject1
public String getServiceName(){
return complexObject1.getServiceName();
}
}
我的问题是:
请问上述方式来包装类的首选方式?我的目标是不要混淆由xjc创建的基础类;提供一个更好的命名API(类以及方法名称)。
我也想验证这些对象中的数据。因此,我正在考虑使用修饰器模式 来进一步包装WrappedComplexObject1。这是一个推荐的方法吗?
最后,xsd包含结构相同的元素“参数”(只包含一个值字段)。但是,当xjc创建ComplexService类时,为每个ComplexObject创建一个新的Parameter类。
我应该担心只有一个“Parameter”包装类,或者我应该简单地为每个ComplexObject创建一个Parameter包装类。
任何建议,想法,代码示例将是最有帮助的。
感谢
我对这个问题很感兴趣。你有没有得到它的任何地方? – Martin 2009-12-07 00:01:32
答案如下。 – CaptainHastings 2009-12-07 17:30:43