| java.lang.Object org.apache.tomcat.util.digester.Rule org.apache.tomcat.util.digester.CallMethodRule
CallMethodRule | public class CallMethodRule extends Rule (Code) | | 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.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).
|
Field Summary | |
protected String | bodyText The body text collected from this element. | protected String | methodName The method name to call on the parent object. | protected String | paramClassNames The names of the classes of the parameters to be collected. | protected int | paramCount The number of parameters to collect from MethodParam rules. | protected Class | paramTypes The parameter types of the parameters to be collected. | protected int | targetOffset location of the target object for the call, relative to the
top of the digester object stack. | protected boolean | useExactMatch Should MethodUtils.invokeExactMethod be used for reflection. |
Constructor Summary | |
public | CallMethodRule(Digester digester, String methodName, int paramCount) Construct a "call method" rule with the specified method name. | public | CallMethodRule(Digester digester, String methodName, int paramCount, String paramTypes) Construct a "call method" rule with the specified method name. | public | CallMethodRule(Digester digester, String methodName, int paramCount, Class paramTypes) Construct a "call method" rule with the specified method name. | public | CallMethodRule(String methodName, int paramCount) Construct a "call method" rule with the specified method name. | public | CallMethodRule(int targetOffset, String methodName, int paramCount) Construct a "call method" rule with the specified method name. | public | CallMethodRule(String methodName) Construct a "call method" rule with the specified method name. | public | CallMethodRule(int targetOffset, String methodName) Construct a "call method" rule with the specified method name. | public | CallMethodRule(String methodName, int paramCount, String paramTypes) Construct a "call method" rule with the specified method name and
parameter types. | public | CallMethodRule(int targetOffset, String methodName, int paramCount, String paramTypes) Construct a "call method" rule with the specified method name and
parameter types. | public | CallMethodRule(String methodName, int paramCount, Class paramTypes) Construct a "call method" rule with the specified method name and
parameter types. | public | CallMethodRule(int targetOffset, String methodName, int paramCount, Class paramTypes) Construct a "call method" rule with the specified method name and
parameter types. |
Method Summary | |
public void | begin(Attributes attributes) Process the start of this element. | public void | body(String bodyText) Process the body text of this element. | public void | end() Process the end of this element. | public void | finish() Clean up after parsing is complete. | public boolean | getUseExactMatch() Should MethodUtils.invokeExactMethod
be used for the reflection. | protected void | processMethodCallResult(Object result) Subclasses may override this method to perform additional processing of the
invoked method's result. | public void | setDigester(Digester digester) Set the associated digester. | public void | setUseExactMatch(boolean useExactMatch) Set whether MethodUtils.invokeExactMethod
should be used for the reflection. | public String | toString() Render a printable version of this Rule. |
bodyText | protected String bodyText(Code) | | The body text collected from this element.
|
methodName | protected String methodName(Code) | | The method name to call on the parent object.
|
paramClassNames | protected String paramClassNames(Code) | | The names of the classes of the parameters to be collected.
This attribute allows creation of the classes to be postponed until the digester is set.
|
paramCount | protected int paramCount(Code) | | The number of parameters to collect from MethodParam rules.
If this value is zero, a single parameter will be collected from the
body of this element.
|
paramTypes | protected Class paramTypes(Code) | | The parameter types of the parameters to be collected.
|
targetOffset | protected int targetOffset(Code) | | location of the target object for the call, relative to the
top of the digester object stack. The default value of zero
means the target object is the one on top of the stack.
|
useExactMatch | protected boolean useExactMatch(Code) | | Should MethodUtils.invokeExactMethod be used for reflection.
|
CallMethodRule | public CallMethodRule(Digester digester, String methodName, int paramCount)(Code) | | Construct a "call method" rule with the specified method name. The
parameter types (if any) default to java.lang.String.
Parameters: digester - The associated Digester Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of this element.Digester.addRuleCallMethodRule.CallMethodRule(String methodName,int paramCount) |
CallMethodRule | public CallMethodRule(Digester digester, String methodName, int paramCount, String paramTypes)(Code) | | Construct a "call method" rule with the specified method name.
Parameters: digester - The associated Digester Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java class names of the arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean for a boolean parameter)Digester.addRuleCallMethodRule.CallMethodRule(String methodName,int paramCount,String[] paramTypes) |
CallMethodRule | public CallMethodRule(Digester digester, String methodName, int paramCount, Class paramTypes)(Code) | | Construct a "call method" rule with the specified method name.
Parameters: digester - The associated Digester Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java classes that represent theparameter types of the method arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean.TYPE for a boolean parameter)Digester.addRuleCallMethodRule.CallMethodRule(String methodName,int paramCount,Class[] paramTypes) |
CallMethodRule | public CallMethodRule(String methodName, int paramCount)(Code) | | Construct a "call method" rule with the specified method name. The
parameter types (if any) default to java.lang.String.
Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of this element. |
CallMethodRule | public CallMethodRule(int targetOffset, String methodName, int paramCount)(Code) | | Construct a "call method" rule with the specified method name. The
parameter types (if any) default to java.lang.String.
Parameters: targetOffset - location of the target object. Positive numbers arerelative to the top of the digester object stack. Negative numbers are relative to the bottom of the stack. Zero implies the topobject on the stack. Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of this element. |
CallMethodRule | public CallMethodRule(String methodName)(Code) | | Construct a "call method" rule with the specified method name.
The method should accept no parameters.
Parameters: methodName - Method name of the parent method to call |
CallMethodRule | public CallMethodRule(int targetOffset, String methodName)(Code) | | Construct a "call method" rule with the specified method name.
The method should accept no parameters.
Parameters: targetOffset - location of the target object. Positive numbers arerelative to the top of the digester object stack. Negative numbers are relative to the bottom of the stack. Zero implies the topobject on the stack. Parameters: methodName - Method name of the parent method to call |
CallMethodRule | public CallMethodRule(String methodName, int paramCount, String paramTypes)(Code) | | Construct a "call method" rule with the specified method name and
parameter types. If 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.
Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java class names of the arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean for a boolean parameter) |
CallMethodRule | public CallMethodRule(int targetOffset, String methodName, int paramCount, String paramTypes)(Code) | | Construct a "call method" rule with the specified method name and
parameter types. If 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.
Parameters: targetOffset - location of the target object. Positive numbers arerelative to the top of the digester object stack. Negative numbers are relative to the bottom of the stack. Zero implies the topobject on the stack. Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java class names of the arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean for a boolean parameter) |
CallMethodRule | public CallMethodRule(String methodName, int paramCount, Class paramTypes)(Code) | | Construct a "call method" rule with the specified method name and
parameter types. If 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.
Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java classes that represent theparameter types of the method arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean.TYPE for a boolean parameter) |
CallMethodRule | public CallMethodRule(int targetOffset, String methodName, int paramCount, Class paramTypes)(Code) | | Construct a "call method" rule with the specified method name and
parameter types. If 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.
Parameters: targetOffset - location of the target object. Positive numbers arerelative to the top of the digester object stack. Negative numbers are relative to the bottom of the stack. Zero implies the topobject on the stack. Parameters: methodName - Method name of the parent method to call Parameters: paramCount - The number of parameters to collect, orzero for a single argument from the body of ths element Parameters: paramTypes - The Java classes that represent theparameter types of the method arguments(if you wish to use a primitive type, specify the corresondingJava wrapper class instead, such as java.lang.Boolean.TYPE for a boolean parameter) |
begin | public void begin(Attributes attributes) throws Exception(Code) | | Process the start of this element.
Parameters: attributes - The attribute list for this element |
body | public void body(String bodyText) throws Exception(Code) | | Process the body text of this element.
Parameters: bodyText - The body text of this element |
end | public void end() throws Exception(Code) | | Process the end of this element.
|
finish | public void finish() throws Exception(Code) | | Clean up after parsing is complete.
|
getUseExactMatch | public boolean getUseExactMatch()(Code) | | Should MethodUtils.invokeExactMethod
be used for the reflection.
|
processMethodCallResult | protected void processMethodCallResult(Object result)(Code) | | Subclasses may override this method to perform additional processing of the
invoked method's result.
Parameters: result - the Object returned by the method invoked, possibly null |
setDigester | public void setDigester(Digester digester)(Code) | | Set the associated digester.
If needed, this class loads the parameter classes from their names.
|
setUseExactMatch | public void setUseExactMatch(boolean useExactMatch)(Code) | | Set whether MethodUtils.invokeExactMethod
should be used for the reflection.
|
toString | public String toString()(Code) | | Render a printable version of this Rule.
|
|
|