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 | bodyText
The body text collected from this element. |
| protected final String | methodName
The method name to call on the parent object. |
| protected final int | paramCount
The number of parameters to collect from |
| protected Class | paramTypes
The parameter types of the parameters to be collected. |
| protected final int | targetOffset
location of the target object for the call, relative to the top of the digester object stack. |
| protected boolean | useExactMatch
Should |
| Access | Constructor and Description |
|---|---|
| public | CallMethodRule(String
Method name of the parent method to call methodName, int The number of parameters to collect, or
zero for a single argument from the body of this element. paramCount)Construct a "call method" rule with the specified method name. |
| public | CallMethodRule(int
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. targetOffset, String Method name of the parent method to call methodName, int The number of parameters to collect, or
zero for a single argument from the body of this element. paramCount)Construct a "call method" rule with the specified method name. |
| public | CallMethodRule(String
Method name of the parent method to call methodName)Construct a "call method" rule with the specified method name. |
| public | CallMethodRule(int
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. targetOffset, String Method name of the parent method to call methodName, int The number of parameters to collect, or
zero for a single argument from the body of this element paramCount, Class<?>[] 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 paramTypes)java.lang.Boolean.TYPE
for a boolean parameter)Construct a "call method" rule with the specified method name and parameter types. |
| Modifier and Type | Method and Description |
|---|---|
| public void | begin(String
the namespace URI of the matching element, or an
empty string if the parser is not namespace aware or the element has
no namespace namespace, String the local name if the parser is namespace aware, or just
the element name otherwise name, Attributes The attribute list for this element attributes)Overrides org. Process the start of this element. |
| public void | body(String
the namespace URI of the matching element, or an
empty string if the parser is not namespace aware or the element has
no namespace namespace, String the local name if the parser is namespace aware, or just
the element name otherwise name, String The body text of this element bodyText)Overrides org. Process the body text of this element. |
| public void | end(String
the namespace URI of the matching element, or an
empty string if the parser is not namespace aware or the element has
no namespace namespace, String the local name if the parser is namespace aware, or just
the element name otherwise name)Overrides org. Process the end of this element. |
| public void | |
| public boolean | Returns: true if invokeExactMethod is usedShould |
| protected void | processMethodCallResult(Object
the Object returned by the method invoked, possibly null result)Subclasses may override this method to perform additional processing of the invoked method's result. |
| public void | setUseExactMatch(boolean
The flag value useExactMatch)Set whether |
| public String |
| bodyText | back to summary |
|---|---|
| protected String bodyText The body text collected from this element. | |
| methodName | back to summary |
|---|---|
| protected final String methodName The method name to call on the parent object. | |
| paramCount | back to summary |
|---|---|
| protected final int paramCount The number of parameters to collect from | |
| paramTypes | back to summary |
|---|---|
| protected Class<?>[] paramTypes The parameter types of the parameters to be collected. | |
| targetOffset | back to summary |
|---|---|
| protected final int targetOffset 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 | back to summary |
|---|---|
| protected boolean useExactMatch Should | |
| CallMethodRule | back to summary |
|---|---|
| public CallMethodRule(String methodName, int paramCount) Construct a "call method" rule with the specified method name. The parameter types (if any) default to java.lang.String.
| |
| CallMethodRule | back to summary |
|---|---|
| public CallMethodRule(int targetOffset, String methodName, int paramCount) Construct a "call method" rule with the specified method name. The parameter types (if any) default to java.lang.String.
| |
| CallMethodRule | back to summary |
|---|---|
| public CallMethodRule(String methodName) Construct a "call method" rule with the specified method name. The method should accept no parameters.
| |
| CallMethodRule | back to summary |
|---|---|
| public CallMethodRule(int targetOffset, String methodName, int paramCount, Class<?>[] paramTypes) Construct a "call method" rule with the specified method name and
parameter types. If
| |
| begin | back to summary |
|---|---|
| public void begin(String namespace, String name, Attributes attributes) throws Exception Overrides org. Process the start of this element.
| |
| body | back to summary |
|---|---|
| public void body(String namespace, String name, String bodyText) throws Exception Overrides org. Process the body text of this element.
| |
| end | back to summary |
|---|---|
| public void end(String namespace, String name) throws Exception Overrides org. Process the end of this element.
| |
| finish | back to summary |
|---|---|
| public void finish() throws Exception Overrides org. Clean up after parsing is complete.
| |
| getUseExactMatch | back to summary |
|---|---|
| public boolean getUseExactMatch() Should
| |
| processMethodCallResult | back to summary |
|---|---|
| protected void processMethodCallResult(Object result) Subclasses may override this method to perform additional processing of the invoked method's result.
| |
| setUseExactMatch | back to summary |
|---|---|
| public void setUseExactMatch(boolean useExactMatch) Set whether
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Render a printable version of this Rule.
| |