On 3 Dec 2004, at 10:40, Lee Francis Wilhelmsen wrote:
Hi
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?
i don't think that this can be done with the standard rules right now. it should be possible to extend CallParamRule (or perhaps create a new class) to give an option to push a value onto the parameter. a patch for this feature would be gratefully accepted ;)
until this feature is added to the standard set of rules shipping with digester, the quickest way to solve your problem would be to create a custom rule.
- robert
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
