users@jaxb.java.net

Re: controlling inheritence/inlining classes

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Sun, 2 Sep 2012 23:27:04 +0200

Hi,

I don't think it is possible at the moment. Three types into one
class... No, I would't know how to do this.
Pre-transformation would be the simplest thing to make it work.
Otherwise I could imagine a special plugin.



By the way, your sample has an element ref onto complex type which is
a bit incorrect. You probably have a pairing global element. But then
the merging of three classes as you want it won't be as you show it.
Elements of Sub1 and Sub2 wll be subelements of Sub1.

Bye,
/lexi

On Wed, Aug 15, 2012 at 2:32 PM, Andrew Geery <andrew.geery_at_gmail.com> wrote:
> When I use xjc on the schema fragment at the bottom of this message, I end
> up with three classes: TopLevel, Sub1 which extends Sub2. I would like to
> use the generated classes for JPA (in fact, I'm using hyperjaxb3 to generate
> both the JPA and XML bindings). In order for this to work, I really don't
> want the classes Sub1 and Sub2 generated; I want their definitions to be
> rolled up into the TopLevel class (otherwise, I end up on the JPA side of
> things with Sub1 being an @Embeddable class, but extending Sub2 which isn't
> supported in JPA; plus, Sub1 has one-to-many relationships with other
> entities which don't map well with an @Embeddable class). That is, I really
> want a TopLevel class generated from this structure:
>
> <xsd:complexType name="TopLevel">
> <xsd:sequence>
> <!-- TopLevel elements -->
> <!-- Sub1 elements -->
> <!-- Sub2 elements -->
> </xsd:sequence>
> </xsd:complexType>
>
> Is there any way to tell xjc, via the bindings.xml file, to in-line the
> properties into a single class or to "flatten" the class hierarchy? Is
> there an option in hyperjaxb3 to do this? My workaround is to transform the
> schema before I run xjc, but I was wondering if there was a better way?
>
> Thanks
> Andrew
>
> <xsd:complexType name="TopLevel">
> <xsd:sequence>
> <!-- other elements -->
> <xsd:element ref="Sub1"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Sub1">
> <xsd:complexContent>
> <xsd:extension base="Sub2">
> <xsd:sequence>
> <!-- other elements -->
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="Sub2">
> <xsd:complexContent>
> <xsd:sequence>
> <!-- elements -->
> </xsd:sequence>
> </xsd:complexContent>
> </xsd:complexType>