commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: Inner Class and Digester
Date Sun, 21 Sep 2003 19:52:39 GMT
hi Bahram

digester uses reflection to create instances. i strongly suspect that 
inner classes must have enclosing instances and therefore they cannot be 
created by reflection.

i would suggest that you use an ObjectCreationFactory or a custom rule.

- robert

On Friday, September 19, 2003, at 09:08 PM, Enshayan, Bahram wrote:

> I want to use the Digester package to parse an xml file and create an
> instance of a class.  The class has an inner class and I want to
> instantiate this inner class from digester, but I run in to some
> problems.
>
> Does anybody know of a way to use the Digester package to instantiate
> an inner class?  I cannot make the class static-inner class and I
> cannot make it a seperate class.
>
> Details of my situation:
>
> - java code
> public ClassA {
>     String name;
>
>     public ClassA() {
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public class ClassB {
>         String name;
>
>         public ClassB() {
>         }
>
>         public void setName(String name) {
>             this.name = name;
>         }
>     }
> }
>
> - Here are the Digester rules:
> addObjectCreate("classa", "ClassA");
> addCallMethod("classa/name", "setName", 0);
> addObjectCreate("classa/classb", "ClassB");
> addCallMethod("classa/classb/name", "setName", 0);
>
>
> - Here is the xml:
> <classa>
>    <name>somename</name>
>    <classb>
>       <name>someothername</name>
>    </classb>
> </classa>
>
>
> I get classNotFoundExcepton if have the above setup. If I change the
> second last line in the Digester rules to:
> addObjectCreate("classa/classb", "ClassA$ClassB");
> then I get InstantiationException.
>
>
> Does anyone know why I am getting these errors?
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message