users@jaxb.java.net

typesafe enum error

From: R Bagge <asdzxc_at_comcast.net>
Date: Tue, 11 Feb 2003 09:35:08 -0500

The typesafe enum shown in SampleApp6 works.
However, if the typesafe enum USState is used in another element, the
result in the USState.java file contains multiple declarations of the
same object, e.g.

So, is this me or JAXB? Other than that, I have found JAXB to solve
all my needs.

RB

The generated USState.java file:

public final static primer.myPo.USState AK = new primer.myPo.USState
("AK");
private final static Object $$$_AK =
com.sun.xml.bind.WhiteSpaceProcessor.collapse("AK");
public final static primer.myPo.USState AL = new primer.myPo.USState
("AL");
private final static Object $$$_AL =
com.sun.xml.bind.WhiteSpaceProcessor.collapse("AL");
    public final static primer.myPo.USState AK = new primer.myPo.USState
("AK");
...
// Then it repeats again!
private final static Object $$$_AK =
com.sun.xml.bind.WhiteSpaceProcessor.collapse("AK");
public final static primer.myPo.USState AL = new primer.myPo.USState
("AL");
private final static Object $$$_AL =
com.sun.xml.bind.WhiteSpaceProcessor.collapse("AL");
...


The following is the enclosed XSD file:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            jxb:version="1.0">
  <xsd:annotation>
  <xsd:appinfo>
    <jxb:globalBindings
        fixedAttributeAsConstantProperty="false"
        collectionType="java.util.Vector"

        typesafeEnumBase="xsd:NMToken"
        typesafeEnumMemberName="generateName"

        choiceContentProperty="false"
        modelGroupAsClass="false"
        enableFailFastCheck="false"
        generateIsSetMethod="false"
        underscoreBinding="asCharInWord"/>
    <jxb:schemaBindings>
        <jxb:package name="primer.myPo"/>
        <jxb:nameXmlTransform>
          <jxb:elementName suffix="Element"/>
        </jxb:nameXmlTransform>
    </jxb:schemaBindings>
  </xsd:appinfo>
  </xsd:annotation>

<xsd:element name="purchaseOrder">
        <xsd:complexType >
                  <xsd:sequence>
                    <xsd:element name="shipTo" type="USState"/>
<!-- adding billTo results in bad compilation of USState.java -->
                    <xsd:element name="billTo" type="USState"/>
                  </xsd:sequence>
        <xsd:attribute name="myState" type="USState" />
        </xsd:complexType>
</xsd:element>

<xsd:simpleType name="USState">
  <xsd:annotation>
  <xsd:appinfo>
  <jxb:typesafeEnumClass/>
  </xsd:appinfo>
     <xsd:documentation>
          This is a localized way to map this simple type definition
          to a typesafe enum class. See jxb:globalBindings
          @typesafeEnumBase above for a global way to accomplish this
          for all simple type definitions similar to this one.
      </xsd:documentation>
  </xsd:annotation>
  <xsd:restriction base="xsd:NMTOKEN">
    <xsd:enumeration value="AK"/>
    <xsd:enumeration value="AL"/>
    <xsd:enumeration value="AR"/>
    <xsd:enumeration value="CA"/>
    <xsd:enumeration value="MA"/>
  </xsd:restriction>
</xsd:simpleType>
</xsd:schema>