users@jaxb.java.net

Re: Getting a Java 5 enum from XJC

From: Gregory Kick <gk5885_at_gmail.com>
Date: Wed, 31 Jan 2007 10:54:13 -0800

Well, if the issue is with the spec rather than the implementation
then it's not that big of a deal. It only came up because I tend to
leave my enumerations anonymous, but making that change isn't a big
deal.

In any event, I recorded the issue (#318) as an rfe.

Thanks to you both for the help.

On 1/30/07, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_sun.com> wrote:
> Gregory Kick wrote:
> > Kenny,
> >
> > On 1/26/07, Kenny MacLeod <kennym_at_kizoom.com> wrote:
> >> As you say, XJC will only generated an Enum for a Schema type which has
> >> a name, i.e. isn't an anonymous nested type. It doesn't generate enum
> >> types for anonymous schema types - what would it call them?
> >
> > Wouldn't it be expected that it behave the same as an other anonymous
> > type? If I have an element named "something" that is an anonymous
> > simple type, xjc generates an inner class called "Something" that is
> > equivalent to the class I would get if I had named the simple type
> > "Something" and referenced it. Why would enums behave differently?
>
> Kenny is correct that the JAXB spec says no default enum generation from
> anonymous simple types. In some way this is the same as handling
> anonymous complex type inside a global element:
>
> <element name="foo">
> <complexType>
> <sequence>
> ...
>
> But I guess you are right that in some other cases this behavior is not
> necessarily consistent. The spec often fails to achieve certain
> optimizations, because there are just so many possible optimizations.
>
> The main reason why we chose not to generate enums from anonymous simple
> type is to avoid name conflicts. In my experience people are more angry
> when they can't compile their schema, compared to when they can compile
> the schema but the binding was not optimal.
>
> We should probably record this in the issue tracker, I think we might be
> able to do something either in a future version of the spec or as an RI
> extension, like maybe in the simple binding mode.
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
>


-- 
Gregory Kick
gk5885_at_gmail.com