Hi All,

I have encountered a problem when trying to create a binding that would accept 
an XML like:

<Container>
  <ItemA>
  <ItemB>
  <!-- possibly followed by more ItemA and/or ItemB elements-->
</Container>

, and result in a collection of objects of the same type, say "Item", that 
would hold the original type ("ItemA" or "ItemB") information in its "type" 
property. I thought I could achieve that with the following binding:

<binding>
  <mapping class="Collection" name="Collection">
    <collection item-type="Item" add-method="add" iter-method="iterator">
      <structure name="ItemA" type="Item" usage="optional" 
test-method="isTypeA">
        <value name="type" style="attribute" usage="optional" default="A" 
        get-method="getType" set-method="setType" />
      </structure>
      <structure name="ItemB" type="Item" usage="optional" 
test-method="isTypeB">
        <value name="type" style="attribute" usage="optional" default="B"
          get-method="getType" set-method="setType" />
      </structure>
    </collection>
  </mapping>
</binding>

However this doesn't seem to work, resulting in org.jibx.runtime.JiBXException: 
Property definition not allowed for collection items at tag "structure"(line 4, 
col 78, in test.xml). Apparently the "property definition" refers to 
"test-method" that is listed under "property" attribute group. I also tried 
leaving just one "test-method" declaration in either of the two Item-type 
structures contained within the collection (as is done in 
http://jira.codehaus.org/browse/JIBX-142). As long as the first structure 
declaration defined a "test-method", the error remained the same. When 
test-method was removed from the first structure declaration, it resulted in a 
different error: Collection component must specify a test-method to distinguish 
from next component of compatible type for marshalling; on structure element at 
(line 4, col 60, in test.xml)... So, did I understand these error messages 
right, and the "test-method" definition is both required and disallowed for 
collection items, 
 or am I doing something wrong there?

P.S: Not really related to the above problem, but how are optional elements 
having a default value being treated when marshalling? Assuming the above 
binding would work, would it result in item XML representation looking like 
<ItemA type="A">, or just <ItemA>? Would it make a difference if Item.getType() 
returned null instead of the actual type?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to