Class CallMethodRule

java.lang.Object
org.apache.tomcat.util.digester.Rule
org.apache.tomcat.util.digester.CallMethodRule

public class CallMethodRule extends Rule

Rule implementation that calls a method on an object on the stack (normally the top/parent object), passing arguments collected from subsequent CallParamRule rules or from the body of this element.

By using CallMethodRule(String methodName) a method call can be made to a method which accepts no arguments.

Incompatible method parameter types are converted using org.apache.commons.beanutils.ConvertUtils.

This rule now uses org.apache.commons.beanutils.MethodUtils#invokeMethod by default. This increases the kinds of methods successfully and allows primitives to be matched by passing in wrapper classes. There are rare cases when org.apache.commons.beanutils.MethodUtils#invokeExactMethod (the old default) is required. This method is much stricter in its reflection. Setting the UseExactMatch to true reverts to the use of this method.

Note that the target method is invoked when the end of the tag the CallMethodRule fired on is encountered, not when the last parameter becomes available. This implies that rules which fire on tags nested within the one associated with the CallMethodRule will fire before the CallMethodRule invokes the target method. This behaviour is not configurable.

Note also that if a CallMethodRule is expecting exactly one parameter and that parameter is not available (eg CallParamRule is used with an attribute name but the attribute does not exist) then the method will not be invoked. If a CallMethodRule is expecting more than one parameter, then it is always invoked, regardless of whether the parameters were available or not (missing parameters are passed as null values).