org.springframework.aop.framework
Interface Advised

All Known Implementing Classes:
AdvisedSupport

public interface Advised

Interface to be implemented by classes that hold the configuration of a factory of AOP proxies. This configuration includes the Interceptors and other advice, and Advisors, and the proxied interfaces.

Any AOP proxy obtained from Spring can be cast to this interface to allow manipulation of its AOP advice.

Since:
13-Mar-2003
Author:
Rod Johnson
See Also:
AdvisedSupport

Method Summary
 void addAdvice(Advice advice)
          Add the given AOP Alliance advice to the tail of the advice (interceptor) chain.
 void addAdvice(int pos, Advice advice)
          Add the given AOP Alliance Advice at the specified position in the advice chain.
 void addAdvisor(Advisor advisor)
          Add an Advisor at the end of the advisor chain.
 void addAdvisor(int pos, Advisor advisor)
          Add an Advisor at the specified position in the chain.
 void addAfterReturningAdvice(AfterReturningAdvice afterReturningAdvice)
          Deprecated. in favor of addAdvice
 void addBeforeAdvice(MethodBeforeAdvice beforeAdvice)
          Deprecated. in favor of addAdvice
 void addInterceptor(Interceptor interceptor)
          Deprecated. in favor of addAdvice
 void addInterceptor(int pos, Interceptor interceptor)
          Deprecated. in favor of addAdvice
 void addThrowsAdvice(ThrowsAdvice throwsAdvice)
          Deprecated. in favor of addAdvice
 Advisor[] getAdvisors()
          Return the Advisors applying to this proxy.
 boolean getExposeProxy()
          Deprecated. in favor of isExposeProxy
 Class[] getProxiedInterfaces()
          Return the interfaces proxied by the AOP proxy.
 boolean getProxyTargetClass()
          Deprecated. in favor of isProxyTargetClass
 TargetSource getTargetSource()
          Return the TargetSource used by this Advised object.
 int indexOf(Advisor advisor)
          Return the index (from 0) of the given advisor, or -1 if no such advisor applies to this proxy.
 boolean isExposeProxy()
          Return whether the factory should expose the proxy as a ThreadLocal.
 boolean isFrozen()
          Return whether the Advised configuration is frozen, and no advice changes can be made.
 boolean isInterfaceProxied(Class intf)
          Return whether this interface is proxied.
 boolean isProxyTargetClass()
          Should we proxy the target class as well as any interfaces?
 boolean removeAdvice(Advice advice)
          Remove the Advisor containing the given advice.
 boolean removeAdvisor(Advisor advisor)
          Remove the given advisor.
 void removeAdvisor(int index)
          Remove the advisor at the given index.
 boolean replaceAdvisor(Advisor a, Advisor b)
          Replace the given advisor.
 void setExposeProxy(boolean exposeProxy)
          Set whether the proxy should be exposed by the AOP framework as a ThreadLocal for retrieval via the AopContext class.
 void setTargetSource(TargetSource targetSource)
          Change the TargetSource used by this Advised object.
 String toProxyConfigString()
          As toString() will normally be delegated to the target, this returns the equivalent for the AOP proxy.
 

Method Detail

setTargetSource

public void setTargetSource(TargetSource targetSource)
Change the TargetSource used by this Advised object. Only works if the configuration isn't frozen.

Parameters:
targetSource - new TargetSource to use

getTargetSource

public TargetSource getTargetSource()
Return the TargetSource used by this Advised object.


setExposeProxy

public void setExposeProxy(boolean exposeProxy)
Set whether the proxy should be exposed by the AOP framework as a ThreadLocal for retrieval via the AopContext class. This is useful if an advised object needs to call another advised method on itself. (If it uses this, the invocation will not be advised).

Default is false, for optimal performance.


isExposeProxy

public boolean isExposeProxy()
Return whether the factory should expose the proxy as a ThreadLocal. This can be necessary if a target object needs to invoke a method on itself benefitting from advice. (If it invokes a method on this no advice will apply.) Getting the proxy is analogous to an EJB calling getEJBObject().

See Also:
AopContext

getExposeProxy

public boolean getExposeProxy()
Deprecated. in favor of isExposeProxy

See Also:
isExposeProxy()

isProxyTargetClass

public boolean isProxyTargetClass()
Should we proxy the target class as well as any interfaces? Can use this to force CGLIB proxying.


getProxyTargetClass

public boolean getProxyTargetClass()
Deprecated. in favor of isProxyTargetClass

See Also:
isProxyTargetClass()

getAdvisors

public Advisor[] getAdvisors()
Return the Advisors applying to this proxy.

Returns:
a list of Advisors applying to this proxy. Cannot return null, but may return the empty array.

getProxiedInterfaces

public Class[] getProxiedInterfaces()
Return the interfaces proxied by the AOP proxy. Will not include the target class, which may also be proxied.

Returns:
the interfaces proxied by the AOP proxy

isInterfaceProxied

public boolean isInterfaceProxied(Class intf)
Return whether this interface is proxied.

Parameters:
intf - interface to test

addInterceptor

public void addInterceptor(Interceptor interceptor)
                    throws AopConfigException
Deprecated. in favor of addAdvice

Add the given AOP Alliance interceptor to the tail of the advice (interceptor) chain.

Use the addAdvice method instead.

Parameters:
interceptor - to add to the tail of the chain
Throws:
AopConfigException
See Also:
addAdvice(org.aopalliance.aop.Advice)

addAdvice

public void addAdvice(Advice advice)
               throws AopConfigException
Add the given AOP Alliance advice to the tail of the advice (interceptor) chain. This will be wrapped in a DefaultPointcutAdvisor with a pointcut that always applies, and returned from the getAdvisors() method in this wrapped form.

Parameters:
advice - advice to add to the tail of the chain
Throws:
AopConfigException
See Also:
addAdvice(int, Advice), DefaultPointcutAdvisor

addInterceptor

public void addInterceptor(int pos,
                           Interceptor interceptor)
                    throws AopConfigException
Deprecated. in favor of addAdvice

Add the given AOP Alliance interceptor at the specified position in the interceptor chain.

Use the addAdvice method instead.

Parameters:
pos - index from 0 (head)
interceptor - interceptor to add at the specified position in the interceptor chain
Throws:
AopConfigException
See Also:
addAdvice(int, org.aopalliance.aop.Advice)

addAdvice

public void addAdvice(int pos,
                      Advice advice)
               throws AopConfigException
Add the given AOP Alliance Advice at the specified position in the advice chain.

Parameters:
pos - index from 0 (head)
advice - advice to add at the specified position in the advice chain
Throws:
AopConfigException

addAfterReturningAdvice

public void addAfterReturningAdvice(AfterReturningAdvice afterReturningAdvice)
                             throws AopConfigException
Deprecated. in favor of addAdvice

Add an AfterReturningAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Parameters:
afterReturningAdvice - AfterReturningAdvice to add
Throws:
AopConfigException - if the advice cannot be added (for example, because the proxy configuration is frozen)
See Also:
addAdvice(org.aopalliance.aop.Advice)

addBeforeAdvice

public void addBeforeAdvice(MethodBeforeAdvice beforeAdvice)
                     throws AopConfigException
Deprecated. in favor of addAdvice

Add a MethodBeforeAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Parameters:
beforeAdvice - MethodBeforeAdvice to add
Throws:
AopConfigException - if the advice cannot be added (for example, because the proxy configuration is frozen)
See Also:
addAdvice(org.aopalliance.aop.Advice)

addThrowsAdvice

public void addThrowsAdvice(ThrowsAdvice throwsAdvice)
                     throws AopConfigException
Deprecated. in favor of addAdvice

Add a ThrowsAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Parameters:
throwsAdvice - ThrowsAdvice to add
Throws:
AopConfigException - if the advice cannot be added (for example, because the proxy configuration is frozen)
See Also:
addAdvice(org.aopalliance.aop.Advice)

addAdvisor

public void addAdvisor(Advisor advisor)
                throws AopConfigException
Add an Advisor at the end of the advisor chain.

The Advisor may be an IntroductionAdvisor, in which new interfaces will be available when a proxy is next obtained from the relevant factory.

Parameters:
advisor - Advisor to add to the end of the chain
Throws:
AopConfigException

addAdvisor

public void addAdvisor(int pos,
                       Advisor advisor)
                throws AopConfigException
Add an Advisor at the specified position in the chain.

Parameters:
advisor - advisor to add at the specified position in the chain
pos - position in chain (0 is head). Must be valid.
Throws:
AopConfigException

indexOf

public int indexOf(Advisor advisor)
Return the index (from 0) of the given advisor, or -1 if no such advisor applies to this proxy.

The return value of this method can be used to index into the Advisors array.

Parameters:
advisor - advisor to search for
Returns:
index from 0 of this advisor, or -1 if there's no such advisor.

removeAdvisor

public boolean removeAdvisor(Advisor advisor)
                      throws AopConfigException
Remove the given advisor.

Parameters:
advisor - advisor to remove
Returns:
true if the advisor was removed; false if the advisor was not found and hence could not be removed
Throws:
AopConfigException

removeAdvisor

public void removeAdvisor(int index)
                   throws AopConfigException
Remove the advisor at the given index.

Parameters:
index - index of advisor to remove
Throws:
AopConfigException - if the index is invalid

removeAdvice

public boolean removeAdvice(Advice advice)
                     throws AopConfigException
Remove the Advisor containing the given advice.

Parameters:
advice - advice to remove
Returns:
whether the Advice was found and removed (false if there was no such advice)
Throws:
AopConfigException

replaceAdvisor

public boolean replaceAdvisor(Advisor a,
                              Advisor b)
                       throws AopConfigException
Replace the given advisor.

NB:If the advisor is an IntroductionAdvisor and the replacement is not or implements different interfaces, the proxy will need to be re-obtained or the old interfaces won't be supported and the new interface won't be implemented.

Parameters:
a - advisor to replace
b - advisor to replace it with
Returns:
whether it was replaced. If the advisor wasn't found in the list of advisors, this method returns false and does nothing.
Throws:
AopConfigException

isFrozen

public boolean isFrozen()
Return whether the Advised configuration is frozen, and no advice changes can be made.


toProxyConfigString

public String toProxyConfigString()
As toString() will normally be delegated to the target, this returns the equivalent for the AOP proxy.

Returns:
a string description of the proxy configuration


Copyright (C) 2003-2004 The Spring Framework Project.