public class ReflectiveMethodInvocation extends java.lang.Object implements ProxyMethodInvocation, java.lang.Cloneable
MethodInvocation
interface,
implementing the extended
ProxyMethodInvocation
interface.
Invokes the target object using reflection. Subclasses can override the
invokeJoinpoint()
method to change this behavior, so this is also
a useful base class for more specialized MethodInvocation implementations.
It is possible to clone an invocation, to invoke proceed()
repeatedly (once per clone), using the invocableClone()
method.
It is also possible to attach custom attributes to the invocation,
using the setUserAttribute(java.lang.String, java.lang.Object)
/ getUserAttribute(java.lang.String)
methods.
NOTE: This class is considered internal and should not be
directly accessed. The sole reason for it being public is compatibility
with existing framework integrations (e.g. Pitchfork). For any other
purposes, use the ProxyMethodInvocation
interface instead.
invokeJoinpoint()
,
proceed()
,
invocableClone()
,
setUserAttribute(java.lang.String, java.lang.Object)
,
getUserAttribute(java.lang.String)
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object[] |
arguments |
protected java.util.List<?> |
interceptorsAndDynamicMethodMatchers
List of MethodInterceptor and InterceptorAndDynamicMethodMatcher
that need dynamic checks.
|
protected java.lang.reflect.Method |
method |
protected java.lang.Object |
proxy |
protected java.lang.Object |
target |
Modifier | Constructor and Description |
---|---|
protected |
ReflectiveMethodInvocation(java.lang.Object proxy,
java.lang.Object target,
java.lang.reflect.Method method,
java.lang.Object[] arguments,
java.lang.Class<?> targetClass,
java.util.List<java.lang.Object> interceptorsAndDynamicMethodMatchers)
Construct a new ReflectiveMethodInvocation with the given arguments.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object[] |
getArguments()
Get the arguments as an array object.
|
java.lang.reflect.Method |
getMethod()
Return the method invoked on the proxied interface.
|
java.lang.Object |
getProxy()
Return the proxy that this method invocation was made through.
|
java.lang.reflect.AccessibleObject |
getStaticPart()
Return the static part of this joinpoint.
|
java.lang.Object |
getThis()
Return the object that holds the current joinpoint's static part.
|
java.lang.Object |
getUserAttribute(java.lang.String key)
Return the value of the specified user attribute.
|
java.util.Map<java.lang.String,java.lang.Object> |
getUserAttributes()
Return user attributes associated with this invocation.
|
MethodInvocation |
invocableClone()
This implementation returns a shallow copy of this invocation object,
including an independent copy of the original arguments array.
|
MethodInvocation |
invocableClone(java.lang.Object... arguments)
This implementation returns a shallow copy of this invocation object,
using the given arguments array for the clone.
|
protected java.lang.Object |
invokeJoinpoint()
Invoke the joinpoint using reflection.
|
java.lang.Object |
proceed()
Proceed to the next interceptor in the chain.
|
void |
setArguments(java.lang.Object... arguments)
Set the arguments to be used on subsequent invocations in the any advice
in this chain.
|
void |
setUserAttribute(java.lang.String key,
java.lang.Object value)
Add the specified user attribute with the given value to this invocation.
|
java.lang.String |
toString() |
protected final java.lang.Object proxy
@Nullable protected final java.lang.Object target
protected final java.lang.reflect.Method method
protected java.lang.Object[] arguments
protected final java.util.List<?> interceptorsAndDynamicMethodMatchers
protected ReflectiveMethodInvocation(java.lang.Object proxy, @Nullable java.lang.Object target, java.lang.reflect.Method method, @Nullable java.lang.Object[] arguments, @Nullable java.lang.Class<?> targetClass, java.util.List<java.lang.Object> interceptorsAndDynamicMethodMatchers)
proxy
- the proxy object that the invocation was made ontarget
- the target object to invokemethod
- the method to invokearguments
- the arguments to invoke the method withtargetClass
- the target class, for MethodMatcher invocationsinterceptorsAndDynamicMethodMatchers
- interceptors that should be applied,
along with any InterceptorAndDynamicMethodMatchers that need evaluation at runtime.
MethodMatchers included in this struct must already have been found to have matched
as far as was possibly statically. Passing an array might be about 10% faster,
but would complicate the code. And it would work only for static pointcuts.public final java.lang.Object getProxy()
ProxyMethodInvocation
getProxy
in interface ProxyMethodInvocation
@Nullable public final java.lang.Object getThis()
Joinpoint
For instance, the target object for an invocation.
public final java.lang.reflect.AccessibleObject getStaticPart()
Joinpoint
The static part is an accessible object on which a chain of interceptors are installed.
getStaticPart
in interface Joinpoint
public final java.lang.reflect.Method getMethod()
getMethod
in interface MethodInvocation
public final java.lang.Object[] getArguments()
Invocation
getArguments
in interface Invocation
public void setArguments(java.lang.Object... arguments)
ProxyMethodInvocation
setArguments
in interface ProxyMethodInvocation
arguments
- the argument array@Nullable public java.lang.Object proceed() throws java.lang.Throwable
Joinpoint
The implementation and the semantics of this method depends on the actual joinpoint type (see the children interfaces).
@Nullable protected java.lang.Object invokeJoinpoint() throws java.lang.Throwable
java.lang.Throwable
- if invoking the joinpoint resulted in an exceptionpublic MethodInvocation invocableClone()
We want a shallow copy in this case: We want to use the same interceptor chain and other object references, but we want an independent value for the current interceptor index.
invocableClone
in interface ProxyMethodInvocation
proceed()
can be called once per clone.Object.clone()
public MethodInvocation invocableClone(java.lang.Object... arguments)
We want a shallow copy in this case: We want to use the same interceptor chain and other object references, but we want an independent value for the current interceptor index.
invocableClone
in interface ProxyMethodInvocation
arguments
- the arguments that the cloned invocation is supposed to use,
overriding the original argumentsproceed()
can be called once per clone.Object.clone()
public void setUserAttribute(java.lang.String key, @Nullable java.lang.Object value)
ProxyMethodInvocation
Such attributes are not used within the AOP framework itself. They are just kept as part of the invocation object, for use in special interceptors.
setUserAttribute
in interface ProxyMethodInvocation
key
- the name of the attributevalue
- the value of the attribute, or null
to reset it@Nullable public java.lang.Object getUserAttribute(java.lang.String key)
ProxyMethodInvocation
getUserAttribute
in interface ProxyMethodInvocation
key
- the name of the attributenull
if not setProxyMethodInvocation.setUserAttribute(java.lang.String, java.lang.Object)
public java.util.Map<java.lang.String,java.lang.Object> getUserAttributes()
This map is initialized lazily and is not used in the AOP framework itself.
null
)public java.lang.String toString()
toString
in class java.lang.Object