You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by otisg <ot...@ureach.com> on 2003/03/14 05:14:35 UTC

[Digester] inner class instantiation failing

Hello,

I am using Commons Digester HEAD version
(stright out of CVS).
I am trying to parse an XML file that look
like this:

<command-mappings>
    <command name="Foo"
logic="com.example.Foo"/>
    <command name="Bar"
logic="com.example.Bar"/>
    ...
</command-mappings>

I want to end up with a Map where name
attribute is the key, and logic attribute is
the value of that Map.

I have a solution that does this, but it
consists of 2 separate classes.  What I
would like to have though is a solution that
requires only 1 class.
I have tried using an inner class, but it
looks like Commons Digester cannot
instantiate an inner class.

The code I have looks roughly like this:

Digester digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate("command-mappings",
CLM.class );
digester.addObjectCreate("command-mappings/command",
Cmd.class );
digester.addSetProperties("command-mappings/command",
"name", "name" );
digester.addSetProperties("command-mappings/command",
"logic", "logic" );
digester.addSetNext("command-mappings/command",
"addCommand" );
CLM clm = (CLM) digester.parse(new
File(args[0]));

The problem is that I want that 'Cmd' class
to be an inner class.
If I make Cmd a separate public class, the
code above works.
If I make Cmd an inner class instead, the
code breaks with the following error:

11 [main] ERROR digester.Digester  - Begin
event threw exception
java.lang.InstantiationException: CLM$MyCmd
        at
java.lang.Class.newInstance0(Class.java:291)
        at
java.lang.Class.newInstance(Class.java:259)
        at
org.apache.commons.digester.ObjectCreateRule.begin(ObjectCreateRule.java:253)
        at
org.apache.commons.digester.Rule.begin(Rule.java:200)
        at
org.apache.commons.digester.Digester.startElement(Digester.java:1268)


Is there a 'trick' for getting the Digester
to instantiate inner classes just like it
does regular classes?

Thanks,
Otis


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag