Dear All, I am trying to figure out a reason for this stack trace while I was trying to marshal. I am using descriptors at present but not yet a mapping file for marshalling. It seems to me that Castor cant figure out the descriptor for my class "TcmFrmExportCompte" although it exists in the same package. Pls find the source below for my class and its descriptor. Maybe I am doing something fundamentally wrong.
What quizzes me is that I have a similar implementation running doing unmarshalling with descriptors and mapping file which I did few months back. I dont know why a similar pattern implementation is giving me a problem while marshalling. If you require all sources, I will do the needful but from my experience, someone's gonna just know by looking at this code whats wrong. Many thanks, Saurabh ---------------------------------------------------------------------------- ----------------------- ValidationException: The given object is not an instance of the class described by this ClassDecriptor.; - location of error: XPATH: TcmFrmExportCompte at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(Unknown Source) at org.exolab.castor.xml.Validator.validate(Unknown Source) at org.exolab.castor.xml.Marshaller.validate(Unknown Source) at org.exolab.castor.xml.Marshaller.marshal(Unknown Source) at org.exolab.castor.xml.Marshaller.marshal(Unknown Source) at com.borland.samples.xml.databinding.castor.types.TcmFrmExportCompte.marshal( TcmFrmExportCompte.java:119) at com.borland.samples.xml.databinding.castor.DB_Castor.main(DB_Castor.java:97) Exception in thread "main" ---------------------------------------------------------------------------- ----------------------- package com.borland.samples.xml.databinding.castor; /** * Title: XML Tutorial * Description: XML Tutorial for JBuilder * Company: Borland Software Coporation * @author * @version 1.0 */ import java.io.*; import org.exolab.castor.xml.*; import org.xml.sax.InputSource; import org.exolab.castor.mapping.Mapping; import com.borland.samples.xml.databinding.castor.types.*; import java.util.ArrayList; public class DB_Castor { private static ArrayList al = new ArrayList(); public ArrayList getList(){ return al; } public void setList(ArrayList al){ this.al = al; } public static void main(String [] args) throws Exception { // Locale l = new Locale(); // l.setLanguage("en"); // l.setCountry("GB"); // l.marshal(new PrintWriter(System.out)); // // al.add("Contribuable"); // al.add("Compte"); // // Marshal the person object // //Marshaller.marshal(al, writer); // // // Load Mapping // Mapping mapping = new Mapping(); // File file = new File("mymapping.xml"); // if (file.exists()) // mapping.loadMapping("mymapping.xml"); // // // Create a File to marshal to // FileWriter writer = new FileWriter("test.xml"); // // Marshaller marshaller = new Marshaller(writer); // marshaller.setMapping(mapping); // marshaller.setRootElement("someroot"); // marshaller.setNSPrefixAtRoot(false); // marshaller.setSuppressXSIType(true); // marshaller.marshal(al, writer); TcmFrmExportCompte tcmExport = new TcmFrmExportCompte(); ArrayList listeComptes = new ArrayList(); // create compte 1 TcmOdCompte compte1 = new TcmOdCompte(); compte1.setRefContrib("00000000"); compte1.setTypeImpot("ICC"); compte1.setAnneeTaxation("2002"); compte1.setNumeroTaxation("1"); // create compte 2 TcmOdCompte compte2 = new TcmOdCompte(); compte2.setRefContrib("55555555"); compte2.setTypeImpot("IFD"); compte2.setAnneeTaxation("2001"); compte2.setNumeroTaxation("1"); // add the 2 comptes to the ArrayList listeComptes.add(compte1); listeComptes.add(compte2); ArrayList listeContribuables = new ArrayList(); // create contrib 1 TcmOdContribuable contribuable1 = new TcmOdContribuable(); contribuable1.setReferenceContribuable("88888888"); // create contrib 2 TcmOdContribuable contribuable2 = new TcmOdContribuable(); contribuable2.setReferenceContribuable("11111111"); // add the 2 contribs to the ArrayList listeContribuables.add(contribuable1); listeContribuables.add(contribuable2); // add the ArrayLists to tcmExport tcmExport.setListeComptes(listeComptes); tcmExport.setListeContribuables(listeContribuables); tcmExport.marshal(new PrintWriter(System.out)); } } ---------------------------------------------------------------------------- ----------------------------------------------- /* * This class was automatically generated with * <a href="http://castor.exolab.org">Castor 0.9.4</a>, using an * XML Schema. * $Id$ */ package com.borland.samples.xml.databinding.castor.types; //---------------------------------/ //- Imported classes and packages -/ //---------------------------------/ import java.util.*; import org.exolab.castor.xml.*; /** * * * @version $Revision$ $Date$ **/ public class TcmFrmExportCompte implements java.io.Serializable { //--------------------------/ //- Class/Member Variables -/ //--------------------------/ private ArrayList _listeContribuables; private ArrayList _listeComptes; //----------------/ //- Constructors -/ //----------------/ public TcmFrmExportCompte() { super(); _listeContribuables = new ArrayList(); _listeComptes = new ArrayList(); } //-- com.borland.samples.xml.databinding.castor.types.TcmFrmExportCompte() //-----------/ //- Methods -/ //-----------/ /** **/ public TcmOdCompteType[] getArrayComptes() { int size = _listeComptes.size(); TcmOdCompteType[] mArray = new TcmOdCompteType[size]; for (int index = 0; index < size; index++) { mArray[index] = (TcmOdCompteType) _listeComptes.get(index); } return mArray; } /** **/ public TcmOdContribuableType[] getArrayContribuables() { int size = _listeContribuables.size(); TcmOdContribuableType[] mArray = new TcmOdContribuableType[size]; for (int index = 0; index < size; index++) { mArray[index] = (TcmOdContribuableType) _listeContribuables.get(index); } return mArray; } /** * Returns the value of field 'tcmOdCompte'. * * @return the value of field 'tcmOdCompte'. **/ public ArrayList getListeComptes() { return this._listeComptes; } //-- TcmOdCompte getTcmOdCompte() /** * Returns the value of field 'tcmOdContribuable'. * * @return the value of field 'tcmOdContribuable'. **/ public ArrayList getListeContribuables() { return this._listeContribuables; } //-- TcmOdContribuable getTcmOdContribuable() /** **/ public boolean isValid() { try { validate(); } catch (org.exolab.castor.xml.ValidationException vex) { return false; } return true; } //-- boolean isValid() /** * * * @param out **/ public void marshal(java.io.Writer out) throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { Marshaller.marshal(this, out); } //-- void marshal(java.io.Writer) /** * * * @param handler **/ public void marshal(org.xml.sax.ContentHandler handler) throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { Marshaller.marshal(this, handler); } //-- void marshal(org.xml.sax.ContentHandler) /** * Sets the value of field 'tcmOdCompte'. * * @param tcmOdCompte the value of field 'tcmOdCompte'. **/ public void setListeComptes(ArrayList pListeComptes) { this._listeComptes = pListeComptes; } //-- void setTcmOdCompte(TcmOdCompte) /** * Sets the value of field 'tcmOdContribuable'. * * @param tcmOdContribuable the value of field * 'tcmOdContribuable'. **/ public void setListeContribuables(ArrayList pListeContribuables) { this._listeContribuables = pListeContribuables; } //-- void setTcmOdContribuable(TcmOdContribuable) /** * * * @param reader **/ public static com.borland.samples.xml.databinding.castor.types.TcmFrmExportCompte unmarshal(java.io.Reader reader) throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { return (com.borland.samples.xml.databinding.castor.types.TcmFrmExportCompte) Unmarshaller.unmarshal(com.borland.samples.xml.databinding.castor.types.TcmF rmExportCompte.class, reader); } //-- com.borland.samples.xml.databinding.castor.types.TcmFrmExportCompte unmarshal(java.io.Reader) /** **/ public void validate() throws org.exolab.castor.xml.ValidationException { org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator(); validator.validate(this); } //-- void validate() /** * @param pPerOtTestData **/ public void addTcmOdContribuableType(TcmOdContribuableType pTcmOdContribuableType) throws java.lang.IndexOutOfBoundsException { _listeContribuables.add(pTcmOdContribuableType); } /** * @param index * @param pPerOtTestData **/ public void addTcmOdContribuable(int index, TcmOdContribuableType pTcmOdContribuableType) throws java.lang.IndexOutOfBoundsException { _listeContribuables.add(index, pTcmOdContribuableType); } /** * @param pPerOtTestData **/ public void addTcmOdCompteType(TcmOdCompteType pTcmOdCompteType) throws java.lang.IndexOutOfBoundsException { _listeComptes.add(pTcmOdCompteType); } /** * @param index * @param pPerOtTestData **/ public void addTcmOdCompteType(int index, TcmOdCompteType pTcmOdCompteType) throws java.lang.IndexOutOfBoundsException { _listeComptes.add(index, pTcmOdCompteType); } } ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ------- /* * This class was automatically generated with * <a href="http://castor.exolab.org">Castor 0.9.4</a>, using an * XML Schema. * $Id$ */ package com.borland.samples.xml.databinding.castor.types; //---------------------------------/ //- Imported classes and packages -/ //---------------------------------/ import org.exolab.castor.xml.*; import org.exolab.castor.xml.util.*; /** * * * @version $Revision$ $Date$ **/ public class TcmFrmExportCompteDescriptor extends org.exolab.castor.xml.util.XMLClassDescriptorImpl { //--------------------------/ //- Class/Member Variables -/ //--------------------------/ private java.lang.String nsPrefix; private java.lang.String nsURI; private java.lang.String xmlName; private org.exolab.castor.xml.XMLFieldDescriptor identity; //----------------/ //- Constructors -/ //----------------/ public TcmFrmExportCompteDescriptor() { super(); xmlName = "TcmFrmExportCompte"; //-- set grouping compositor setCompositorAsSequence(); XMLFieldDescriptorImpl desc = null; XMLFieldHandler handler = null; FieldValidator fieldValidator = null; //-- initialize attribute descriptors //-- initialize element descriptors //-- listeContribuables desc = new XMLFieldDescriptorImpl(TcmOdContribuableType.class, "_listeContribuables", "TcmOdContribuableType", NodeType.Element); handler = (new XMLFieldHandler() { // this is used in marshalling to recover value objects from Java to XML public java.lang.Object getValue( java.lang.Object object ) throws IllegalStateException { TcmFrmExportCompte target = (TcmFrmExportCompte) object; return target.getArrayContribuables(); } // this is used for unmarshalling to set a value object to Java from XML public void setValue( java.lang.Object object, java.lang.Object value) throws IllegalStateException, IllegalArgumentException { try { TcmFrmExportCompte target = (TcmFrmExportCompte) object; target.addTcmOdContribuableType((TcmOdContribuableType) value); } catch (Exception ex) { throw new IllegalStateException(ex.toString()); } } public java.lang.Object newInstance( java.lang.Object parent ) { return new TcmOdContribuable(); } } ); desc.setHandler(handler); desc.setRequired(true); desc.setMultivalued(true); addFieldDescriptor(desc); //-- validation code for: _listeContribuables fieldValidator = new FieldValidator(); fieldValidator.setMinOccurs(0); desc.setValidator(fieldValidator); //-- listeComptes desc = new XMLFieldDescriptorImpl(TcmOdCompteType.class, "_listeComptes", "TcmOdCompteType", NodeType.Element); handler = (new XMLFieldHandler() { // this is used in marshalling to recover value objects from Java to XML public java.lang.Object getValue( java.lang.Object object ) throws IllegalStateException { TcmFrmExportCompte target = (TcmFrmExportCompte) object; return target.getArrayComptes(); } // this is used for unmarshalling to set a value object to Java from XML public void setValue( java.lang.Object object, java.lang.Object value) throws IllegalStateException, IllegalArgumentException { try { TcmFrmExportCompte target = (TcmFrmExportCompte) object; target.addTcmOdCompteType((TcmOdCompteType) value); } catch (Exception ex) { throw new IllegalStateException(ex.toString()); } } public java.lang.Object newInstance( java.lang.Object parent ) { return new TcmOdCompte(); } } ); desc.setHandler(handler); desc.setRequired(true); desc.setMultivalued(true); addFieldDescriptor(desc); //-- validation code for: _listeComptes fieldValidator = new FieldValidator(); fieldValidator.setMinOccurs(0); desc.setValidator(fieldValidator); } public org.exolab.castor.mapping.AccessMode getAccessMode() { return null; } public org.exolab.castor.mapping.ClassDescriptor getExtends() { return null; } public org.exolab.castor.mapping.FieldDescriptor getIdentity() { return identity; } public java.lang.Class getJavaClass() { //return afc.rper.outils.ot.PerOtListeTestData.class; return TcmFrmExportCompteDescriptor.class; } public java.lang.String getNameSpacePrefix() { return nsPrefix; } public java.lang.String getNameSpaceURI() { return nsURI; } public org.exolab.castor.xml.TypeValidator getValidator() { return this; } public java.lang.String getXMLName() { return xmlName; } } ---------------------------------------------------------------------------- ---------------------------------------------------------- ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-user