users@jaxb.java.net

RE: Flattenning complex XSD structure during Java classes generation

From: Gary Gregory <GGregory_at_seagullsoftware.com>
Date: Wed, 27 Jan 2010 12:57:57 -0500

I am not sure I was clear enough about my suggestion to roll your own XSD and then match it with your required XSD via XSL.

Another approach would be to generate JAXB from your Java classes and then match the XML JAXB produces with your runtime XML via XSL.

Either way the idea is to use XSL at runtime to convert documents that are instances of your “big” required XSD to match XML that your application can find easier to digest.

I hope this is less confusing ;)

Gary

From: Jeremy JGR. Grumbach [mailto:JGR_at_pulsar.be]
Sent: Wednesday, January 27, 2010 08:48
To: users_at_jaxb.dev.java.net
Subject: RE: Flattenning complex XSD structure during Java classes generation

Thanks for your answers!

Indeed, writing my own XSD is not an option because I am not the owner of the XSD and its size is really big.

It seems that the Code Injection Plugin requires changes in the XSD itself. And I cannot change it. However, a solution could be to create my own JAXB Plugin dedicated to my “business”. I will search more information about JAXB Plugin possibilities (for unmarshalling and marshalling) .

Jeremy

From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: Tuesday, January 26, 2010 7:41 PM
To: users_at_jaxb.dev.java.net
Subject: Re: Flattenning complex XSD structure during Java classes generation


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<mailto: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<mailto:users-unsubscribe_at_jaxb.dev.java.net>
For additional commands, e-mail: users-help_at_jaxb.dev.java.net<mailto:users-help_at_jaxb.dev.java.net>