You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jon Steelman <JS...@incomm.com> on 2005/06/16 06:35:11 UTC
[Digester] How to assign from a property with a BeanPropertySetter?
I have a brief example below where I'm uncertain how to assign the value
"activate" from cardAction's action. Here's the xml:
<?xml version="1.0"?>
<!DOCTYPE cardActionVendor SYSTEM "cardActionVendor.dtd">
<cardActionVendor>
<response>
<cardid>1234567890</cardid>
<locationID>55555</locationID>
<cardAction action="activate"/>
<merchant><merchantID>4444</merchantID></merchant>
</response>
</cardActionVendor>
Here's the code:
digester.addObjectCreate("cardActionVendor/response",
ActivateResponse.class);
digester.addBeanPropertySetter(PREFIX + "cardid",
"primaryAccountNumber");
digester.addBeanPropertySetter(PREFIX + "locationID");
digester.addBeanPropertySetter(PREFIX + "/merchant/merchantID");
The ActivateResponse class basically has these properties:
primaryAccountNumber, locationID, merchantID, & action.
I see how I can nest the merchant/merchantID to assign a property in my
class ActivateResponse. I have another direct property in
ActivateResponse that is the value of cardAction's action, but I don't
know how to assign it. The following won't work:
digester.addBeanPropertySetter(PREFIX + "/cardAction/action");
The ActivateRespone property is at the same level as the other
properties, cardid & locationID, but how does one set it?
Thanks,
Jon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Digester] How to assign from a property with a
BeanPropertySetter?
Posted by Simon Kitching <sk...@apache.org>.
Hi Jon,
On Thu, 2005-06-16 at 00:35 -0400, Jon Steelman wrote:
> <response>
> <cardid>1234567890</cardid>
> <locationID>55555</locationID>
> <cardAction action="activate"/>
> <merchant><merchantID>4444</merchantID></merchant>
> </response>
> </cardActionVendor>
>
> Here's the code:
> digester.addObjectCreate("cardActionVendor/response",
> ActivateResponse.class);
> digester.addBeanPropertySetter(PREFIX + "cardid",
> "primaryAccountNumber");
> digester.addBeanPropertySetter(PREFIX + "locationID");
> digester.addBeanPropertySetter(PREFIX + "/merchant/merchantID");
>
> The ActivateResponse class basically has these properties:
> primaryAccountNumber, locationID, merchantID, & action.
>
> I see how I can nest the merchant/merchantID to assign a property in my
> class ActivateResponse. I have another direct property in
> ActivateResponse that is the value of cardAction's action, but I don't
> know how to assign it. The following won't work:
> digester.addBeanPropertySetter(PREFIX + "/cardAction/action");
> The ActivateRespone property is at the same level as the other
> properties, cardid & locationID, but how does one set it?
You can use CallMethodRule:
digester.addCallMethod("response/cardAction", "setAction", 1);
digester.addCallParam("response/cardAction", 0, "action");
As the xml attribute name "action" matches the name of the property to
be set, you could also use SetPropertiesRule:
digester.addSetProperties("response/cardAction");
While the latter is shorter, the former seems more appropriate as you
are specifically grabbing the "action" attribute rather than the set of
all attributes (which just happens to be a set of one).
Are you aware that there is a set of examples available with Digester?
I recommend downloading the src distribution and looking in
"src/examples/api"; alternatively browse the source:
http://svn.apache.org/repos/asf/jakarta/commons/proper/digester/trunk/src/examples/api/
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org