views:

47

answers:

2

Hello,

I recently generate two versions of Java classes generated by JAXB. So I get two packages : V1_0 and V2_0

I notice that I have only one ObjectFactory generated. The problem is that this ObjectFactory is specific to a version (here it's specific to my version v1_0).

So the question is : Could I configure JAXB to allow to make one ObjectFactory for each version ?

Thanks a lot.

A: 

One object factory for both versions? Not, it is not possible. You get two sets of classes in two packages - it is not possible that one object factory serves both of them.

lexicore
No, I meant one object factory for EACH version. I would like JAXB to generate two Object Factories in two different packages. So that an objectFactory can still be specific to V1_0 or V2_0 without no problem. Thanks a lot.
mica16
I am not sure I understand the problem then. XJC normally generates an object factory per package. How exactly do you generate these two versions?
lexicore
A: 

If the two versions of the API are in the same namespace, that's horrible! You'll have the object factory from one round of generation overwriting the object factory produced by the other (or inhibiting; I forget which xjc actually does). It's also horrible for clients of the API since they won't know what version of the API they're dealing with (unless you're doing other nasty tricks, which ought to be discouraged; if they're in the same namespace they should be the same API).

The fix is to put the two APIs in different namespaces so that they get generated into different packages with different object factories. (Also beware of any use of the -p option to xjc; that can cause things to go into the same namespace and give you these overwriting headaches.)

Donal Fellows