users@jaxb.java.net

Need a schema representation of a multivalue attribute for JAXB

From: Daniel Einspanjer <daniel-java_at_YIPYIP.COM>
Date: Sat, 21 Jun 2003 00:32:30 -0600

I am writing a program that uses an XML file in conjunction with JAXB to generically access a database. This is my first foray into Schema, and it has been fun, but I'm having trouble with one small part.

I have an attribute of my "fieldModel" element, "editLevel". This is annotated as a type safe enum in JAXB. The current values are NONE, ADD, CHANGE, DELETE, ADD_DELETE, and ADD_CHANGE_DELETE. I bet you can guess my problem already. :) I don't want those combo entries because they limit me and they also make it difficult to test for a particular access type.

I believe if I just changed them to be child elements in a choice group, I'd lose the ability to have them as a type safe enum. So I guess the question would be:
<me><posessions><cake accessLevel="HAVE,EAT"/></posessions></me> ?

Here is a snippit of the current attributes in case it helps:
<xs:attribute name="editLevel" use="required">
 <xs:simpleType>
  <xs:annotation>
   <xs:appinfo>
    <jaxb:typesafeEnumClass name="EditLevel"/>
   </xs:appinfo>
  </xs:annotation>
  <xs:restriction base="xs:NCName">
   <xs:enumeration value="none">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="NONE"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
   <xs:enumeration value="change">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="CHANGE"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
   <xs:enumeration value="add">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="ADD"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
   <xs:enumeration value="delete">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="DELETE"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
   <xs:enumeration value="add-delete">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="ADD_DELETE"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
   <xs:enumeration value="change-add-delete">
    <xs:annotation>
     <xs:appinfo>
      <jaxb:typesafeEnumMember name="CHANGE_ADD_DELETE"/>
     </xs:appinfo>
    </xs:annotation>
   </xs:enumeration>
  </xs:restriction>
 </xs:simpleType>
</xs:attribute>