You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Strachan <ja...@yahoo.co.uk> on 2001/12/04 17:43:56 UTC

[digester] setting attributes & text content on the same object...

Has anyone found any ways to do the following in digester.

Imagine the folllowing class

public class Param {
    public void setName(String name);
    public void setValue(String name);
}

And I want to parse XML like this...

    <param name="foo">bar</param>

And I want the text value of the <param> element to be associated with the
'value' property of the Param.

Then in Digester I'm doing this...

        String path = "foo/param";
        addObjectCreate( path, paramClassName, "className" );
        addSetProperties( path );
        addCallMethod( path, "setValue", 0 );
        addSetNext( path, "addParam", paramClassName );

Which works but the value is never set. Is anyone aware of any way around
this problem? I'm guessing its a current digester limitation.

I know I can parse this fine...


    <param name="foo" value="bar"/>

Which is a work around for now - I'm just wondering if there's a way of
using attributes and text content for the same object & element in digester.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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


Re: [digester] setting attributes & text content on the same object...

Posted by James Strachan <ja...@yahoo.co.uk>.
Actually it turned out to be a bug in my code to do with the order in which
the properties were set and when the addParam() method was called by the
addSetNext() rule. Sorry about that everyone!

So either of these approaches work fine.

        String path = "foo/param";
        addObjectCreate( path, paramClassName, "className" );
        addSetProperties( path );
        addBeanPropertySetter( "value" ) );
        addSetNext( path, "addParam", paramClassName );

or

        addObjectCreate( path, paramClassName, "className" );
        addSetProperties( path );
        addCallMethod( path, "setValue", 0 );
        addSetNext( path, "addParam", paramClassName );

Its just that the "value" property may be set after the addParam() method is
called (the addSetNext() rule).


James
----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Tuesday, December 04, 2001 6:10 PM
Subject: Re: [digester] setting attributes & text content on the same
object...


>
>
> On Tue, 4 Dec 2001, robert burrell donkin wrote:
>
> > Date: Tue, 4 Dec 2001 18:04:48 +0000
> > From: robert burrell donkin <ro...@mac.com>
> > Reply-To: Jakarta Commons Developers List
<co...@jakarta.apache.org>
> > To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> > Subject: Re: [digester] setting attributes & text content on the same
> >     object...
> >
> >
> > On Tuesday, December 4, 2001, at 05:30 PM, Craig R. McClanahan wrote:
> >
> > > On Tue, 4 Dec 2001, James Strachan wrote:
> > >
> > >> Date: Tue, 4 Dec 2001 16:43:56 -0000
> > >> From: James Strachan <ja...@yahoo.co.uk>
> > >> Reply-To: Jakarta Commons Developers List <commons-
> > >> dev@jakarta.apache.org>
> > >> To: Jakarta Commons Developers <co...@jakarta.apache.org>
> > >> Subject: [digester] setting attributes & text content on the same
> > >>     object...
> > >>
> > >> Has anyone found any ways to do the following in digester.
> > >>
> > >> Imagine the folllowing class
> > >>
> > >> public class Param {
> > >>     public void setName(String name);
> > >>     public void setValue(String name);
> > >> }
> > >>
> > >> And I want to parse XML like this...
> > >>
> > >>     <param name="foo">bar</param>
> > >>
> > >> And I want the text value of the <param> element to be associated
with
> > >> the
> > >> 'value' property of the Param.
> >
> > <snip>
> >
> > > This is courtesy of the (relatively) new SetPropertyRule -- Jason van
Zyl
> > > ran into a need for this one, and suggested this approach.
> >
> > hi craig
> > you mean the BeanPropertySetterRule, don't you?
> >
> > > We could
> > > probably extend SetPropertyRule to work they way you want by grabbing
the
> > > value from the body content if there is no "value" argument.
> >
> > i think that you should be able to use the BeanPropertySetterRule to set
a
> > specified property with the body text.
>
> Yep ... I looked at the wrong rule.
>
> >
> > - robert
> >
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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


Re: [digester] setting attributes & text content on the same object...

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 4 Dec 2001, robert burrell donkin wrote:

> Date: Tue, 4 Dec 2001 18:04:48 +0000
> From: robert burrell donkin <ro...@mac.com>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> Subject: Re: [digester] setting attributes & text content on the same
>     object...
>
>
> On Tuesday, December 4, 2001, at 05:30 PM, Craig R. McClanahan wrote:
>
> > On Tue, 4 Dec 2001, James Strachan wrote:
> >
> >> Date: Tue, 4 Dec 2001 16:43:56 -0000
> >> From: James Strachan <ja...@yahoo.co.uk>
> >> Reply-To: Jakarta Commons Developers List <commons-
> >> dev@jakarta.apache.org>
> >> To: Jakarta Commons Developers <co...@jakarta.apache.org>
> >> Subject: [digester] setting attributes & text content on the same
> >>     object...
> >>
> >> Has anyone found any ways to do the following in digester.
> >>
> >> Imagine the folllowing class
> >>
> >> public class Param {
> >>     public void setName(String name);
> >>     public void setValue(String name);
> >> }
> >>
> >> And I want to parse XML like this...
> >>
> >>     <param name="foo">bar</param>
> >>
> >> And I want the text value of the <param> element to be associated with
> >> the
> >> 'value' property of the Param.
>
> <snip>
>
> > This is courtesy of the (relatively) new SetPropertyRule -- Jason van Zyl
> > ran into a need for this one, and suggested this approach.
>
> hi craig
> you mean the BeanPropertySetterRule, don't you?
>
> > We could
> > probably extend SetPropertyRule to work they way you want by grabbing the
> > value from the body content if there is no "value" argument.
>
> i think that you should be able to use the BeanPropertySetterRule to set a
> specified property with the body text.

Yep ... I looked at the wrong rule.

>
> - robert
>

Craig


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


Re: [digester] setting attributes & text content on the same object...

Posted by robert burrell donkin <ro...@mac.com>.
On Tuesday, December 4, 2001, at 05:30 PM, Craig R. McClanahan wrote:

> On Tue, 4 Dec 2001, James Strachan wrote:
>
>> Date: Tue, 4 Dec 2001 16:43:56 -0000
>> From: James Strachan <ja...@yahoo.co.uk>
>> Reply-To: Jakarta Commons Developers List <commons-
>> dev@jakarta.apache.org>
>> To: Jakarta Commons Developers <co...@jakarta.apache.org>
>> Subject: [digester] setting attributes & text content on the same
>>     object...
>>
>> Has anyone found any ways to do the following in digester.
>>
>> Imagine the folllowing class
>>
>> public class Param {
>>     public void setName(String name);
>>     public void setValue(String name);
>> }
>>
>> And I want to parse XML like this...
>>
>>     <param name="foo">bar</param>
>>
>> And I want the text value of the <param> element to be associated with 
>> the
>> 'value' property of the Param.

<snip>

> This is courtesy of the (relatively) new SetPropertyRule -- Jason van Zyl
> ran into a need for this one, and suggested this approach.

hi craig
you mean the BeanPropertySetterRule, don't you?

> We could
> probably extend SetPropertyRule to work they way you want by grabbing the
> value from the body content if there is no "value" argument.

i think that you should be able to use the BeanPropertySetterRule to set a 
specified property with the body text.

- robert


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


Re: [digester] setting attributes & text content on the same object...

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 4 Dec 2001, James Strachan wrote:

> Date: Tue, 4 Dec 2001 16:43:56 -0000
> From: James Strachan <ja...@yahoo.co.uk>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers <co...@jakarta.apache.org>
> Subject: [digester] setting attributes & text content on the same
>     object...
>
> Has anyone found any ways to do the following in digester.
>
> Imagine the folllowing class
>
> public class Param {
>     public void setName(String name);
>     public void setValue(String name);
> }
>
> And I want to parse XML like this...
>
>     <param name="foo">bar</param>
>
> And I want the text value of the <param> element to be associated with the
> 'value' property of the Param.
>
> Then in Digester I'm doing this...
>
>         String path = "foo/param";
>         addObjectCreate( path, paramClassName, "className" );
>         addSetProperties( path );
>         addCallMethod( path, "setValue", 0 );
>         addSetNext( path, "addParam", paramClassName );
>
> Which works but the value is never set. Is anyone aware of any way around
> this problem? I'm guessing its a current digester limitation.
>
> I know I can parse this fine...
>
>
>     <param name="foo" value="bar"/>
>

This is courtesy of the (relatively) new SetPropertyRule -- Jason van Zyl
ran into a need for this one, and suggested this approach.  We could
probably extend SetPropertyRule to work they way you want by grabbing the
value from the body content if there is no "value" argument.

> Which is a work around for now - I'm just wondering if there's a way of
> using attributes and text content for the same object & element in digester.
>
> James
>

Craig


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