users@jaxb.java.net

Re: enumeration with empty string as value

From: Lisa Bahler <bahler_at_research.telcordia.com>
Date: Tue, 03 Dec 2002 13:29:39 -0500

Ed,

This does seem weird, does it not, to use an empty string as an
enumeration? We wanted to use nillable in our schemas for our string
elements, but we found that Turbo XML did not work as we expected,
although XML Spy worked fine. Wanting to produce schemas that worked
with the largest number of tools out there, we decided to implement
nillable by using a union, as so, since we are not concerned with
defaults:

         <xsd:element name = "PMD_RATING" minOccurs="0" maxOccurs="1" >
            <xsd:simpleType>
               <xsd:union memberTypes = "PMD_RATING" >
                  <xsd:simpleType>
                     <xsd:restriction base = "xsd:string">
                        <xsd:enumeration value= "" />
                     </xsd:restriction>
                  </xsd:simpleType>
               </xsd:union>
            </xsd:simpleType>
         </xsd:element>


We are unioning "" with the simple type PMD_RATING, which is defined so:

<xsd:simpleType name ="PMD_RATING">
        <xsd:annotation>
                <xsd:documentation>
Description = Polarized Mode Dispersion Rating
                </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
                <xsd:pattern value="(\+|\-)?\d{0,5}\.\d{0,2}"/>
        </xsd:restriction>
</xsd:simpleType>

There are many such examples in our schemas.

Are you one of the programmers for the ref implementation? Any idea
when the rest of the "not implemented" features will be ready?
Specifically, it looks like (but I am not sure) setting
typesafeEnumMemberName to generateName in jaxb:globalBindings would get
me past this hurdle in the short run, but it is not yet implemented.

At this point, I am unable to produce classes for most of my schemas
because of this problem with enum. If this is a bug, will I be able to
get a patch to try out?

Thanks,
Lisa


Ed Mooney wrote:
>
> Hi Lisa,
>
> This failure mode would seem to be a bug. Thanks for pointing it out ...
> I'll investigate further.
>
> If you don't mind, what's your motivation for wanting an empty
> enumeration value?
>
> 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
>
> Lisa Bahler wrote:
> > I am unable to produce classes for a schema that contains an enumeration
> > that has the empty string "" as a value.
> >
> > As an example, I have modified po.xsd from SampleApp6 to look like:
> >
> > <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:string">
> > <xsd:enumeration value="AK"/>
> > <xsd:enumeration value="AL"/>
> > <xsd:enumeration value="AR"/>
> > <xsd:enumeration value="CA"/>
> > <xsd:enumeration value="MA"/>
> > <!-- *****This next line is added by me.***** -->
> > <xsd:enumeration value="" />
> > <!-- and so on ... -->
> > </xsd:restriction>
> > </xsd:simpleType>
> >
> > This is what I get when I try to generate classes:
> >
> > $ test.bat
> > parsing a schema...
> > Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
> > at com.sun.msv.verifier.identity.IDConstraintChecker.feedAttribute(IDCon
> > straintChecker.java:218)
> > at com.sun.msv.verifier.Verifier.startElement(Verifier.java:204)
> > at org.iso_relax.verifier.impl.VerifierFilterImpl.startElement(Unknown S
> > ource)
> > at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXP
> > arser.java:459)
> > at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Abst
> > ractXMLDocumentParser.java:221)
> > at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNames
> > paceBinder.java:874)
> > at org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBi
> > nder.java:591)
> > at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
> > t(XMLDocumentFragmentScannerImpl.java:747)
> > at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
> > Dispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1477)
> > at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XM
> > LDocumentFragmentScannerImpl.java:329)
> > at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.jav
> > a:525)
> > at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.jav
> > a:581)
> > at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
> > at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.j
> > ava:1175)
> > at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
> > at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
> > at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
> > at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.
> > java:151)
> > at com.sun.xml.xsom.impl.parser.XSOMParser.parse(XSOMParser.java:116)
> > at com.sun.tools.xjc.Driver.loadXMLSchemaGrammar(Driver.java:511)
> > at com.sun.tools.xjc.Driver.loadGrammar(Driver.java:404)
> > at com.sun.tools.xjc.Driver.run(Driver.java:268)
> > at com.sun.tools.xjc.Driver.main(Driver.java:88)
> >
> > Is there some customization that will get me past this?
> >
> > Thanks,
> > Lisa