Hi all,

I have encountered one more problem. I looked at the mailing list so far and tried a few variations of my mapping file ( collection = “vector” ; collection=”enumerate”; container=”false” ) but to no avail. I shall explain:

 

I need to create the following xml:

 

<Message>

<RequestedReports>

                        <Report Type=”Exception”/>

                        <Report Type=”COA”/>

</RequestedReports>

</Message>

 

I also have to use pre-existing java objects (i.e. not created using castors source generator).

 

I have a Message object that contains a Vector of Report objects. This vector represents the RequestedReports element.

The code may explain this better:

 

import com.mypackage.Report;

import java.util.Enumeration;

import java.util.Vector;

public class Message

{

private Vector mRequestedReportsVector;

public Message()

{

this.mRequestedReportsVector = new Vector();

}

           

            public void addReport( Report pNewReport)

            {

                        this.mRequestedReportsVector.add(Report);

            }

 

public Report getReport( int  pNewIndex)

            {

                        return (Report) mRequestedReportsVector.elementAt(pNewIndex);

            }

 

 

public void addReport( Report pNewReport)

            {

                        this.mRequestedReportsVector.add(Report);

            }

 

            public Enumeration enumerateRequestedReports()

            {

                        return this.mRequestedReportsVector;

            }

 

            .          

            .

            .

 

}

 

package com.mypackage;

public class Report

{

            private string mType;

                       

            public Report()

            {

            }

           

            public void setType( String pNewType)

            {

                        this.mType = pNewType;

            }

 

            public String getType()

            {

                        return mType;

            }

           

            .          

            .

            .

 

}

 

 

Lastly, I have a mapping file as follows

<mapping>

<class name=”Message”>

            <field name=”mRequestedReportVector” type=”com.mypackage.Report” collection=”enumerate” container=”false” get-method=”enumerateRequestedReports”>

                        <bind-xml name=”RequestedReports”/>

            </field>

</class>

 

<class name=”com.mypackage.Report”>

            <map-to xml=”Report”/>

            <field name=”mType” type=”string” get-method=”getType” set-method=”setType”>

                        <bind-xml name=”Type” node=”attribute”/>

            </field>

</class>

</mapping>

 

However the resulting xml is as follows:

<Message>

            <RequestedReports Type=”EXCEPTION”/>

</Message>

 

Can anyone tell me if my mapping file is incorrect or if this is a “bug” in castor (i.e. that I will have to wrap my vector into it’s own class in order to give it an element tag in the XML)???

Thanks

 

Corina Coughlan

 

Reply via email to