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
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 Interceptors and Advisors, but doesn't actually implement proxy creation methods, which are provided by subclasses.

Version:
$Id: AdvisedSupport.java,v 1.27 2004/03/18 02:46:05 trisberg Exp $
Author:
Rod Johnson
See Also:
AopProxy

Field Summary
protected  AdvisorChainFactory advisorChainFactory
           
static TargetSource EMPTY_TARGET_SOURCE
          Canonical TargetSource when there's no target, and behaviour is supplied by the advisors.
protected  TargetSource targetSource
           
 
Fields inherited from class org.springframework.aop.framework.ProxyConfig
exposeProxy, logger
 
Constructor Summary
AdvisedSupport()
          No arg constructor to allow use as a Java bean.
AdvisedSupport(java.lang.Class[] interfaces)
          Create a DefaultProxyConfig with the given parameters.
 
Method Summary
 void addAdvisor(Advisor advice)
          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 addBeforeAdvice(MethodBeforeAdvice ba)
           
 void addInterceptor(org.aopalliance.intercept.Interceptor interceptor)
          Add the given interceptor to the tail of the advice (interceptor) chain.
 void addInterceptor(int pos, org.aopalliance.intercept.Interceptor interceptor)
          Cannot add IntroductionInterceptors this way.
 void addInterface(java.lang.Class newInterface)
          Add a new proxied interface.
 void addListener(AdvisedSupportListener l)
           
 void addThrowsAdvice(ThrowsAdvice throwsAdvice)
           
protected  void copyConfigurationFrom(AdvisedSupport other)
          Call this method on a new instance created by the no-arg consructor to create an independent copy of the configuration from the other.
 int countInterceptorsOfType(java.lang.Class interceptorClass)
          Count interceptors of the given class
protected  AopProxy createAopProxy()
          Subclasses should call this to get a new AOP proxy.
 AdvisorChainFactory getAdvisorChainFactory()
          Return the AdvisorChainFactory associated with this ProxyConfig.
 Advisor[] getAdvisors()
          Return the Advisors applying to this proxy.
 MethodInvocationFactory getMethodInvocationFactory()
           
 java.lang.Class[] getProxiedInterfaces()
          Return the interfaces proxied by the AOP proxy.
 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.
 int indexOf(org.aopalliance.intercept.Interceptor interceptor)
          Return the index (from 0) of the given AOP Alliance interceptor, or -1 if no such interceptor is an advice for this proxy.
 boolean interceptorIncluded(org.aopalliance.intercept.Interceptor mi)
          Is this interceptor included in any advisor?
protected  boolean isActive()
          Subclasses can call this to check whether any AOP proxies have been created yet.
 boolean isInterfaceProxied(java.lang.Class intf)
          Return whether this interface is proxied
 boolean removeAdvisor(Advisor advisor)
          Remove the given advisor
 void removeAdvisor(int index)
          Remove the advisor at the given index
 boolean removeInterceptor(org.aopalliance.intercept.Interceptor interceptor)
          Convenience method to remove an interceptor
 boolean removeInterface(java.lang.Class intf)
          Remove a proxied interface.
 void removeListener(AdvisedSupportListener l)
           
 boolean replaceAdvisor(Advisor a, Advisor b)
          Replace the given advisor.
 void setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)
           
 void setInterfaces(java.lang.Class[] interfaces)
          Set the interfaces to be proxied.
 void setMethodInvocationFactory(MethodInvocationFactory methodInvocationFactory)
           
 void setTarget(java.lang.Object target)
           
 void setTargetSource(TargetSource ts)
           
 java.lang.String toProxyConfigString()
          As toString() will normally pass to the target, this returns the equivalent for the AOP proxy
 java.lang.String toString()
          For debugging/diagnostic use.
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, getAopProxyFactory, getExposeProxy, getOptimize, getProxyTargetClass, isFrozen, setAopProxyFactory, setExposeProxy, setFrozen, 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, isFrozen
 

Field Detail

EMPTY_TARGET_SOURCE

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


targetSource

protected TargetSource targetSource

advisorChainFactory

protected AdvisorChainFactory advisorChainFactory
Constructor Detail

AdvisedSupport

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


AdvisedSupport

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

Parameters:
interfaces - the proxied interfaces
Method Detail

addListener

public void addListener(AdvisedSupportListener l)

removeListener

public void removeListener(AdvisedSupportListener l)

setTargetSource

public void setTargetSource(TargetSource ts)

setTarget

public void setTarget(java.lang.Object target)

getTargetSource

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

Specified by:
getTargetSource in interface Advised
Returns:
the TargetSource. Never returns null

setAdvisorChainFactory

public void setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)

getAdvisorChainFactory

public final AdvisorChainFactory getAdvisorChainFactory()
Return the AdvisorChainFactory associated with this ProxyConfig.


getMethodInvocationFactory

public final MethodInvocationFactory getMethodInvocationFactory()
Returns:
Returns the methodInvocationFactory.

setMethodInvocationFactory

public void setMethodInvocationFactory(MethodInvocationFactory methodInvocationFactory)
Parameters:
methodInvocationFactory - The methodInvocationFactory to set.

copyConfigurationFrom

protected void copyConfigurationFrom(AdvisedSupport other)
Call this method on a new instance created by the no-arg consructor to create an independent copy of the configuration from the other. Does not copy MethodInvocationFactory; a parameter should be provided to the constructor if necessary. Note that the same MethodInvocationFactory should not be used for the new instance, or it may not be independent.

Parameters:
other - DefaultProxyConfig to copy configuration from

addInterceptor

public void addInterceptor(org.aopalliance.intercept.Interceptor interceptor)
                    throws AopConfigException
Description copied from interface: Advised
Add the given interceptor to the tail of the advice (interceptor) chain. This will be wrapped in a DefaultInterceptionAroundAdvisor with a pointcut that always applies, and returned from the getAdvisors() method in this wrapped form.

Specified by:
addInterceptor in interface Advised
Parameters:
interceptor - to add to the tail of the chain
Throws:
AopConfigException
See Also:
Advised.addInterceptor(int, Interceptor)

isInterfaceProxied

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

Specified by:
isInterfaceProxied in interface Advised
Parameters:
intf - interface to test
Returns:
whether the interface is proxied

addInterceptor

public void addInterceptor(int pos,
                           org.aopalliance.intercept.Interceptor interceptor)
                    throws AopConfigException
Cannot add IntroductionInterceptors this way.

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

addBeforeAdvice

public void addBeforeAdvice(MethodBeforeAdvice ba)
                     throws AopConfigException
Throws:
AopConfigException

addThrowsAdvice

public void addThrowsAdvice(ThrowsAdvice throwsAdvice)
                     throws AopConfigException
Throws:
AopConfigException

indexOf

public int indexOf(org.aopalliance.intercept.Interceptor interceptor)
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.

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

removeInterceptor

public final boolean removeInterceptor(org.aopalliance.intercept.Interceptor interceptor)
                                throws AopConfigException
Convenience method to remove an interceptor

Throws:
AopConfigException

setInterfaces

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

Parameters:
interfaces - the interfaces to set

addInterface

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

Parameters:
newInterface - additional interface to proxy

removeInterface

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


getProxiedInterfaces

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

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 advice)
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:
advice - 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(org.aopalliance.intercept.Interceptor mi)
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

countInterceptorsOfType

public final int countInterceptorsOfType(java.lang.Class interceptorClass)
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

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.


toProxyConfigString

public java.lang.String toProxyConfigString()
Description copied from interface: Advised
As toString() will normally pass 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 java.lang.String toString()
For debugging/diagnostic use.

Overrides:
toString in class ProxyConfig


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