users@jaxb.java.net

JAXB multiple schemas with element reference

From: Alexander Broekhuis <a.broekhuis_at_gmail.com>
Date: Wed, 2 Mar 2011 07:48:05 +0100

Hi all,

The following question was posted, by me, to stackoverflow, but maybe
this is a better place to ask.
(http://stackoverflow.com/questions/5155414/jaxb-multiple-schemas-with-element-reference)

I have two schema's which are processed using JAXB. The first schema
is preprocessed and information of this is used using an episode file
(following http://www.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21).
The second schema imports the first, and again using jaxb, is
processed. This all works as expected.

But now I have an element in the first schema, which is used in the
second using a reference.

Schema a:

<schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Test/">
<element name="type" type="test:MyType"></element>

Schema b:

<schema elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:second="http://www.example.org/Second/"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Second/">

<import namespace="http://www.example.org/Test/" />

<complexType name="SomeType">
    <sequence>
        <element ref="test:type" minOccurs="1" maxOccurs="unbounded" />
    </sequence>
</complexType>

During processing nothing is wrong, but the generated code for both
schemas provide the same method:

public JAXBElement<EventType> createType(TypeType value)

At runtime, this results in the following error:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
    IllegalAnnotationExceptions
The element name {http://www.example.org/Type/}type has more than one mapping.

How can I prevent JAXB from creating the duplicate createType methods?

Thanks in advance!


-- 
Met vriendelijke groet,
Alexander Broekhuis