org.springframework.aop.framework
Class AdvisedSupport

java.lang.Object
  extended byorg.springframework.aop.framework.ProxyConfig
      extended byorg.springframework.aop.framework.AdvisedSupport
All Implemented Interfaces:
Advised, Serializable
Direct Known Subclasses:
ProxyFactory, ProxyFactoryBean

public class AdvisedSupport
extends ProxyConfig
implements Advised

Superclass for AOP proxy configuration managers. These are not themselves AOP proxies, but subclasses of this class are normally factories from which AOP proxy instances are obtained directly.

This class frees subclasses of the housekeeping of Advices and Advisors, but doesn't actually implement proxy creation methods, which are provided by subclasses.

This class is serializable; subclasses need not be. This class is used to hold snapshots of proxies.

Author:
Rod Johnson
See Also:
AopProxy, Serialized Form

Field Summary
(package private)  AdvisorChainFactory advisorChainFactory
           
static TargetSource EMPTY_TARGET_SOURCE
          Canonical TargetSource when there's no target, and behavior is supplied by the advisors.
(package private)  TargetSource targetSource
          Package-protected to allow direct access for efficiency
 
Fields inherited from class org.springframework.aop.framework.ProxyConfig
exposeProxy, logger
 
Constructor Summary
AdvisedSupport()
          No arg constructor to allow use as a JavaBean.
AdvisedSupport(Class[] interfaces)
          Create a DefaultProxyConfig with the given parameters.
 
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)
          Cannot add introductions this way unless the advice implements IntroductionInfo.
 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 addAdvisor(int pos, IntroductionAdvisor advisor)
           
 void addAfterReturningAdvice(AfterReturningAdvice ara)
          Add an AfterReturningAdvice to the tail of the advice chain.
 void addBeforeAdvice(MethodBeforeAdvice ba)
          Add a MethodBeforeAdvice to the tail of the advice chain.
 void addInterceptor(Interceptor interceptor)
          Add the given AOP Alliance interceptor to the tail of the advice (interceptor) chain.
 void addInterceptor(int pos, Interceptor interceptor)
          Add the given AOP Alliance interceptor at the specified position in the interceptor chain.
 void addInterface(Class newInterface)
          Add a new proxied interface.
 void addListener(AdvisedSupportListener listener)
           
 void addThrowsAdvice(ThrowsAdvice throwsAdvice)
          Add a ThrowsAdvice to the tail of the advice chain.
 boolean adviceIncluded(Advice advice)
          Is this advice included in any advisor?
protected  void copyConfigurationFrom(AdvisedSupport other)
          Call this method on a new instance created by the no-arg constructor to create an independent copy of the configuration from the other.
protected  void copyConfigurationFrom(AdvisedSupport other, TargetSource ts, List pAdvisors)
          Take interfaces and ProxyConfig configuration from the other AdvisedSupport, but allow substitution of a fresh TargetSource and interceptor chain
 int countAdvicesOfType(Class interceptorClass)
          Count advices of the given class
 int countInterceptorsOfType(Class interceptorClass)
          Deprecated. in favor of countAdvicesOfType
protected  AopProxy createAopProxy()
          Subclasses should call this to get a new AOP proxy.
 AdvisorChainFactory getAdvisorChainFactory()
           
 Advisor[] getAdvisors()
          Return the Advisors applying to this proxy.
 Class[] getProxiedInterfaces()
          Return the interfaces proxied by the AOP proxy.
 TargetSource getTargetSource()
          Return the TargetSource used by this Advised object.
 int indexOf(Advice advice)
          Return the index (from 0) of the given AOP Alliance Advice, or -1 if no such advice is an advice for this proxy.
 int indexOf(Advisor advisor)
          Return the index (from 0) of the given advisor, or -1 if no such advisor applies to this proxy.
 int indexOf(Interceptor interceptor)
          Deprecated. in favor of indexOf(Advice)
 boolean interceptorIncluded(Interceptor mi)
          Deprecated. in favor of adviceIncluded
protected  boolean isActive()
          Subclasses can call this to check whether any AOP proxies have been created yet.
 boolean isInterfaceProxied(Class intf)
          Return whether this interface is proxied.
protected  Object readResolve()
          Used to initialize transient state.
 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 removeInterceptor(Interceptor interceptor)
          Deprecated. in favor or removeAdvice
 boolean removeInterface(Class intf)
          Remove a proxied interface.
 void removeListener(AdvisedSupportListener listener)
           
 boolean replaceAdvisor(Advisor a, Advisor b)
          Replace the given advisor.
 void setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)
           
 void setInterfaces(Class[] interfaces)
          Set the interfaces to be proxied.
 void setTarget(Object target)
          Set the given object as target.
 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.
 String toString()
          For debugging/diagnostic use.
protected  Object writeReplace()
          Serialize a copy of the state of this class, ignoring subclass state.
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, getAopProxyFactory, getExposeProxy, getOpaque, getOptimize, getProxyTargetClass, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setAopProxyFactory, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.aop.framework.Advised
getExposeProxy, getProxyTargetClass, isExposeProxy, isFrozen, isProxyTargetClass, setExposeProxy
 

Field Detail

EMPTY_TARGET_SOURCE

public static final TargetSource EMPTY_TARGET_SOURCE
Canonical TargetSource when there's no target, and behavior is supplied by the advisors.


targetSource

TargetSource targetSource
Package-protected to allow direct access for efficiency


advisorChainFactory

transient AdvisorChainFactory advisorChainFactory
Constructor Detail

AdvisedSupport

public AdvisedSupport()
No arg constructor to allow use as a JavaBean.


AdvisedSupport

public AdvisedSupport(Class[] interfaces)
Create a DefaultProxyConfig with the given parameters.

Parameters:
interfaces - the proxied interfaces
Method Detail

addListener

public void addListener(AdvisedSupportListener listener)

removeListener

public void removeListener(AdvisedSupportListener listener)

setTarget

public void setTarget(Object target)
Set the given object as target. Will create a SingletonTargetSource for the object.

See Also:
setTargetSource(org.springframework.aop.TargetSource), SingletonTargetSource

setTargetSource

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

Specified by:
setTargetSource in interface Advised
Parameters:
targetSource - new TargetSource to use

getTargetSource

public TargetSource getTargetSource()
Description copied from interface: Advised
Return the TargetSource used by this Advised object.

Specified by:
getTargetSource in interface Advised

setAdvisorChainFactory

public void setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)

getAdvisorChainFactory

public AdvisorChainFactory getAdvisorChainFactory()

copyConfigurationFrom

protected void copyConfigurationFrom(AdvisedSupport other)
Call this method on a new instance created by the no-arg constructor to create an independent copy of the configuration from the other.

Parameters:
other - AdvisedSupport to copy configuration from

copyConfigurationFrom

protected void copyConfigurationFrom(AdvisedSupport other,
                                     TargetSource ts,
                                     List pAdvisors)
Take interfaces and ProxyConfig configuration from the other AdvisedSupport, but allow substitution of a fresh TargetSource and interceptor chain

Parameters:
other - other AdvisedSupport object to take interfaces and ProxyConfig superclass configuration from
ts - new TargetSource
pAdvisors - new Advisor chain

setInterfaces

public void setInterfaces(Class[] interfaces)
Set the interfaces to be proxied.


addInterface

public void addInterface(Class newInterface)
Add a new proxied interface.

Parameters:
newInterface - additional interface to proxy

getProxiedInterfaces

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

Specified by:
getProxiedInterfaces in interface Advised
Returns:
the interfaces proxied by the AOP proxy

removeInterface

public boolean removeInterface(Class intf)
Remove a proxied interface. Does nothing if it isn't proxied.


addInterceptor

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

Description copied from interface: Advised
Add the given AOP Alliance interceptor to the tail of the advice (interceptor) chain.

Use the addAdvice method instead.

Specified by:
addInterceptor in interface Advised
Parameters:
interceptor - to add to the tail of the chain
Throws:
AopConfigException
See Also:
addAdvice(org.aopalliance.aop.Advice), Advised.addInterceptor(org.aopalliance.intercept.Interceptor)

addAdvice

public void addAdvice(Advice advice)
               throws AopConfigException
Description copied from interface: Advised
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.

Specified by:
addAdvice in interface Advised
Parameters:
advice - advice to add to the tail of the chain
Throws:
AopConfigException
See Also:
Advised.addAdvice(int, Advice), DefaultPointcutAdvisor

isInterfaceProxied

public boolean isInterfaceProxied(Class intf)
Description copied from interface: Advised
Return whether this interface is proxied.

Specified by:
isInterfaceProxied in interface Advised
Parameters:
intf - interface to test

addInterceptor

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

Description copied from interface: Advised
Add the given AOP Alliance interceptor at the specified position in the interceptor chain.

Use the addAdvice method instead.

Specified by:
addInterceptor in interface Advised
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), Advised.addInterceptor(int, org.aopalliance.intercept.Interceptor)

addAdvice

public void addAdvice(int pos,
                      Advice advice)
               throws AopConfigException
Cannot add introductions this way unless the advice implements IntroductionInfo.

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

removeInterceptor

public final boolean removeInterceptor(Interceptor interceptor)
                                throws AopConfigException
Deprecated. in favor or removeAdvice

Convenience method to remove an interceptor.

Throws:
AopConfigException
See Also:
removeAdvice(org.aopalliance.aop.Advice)

removeAdvice

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

Specified by:
removeAdvice in interface Advised
Parameters:
advice - advice to remove
Returns:
whether the Advice was found and removed (false if there was no such advice)
Throws:
AopConfigException

addAfterReturningAdvice

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

Description copied from interface: Advised
Add an AfterReturningAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Specified by:
addAfterReturningAdvice in interface Advised
Parameters:
ara - 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), Advised.addAfterReturningAdvice(org.springframework.aop.AfterReturningAdvice)

addBeforeAdvice

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

Description copied from interface: Advised
Add a MethodBeforeAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Specified by:
addBeforeAdvice in interface Advised
Parameters:
ba - 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), Advised.addBeforeAdvice(org.springframework.aop.MethodBeforeAdvice)

addThrowsAdvice

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

Description copied from interface: Advised
Add a ThrowsAdvice to the tail of the advice chain.

Use the addAdvice method instead.

Specified by:
addThrowsAdvice in interface Advised
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), Advised.addThrowsAdvice(org.springframework.aop.ThrowsAdvice)

indexOf

public int indexOf(Interceptor interceptor)
Deprecated. in favor of indexOf(Advice)

Return the index (from 0) of the given AOP Alliance interceptor, or -1 if no such interceptor is an advice for this proxy. The return value of this method can be used to index into the Advisors array.

Parameters:
interceptor - AOP Alliance interceptor to search for
Returns:
index from 0 of this interceptor, or -1 if there's no such advice.
See Also:
indexOf(org.aopalliance.aop.Advice)

indexOf

public int indexOf(Advice advice)
Return the index (from 0) of the given AOP Alliance Advice, or -1 if no such advice is an advice for this proxy. The return value of this method can be used to index into the Advisors array.

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

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.

Specified by:
indexOf in interface Advised
Parameters:
advisor - advisor to search for
Returns:
index from 0 of this advisor, or -1 if there's no such advisor.

removeAdvisor

public final boolean removeAdvisor(Advisor advisor)
Description copied from interface: Advised
Remove the given advisor.

Specified by:
removeAdvisor in interface Advised
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

removeAdvisor

public void removeAdvisor(int index)
                   throws AopConfigException
Description copied from interface: Advised
Remove the advisor at the given index.

Specified by:
removeAdvisor in interface Advised
Parameters:
index - index of advisor to remove
Throws:
AopConfigException - if the index is invalid

addAdvisor

public void addAdvisor(int pos,
                       IntroductionAdvisor advisor)
                throws AopConfigException
Throws:
AopConfigException

addAdvisor

public void addAdvisor(int pos,
                       Advisor advisor)
                throws AopConfigException
Description copied from interface: Advised
Add an Advisor at the specified position in the chain.

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

addAdvisor

public void addAdvisor(Advisor advisor)
Description copied from interface: Advised
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.

Specified by:
addAdvisor in interface Advised
Parameters:
advisor - Advisor to add to the end of the chain

getAdvisors

public final Advisor[] getAdvisors()
Description copied from interface: Advised
Return the Advisors applying to this proxy.

Specified by:
getAdvisors in interface Advised
Returns:
a list of Advisors applying to this proxy. Cannot return null, but may return the empty array.

replaceAdvisor

public final 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.

Specified by:
replaceAdvisor in interface Advised
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

interceptorIncluded

public final boolean interceptorIncluded(Interceptor mi)
Deprecated. in favor of adviceIncluded

Is this interceptor included in any advisor?

Parameters:
mi - interceptor to check inclusion of
Returns:
whether this interceptor instance could be run in an invocation
See Also:
adviceIncluded(org.aopalliance.aop.Advice)

adviceIncluded

public final boolean adviceIncluded(Advice advice)
Is this advice included in any advisor?

Parameters:
advice - advice to check inclusion of
Returns:
whether this advice instance could be run in an invocation

countInterceptorsOfType

public final int countInterceptorsOfType(Class interceptorClass)
Deprecated. in favor of countAdvicesOfType

Count interceptors of the given class.

Parameters:
interceptorClass - class of the interceptor to check
Returns:
the count of the interceptors of this class or subclasses
See Also:
countAdvicesOfType(java.lang.Class)

countAdvicesOfType

public final int countAdvicesOfType(Class interceptorClass)
Count advices of the given class

Parameters:
interceptorClass - class of the interceptor to check
Returns:
the count of the interceptors of this class or subclasses

createAopProxy

protected AopProxy createAopProxy()
Subclasses should call this to get a new AOP proxy. They should not create an AOP proxy with this as an argument.


isActive

protected final boolean isActive()
Subclasses can call this to check whether any AOP proxies have been created yet.


writeReplace

protected Object writeReplace()
                       throws ObjectStreamException
Serialize a copy of the state of this class, ignoring subclass state.

Throws:
ObjectStreamException

readResolve

protected Object readResolve()
                      throws ObjectStreamException
Used to initialize transient state.

Throws:
ObjectStreamException

toProxyConfigString

public String toProxyConfigString()
Description copied from interface: Advised
As toString() will normally be delegated to the target, this returns the equivalent for the AOP proxy.

Specified by:
toProxyConfigString in interface Advised
Returns:
a string description of the proxy configuration

toString

public String toString()
For debugging/diagnostic use.

Overrides:
toString in class ProxyConfig


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