0
votes

I am currently working on having the Maven JAXB plugin generate the model for a really complex set of Xml schemas. I started with all schemas being in one Maven module. The resulting module was able to parse any document in that language. Unfortunately I had to split up this one module into several ones due to the fact that I needed to import that schema and model in another module. It seems that there are issues with the episode files in case of multi-schema modules.

Now for example I have one schema defining the general structure of the xml format and defines the basic types (Let's call that A). Now there are several other schemas each implementing sub-types of these base types (Let's call one of those B).

I created the modules so B extends A. Unfortunately now it seems that I am unable to parse documents anymore. I can see that in module B a ObjctFactory for A has been created containing only definitions for all the types that B extedns from A. All the others are not present anymore.

As long as this ObjectFactory is present I am not able to parse anything, because the definition of the root elemment is missing. If I delete it, all the elements defined in B are missing from the resulting object tree.

Having compared the original ObjectFactory in the module with all the schemas, I could see that in the first version there were tons of "alternatives" that sort of told the parser which elements could possibly come. In the split-up version these are missing, so I guess that if I delete the partial ObjectFactory in B the one in A is used and this one doesn't know about the elements in B.

So how can I have JAXB parse all alements in A and B. Is there some way to extend ObjectFactories? If yes, how is this done?

I guess the next thing that could be causing trouble could be that I have several schemas extending A so I have documents containing A, B, C, D and E where B, C, D and E all extend A but are completely unreleated to each other. I guess extending woudn't be an option in that case.

1

1 Answers

0
votes

I have ran into this situation a lot when doing the OGC Schemas and Tools Project. This project has tons of schemas using one another.

Here are few tips for you:

  • Separate individual schemas into individual Maven modules. One schema - one jar.
  • Generate episode files.
  • Use these episodes and separate schema compilation to avoid generating classes for the imported schema.
  • Still, XJC will generate things for the imported schema here and there - even if your episode file says you don't need anything. Mostly these things can be just removed. I was using the Ant plugin to delete these files during the build.
  • In the runtime you just include all the JARs you need and build you JAXB context for the context path com.acme.foo:com.acme.bar

You might want to check the OGC project I mentioned. This project has a huge number of interrelated schemas, with different coexisting versions.