users@jaxb.java.net

Re: Class generation and <xsd:include>

From: Pratt, Jerald <jerpratt_at_northropgrumman.com>
Date: Thu, 15 May 2003 14:22:10 -0700

I am trying to do something similar with similar results. In my situation,
I have 3 different namespaces (let's call them A, B, and C). C provides
common tools that are used by both A and B.

My A namespace consists of a collection of XSD files that all belong to the
same namespace with a single file defining the root element. In this root
XSD file, I have an <xs:import namespace="C" schemaLocation="C.xsd">
statement for namespace C and a collection of <xs:include> elements to
include the other XSD files w/in the same namespace.

My B namespace lives in a single XSD file so in this file I only have a
single <xs:import> line that looks just like the one mentioned above.

My problem is that I have not been able to figure out how to get these into
3 different packages w/out having to duplicate the entries found in the
common namespace C. What I've had to do is run xjc for the A namespace
where all the XSD files for A and C existed:

  xjc -d src -p xxx.A A.xsd

And then again, run xjc for the B namespace where all the XSD files for B
and C existed:

  xjc -d src -p xxx.B B.xsd

But this produces duplicate classes for the C namespace items existing in
both the xxx.A and xxx.B package.

Is there anyway to create a common xxx.C package that both xxx.A and xxx.B
can reference so that I don't have to have common classes w/in both of these
packages???

Jerald Pratt


-----Original Message-----
From: Franklin, Brian [mailto:brian.franklin_at_ciraden.com]
Sent: Tuesday, April 22, 2003 1:25 PM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: Class generation and <xsd:include>


If I understand your intent correctly, then I know that it can be
accomplished fairly easily. What you probably need to do is define a
targetNamespace in your common.xsd file. I know that's a quick answer, but
if you'd like I can post an example.

Brian Franklin

-----Original Message-----
From: Doug Holmes [mailto:dholme_at_ACXIOM.COM]
Sent: Tuesday, April 22, 2003 3:38 PM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: Class generation and <xsd:include>


We've been using JAXB 1.0 and are pretty happy with it. I have one question
about how imported schemas are generated, because we would like to share
some common elements across many schemas.

Since each schema that includes these common elements creates JAXB objects
for them in a different package, I can't have common code to pack/unpack the
common elements.

The only solution I can think of is to put the same interface on the various
versions of the same object in the different packages, but JAXB 1.0 seems to
preclude adding specific interfaces to specific generated objects.

Just so I understand what my tradeoffs are, I was wondering what the "good
reason" (see below) is that these common schema definitions are duplicated?



On Tue, 21 Jan 2003 13:30:38 -0800, Kohsuke Kawaguchi
<Kohsuke.Kawaguchi_at_Sun.COM> wrote:

>The package is per-namespace basis. IOW, if two components are in the
>same namespace (regardless of the source .XSD file it is defined), they
>will end up in the same package.
>
>It's not clear to me whether your child schemas are all belong to a
>difference target namespace URI or the same namespace URI.
>
>If they are different, you end up receiving duplicates of
>common_types.xsd in every package (for a good reason, BTW),
>
>If they are the same, all the components from all your children schemas
will
>be generated into the same package.
>
>
>regards,
>--
>Kohsuke KAWAGUCHI 408-276-7063 (x17063)
>Sun Microsystems kohsuke.kawaguchi_at_sun.com