commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lee Francis Wilhelmsen <>
Subject [Digester] Calling a class property setter method using a predefined value not present in xml.
Date Fri, 03 Dec 2004 10:40:44 GMT

My question is pretty simple. How do you call a class method with a
parameter value not present in the xml, but known to be of a defined
value? All the methods I've seen take the value from the tag or
attribute and feed this to the class. This assumes that the xml file
holds all values needed to populate the java class, but this may not
always be the case.

Let's say you have a class like this:

public class MyClass {
    private String tagValue;
    private boolean tagSet;

    public setFlag(boolean b) {tagSet = b}
    public setA(String a) { tagValue = a;}

That you want to populate from a tag <a>. If the tag <a> is available in
the xml then two methods should be called on a java class:
   - the method to set the a value, setA(String)
   - a method to indicate that the value is set, setFlag(true)

My rules would look something like:

<call-method-rule methodname="setA" paramcount="1"/>
<call-param-rule paramnumber='0' attrname='url'/>
<call-method-rule methodname="setFlag" paramcount="1"/>
<call-param-rule paramnumber='0' [..something boolean here...] />

Now, in my example I can get around the problem by just calling
setFlag() from inside the setA() method to notify that the value had
been set so this isn't really a problem, but that's only because I
controlled the class code. What if I didn't and had to use the class
(yes I probably could create a new subclass overiding this method)...

How can I then call a method based on a value not present in the xml,
but known to be of a certain value?

Lee Francis

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message