users@jaxb.java.net

Re: newbe: can xjc generate enums classes from anonomous types

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 18 Sep 2008 10:55:29 +0200

Don't you want enum Types for your one-two types?

The global simple-type should produce an enum type GlobalType anyway.
Anonymous enumeration-restrictions won't result in
enum types, not even nested ones.

But you could instruct JAXB to use this class for your
anonymous inlined types by inserting
<xs:annotation><xs:appinfo>
  <xs:class ref="where.it.is.GlobalType"/>
</..></..>
in all your anonymous <xs:simpleType> definitions.

It should also be possible to put this into an external bindings
file, but then you would have to define the locations by
XPATH expressions. This doesn't appeal to me.

My advice would be to rewrite the schema, if possible.
Wolfgang


On Wed, Sep 17, 2008 at 2:25 PM, Mike Skells <mike.skells_at_validsoft.com>wrote:

>
> hi,
>
> if I have a global simple type (restriction of xs:NCName) definition then
> xjc will generate an enum class, but if the simple type is nested inside
> another type declaration then it will not. |Is there a way to make xjc
> generate enums for all of these cases or do I have to extract all of the
> simple type declarations into global declarations
> so this schema
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="def">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ele">
> <xs:simpleType>
> <xs:restriction
> base="xs:NCName">
> <xs:enumeration
> value="one"/>
> <xs:enumeration
> value="two"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> </xs:sequence>
> <xs:attribute name="attr" use="required">
> <xs:simpleType>
> <xs:restriction base="xs:NCName">
> <xs:enumeration
> value="one"/>
> <xs:enumeration
> value="two"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
> </xs:element>
> <xs:simpleType name="global-type">
> <xs:restriction base="xs:NCName">
> <xs:enumeration value="one"/>
> <xs:enumeration value="two"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:schema>
>
>
> generates
>
>
> public class Def {
>
> @XmlElement(required = true)
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> protected String ele;
> @XmlAttribute(required = true)
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> protected String attr;
> ....
> --
> View this message in context:
> http://www.nabble.com/newbe%3A-can-xjc-generate-enums-classes-from-anonomous-types-tp19530955p19530955.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>