|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Generating one java class for subnodes with the same structureHi.
I m novice on JAXB and I ve faced with next problem. I generate java classes from schema. Used jaxb transformation as follows: <jaxb:bindings node="xsd:complexType[@name='Contract']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType"> <jaxb:typesafeEnumClass name ="Terms"/> </jaxb:bindings> <jaxb:bindings node="xsd:complexType[@name='Task']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType"> <jaxb:typesafeEnumClass name ="Terms"/> </jaxb:bindings> Contract and Task classes are generated and in each one inner class Terms is generated . I want to have just one inner class Terms in one of the classes. And in another this class Terms should be used. Is it possible to do with JAXB? Thanks Yauhen |
|
|
Re: Generating one java class for subnodes with the same structureDefining the same schema type twice is evil. If you can change the schema, create a named
simple type and use it in both elements. No customization will be required any more. If you can't do that, then you could use a more complicated customization on the second element: <jaxb:bindings node="xsd:complexType[@name='Task']/.../xsd:simpleType"> <jaxb:javaType name ="generated.Contract.Terms" parseMethod="util.Helper.parseStr2Terms" printMethod="util.Helper.printTerms2Str"/> </jaxb:bindings> and implement util.Helper: package util; import generated.Contract.Terms; public class Helper { public static Terms parseStr2Terms( String value ){ return Enum.valueOf(Terms.class, value ); } public static String printTerms2Str( Terms value ){ return value.toString(); } } And, if possible, tell the schema author(s) to change their ways ;-) -W On Tue, Oct 6, 2009 at 12:33 PM, yauhen p <yauhen_p@...> wrote:
|
| Free embeddable forum powered by Nabble | Forum Help |