users@jaxb.java.net

Re: How to use XML objects as members of other XML objects?

From: Yakov Polonsky <ypolonsky_at_MARKETSWITCH.COM>
Date: Wed, 14 May 2003 13:31:10 -0600

On Mon, 12 May 2003 08:48:04 -0700, Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com> wrote:

>> 1. Why can't I use TESTA object instead of TESTAType one? Nothing
>> prevents me to create invalid output.
>
>I think our plan is to exploit this to support things like substitution
>groups and type substitutions, if you accept this as a reason.
>
>Another answer might be, TESTA object is defined as an element, so when
>it's asked to marshal itself, it will marshal itself as a whole element.
>So there's nothing the caller can do about it.
>
>I guess both are not really satisfactory...

You are absolutely right. There is a flaw in design where you cannot
distinguish if the object is a container (element) or a content.

...
>> 3. Any idea how to approach this problem if "this is not a bug, but a feature"?
>
>I don't think it's a bug since it's behaving exactly as we expected, but
>I agree that this is ugly.
>
>One thing that the RI can relatively easily do is to have a
>customization that generates:
>
> interface Foo {
> FooType getValue();
> void setValue(FooType t);
> }
>
>instead of:
>
> interface Foo : FooType {
> }
>
>which allows you to say:
>
> typebObject.setValue( typeaObject.getValue() );
>
>this is analogous to the case when the type is a simple type.
>
>
>Any comments appreciated. If we do this, does it help?

I agree that the FooType should be a member of Foo. I think that
the "complexType" of the schema should be a content for the "root"
element which is a container for the "complexType". The interface Foo() is a
container and it should contain the interface FooType as a content. Then,
serializeElements() and other methods should travel through object's
contents instead of it's superclasses. It also allows to avoid passing a container object into the setXXX() method of another container.

May I suggest to avoid setValue()/getValue() naming for special methods so they will not interfere with the bean properties reflection. For example,
you might name it as ____jaxb_ri____getValue() / ____jaxb_ri____setValue(),
or, for simplicity:
    interface Foo {
       FooType content();
       void initContent(FooType t); // or even "void content(FooType t);"
    }

Thanks,
Yakov Polonsky
ypolonsky_at_marketswitch.com