Hello Ralf,

now I managed to get what I want! I started the other way round as you 
suggestet by marshalling my objects.

My Root Object:
import java.util.ArrayList;
import java.util.Collection;

public class Root {
    private Collection collection;

    public Root() {
        this.collection = new ArrayList();
        MyCollectionItem item1 = new MyCollectionItem();
        item1.setValue("foo");
        MyCollectionItem item2 = new MyCollectionItem();
        item2.setValue("bar");
        Collection innerCollection1 = new ArrayList();
        innerCollection1.add(item1);
        innerCollection1.add(item2);
        MyCollectionItem item3 = new MyCollectionItem();
        item3.setValue("baz");
        Collection innerCollection2 = new ArrayList();
        innerCollection2.add(item3);
        this.collection.add(innerCollection1);
        this.collection.add(innerCollection2);
    }

    public Collection getCollection() {
        return collection;
    }

    public void setCollection(Collection collection) {
        this.collection = collection;
    }
}

My sample class contained in my inner collection:
public class MyCollectionItem {
    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

My mapping.xml:
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" 
"http://castor.org/mapping.dtd";>
<mapping>
  <class name="Root">
    <map-to xml="collection-of-collections" />
    <field name="collection" collection="arraylist">
      <bind-xml name="collection"/>
    </field>
  </class>
  <class name="MyCollectionItem">
    <map-to xml="collection-item"/>
    <field name="value">
      <bind-xml node="text"/>
    </field>
  </class>
</mapping>

The resulting xml (have to get rid of the schema information, but I'll find out 
how...):
<collection-of-collections>
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="java:java.util.ArrayList">
                <collection-item 
xsi:type="collection-item">foo</collection-item>
                <collection-item 
xsi:type="collection-item">bar</collection-item>
        </collection>
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="java:java.util.ArrayList">
                <collection-item 
xsi:type="collection-item">baz</collection-item>
        </collection>
</collection-of-collections>

In my opinion this could be a example of using collecitons of collections for 
the test suite. I wasn't able to get the test working
ctfrun -text 
../xmlctf/tests/MasterTestSuite/mapping/collections\CollectionOfCollections
... some stuff ...
There was 1 failure:
1) Test mapping of Collection of 
Collection#Test01_ReferenceDocument(org.castor.xmlctf.TestWithReferenceDocument)junit.framework.AssertionFailedError:
 Exception
 Unmarshaling from disk org.exolab.castor.xml.MarshalException{File: [not 
available]; line: 6; column: 17}
        at 
org.castor.xmlctf.TestWithReferenceDocument.runTest(TestWithReferenceDocument.java:168)
        at 
org.castor.xmlctf.CastorTestSuiteRunner.main(CastorTestSuiteRunner.java:167)

I used MapOfCollections test as a basis and changed all files and values.

Best regards
-------- Original-Nachricht --------
> Datum: Fri, 19 Oct 2007 14:53:09 +0200
> Von: Ralf Joachim <[EMAIL PROTECTED]>
> An: [email protected]
> Betreff: Re: [castor-user] Collection of Collections

> BaBowe, I usually start marshalling my objects as it is much easier to 
> tune your mapping at marshalling because you can see the XML what castor 
> creates with your mapping. In every case I had unmarshalling also worked 
> as expected thereafter.
> 
> Regards
> Ralf
> 
> [EMAIL PROTECTED] schrieb:
> > 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
> > 
> 
> -- 
> 
> Syscon Ingenieurbüro für Meß- und Datentechnik GmbH
> Ralf Joachim
> Raiffeisenstraße 11
> 72127 Kusterdingen
> Germany
> 
> Tel.   +49 7071 3690 52
> Mobil: +49 173 9630135
> Fax    +49 7071 3690 98
> 
> Internet: www.syscon.eu
> E-Mail: [EMAIL PROTECTED]
> 
> Sitz der Gesellschaft: D-72127 Kusterdingen
> Registereintrag: Amtsgericht Stuttgart, HRB 382295
> Geschäftsleitung: Jens Joachim, Ralf Joachim
> 
> ---------------------------------------------------------------------
> 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