users@jaxb.java.net

RE: Resolve error with JAXB XJC

From: Young Matthew (4004) <"Young>
Date: Tue, 28 Dec 2010 10:06:20 +0000

After reading a forum post http://forums.java.net/node/644180 answered by Kohsuke and a blog http://kontrawize.blogs.com/kontrawize/2007/10/the-trouble-wit.html the problem in the example given below is where XSD "A" and XSD "B" share the same namespace. Consolidating XSD "A" and XSD "B" into the same file and my include problem of the common XSD disappears.

So the problem hade nothing to do with XJC at all.


________________________________
Från: Young Matthew (4004)
Skickat: den 27 december 2010 23:03
Till: 'users_at_jaxb.java.net'
Ämne: RE: Resolve error with JAXB XJC

( sorry below should have gone to the user group....by the way I moved all of the XSD fils to C:\temp\another directory to eliminate a potential white-space problem on Windows similar to the http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015239 bug but same results)



hej,

Turns out if I wasn't in a hurry to get help and test more I would have noticed that the error has nothing to do with directory or file arguments to XJC. The problem is when one XSD imports another schema and extends a definition (ie. complex type) in yet another schema that happens to import the same schema. For example,

XSD "A" imports a commons XSD plus XSD "B"
XSD "B" also imports a commons XSD

Wolfgang, specifying a directory takes everything under that directory including the sub-directories.

Gary, the file URI is UTF encoded so the paths seem to be handled alright but I will test paths without spaces just to be sure.


mvh / Matthew

________________________________
Från: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Skickat: den 27 december 2010 17:15
Till: Young Matthew (4004)
Ämne: Re: Resolve error with JAXB XJC



On 27 December 2010 15:54, Young Matthew (4004) <matthew.young_at_forsakringskassan.se<mailto:matthew.young_at_forsakringskassan.se>> wrote:
hej,

If I run the XFCFacade with the following arguments:
@Test
public void execute() throws Throwable {
String[] args = {
"-extension",
"-d",
"C:/temp",
"-b",
"C:/workshop/klistret/CMDB CI/configuration/build/jaxb.binding.xml",
"C:/workshop/klistret/CMDB CI/src/xsd",


I'd have thought that this compiles only the files in ./xsd/, i.e., pojo..., commons..., xmlschemaNamespace

How is the hardware.cmdb.xsd included in this compilation? Is there an import of that from one of those three in ./xsd/? How does this import look like?

I don't think that relative pathnames have to be resolved w.r.t. the pathname of the schema in which it occurs. (See section 5.6, schemaLocation, in "XML Schema Part 0: Primer" - "a hint to the processor". A "hint" is a flimsy definition...)

-W



"-Xcollection-setter-injector",
"-Xinject-code",
"-Xci"};

XJCFacade.main(args);
XJC generates this type of errors:
parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'element:Component' to a(n) 'type definition' component.
line 30 of file:/C:/workshop/klistret/CMDB%20CI/src/xsd/element/component/hardware.cmdb.xsd
But if I specify a chain of files rather than giving a directory the XJC parser works fine even if the xsd files are in a jumbled order:
String[] args = {
"-extension",
"-d",
"C:/temp",
"-b",
"C:/workshop/klistret/CMDB CI/configuration/build/jaxb.binding.xml",
"C:/workshop/klistret/CMDB CI/src/xsd/element/component.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/element/component/hardware.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/pojo.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/commons.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/xmlschemaNamespace.xsd",
"-Xcollection-setter-injector",
"-Xinject-code",
"-Xci"};

XJCFacade.main(args);
Using JAXB 2.2 but have tried 2.2.2 and 2.2.3 releases without any luck. Compiling with Java 1.6. The hardware.cmdb.xsd file imports the component.cmdb.xsd to extend a complex type which subsequently extends a base complex type. So there is an import dependency between the xsd files. Debugging I see the the opt.grammars picks up all the xsd files when using just the directory there after I get lost in the XMLSchemaLoader class.

Example of the xsd files:
[hardware.cmdb.xsd]
<xs:schema xmlns="http://www.klistret.com/cmdb/ci/element/component"
targetNamespace="http://www.klistret.com/cmdb/ci/element/component"
xmlns:element="http://www.klistret.com/cmdb/ci/element"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" jaxb:version="2.0">

<xs:import namespace="http://www.klistret.com/cmdb/ci/element"
schemaLocation="../component.cmdb.xsd" />

<xs:complexType name="Hardware" abstract="true">
<xs:annotation>
<xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="element:Component"></xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="Hardware" type="Hardware"></xs:element>
</xs:schema>


[component.cmdb.xsd]

<xs:schema xmlns="http://www.klistret.com/cmdb/ci/element"
targetNamespace="http://www.klistret.com/cmdb/ci/element"
xmlns:commons="http://www.klistret.com/cmdb/ci/commons"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" jaxb:version="2.0">

<xs:import namespace="http://www.klistret.com/cmdb/ci/commons"
schemaLocation="../commons.cmdb.xsd" />

<xs:complexType name="Component" abstract="true">
<xs:complexContent>
<xs:extension base="commons:Element" />
</xs:complexContent>
</xs:complexType>

<xs:element name="Component" type="Component"></xs:element>
</
xs:schema>