users@jaxb.java.net

Re: JAXB - Automatic creation of mandatory children

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 22 Sep 2004 15:36:35 +0200

Hi.

> I think what you are mentioning makes a lot of sense.
> As you correctly said, a valid XML is not just limited
> to creating the mandatory children.
>
> But all that I understand at the moment is just that
> there are other things that should also be taken care
> of and that "default" XML fragments need to be
> provided.
>
> However, I have absolutely no idea what this looks
> like or how exactly I should do this.
>
> This is something I should start working on
> immediately for my current project. It would be really
> helpful if you can point me to some kind of
> tutorial/example/whatever to help me do this.
>
> Your help is greatly appreciated.

I've desided to check about default XML fragments today. Sorry, I could
not found a satisfactory decision.

Let me sketch that out. The problem is a lot of manual work when
creating new XML objects since we have to initialize a lot of mandatory
fields etc.

This problem could be solved by "defaulting" objects when creating them.
For instance, we could inherti from object factory overriding createXXX
methods so that they default fields of the created objects.
Overriden createXXX method could call other createXXX method when
instantiating values for complex fields.

In this case instances created by this object factory will be somehow
defaulted.

In my opinion this is still a partial solution. It would be great if we
could simply put default XML fragments in files somewhere under
META-INF/jaxb/test/package/MyType and the object factory locates and
unmarshalls them automatically returning defaulted instances.

I've tried to check how this could be implemented. Unfortunatelly it
seems like it currently can't be. The reason is that you cannot
unmarshall non-root elements. So you basically could only default those
types which could be at root.
I've tried emulating parsing of the "root" element but did not succeeded.

Maybe I return to this later, but currently I don't see an elegant
solution. As for myself, I think I will opt to extending an
ObjectFactory and overriding its methods. A bit of manual work, but I've
nothing more suitable.

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net