Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27276

JAXB xjc parsing fails when -binding is used together with -catalog (bug?)

Below is the absolute trivial, minimal example that demonstrates the problem. Three schema files: A.xsd, B.xsd, C.xsd in the following import configuration:

C.xsd ---------------- imports ----------------> A.xsd
  \                                          /  
   \---- imports ---> B.xsd --- imports ----/

So A.xsd is imported directly by C.xsd and again indirectly through B.xsd. The problem occurs when trying to run xjc (ver. 2.2.4) on C.xsd when both a catalog and a binding file is used (even an empty one).

A.xsd

<schema targetNamespace="foo://a"
           xmlns="http://www.w3.org/2001/XMLSchema">
   <simpleType name="year">
      <restriction base="dateTime">
         <pattern value="\d{4}"/>
      </restriction>
   </simpleType>
</schema>

B.xsd

<schema targetNamespace="foo://b"
xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="foo://a" schemaLocation="boo://a.xsd"/>
</schema>

C.xsd

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="foo://c">
  <import namespace="foo://a" schemaLocation="A.xsd"/>
  <import namespace="foo://b" schemaLocation="B.xsd"/>
</schema>

catalog.xml

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> 
    <system systemId="boo://a.xsd"  uri="A.xsd"/>
</catalog>

binding.xjb

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1"/>

Given the above files, all placed in the same directory the below invocation succeeds:

xjc -d src -extension -catalog catalog.xml C.xsd 

whereas the following invocation:

xjc -d src -extension -catalog catalog.xml C.xsd -b bindings.xjb 

... fails with the bug-like message (pointing to some internal mess-up?):

parsing a schema...
[ERROR] 'year' is already defined
  line 8 of file:/home/brutus/A.xsd

[ERROR] (related to above error) the first definition appears here
  line 3 of file:/home/brutus/A.xsd

Failed to parse a schema.

UPDATE

Posted a bug report.

Upvotes: 2

Views: 2099

Answers (2)

matthes
matthes

Reputation: 3002

I have a very similar if not the same issue. Could you find any workaround? Tested with jaxb-ri-2.2.7, xjc 2.2.4-2 (OpenJDK 7u25) and jaxb-ri-2.2.1.1-4 of GlassFish.

The most interesting thing is that when using an import without a schemaLocation in combination with a public catalog entry everything works. Unfortunately I am not able to adjust the schemas.

Here's a little example.

Failing:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:test="http://www.test.com/1.0" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" targetNamespace="http://www.test.com/1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd"/>

    <element name="TestElement" type="test:TestType"/>
    <complexType name="TestType">
        <sequence>
            <element name="name" type="string"/>
        </sequence>
        <attribute ref="xlink:title" use="required"/>
    </complexType>
</schema>

Working:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:test="http://www.test.com/1.0" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" targetNamespace="http://www.test.com/1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <import namespace="http://www.w3.org/1999/xlink"/>

    <element name="TestElement" type="test:TestType"/>
    <complexType name="TestType">
        <sequence>
            <element name="name" type="string"/>
        </sequence>
        <attribute ref="xlink:title" use="required"/>
    </complexType>
</schema>

Catalog file (for both):

<!DOCTYPE catalog
    PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
           "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">

    <system
        systemId="http://www.w3.org/1999/xlink.xsd"
        uri="../schemas/xlink/1.0.0/xlinks.xsd"/>
    <public
        publicId="http://www.w3.org/1999/xlink"
        uri="../schemas/xlink/1.0.0/xlinks.xsd"/>

</catalog>

Execution (for both):

xjc schemas/xlink/1.0.0/xlinks.xsd schemas/test.xsd -b xjb/xlink.xjb -extension -d .build -catalog catalog/catalog.xml

Upvotes: 0

bdoughan
bdoughan

Reputation: 148977

I ran your example using the XJC that comes with JDK 1.7.0_21-b12 for the Mac, and it worked fine. You should just need to switch not a newer version of XJC from the JAXB reference implmeentation (see: https://jaxb.java.net/) to get your use case to work.

For More Information

Upvotes: 1

Related Questions