users@jaxb.java.net

Re: Flattenning complex XSD structure during Java classes generation

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 26 Jan 2010 19:41:10 +0100

One solution would be to use the code injection plugin, to add additional
getters and setters to class B for C's fields FieldC1 and FieldC2.

See
http://weblogs.java.net/blog/kohsuke/archive/2005/06/writing_a_plugi.html or
post again, if this isn't clear enough.

An XSL transformation would work, too, but it's not always possible or
convenient to add an XSL processing step.

-W

On Tue, Jan 26, 2010 at 6:27 PM, Jeremy JGR. Grumbach <JGR_at_pulsar.be> wrote:

> Hi all,
>
> I would like to know if it is possible (maybe by using JAXB customizations)
> to simplify/flatten the generated Java classes structure. The reason is that
> my XSD is quite complex with a lot of levels which are really annoying for
> my Java application (and I *cannot* change the XSD).
>
> In the example below, I would like to merge the fields of classes B and C
> in a single "BC" class.
>
> Example:
>
> Here is an XSD:
>
> -------------------------------------------------
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="B" type="BType"/>
> <xs:complexType name="BType">
> <xs:sequence>
> <xs:element name="C" type="CType"/>
> <xs:element name="FieldB1" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
> <xs:complexType name="CType">
> <xs:sequence>
> <xs:element name="FieldC1" type="xs:string"/>
> <xs:element name="FieldC2" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
> -------------------------------------------------
>
> JAXB generation results in the following two classes: BType.java and
> CType.java
>
> -------------------------------------------------
> public class BType {
>
> protected CType c;
> protected String fieldB1;
>
> [...]
>
> }
>
> public class CType {
>
> protected String fieldC1;
> protected String fieldC2;
>
> [...]
>
> }
> -------------------------------------------------
>
> And I would like to merge these two classes to have something like that
>
> -------------------------------------------------
> public class BCType {
>
> protected String fieldB1;
> protected String fieldC1;
> protected String fieldC2;}
> -------------------------------------------------
>
> Thanks!
>
> Jeremy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>