users@jaxb.java.net

Re: jaxb1 problem with complex-types vs elements

From: Christoph Sturm <christoph.sturm_at_gmail.com>
Date: Tue, 27 Jun 2006 03:26:07 +0200

Hello again!

Here is the testcase i sent along:


        MyEL myEL = o.createMyEL();
        myEL.setWhatever("whatever");
        AnotherElement anotherElement = o.createAnotherElement();

If MyEL didnt extend MyCT, the next line would generate a compile time error:
        anotherElement.setCtHolder(myEL);

I just think it is error prone that in the code that xjc generates
MyEL extends MyCT. I dont see what benefits it brings, it just makes
it easy to make coding mistakes.
MyEL and MyCT dont have a "is a" relationship, you cant say MyEL is a
MyCT. making MyEL extend MyCT just isnt correct from an OO
perspective.

this setter: anotherElement.setCtHolder();
must always be invoked with an object of type MyCT. Making MyEL extend
MyCT gives the impression that MyEL can be used in any place that MyCT
can be used.

If you still dont kno where I'm getting to, please finish this sentence:
"In the code that xjc generated for your schema, MyEL extends MyCT
because _____"

thanks, and sorry if that was too verbose, I just want to make sure
you know what my issue is.

regards
 chris


On 6/27/06, Ed Mooney <Ed.Mooney_at_sun.com> wrote:
> Hi Christoph,
>
> I'm sorry, but I don't follow. The test case you provided builds up a
> content tree that's invalid with respect to the original schema, causing
> the exception you reported. This is allowed by the spec and up to the
> programmer to avoid. It has nothing to do with the inheritance model.
>
> Regards,
> --
> Ed Mooney |Sun Microsystems, Inc.|Time flies like
> Java Web Services |UBUR02-201 |an arrow, but
> Ed.Mooney_at_Sun.COM |1 Network Drive |fruit flies like
> 781-442-0459 |Burlington, MA 01803 |a banana. Groucho
>
> Christoph Sturm wrote:
> > Hey Ed!
> >
> > My only issue with this behavior is this:
> >
> > <element name="x" type="y"/> generates code like this:
> >
> > class X extends Y
> >
> > and thus every setter that takes an argument of Y can als be invoked
> > with an instance of type X. And there goes my typesafety.
> >
> > If X would not extend Y everything would be fine, and i would get a
> > compiler error.
> >
> > do you understand my issue?
> >
> > regards
> > chris
> [ ... ]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
christoph.sturm_at_gmail.com