commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject RE: [Digester] Question on CallMethodRule
Date Wed, 19 Nov 2003 23:24:27 GMT
On Thu, 2003-11-20 at 07:43, Shapira, Yoav wrote:
> Howdy,
> That works perfectly!!  Thanks so much ;)
> 
> I have hopefully one final question.
> 
> XML:
> <b attribute1="something"
>    attribute2="something"
>    attribtue3="something" />
> 
> Class B extends C.  Class B has public methods setAttribute1 and setAttribute2.  The
public setAttribute3 method is in the superclass, class C.  I use digester.addSetProperties("b"),
but only attributes 1 and 2
> are filled out.  The setAttribute3 method is not called.
> 
> Why does this happen?  Is it the limitation noted on the digester javadoc page, "Accessing
Public Methods In A Default Access Superclass" ??  If so, what is the work-around?

hmm .. inherited attributes should be settable.

SetPropertiesRule just uses BeanUtils.setProperty(.....) to do the
actual call to the setter method.

There are two possibilities:
(a) 
you have mis-spelled attribute3 in the above example. Is this just a
typo in the email, or really in the code?
(b)
properties must *really* comply with the JavaBeans spec.

If you have
  public void setFoo(String foo);
  int getFoo();
then this is not javabeans-compliant. You will then need to use
something like CallMethodRule rather than SetPropertiesRule.

--

Re an earlier post of yours:

On Thu, 2003-11-20 at 06:29, José Antonio Pérez Testa wrote: 
> Hi Yoav,
> Your xml format has to be that one?
> With this other format the solution will be straightforward
> 
> <a>
>   <b class="package.class">
>     <foo>bar</foo>
>   </b>
> </a>
> 
> digester.addSetProperties("a/b");
> 

The SetPropertiesRule maps xml *attributes* to java object properties.
So if your xml input is like this, then SetPropertiesRule will help:
 <b class="package.class" foo="bar" who="me"/>

If your xml looks like this, then SetPropertyRule is your friend:
  <b class="package.class"
    <property name="foo" value="bar"/>
    <property name="who" value="me"/>
  </b>

And this style of xml:
  <b class="package.class">
    <foo>bar</foo>
    <who>me</who>
  </b>
can be processed in two ways:

* 
BeanPropertySetterRule can be used to map elements like foo and who to
appropriate properties. However the pattern associated with the
BeanPropertySetterRule needs to match the child element (eg foo).
Therefore you must either know all the possible child elements in
advance and add a rule for each one (one for "foo", one for "who") or
use the ExtendedBaseRules with trailing wildcard pattern.

*
SetNestedPropertiesRule can process the above xml without wildcard
patterns or explicitly specifying the child elements. However it was
added very recently (only yesterday!) so you'll need to use CVS - and
will be on the bleeding edge of Digester technology :-)

Personally, I would recommend either using SetPropertiesRule (with
properties in xml attributes) or SetPropertyRule. But it all depends on
how adventurous you are...


Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message