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