Dean Hiller
Dean Hiller

Reputation: 20190

complex jaxb scenario on generation of java objects

I have a project that does JAXB generation with framework.xsd. This generates a jar with the xsd and the jaxb objects and other classes around that stuff.

Then another group(two different groups) will be extending framework.xsd and subxmling using the schema extends stuff to extend objects in framework.xsd. They also want to generate jaxb objects BUT they want their SomeClass.java to obviously extend my Framework.java and don't want to end up with a whole new heirarchy.

  1. Is this even possible?
  2. How to do something like this? as the solution would need to
    1. tell the jaxb compiler that the namespace yy is already generated so do not generate
    2. tell the jaxb compiler that it needs to refer to the classes in the package zzzzzz or to look at the xjb file from the framework jar file or something.

Is this possible? thanks, Dean

Upvotes: 2

Views: 314

Answers (1)

Patrice M.
Patrice M.

Reputation: 4319

You want to use an episode file : http://weblogs.java.net/blog/kohsuke/archive/2006/09/separate_compil.html when generating JAXB classes for your first schema.

$ xjc -episode framework.episode framework.xsd

Then the other group that consumes your framework.jar should:

1) import your schema in their own schema e.g.:

<xsd:import namespace="http://www.myorg.com/framework" schemaLocation="framework.xsd"/>

2) generate their JAXB classes

$ xjc extend.xsd -b framework.episode

(they'll need a copy of your xsd and episode file at xjc time, as well as the framework.jar in the classpath)

Note that according to the blog post above, you can also place the framework.episode file inside your jar (e.g. /META-INF/sun-jaxb.episode for JAXB RI at least - other JAXB impl may have other ways of accomplishing the same thing), so that the -b framework.episode option can be omitted. I personally find it a bit impractical, you still need the XSD anyway.

Upvotes: 1

Related Questions