users@jaxb.java.net

Question about primitive types API: determing if an element is set or not?

From: Han Ming Ong <hanming_at_mac.com>
Date: Thu, 29 May 2003 12:17:30 -0700

Hi all,

        Say I have a fragment of a Schema:

  <xs:element name="read-only" type="xs:boolean"/>

   <xs:element name="stats">
     <xs:complexType>
       <xs:sequence>
         <xs:element minOccurs="0" ref="read-only"/>
         <xs:element minOccurs="0" ref="read-time-out"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>

        From JAXB, I would get the following APIs for the StatsType class:

        ...
     boolean isReadOnly();
     void setReadOnly(boolean value);
        ...

        My problem is that my users want me to tell them if in the original
XML document, the element <read-only> is actually present or not. For
Java, isReadOnly() will return 'false' if not initialized, hence it
becomes ambiguous if the actually value is 'false' or just plain
missing.

        This problem occurs in all primitive types mapping. String is OK since
'null' is returned if element is missing.

        Any cool thoughts? Workaround (note: I prefer not to change the
Schema) ?

Thanks much, Han Ming