Hi 
Hi
I want to use Castor...but I am stuck while trying it out
Can you help me.......?

I Have an Object 'AipXMLContainer' which contains a collection of other
objects 'AipXml' I want to marshal this Object When I marshal the
AipXMLContainer I get following XML

<?xml version="1.0" encoding="UTF-8"?>
<aip-xMLContainer>
        <aip-xmls
xsi:type="java:model.content_data_access.AIPOPImpl.AipXml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                <XML>src1.xml</XML>
                <location>c:/temp</location>
                <date>2003-03-02T06:24:33.597Z</date>
        </aip-xmls>
        <aip-xmls
xsi:type="java:model.content_data_access.AIPOPImpl.AipXml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                <XML>src2.xml</XML>
                <location>c:/temp</location>
                <date>2004-01-20T06:24:33.597Z</date>
        </aip-xmls>
</aip-xMLContainer>

But when I try to unmarshal it I get following exception
ValidationException: element "aip-xmls" occurs more than once.
(XMLFieldDesciptor: aipXmls AS aip-xmls)
        at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:
802)
        at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:
918)
        at
org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser
.java:559)
        at
org.apache.xerces.impl.XMLNamespaceBinder.endElement(XMLNamespaceBinder.
java:646)
        at
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValida
tor.java:2978)
        at
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.ja
va:918)


I am using following code to unmarshal it

Marshaller.marshal(container,writer);
Object object = Unmarshaller.unmarshal(AipXMLContainer.class,reader);


My Object is as following

---------------------------------------------------
package model.user_data_access;

/**
 * @author chopra_mz
 *
 */

import java.util.*;

import model.content_data_access.AIPOPImpl.AipXml;

public class AipXMLContainer {

        ArrayList xmls;
        public AipXMLContainer(){
                this(null);
        }
        
        public AipXMLContainer(Collection aipXmls){
                if(aipXmls==null)xmls = new ArrayList();
                else xmls = new ArrayList(aipXmls);
        }
        
        public void add(AipXml aipXml){
                if(aipXml!=null)xmls.add(aipXml);
        }
        
        public Collection getAipXmls(){
                return this.xmls;
        }
        public void setAipXmls(Collection aipXmls){
                if(aipXmls != null)
                this.xmls = new ArrayList(aipXmls);
        }
        
        public void clearList(){
                this.xmls.clear();
        }
}

---------------------------------------------------------------

/*
 * Created on 16/09/2003
 */
package model.content_data_access.AIPOPImpl;

import java.io.Serializable;
import java.util.*;
import java.lang.Integer;

/**
 * A wrapper class for holding an Oip XML file and its properties
 * 
 * @author chopra_mz
 *  
 */
public class AipXml implements Serializable{
        private Date date;
        private Calendar cal;
        private String location;
        private String xml;

        /**
         * This constructor is must as this class has to
         * be serialized
         */
        public AipXml(){
        }
        
        /**
         * creates an instance of OipXml to be used with 
         * Object prevalenece 
         * 
         * @param cal  Calendar representing the Date Of Interest
         * @param location location of the file on the server
         * @param xml  contents of the Oip xml file
         */
        public AipXml(Calendar cal,String location,String xml){
                this.cal = cal;
                this.date = cal.getTime();
                this.location = location;
                this.xml = xml; 
        }
        
        public AipXml(Integer date,Integer month,Integer year,String
location,String xml){
                        
                        cal = Calendar.getInstance();
                        cal.set(Calendar.DAY_OF_MONTH, date.intValue());
                        cal.set(Calendar.MONTH, month.intValue());
                        cal.set(Calendar.YEAR, year.intValue());
                        
                        this.location = location;
                        this.xml = xml; 
        }

        /**
         * Normally instace of OipXml is created while reading 
         * oipconfig.properties and xml string is passed as null
         * After reading other properties like location teh xml file
         * is read and the String representing xml content is set using
         * this method
         * @param doc String content of the xml file
         */
        void setXML(String doc){
                this.xml=doc;
        }
        /**
         * gets the text content of the XML
         * @return
         */
        public String getXML(){
                return this.xml;
        }
        /**
         * Gets the physical location of the Xml file
         * @return location
         */
        public String getLocation(){
                return this.location;   
        }
        
        public void setDate(Date date){
                this.date=date;
                this.cal=getCalendar(date);
        }
        
        public Date getDate(){
                if(cal!=null)this.date=cal.getTime();
                return this.date;
        }
        /**
         * Gets the Calendar object associated with the Date Of Interest

         * of this XML
         * @return calendar
         */
        public Calendar getCalendar(){
                if(cal==null)cal = getCalendar(this.date);
                return cal;
        }
        
        
        private Calendar getCalendar(Date date){
                if(date==null)return null;      
                Calendar cal = Calendar.getInstance();
                cal.setTime(date);
                return cal;
        }
        
        public String toString (){
                return (""+getCalendar().get(Calendar.DAY_OF_MONTH)+
                                ":"+getCalendar().get(Calendar.MONTH)+
                                ":"+getCalendar().get(Calendar.YEAR)
                                +"  "+location);
        }
}
------------------------------------------------------------

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to