commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [digester] give Digester access to private data
Date Mon, 17 Mar 2003 19:53:08 GMT

On Mon, 17 Mar 2003, Erik Price wrote:

> Date: Mon, 17 Mar 2003 11:34:18 -0500
> From: Erik Price <>
> Reply-To: Jakarta Commons Users List <>
> To: Jakarta Commons Users List <>
> Subject: Re: [digester] give Digester access to private data
> Dominique Devienne wrote:
> > Why do you need to call a private method???
> >
> > In any case, if you're running without a security manager, you can simply
> > call AccessibleObject/Method.setAccessible(true) to bypass Java's access
> > checking rules (and get all methods instead of just the public ones, by
> > calling Class.getDeclaredMethods). It's technically possible, but again, why
> > would you need it... --DD
> I didn't know about the setAccessible method -- guess I have more to
> learn about java.lang.reflect.
> As for where I'd need it, I have a class that uses a digester to "set
> itself up" (setting some parameters) using methods that I wanted to keep
> private simply because the class shouldn't be used /without/ a digester.
>   But it's not according to some official design, I'm sort of just
> playing about with it and making these methods public isn't really going
> to compromise my class's integrity, so it will be just easier to do
> that.  I was simply following the suggestion that generally methods
> should be left private unless they absolutely have to be public in order
> to fulfill their purpose.
> Thanks for the pointer Dominique.

I haven't actually tried this, so YMMV, but this approach might work --
create your "real" object with package protection on the configurable
property setters.  Then, in your digester rules, create a proxy object
(of a class in the same package) that has public setters and just
delegates them through to calls on the real object.  When you're done
configuring things, throw away the proxy class instance.

This way, you don't have to mess with the real class at all, and you don't
risk making setter methods public that you don't want to have globally

> Erik


View raw message