users@jaxb.java.net

Re: JAXB multiple schemas with element reference

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 8 Mar 2011 09:13:36 +0100

On 8 March 2011 09:04, Alexander Broekhuis <a.broekhuis_at_gmail.com> wrote:

> Hi,
>
> Thanks for the reply.
>
> > I'm not sure either way.
> >
> > In exactly the same situation, I have simply called xjc repeatedly,
> always
> > including the common part. Either tolerate that the classes generated
> from
> > the common part are overwritten each time, or discard them. (For the
> latter,
> > consider generating into a temporary directory and running copy, compare
> or
> > both.) We were doing this in a (complex) production environment, and we
> > never had any problems.
>
> If I understand you correctly, this only works if the generated code
> is in the same project and no episode file is used, which in our
> situation is not the case.
>
> Some workarounds I can think of are:
> 1) Do generate all the schema code in one project, instead of
> splitting them up (effectively removing the need for the episode file)
> 2) Generate the code in a package per namespace (how can I do this?),
> and ignoring the namespace of the first schema (since it is already in
> a package somewhere).
>

But B.xsd is targeted into namespace ".../B". If you omit the -d
srcgen/{a,b},
you'll get A.xsd into org/.../a and stuff from B.xsd into org/.../b.

You could build the common part A.xsd -> .java -> .class in one place.

Builds B.xsd + A.xsd, C.xsd + A.xsd,... could be done wherever convenient;
just discard the result from A.xsd and refer to the common part.

Even generating the stuff from A.xsd again with each project would not
scare me too much as long as I can make sure that all build from the same
XML schema using the same compiler.

-W


> I'd like to be able to keep the separation of the schemas and
> generated code, but for (2) to work, I need to generate part of the
> second schema in a different package. Is this possible using an xpath
> expression and a binding file? The part for the different schema has
> the same namespace as the first schema has, and therefor can be
> discarded.
>
> >
> > -W
> >
> >
> >>
> >> Thanks in advance!
> >>
> >> On 3 March 2011 13:41, Alexander Broekhuis <a.broekhuis_at_gmail.com>
> wrote:
> >> > Hi,
> >> >
> >> > I've created an example. As can be seen, generating a model for B.xsd,
> >> > also generates a ObjectFactory for an element from A.xsd. The content
> >> > of this ObjectFactory is already in the generated files for A.xsd.
> >> >
> >> > A.xsd:
> >> > ---------
> >> > <?xml version="1.0" encoding="UTF-8"?>
> >> > <schema elementFormDefault="qualified"
> >> > xmlns="http://www.w3.org/2001/XMLSchema"
> >> > xmlns:a="http://www.example.org/A/"
> >> > targetNamespace="http://www.example.org/A/">
> >> >
> >> > <element name="someType" type="a:SomeType"></element>
> >> >
> >> > <complexType name="SomeType">
> >> > <sequence>
> >> > <element name="field" type="string"></element>
> >> > </sequence>
> >> > <attribute name="attr" type="string" />
> >> > </complexType>
> >> >
> >> > </schema>
> >> >
> >> > --------
> >> > B.xsd
> >> > --------
> >> > <?xml version="1.0" encoding="UTF-8"?>
> >> > <schema elementFormDefault="qualified"
> >> > xmlns="http://www.w3.org/2001/XMLSchema"
> >> > xmlns:b="http://www.example.org/B/"
> >> > xmlns:a="http://www.example.org/A/"
> >> > targetNamespace="http://www.example.org/B/">
> >> >
> >> > <import namespace="http://www.example.org/A/" />
> >> >
> >> > <complexType name="SomeTypeGroup">
> >> > <sequence>
> >> > <element ref="a:someType" minOccurs="1"
> >> > maxOccurs="unbounded" />
> >> > </sequence>
> >> > </complexType>
> >> >
> >> >
> >> > <element name="root" type="b:RootType"></element>
> >> > <complexType name="RootType">
> >> > <sequence>
> >> > <element name="someTypes" type="b:SomeTypeGroup" />
> >> > </sequence>
> >> > </complexType>
> >> > </schema>
> >> >
> >> > ---------
> >> > catalog.xml
> >> > ---------
> >> > <?xml version="1.0" encoding="UTF-8"?>
> >> > <catalog
> >> > xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
> >> >
> >> > <public publicId="http://www.example.org/A/"
> >> > uri="A.xsd"/>
> >> >
> >> > </catalog>
> >> >
> >> > --------
> >> > Shell commands
> >> > --------
> >> > mkdir srcgen
> >> > mkdir srcgen/a
> >> > mkdir srcgen/b
> >> > xjc -d srcgen/a -episode a.episode A.xsd
> >> > xjc -d srcgen/b B.xsd -b a.episode -catalog catalog.xml -extension
> >> > -classpath srcgen/a
> >> >
> >> > --------
> >> >
> >> >
> >> > On 2 March 2011 21:08, Alexander Broekhuis <a.broekhuis_at_gmail.com>
> >> > wrote:
> >> >> Hi,
> >> >>
> >> >> Thx for your reply.
> >> >>
> >> >> On 2 March 2011 18:32, Wolfgang Laun <wolfgang.laun_at_gmail.com>
> wrote:
> >> >>> There is no connection of the type/class names EventType and
> TypeType
> >> >>> to the
> >> >>> schema snippets. Please clarify this. A complete working example
> >> >>> reproducing
> >> >>> the effect would help.
> >> >>
> >> >> I "edited" my working example to something simpler, and forgot to
> >> >> rename that one EventType. I will create a small working example
> >> >> tomorrow.
> >> >>
> >> >>>
> >> >>> But is it really necessary to use an episode file? Ususally,
> compiling
> >> >>> all
> >> >>> in one run is the way to go.
> >> >>
> >> >> The project I need this for is split into multiple parts. One scheme
> >> >> belongs to a basic module, and can be extended by other modules. So
> >> >> yes, unfortunately in this case it is needed.
> >> >>
> >> >>
> >> >> --
> >> >> Met vriendelijke groet,
> >> >>
> >> >> Alexander Broekhuis
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Met vriendelijke groet,
> >> >
> >> > Alexander Broekhuis
> >> >
> >>
> >>
> >>
> >> --
> >> Met vriendelijke groet,
> >>
> >> Alexander Broekhuis
> >
> >
>
>
>
> --
> Met vriendelijke groet,
>
> Alexander Broekhuis
>