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).
| Modifier and Type | Field and Description | 
|---|---|
| protected String | bodyTextThe body text collected from this element. | 
| protected String | methodNameThe method name to call on the parent object. | 
| protected String[] | paramClassNamesThe names of the classes of the parameters to be collected. | 
| protected int | paramCountThe number of parameters to collect from  MethodParamrules. | 
| protected Class<?>[] | paramTypesThe parameter types of the parameters to be collected. | 
| protected int | targetOffsetlocation of the target object for the call, relative to the
 top of the digester object stack. | 
| protected boolean | useExactMatchShould  MethodUtils.invokeExactMethodbe used for reflection. | 
digester, namespaceURI| Constructor and Description | 
|---|
| CallMethodRule(int targetOffset,
              String methodName)Construct a "call method" rule with the specified method name. | 
| CallMethodRule(int targetOffset,
              String methodName,
              int paramCount)Construct a "call method" rule with the specified method name. | 
| CallMethodRule(int targetOffset,
              String methodName,
              int paramCount,
              Class<?>[] paramTypes)Construct a "call method" rule with the specified method name and
 parameter types. | 
| CallMethodRule(int targetOffset,
              String methodName,
              int paramCount,
              String[] paramTypes)Construct a "call method" rule with the specified method name and
 parameter types. | 
| CallMethodRule(String methodName)Construct a "call method" rule with the specified method name. | 
| CallMethodRule(String methodName,
              int paramCount)Construct a "call method" rule with the specified method name. | 
| CallMethodRule(String methodName,
              int paramCount,
              Class<?>[] paramTypes)Construct a "call method" rule with the specified method name and
 parameter types. | 
| CallMethodRule(String methodName,
              int paramCount,
              String[] paramTypes)Construct a "call method" rule with the specified method name and
 parameter types. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | begin(String namespace,
     String name,
     Attributes attributes)Process the start of this element. | 
| void | body(String namespace,
    String name,
    String bodyText)Process the body text of this element. | 
| void | end(String namespace,
   String name)Process the end of this element. | 
| void | finish()Clean up after parsing is complete. | 
| boolean | getUseExactMatch()Should  MethodUtils.invokeExactMethodbe used for the reflection. | 
| protected void | processMethodCallResult(Object result)Subclasses may override this method to perform additional processing of the
 invoked method's result. | 
| void | setDigester(Digester digester)Set the associated digester. | 
| void | setUseExactMatch(boolean useExactMatch)Set whether  MethodUtils.invokeExactMethodshould be used for the reflection. | 
| String | toString()Render a printable version of this Rule. | 
begin, body, end, getDigester, getNamespaceURI, setNamespaceURIprotected String bodyText
protected int targetOffset
protected String methodName
protected int paramCount
MethodParam rules.
 If this value is zero, a single parameter will be collected from the
 body of this element.protected Class<?>[] paramTypes
protected String[] paramClassNames
protected boolean useExactMatch
MethodUtils.invokeExactMethod be used for reflection.public CallMethodRule(String methodName, int paramCount)
methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this element.public CallMethodRule(int targetOffset,
              String methodName,
              int paramCount)
targetOffset - location of the target object. Positive numbers are
 relative to the top of the digester object stack. Negative numbers
 are relative to the bottom of the stack. Zero implies the top
 object on the stack.methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this element.public CallMethodRule(String methodName)
methodName - Method name of the parent method to callpublic CallMethodRule(int targetOffset,
              String methodName)
targetOffset - location of the target object. Positive numbers are
 relative to the top of the digester object stack. Negative numbers
 are relative to the bottom of the stack. Zero implies the top
 object on the stack.methodName - Method name of the parent method to callpublic CallMethodRule(String methodName, int paramCount, String[] paramTypes)
paramCount is set to zero the rule
 will use the body of this element as the single argument of the
 method, unless paramTypes is null or empty, in this
 case the rule will call the specified method with no arguments.methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this elementparamTypes - The Java class names of the arguments
  (if you wish to use a primitive type, specify the corresponding
  Java wrapper class instead, such as java.lang.Boolean
  for a boolean parameter)public CallMethodRule(int targetOffset,
              String methodName,
              int paramCount,
              String[] paramTypes)
paramCount is set to zero the rule
 will use the body of this element as the single argument of the
 method, unless paramTypes is null or empty, in this
 case the rule will call the specified method with no arguments.targetOffset - location of the target object. Positive numbers are
 relative to the top of the digester object stack. Negative numbers
 are relative to the bottom of the stack. Zero implies the top
 object on the stack.methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this elementparamTypes - The Java class names of the arguments
  (if you wish to use a primitive type, specify the corresponding
  Java wrapper class instead, such as java.lang.Boolean
  for a boolean parameter)public CallMethodRule(String methodName, int paramCount, Class<?>[] paramTypes)
paramCount is set to zero the rule
 will use the body of this element as the single argument of the
 method, unless paramTypes is null or empty, in this
 case the rule will call the specified method with no arguments.methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this elementparamTypes - The Java classes that represent the
  parameter types of the method arguments
  (if you wish to use a primitive type, specify the corresponding
  Java wrapper class instead, such as java.lang.Boolean.TYPE
  for a boolean parameter)public CallMethodRule(int targetOffset,
              String methodName,
              int paramCount,
              Class<?>[] paramTypes)
paramCount is set to zero the rule
 will use the body of this element as the single argument of the
 method, unless paramTypes is null or empty, in this
 case the rule will call the specified method with no arguments.targetOffset - location of the target object. Positive numbers are
 relative to the top of the digester object stack. Negative numbers
 are relative to the bottom of the stack. Zero implies the top
 object on the stack.methodName - Method name of the parent method to callparamCount - The number of parameters to collect, or
  zero for a single argument from the body of this elementparamTypes - The Java classes that represent the
  parameter types of the method arguments
  (if you wish to use a primitive type, specify the corresponding
  Java wrapper class instead, such as java.lang.Boolean.TYPE
  for a boolean parameter)public boolean getUseExactMatch()
MethodUtils.invokeExactMethod
 be used for the reflection.public void setUseExactMatch(boolean useExactMatch)
MethodUtils.invokeExactMethod
 should be used for the reflection.public void setDigester(Digester digester)
setDigester in class Rulepublic void begin(String namespace, String name, Attributes attributes) throws Exception
begin in class Rulenamespace - the namespace URI of the matching element, or an
   empty string if the parser is not namespace aware or the element has
   no namespacename - the local name if the parser is namespace aware, or just
   the element name otherwiseattributes - The attribute list for this elementExceptionpublic void body(String namespace, String name, String bodyText) throws Exception
body in class Rulenamespace - the namespace URI of the matching element, or an
   empty string if the parser is not namespace aware or the element has
   no namespacename - the local name if the parser is namespace aware, or just
   the element name otherwisebodyText - The body text of this elementExceptionpublic void end(String namespace, String name) throws Exception
public void finish()
            throws Exception
protected void processMethodCallResult(Object result)
result - the Object returned by the method invoked, possibly nullCopyright © 2000-2020 Apache Software Foundation. All Rights Reserved.