Hi,

I still don't know how to get it right. Example for a collection of collections:
<collection-of-collections>
  <collection>
    <collection-item>foo</collection-item>
    <collection-item>bar</collection-item>
  </collection>
  <collection>
    <collection-item>baz</collection-item>
  </collection>
</collection-of-collections>

My mapping so far:
<mapping>
  <class name="CollectionItem">
    <map-to xml="collection-of-collections" />
    <field name="collection" collection="collection">
      <bind-xml name="collection">
        <class name="CollectionItem">
          <field name="collection" collection="collection" type="string">
            <bind-xml name="collection-item" />
          </field>
        </class>
      </bind-xml>
    </field>
  </class>
</mapping>

The CollectionItem class:
import java.util.Collection;
public class CollectionItem {
    private Collection collection;
    public Collection getCollection() {
        return collection;
    }
    public void setCollection(Collection collection) {
        this.collection = collection;
    }
}

Exception when unmarshalling XML:
java.lang.NullPointerException
        at 
org.exolab.castor.xml.util.XMLFieldDescriptorImpl.hashCode(XMLFieldDescriptorImpl.java:713)
        at java.util.HashMap.hash(HashMap.java:261)
        at java.util.HashMap.put(HashMap.java:379)
        at java.util.HashSet.add(HashSet.java:192)
        at 
org.exolab.castor.xml.UnmarshalState.markAsUsed(UnmarshalState.java:204)
        at 
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:986)
        at 
org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:250)
        at 
org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:183)
        at 
org.exolab.castor.xml.util.DOMEventProducer.processChildren(DOMEventProducer.java:334)
        at 
org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:248)
        at 
org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:183)
        at 
org.exolab.castor.xml.util.DOMEventProducer.start(DOMEventProducer.java:111)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:631)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:741)

-------- Original-Nachricht --------
> Datum: Fri, 19 Oct 2007 12:40:04 +0200
> Von: Werner Guttmann <[EMAIL PROTECTED]>
> An: [email protected]
> Betreff: Re: [castor-user] Collection of Collections

> Hi
> 
> [EMAIL PROTECTED] wrote:
> > I couldn't find the example. I just found
> >
> castor-1.1.2.1\xmlctf\tests\MasterTestSuite\mapping\collections\Maps\NestedMaps\MapOfCollections.
> > I don't know how to transfer that example to work with collection of
> > collections.
> Well, within the mapping for the Result class, you will have another 
> collection mapping for your nested collection. Nothing special, just a 
> plain field mapping.
> > 
> > Another question was regarded to collections: Is there a way to map a
> > collection containing different types. <root> <mycollection> 
> > <string>test1</string> <integer>1</integer> <integer>2</integer> 
> > <string>test2</string> </mycollection> </root>
> Not to my knowledge.
> 
> > I couldn't find a example for this and can't imagine how to do it as
> > I think that a type attribute for a <field collection="collection"/>
> > is required. -------- Original-Nachricht --------
> >> Datum: Thu, 18 Oct 2007 13:47:21 +0200 Von: Werner Guttmann
> >> <[EMAIL PROTECTED]> An: [email protected] Betreff: Re:
> >> [castor-user] Collection of Collections
> > 
> >> Yes, it does. Have a look at teh current CTF test suite that has 
> >> examples on how to map nested collections.
> >> 
> >> Werner
> >> 
> >> [EMAIL PROTECTED] wrote:
> >>> Hello,
> >>> 
> >>> I would like to map the following XML to Java:
> >>> 
> >>> <result> <bar>baz</bar> <rows> <row> <integer>123</integer> 
> >>> <integer>321</integer> <string>foo</string> </row> <row> 
> >>> <integer>123</integer> <integer isNull="true"/> 
> >>> <string>foo</string> </row> </rows> </result>
> >>> 
> >>> In Java words this is a Result class with one String bar
> >>> attribute and a rows Collection. The Collection contains row
> >>> elements which are themself Collection (a row can a have
> >>> arbitrary number of cells). My question is: does Castor support
> >>> Collections of Collections (rows->row->cell)? How would the
> >>> mapping xml file look like? If there is a problem for castor with
> >>> the mixed types of the cells, the following xml would be okay
> >>> too:
> >>> 
> >>> <result> <bar>baz</bar> <rows> <row> <col
> >>> type="integer">123</col> <col type="integer">321</col> <col
> >>> type="string">foo</col> </row> <row> <col
> >>> type="integer">123</col> <col type="integer" isNull="true"/> <col
> >>> type="string">foo</col> </row> </rows> </result>
> >>> 
> >>> Kind regards
> >> 
> >> ---------------------------------------------------------------------
> >>  To unsubscribe from this list please visit:
> >> 
> >> http://xircles.codehaus.org/manage_email
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
> 
>     http://xircles.codehaus.org/manage_email

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to