commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Digester:
Date Wed, 08 May 2002 02:42:05 GMT


On Tue, 7 May 2002, Kris Schneider wrote:

> Date: Tue, 07 May 2002 21:23:29 -0400
> From: Kris Schneider <kris@dotech.com>
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>,
>      Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: Jakarta Commons Developers List <commons-dev@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:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message