I'd like to call ISAN Restful API from my Java project, so I'm trying to generate java beans from xsd files using maven-jaxb2-plugin. Here are the xsds:
- http://www.isan.org/schema/v1.11/common/common.xsd
- http://www.isan.org/schema/v1.21/common/serial.xsd
- http://www.isan.org/schema/v1.11/common/version.xsd
- http://www.isan.org/ISAN/isan.xsd
- http://www.isan.org/schema/v1.11/common/title.xsd
- http://www.isan.org/schema/v1.11/common/externalid.xsd
- http://www.isan.org/schema/v1.11/common/participant.xsd
- http://www.isan.org/schema/v1.11/common/language.xsd
- http://www.isan.org/schema/v1.11/common/country.xsd
I downloaded theses files and copied them into my src/main/resources folder and defined a catalog. When I build the project, I get an error because two types have the same name:
org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/language; systemId: http://www.isan.org/schema/v1.11/common/language.xsd; lineNumber: 39; columnNumber: 48; A class/interface with the same name "org.isan.CodingSystemType" is already in use. Use a class customization to resolve this conflict.
org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/country; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (Relevant to above error) another "CodingSystemType" is generated from here.
That is correct : language.xsd and country.xsd both define a type named CodingSystemType:
<xs:simpleType name="CodingSystemType">
<xs:restriction base="xs:string">
<xs:enumeration value="ISO639_2"/>
<xs:enumeration value="RFC3066"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="CodingSystemType">
<xs:restriction base="xs:string">
<xs:enumeration value="ISO3166_1"/>
</xs:restriction>
</xs:simpleType>
As suggested, I tried to use a class customization for the country.xsd type. I added this binding in pom.xml:
<bindings>
<binding>
<url>http://www.isan.org/schema/v1.11/common/country.xjb</url>
</binding>
</bindings>
The xjc file :
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:annox="http://annox.dev.java.net"
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
<bindings schemaLocation="http://www.isan.org/schema/v1.11/common/country.xsd">
<bindings node="//xs:simpleType[@name='CodingSystemType']">
<class name="CountryCodingSystemType" />
</bindings>
</bindings>
</bindings>
Now, I get another error I can't deal with :
[ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xjb{7,58}].
com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xjb; lineNumber: 7; columnNumber: 58; compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.
[ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xsd{39,48}].
com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (the above customization is attached to the following location in the schema)