org.springframework.aop.framework
Class ReflectiveMethodInvocation

java.lang.Object
  extended by org.springframework.aop.framework.ReflectiveMethodInvocation
All Implemented Interfaces:
Cloneable, Invocation, Joinpoint, MethodInvocation, ProxyMethodInvocation

public class ReflectiveMethodInvocation
extends Object
implements ProxyMethodInvocation, Cloneable

Spring's implementation of the AOP Alliance 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.

Author:
Rod Johnson, Juergen Hoeller, Adrian Colyer
See Also:
invokeJoinpoint(), proceed(), invocableClone(), setUserAttribute(java.lang.String, java.lang.Object), getUserAttribute(java.lang.String)

Field Summary
protected  Object[] arguments
           
protected  List interceptorsAndDynamicMethodMatchers
          List of MethodInterceptor and InterceptorAndDynamicMethodMatcher that need dynamic checks.
protected  Method method
           
protected  Object proxy
           
protected  Object target
           
 
Constructor Summary
protected ReflectiveMethodInvocation(Object proxy, Object target, Method method, Object[] arguments, Class targetClass, List interceptorsAndDynamicMethodMatchers)
          Construct a new ReflectiveMethodInvocation with the given arguments.
 
Method Summary
 Object[] getArguments()
           
 Method getMethod()
          Return the method invoked on the proxied interface.
 Object getProxy()
          Return the proxy that this method invocation was made through.
 AccessibleObject getStaticPart()
           
 Object getThis()
           
 Object getUserAttribute(String key)
          Return the value of the specified user attribute.
 Map 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(Object[] arguments)
          This implementation returns a shallow copy of this invocation object, using the given arguments array for the clone.
protected  Object invokeJoinpoint()
          Invoke the joinpoint using reflection.
 Object proceed()
           
 void setArguments(Object[] arguments)
          Set the arguments to be used on subsequent invocations in the any advice in this chain.
 void setUserAttribute(String key, Object value)
          Add the specified user attribute with the given value to this invocation.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

proxy

protected final Object proxy

target

protected final Object target

method

protected final Method method

arguments

protected Object[] arguments

interceptorsAndDynamicMethodMatchers

protected final List interceptorsAndDynamicMethodMatchers
List of MethodInterceptor and InterceptorAndDynamicMethodMatcher that need dynamic checks.

Constructor Detail

ReflectiveMethodInvocation

protected ReflectiveMethodInvocation(Object proxy,
                                     Object target,
                                     Method method,
                                     Object[] arguments,
                                     Class targetClass,
                                     List interceptorsAndDynamicMethodMatchers)
Construct a new ReflectiveMethodInvocation with the given arguments.

Parameters:
proxy - the proxy object that the invocation was made on
target - the target object to invoke
method - the method to invoke
arguments - the arguments to invoke the method with
targetClass - the target class, for MethodMatcher invocations
interceptorsAndDynamicMethodMatchers - 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.
Method Detail

getProxy

public final Object getProxy()
Description copied from interface: ProxyMethodInvocation
Return the proxy that this method invocation was made through.

Specified by:
getProxy in interface ProxyMethodInvocation
Returns:
the original proxy object

getThis

public final Object getThis()
Specified by:
getThis in interface Joinpoint

getStaticPart

public final AccessibleObject getStaticPart()
Specified by:
getStaticPart in interface Joinpoint

getMethod

public final Method getMethod()
Return the method invoked on the proxied interface. May or may not correspond with a method invoked on an underlying implementation of that interface.

Specified by:
getMethod in interface MethodInvocation

getArguments

public final Object[] getArguments()
Specified by:
getArguments in interface Invocation

setArguments

public void setArguments(Object[] arguments)
Description copied from interface: ProxyMethodInvocation
Set the arguments to be used on subsequent invocations in the any advice in this chain.

Specified by:
setArguments in interface ProxyMethodInvocation
Parameters:
arguments - the argument array

proceed

public Object proceed()
               throws Throwable
Specified by:
proceed in interface Joinpoint
Throws:
Throwable

invokeJoinpoint

protected Object invokeJoinpoint()
                          throws Throwable
Invoke the joinpoint using reflection. Subclasses can override this to use custom invocation.

Returns:
the return value of the joinpoint
Throws:
Throwable - if invoking the joinpoint resulted in an exception

invocableClone

public MethodInvocation invocableClone()
This implementation returns a shallow copy of this invocation object, including an independent copy of the original arguments array.

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.

Specified by:
invocableClone in interface ProxyMethodInvocation
Returns:
an invocable clone of this invocation. proceed() can be called once per clone.
See Also:
Object.clone()

invocableClone

public MethodInvocation invocableClone(Object[] arguments)
This implementation returns a shallow copy of this invocation object, using the given arguments array for the clone.

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.

Specified by:
invocableClone in interface ProxyMethodInvocation
Parameters:
arguments - the arguments that the cloned invocation is supposed to use, overriding the original arguments
Returns:
an invocable clone of this invocation. proceed() can be called once per clone.
See Also:
Object.clone()

setUserAttribute

public void setUserAttribute(String key,
                             Object value)
Description copied from interface: ProxyMethodInvocation
Add the specified user attribute with the given value to this invocation.

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.

Specified by:
setUserAttribute in interface ProxyMethodInvocation
Parameters:
key - the name of the attribute
value - the value of the attribute, or null to reset it

getUserAttribute

public Object getUserAttribute(String key)
Description copied from interface: ProxyMethodInvocation
Return the value of the specified user attribute.

Specified by:
getUserAttribute in interface ProxyMethodInvocation
Parameters:
key - the name of the attribute
Returns:
the value of the attribute, or null if not set
See Also:
ProxyMethodInvocation.setUserAttribute(java.lang.String, java.lang.Object)

getUserAttributes

public Map getUserAttributes()
Return user attributes associated with this invocation. This method provides an invocation-bound alternative to a ThreadLocal.

This map is initialized lazily and is not used in the AOP framework itself.

Returns:
any user attributes associated with this invocation (never null)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002-2008 The Spring Framework.