You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Kris Schneider <kr...@dotech.com> on 2002/05/08 03:23:29 UTC
Digester:
Just started using Digester and can't see built-in support for the
scenario where an attribute name doesn't map directly to a bean property
name. For instance, if I've got an element:
<proc name="shutdown" proc-type="admin"/>
and a bean with a procedureType property, how can I get the value of the
proc-type attribute into the procedureType property?
I've gone ahead and written my own rule to handle it, but it seems like
such a common occurrence that I must have missed something. Thanks for
any pointers.
Ah, apologies for reading Javadoc while composing, but can
CallMethodRule/CallParamRule do this?
digester.addObjectCreate("procs/proc", "ProcBean");
digester.addSetProperties("procs/proc");
digester.addCallMethod("procs/proc", "setProcedureType", 1);
digester.addCallParam("procs/proc", 0, "proc-type");
"Waldhoff, Rodney" wrote:
>
> > I've got a couple of user questions about Digester, but can only locate
> > a developer list. Is there a list for posting general usage questions?
>
> There is only commons-dev for now. Post away.
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
Re: Digester:
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 7 May 2002, Kris Schneider wrote:
> Date: Tue, 07 May 2002 21:23:29 -0400
> From: Kris Schneider <kr...@dotech.com>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>,
> Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> Subject: Digester:
>
> Just started using Digester and can't see built-in support for the
> scenario where an attribute name doesn't map directly to a bean property
> name. For instance, if I've got an element:
>
> <proc name="shutdown" proc-type="admin"/>
>
> and a bean with a procedureType property, how can I get the value of the
> proc-type attribute into the procedureType property?
>
> I've gone ahead and written my own rule to handle it, but it seems like
> such a common occurrence that I must have missed something. Thanks for
> any pointers.
>
Digester (well, it's really PropertyUtils underneath) uses standard Java
introspection techniques to discover the names of the supported properties
of a JavaBean, as well as the names of the getter and setter methods. So,
one approach would be to define a BeanInfo class for your bean, which
defined the existence of a "proc-type" property, and defined
"setProcedureType" as the property setter.
See the JavaBeans spec for more details:
http://java.sun.com/products/javabeans/
> Ah, apologies for reading Javadoc while composing, but can
> CallMethodRule/CallParamRule do this?
>
> digester.addObjectCreate("procs/proc", "ProcBean");
> digester.addSetProperties("procs/proc");
> digester.addCallMethod("procs/proc", "setProcedureType", 1);
> digester.addCallParam("procs/proc", 0, "proc-type");
>
Should work, although addSetProperties() probably isn't relevant unless
you have other property names that actually do match.
Craig McClanahan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>