Harald is right about the underlying issue, but there is at least one
additional alternative to consider -- you can try using a
FactoryCreateRule instead of an ObjectCreateRule for creating an object.
The ObjectCreateRule implementation can do anything it wants to create the
object instance to be pushed on the stack.

Craig

On Sat, 11 Jan 2003, Harald Meyer wrote:

> Date: Sat, 11 Jan 2003 09:34:25 +0100
> From: Harald Meyer <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> Subject: Re: [Digester] Unable to instanciate inner classes
>
> Jeanfrancois Arcand wrote:
>
> > before investigating further, I would like to see if somebody else
> > have seen this problem (or aware of...nothing in bugzilla). I have a
> > framework that use the digester this way:
> >
> > public class HandlerChainDispatcher{
> >
> > [...]
> >
> > protected void loadConfiguration(){
> >        Digester digester = new Digester();
> >        digester.setValidating(false);
> >     digester.addObjectCreate("dispatcher/protocol-mappings/protocol-mapping",
> > ProtocolMappingConfig.class);
> > [...]
> >
> > ProtocolMappingConfig is an inner class of HandlerChainDispatcher.
> > ProtocolMappingConfig has a default constructor and it is not abstract.
> >
> > I'm always having this exception:
> >
> >      [java] java.lang.InstantiationException: HandlerChainDispatcher.
> > $ProtocolMappingConfig
> >      [java]     at      [java]     at
> > java.lang.Class.newInstance0(Class.java:291)
> >      [java]     at java.lang.Class.newInstance(Class.java:259)
> >      [java]     at
> > org.apache.commons.digester.ObjectCreateRule.begin(ObjectCreateRule.ja
> > va:253)
> >
> > I have tried making the inner class final without success.
> >
> > My framework is very simple and doesn't use special classloader. I'm
> > trying to track down the problem (and fix it). Any ideas?
>
> Bonjour Jeanfrancois,
> I think your trouble is caused by the object generation mode that is
> used by the Digester.
> The Digester tries to create your ProtocolMappingConfig instance via
> reflection,
> more precisely: by calling the Class.newInstance() method. This object
> creation
> fails for inner classes. I'm afraid you MUST change your sources so that
> ProtocolMappingConfig is no inner class.
>
> The following tiny sample program demonstrates this behaviour:
>
> public class Foo {
>
>     private void say ( String s ) {
>       System.err.println(s);
>     }
>
>     public Foo() throws Exception {
>       Bar bar1 = new Bar();
>         say("Created bar1: " + bar1);
>
>       Class clazz = Bar.class;
>       Bar bar2 = (Bar) clazz.newInstance();
>       say("Created bar2: " + bar2);
>     }
>
>     public static void main(String[] args) throws Exception {
>       new Foo();
>       System.exit(0);
>     }
>
>     public class Bar {
>       public Bar() {
>           say("Hello, I'm the Bar constructor");
>       }
>     }
> }
>
> bar1 will be created successfully, but the attempt to create bar2 will
> fail.
>
> Greetings,
> Harald
>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to