Hi Keith,
     I do have default public constructors defined, and I think I have
     located the problem to be in Castor.
     I found that the inner class needs to be declared 'static'.
     I looked up in the castor source code and I think
     it needs to be modified so that if the class is inner class then
     care must be taken to get the default constructor and then
     instantiate it using reflection api.
     I have modified the code locally at two places in the castor
     source code and confirmed it to be working.
     Following are the changes made at the two places.

    Constructor defConstructor = null;
    Class outerClass = null;
    Constructor[] contructors = _class.getConstructors();
    for (int i =0; i < contructors.length; i++)
    {
     Class[] paramClasses = contructors[i].getParameterTypes();
     if (1 == paramClasses.length)
     {
       defConstructor = contructors[i];
       outerClass = paramClasses[0];
       break;
     }
    }
    if ((null != defConstructor) && (null != outerClass))
    {
      state.object = defConstructor.newInstance(new Object[]
{outerClass.newInstance()});
    }

    Was this case left out intentionally? If so could you plese tell me why
it is so?

    If the changes are correct it would be nice if you guys could incoporate
the changes
    or let me know if  I am eligible to make the change to your repository,
and if yes how
    could it be done.

    Thanks.

Regards,
Uddhav




----- Original Message -----
From: "Keith Visco" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 24, 2002 12:00 PM
Subject: Re: [castor-dev] Castor Support for inner classes


>
> Inner classes must be public and must have a default constructor
>
> --Keith
>
> > Uddhav wrote:
> >
> > Hi,
> >    Can any one please tell me whether castor supports
> >   Inner Classes. If yes how can they be used? I am
> >   provinding the following information for inner classes in
> >   my mapping file
> >         <class name="CastorProxy$HashtableEntriesWrapper">
> >                 <field name="Key">
> >                         <bind-xml name="Key" node="element"/>
> >                 </field>
> >
> >                <field name="Value">
> >                         <bind-xml name="Value" node="element"/>
> >                 </field>
> >         </class>
> >
> >   While loading the mapping information following information is
> >   thrown,
> >
> >     org.exolab.castor.mapping.MappingException: The Java class
> > CastorProxy$HashtableEntriesWrapper is not constructable -- it does
> > not contain a default public constructor
> >
> >  at
> >
org.exolab.castor.mapping.loader.ClassDescriptorImpl.<init>(ClassDescriptorI
mpl.java:127)
> >
> >  at
> >
org.exolab.castor.mapping.loader.MappingLoader.createDescriptor(MappingLoade
r.java:461)
> >
> >  at
> >
org.exolab.castor.xml.XMLMappingLoader.createDescriptor(XMLMappingLoader.jav
a:157)
> >
> >  at
> >
org.exolab.castor.mapping.loader.MappingLoader.loadMapping(MappingLoader.jav
a:212)
> >
> >  at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:278)
> >
> >  at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:234)
> >
> >  at
> > org.exolab.castor.xml.Unmarshaller.setMapping(Unmarshaller.java:224)
> >
> >  at org.exolab.castor.xml.Unmarshaller.<init>(Unmarshaller.java:158)
> >
> >    Any help will be greatly appreciated.
> >
> > Thanks,
> > Uddhav
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>

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

Reply via email to