|
Replies:
8
-
Last Post:
Jun 29, 2007 3:08 PM
by: kohsuke
|
|
|
|
|
|
|
Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 27, 2007 5:47 PM
|
|
|
Basically i have two schemas (different targetnamespace) that reference elements from another common schema. I have to include this common schema in both the schemas as otherwise compiler won't like it. When i do that, compiler complains that a class with given name was already generated coz it would try to create duplicate class while compiling the second schema.
The question is, how could i structure my schemas so that I don't run into this issue. One potentially options is to compile them separately in different packages which works for me on most cases but on some cases i have to compile them in the same package (which is good coz there won't be duplicate classes).
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 6:37 AM
in response to: sjd00d
|
|
|
You can xjc-compile these schemas separately in such a way that the common schema is processed only once despite being imported in more than one other dependent schema. The trick is to make xjc produce for the common schema what is called an "episode" file (which is really just a custom binding file) that is then used in the compilations of the dependent schemas. This binding file basically tells xjc that it doesn't have to generate classes for the types in the common schema, because that has already been done. See the JAXB documentation for the xjc -episode command-line option. I believe it may be necessary to also use the -extension option for the dependent compilations.
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 12:09 PM
in response to: mshaffer55
|
|
|
Thanks for the suggestion. I tried what you suggested and it should solve my problem but here's the issue i get. Basically this common schema doesn't have a target namespace (and i'd like it not to include one as it's a standard RFC schema that probably intentionally didn't have a targetnamespace as it uses common schema elements that can be included in other schemas).
Now i compile this common schema with the episode switch and things are fine. When i compile the other schema (that includes the common schema) with the -b switch, i get the error "x-schema::" didnt match any schema component. This is probably because the common schema doesn't have a targetnamespace.
Is there a solution to this?
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 2:51 PM
in response to: sjd00d
|
|
|
I'm unclear on exactly what your situation is here. Like skaffman, I'm wondering whether the dependent schemas are including or importing the common schema. There's a big difference. You use xs:include to pull together multiple schema documents that all have the same target namespace. That's why the xs:include element doesn't have a namespace attribute. You use xs:import to resolve references to elements and types in a schema that has a target namespace that is different from that of the importing schema. If you are importing a schema that has no target namespace then you just leave the namespace attribute out of the xs:import element. Is that what you're doing?
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 4:19 PM
in response to: mshaffer55
|
|
|
Sorry for not clarifying this. I am INCLUDING the common schema, that common schema doesn't have a targetnamespace and ideally i don't want to have to have a targetnamespace in that and go the import route(unless that's what I have to do to get through the problem) as it's an external schema.
Message was edited by: sjd00d
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 29, 2007 5:09 AM
in response to: sjd00d
|
|
|
I'm sorry, but your problem really has nothing to do with JAXB. It stems from your misuse of xs:include, which is intended for "assembling a schema for a single target namespace from multiple schema definition documents" ( http://www.w3.org/TR/xmlschema-1/#compound-schema ). Compare this with xs:import, which is intended for "references to schema components across namespaces" ( http://www.w3.org/TR/xmlschema-1/#composition-schemaImport ).
But as I tried to tell you before, it is not necessary to add a target namespace to the common schema in order to import it.
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 7:23 AM
in response to: sjd00d
|
|
|
Are you using xsd:include or xsd:import? If the common schema has its own target namespace, then you should use xsd:import, then hopefully XJC won't get confused.
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 28, 2007 10:59 AM
in response to: skaffman
|
|
|
The common schema doesn't have targetnamespace but i can potentially include that and do the import. I tried that as well without much luck.
|
|
|
|
|
|
|
|
Re: Two schemas referencing one common schema. Compilation problem!!!
Posted:
Jun 29, 2007 3:08 PM
in response to: sjd00d
|
|
|
What if you create a dummy wrapper xsd, that has the right target namespace, which includes your common schema?
Then can you compile that schema with -episode?
|
|
|
|
|