I'm struggling trying to figure out the right way to write a binding
for an xsd:choice structure. Consider the following schema fragment:

   <xs:simpleType name="Tmac-48">
      <xs:restriction base="xs:string">
         <xs:pattern value="[\p{Nd}A-F]{2}(-[\p{Nd}A-F]{2}){5}"/>
      </xs:restriction>
   </xs:simpleType>

   <xs:simpleType name="Teui-48">
      <xs:restriction base="Tmac-48"/>
   </xs:simpleType>

   <xs:simpleType name="Teui-64">
      <xs:restriction base="xs:string">
         <xs:pattern value="[\p{Nd}A-F]{2}(-[\p{Nd}A-F]{2}){7}"/>
      </xs:restriction>
   </xs:simpleType>

   <xs:simpleType name="Tfoo">
      <xs:restriction base="xs:normalizedString"/>
   </xs:simpleType>

   <xs:group name="Gdevice-id">
      <xs:choice>
         <xs:element name="mac-48" type="Tmac-48"/>
         <xs:element name="eui-48" type="Teui-48"/>
         <xs:element name="eui-64" type="Teui-64"/>
      </xs:choice>
   </xs:group>

   <xs:complexType name="Tmachine">
      <xs:sequence>
         <xs:group ref="Gdevice-id"/>
         <xs:element name="foo" type="Tfoo"/>
      </xs:sequence>
   </xs:complexType>


That is, there's a complex type "Tmachine" which consists of one of a
"mac-48", "eui-48", or "eui-64" element, and one "foo" element, like
so, materialized in an element called "machine":

   <machine>
      <mac-48>11-22-33-44-55-66</mac-48>
      <foo>bar</foo>
   </machine>

Alternately, one should be able to write:

   <machine>
      <!-- Note the different kind of device id: -->
      <eui-48>11-22-33-44-55-66</eui-48>
      <foo>bar</foo>
   </machine>

My JiBX binding for this "Tmachine" type looks like this:

   <mapping class="Machine" abstract="true">
      <structure choice="true" ordered="false">
         <value name="mac-48" field="mac48"/>
         <value name="eui-48" field="eui48"/>
         <value name="eui-64" field="eui64"/>
      </structure>
      <value name="foo" field="foo"/>
   </mapping>

It's referenced elsewhere in the binding like this:

  <structure name="machine" field="machine"/>

where the field "machine" is of type "Machine" in the containing
class.

When I attempt to unmarshall the element <machine> above, JiBX throws
an exception reporting:

  org.jibx.runtime.JiBXException:
    Missing required element "{...}eui-48"(line 4, col 45)

That is, it sees the "mac-48" element and accepts that, but then
demands an "eui-48" element to follow immediately, which seems as
though it's mistakenly treating the xsd:choice as a sequence.

Actually, if I put a "eui-48" element first followed by a "mac-48"
element, JiBX still demands a "mac-48" element. If I put a "mac-48"
element first followed by an "eui-48" element, JiBX still demands an
"eui-48" element. There's no way to satisfy it, even by violating my
own schema.

When I run the JiBX compiler, I see the following output (namespaces
elided):

       component property machine (Machine)
        object binding for Machine create class Machine
         structure ordered
          mapping reference to Machine using property "this" (Machine)
           base mapping wrapper
            object binding for Machine ("this" reference) create class Machine
             structure ordered
              structure choice
               element {...}:mac-48 from property mac48 (java.lang.String)
               element {...}:eui-48 from property eui48 (java.lang.String)
               element {...}:eui-64 from property eui64 (java.lang.String)
              element {...}:foo from property foo (java.lang.String)

The output shows acknowledgment of the choice structure.

Is there an obvious error in my binding that's causing JiBX to require
all the would-be choice alternates?

-- 
Steven E. Harris


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to