You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Scott Sanders <ss...@nextance.com> on 2002/01/11 01:00:52 UTC

[DIGESTER] simple xml attribute to java attribute mapping?

What is the best way in digester to do a simple xml attr -> java attr
mapping.

For example:

<tag name="foo" style="bar"/>

And the class looks like:

Class Tag {
  public void setName(String name) {...}
  public void setStyleName(String style) {...}
}

The SetPropertiesRule handles the name->setName() case, but what is the
easiest way to handle the style->setStyleName() case?

Silly question, but my brain is dead, I am currently using
CallMethodRule with CallParamRule, and I think there should be a better
way :)

Scott

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DIGESTER] simple xml attribute to java attribute mapping?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Thu, 10 Jan 2002, Scott Sanders wrote:

> Date: Thu, 10 Jan 2002 16:00:52 -0800
> From: Scott Sanders <ss...@nextance.com>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: commons-dev@jakarta.apache.org
> Subject: [DIGESTER]  simple xml attribute to java attribute mapping?
>
> What is the best way in digester to do a simple xml attr -> java attr
> mapping.
>
> For example:
>
> <tag name="foo" style="bar"/>
>
> And the class looks like:
>
> Class Tag {
>   public void setName(String name) {...}
>   public void setStyleName(String style) {...}
> }
>
> The SetPropertiesRule handles the name->setName() case, but what is the
> easiest way to handle the style->setStyleName() case?
>
> Silly question, but my brain is dead, I am currently using
> CallMethodRule with CallParamRule, and I think there should be a better
> way :)
>

There aren't any current Digester rules that do that kind of thing for
you.  Presumably, you'd want to be able to map more than one
attribute-property pair.

A way to make this work would be to define a BeanInfo class for your bean
class that returned a PropertyDescriptor for the 'style' property that
says the setter method is really 'setStyleName'.  This will get picked up
by the introspection mechanism in PropertyUtils (which is what Digester is
using underneath), with no changes to Digester.

> Scott
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>