Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choice between bindings and episodes? #131

Closed
buko opened this issue Aug 17, 2017 · 2 comments
Closed

Choice between bindings and episodes? #131

buko opened this issue Aug 17, 2017 · 2 comments

Comments

@buko
Copy link

buko commented Aug 17, 2017

I have a dependency on a project 'A'.

A defines custom bindings in an .xjb file.

I would like to use the dependency A as both a source of bindings and as an episode file.

It seems like I can't do that.

If I depend on A purely as an episode then everything works but A's bindings are lost. The result is classes are generated with properties in the native JAXB types (eg XMLGregorianCalendar).

If I depend on A purely as a binding then A's bindings get picked up but A's classes will be re-generated into my target/generated-sources/xjc directory.

If I try to depend on A as both a binding and an episode then I get nasty errors of the form:

com.sun.istack.SAXParseException2; systemId: maven:com.bubblegumproject.uia.schema:uia-datatypes-schema-binding:jar::!/xml/bindings/uia-datatypes.xjb; lineNumber: 11; columnNumber: 24; Multiple are defined for the target namespace "urn:schemas-uia:datatypes"

[ERROR] Error while parsing schema(s).Location [ jar:file:/C:/Users/ocean/.m2/repository/com/bubblegumproject/uia/schema/uia-datatypes-schema-binding/0.0.1-SNAPSHOT/uia-datatypes-schema-binding-0.0.1-SNAPSHOT.jar!/META-INF/sun-jaxb.episode{19,74}].
com.sun.istack.SAXParseException2; systemId: jar:file:/C:/Users/ocean/.m2/repository/com/bubblegumproject/uia/schema/uia-datatypes-schema-binding/0.0.1-SNAPSHOT/uia-datatypes-schema-binding-0.0.1-SNAPSHOT.jar!/META-INF/sun-jaxb.episode; lineNumber: 19; columnNumber: 74; Another is defined here

So it finds the binding in the xjb file and then it finds another bindings in the sun-jaxb.episode and it blows up.

Am I doing something wrong?

Is it not okay to have a dependency that provides custom bindings and acts as an episode dependency?

(This is all open source so I can provide links if necessary.)

@buko
Copy link
Author

buko commented Aug 18, 2017

After doing some digging:

  1. No, it's not okay to include both bindings and episodes. Episodes are bindings. They map elements directly to previously generated classes. This is why you get all those nasty multipleSchemaBinding errors if you include both.

  2. I was under the impression that I could define a simpleType and an XMLAdapter in Schema A and then have schema B depend on schema A as an episode|binding. Schema B would then use that simpleType on attributes and what not and it would automatically pick up the XMLAdapter from Schema A's xjb file. This is apparently not possible. xjb files can't be reused. Just episodes and catalogs. So Schema B has to create new bindings that set the XMLAdapter wherever A's simpleType is used.

  3. It may be possible to do this with globalBindings. A globalBindings that knows about all simpleType<=>XMLAdapter mappings could in theory be re-used across several projects. I'll dig into that possibility next. Though this won't actually lead to really modular schema compilation it would prevent endless repetitive bindings.

@buko buko closed this as completed Aug 18, 2017
@highsource
Copy link
Owner

  1. Correct, episodes are essentially bindings but it does not mean you can't use episodes with bindings. Check ogc-schemas/filter/2.0, project for instance. It uses ows-v_1_1_0 as episode via dependency and also uses two binding files.

  2. Essentially yes, you can reuse bindings of the schema A. I don't think, however that this will work via episodes as I think XJC does not generate XMLAdapter for simpleTypes in episodes (but I might be wrong here). However I don't see any problem reusing the binding file from A. Normally if you put your binding file in src/main/resources, this will be packaged in the target JAR. With dependencyResource you can reference binding files as resources in JARs so that should be no big problem. A useful trick is to compile schemas from an absolute URL + use a catalog file to rewrite URLs to local resources.

  3. Really modular schema compilation is somewhat hard. It took me huge effort to implement this in the ogc-schemas project but it is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants