Top Description Fields Constructors Methods
org.apache.tomcat.util.digester

public Class CallMethodRule

extends Rule
Class Inheritance
Known Direct Subclasses
org.apache.tomcat.util.descriptor.web.CallMethodMultiRule, org.apache.tomcat.util.descriptor.web.LifecycleCallbackRule
Imports
java.util.Arrays, org.apache.tomcat.util.IntrospectionUtils, org.xml.sax.Attributes

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).

Field Summary

Modifier and TypeField 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 MethodParam rules.

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 MethodUtils.invokeExactMethod be used for reflection.

Inherited from org.apache.tomcat.util.digester.Rule:
digesternamespaceURIsm

Constructor Summary

AccessConstructor 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 java.lang.Boolean.TYPE for a boolean parameter)
paramTypes
)

Construct a "call method" rule with the specified method name and parameter types.

Method Summary

Modifier and TypeMethod 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.apache.tomcat.util.digester.Rule.begin.

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.apache.tomcat.util.digester.Rule.body.

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.apache.tomcat.util.digester.Rule.end.

Process the end of this element.

public void
finish()

Overrides org.apache.tomcat.util.digester.Rule.finish.

Clean up after parsing is complete.

public boolean

Returns:

true if invokeExactMethod is used
getUseExactMatch
()

Should MethodUtils.invokeExactMethod be used for the reflection.

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 MethodUtils.invokeExactMethod should be used for the reflection.

public String
toString()

Overrides java.lang.Object.toString.

Render a printable version of this Rule.

Inherited from org.apache.tomcat.util.digester.Rule:
getDigestergetNamespaceURIsetDigestersetNamespaceURI

Field Detail

bodyTextback to summary
protected String bodyText

The body text collected from this element.

methodNameback to summary
protected final String methodName

The method name to call on the parent object.

paramCountback to summary
protected final int paramCount

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.

paramTypesback to summary
protected Class<?>[] paramTypes

The parameter types of the parameters to be collected.

targetOffsetback 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.

useExactMatchback to summary
protected boolean useExactMatch

Should MethodUtils.invokeExactMethod be used for reflection.

Constructor Detail

CallMethodRuleback 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.

Parameters
methodName:String

Method name of the parent method to call

paramCount:int

The number of parameters to collect, or zero for a single argument from the body of this element.

CallMethodRuleback 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.

Parameters
targetOffset: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.

methodName:String

Method name of the parent method to call

paramCount:int

The number of parameters to collect, or zero for a single argument from the body of this element.

CallMethodRuleback to summary
public CallMethodRule(String methodName)

Construct a "call method" rule with the specified method name. The method should accept no parameters.

Parameters
methodName:String

Method name of the parent method to call

CallMethodRuleback 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 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: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.

methodName:String

Method name of the parent method to call

paramCount:int

The number of parameters to collect, or zero for a single argument from the body of this element

paramTypes: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 java.lang.Boolean.TYPE for a boolean parameter)

Method Detail

beginback to summary
public void begin(String namespace, String name, Attributes attributes) throws Exception

Overrides org.apache.tomcat.util.digester.Rule.begin.

Process the start of this element.

Parameters
namespace: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

name:String

the local name if the parser is namespace aware, or just the element name otherwise

attributes:Attributes

The attribute list for this element

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.tomcat.util.digester.Rule.begin.

if an error occurs while processing the event

bodyback to summary
public void body(String namespace, String name, String bodyText) throws Exception

Overrides org.apache.tomcat.util.digester.Rule.body.

Process the body text of this element.

Parameters
namespace: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

name:String

the local name if the parser is namespace aware, or just the element name otherwise

bodyText:String

The body text of this element

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.tomcat.util.digester.Rule.body.

if an error occurs while processing the event

endback to summary
public void end(String namespace, String name) throws Exception

Overrides org.apache.tomcat.util.digester.Rule.end.

Process the end of this element.

Parameters
namespace: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

name:String

the local name if the parser is namespace aware, or just the element name otherwise

Annotations
@SuppressWarnings:null
@Override
Exceptions
Exception:

Doc from org.apache.tomcat.util.digester.Rule.end.

if an error occurs while processing the event

finishback to summary
public void finish() throws Exception

Overrides org.apache.tomcat.util.digester.Rule.finish.

Clean up after parsing is complete.

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.tomcat.util.digester.Rule.finish.

if an error occurs while processing the event

getUseExactMatchback to summary
public boolean getUseExactMatch()

Should MethodUtils.invokeExactMethod be used for the reflection.

Returns:boolean

true if invokeExactMethod is used

processMethodCallResultback to summary
protected void processMethodCallResult(Object result)

Subclasses may override this method to perform additional processing of the invoked method's result.

Parameters
result:Object

the Object returned by the method invoked, possibly null

setUseExactMatchback to summary
public void setUseExactMatch(boolean useExactMatch)

Set whether MethodUtils.invokeExactMethod should be used for the reflection.

Parameters
useExactMatch:boolean

The flag value

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Render a printable version of this Rule.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override