> I was looking around to find the functionality to provide a custom
> ObjectFactory when unmarshalling an XML file, and was surprised when I
> didn't find it.
Unfortunately you can't do that right now.
> It seemed to me that a sensible approach to using the JAXB generated classes
> would be to extend those classes into my own specific objects, and then
> extend the generated ObjectFactory and overload the methods to construct my
> derived classes instead.
I agree with you. At least such an use should be supported.
Although you should note that there are some problems with your approach.
Suppose you have the foo type deriving from the bar type. You'll get
Java Foo class extending the Bar class.
If you just override ObjectFactory and use your MyFoo and MyBar, MyFoo
wouldn't be deriving from MyBar.
For this reason, and plus the fact that you are extending from a class
that is supposedly a black box, I don't think it's really the best way
to combine your behaviors to JAXB objects. I agree that it's nice to
have, but I just don't think that should be the recommended way..
I think a better approach is a visitor pattern support. This will let
you combine your logic into JAXB objects without breaking abstractions.
regards,
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net