public class AdvisedSupport extends ProxyConfig implements Advised
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.
AopProxy
,
Serialized FormModifier and Type | Class and Description |
---|---|
private static class |
AdvisedSupport.MethodCacheKey
Simple wrapper class around a Method.
|
Modifier and Type | Field and Description |
---|---|
private Advisor[] |
advisorArray
Array updated on changes to the advisors list, which is easier
to manipulate internally.
|
(package private) AdvisorChainFactory |
advisorChainFactory
The AdvisorChainFactory to use
|
private java.util.List<Advisor> |
advisors
List of Advisors.
|
static TargetSource |
EMPTY_TARGET_SOURCE
Canonical TargetSource when there's no target, and behavior is
supplied by the advisors.
|
private java.util.List<java.lang.Class> |
interfaces
Interfaces to be implemented by the proxy.
|
private java.util.Map<AdvisedSupport.MethodCacheKey,java.util.List<java.lang.Object>> |
methodCache
Cache with Method as key and advisor chain List as value
|
private boolean |
preFiltered
Whether the Advisors are already filtered for the specific target class
|
private static long |
serialVersionUID
use serialVersionUID from Spring 2.0 for interoperability
|
(package private) TargetSource |
targetSource
Package-protected to allow direct access for efficiency
|
exposeProxy, opaque
Constructor and Description |
---|
AdvisedSupport()
No-arg constructor for use as a JavaBean.
|
AdvisedSupport(java.lang.Class[] interfaces)
Create a AdvisedSupport instance with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
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.
|
private void |
addAdvisorInternal(int pos,
Advisor advisor) |
void |
addAdvisors(Advisor... advisors)
Add all of the given advisors to this proxy configuration.
|
void |
addAdvisors(java.util.Collection<Advisor> advisors)
Add all of the given advisors to this proxy configuration.
|
void |
addInterface(java.lang.Class intf)
Add a new proxied interface.
|
protected void |
adviceChanged()
Invoked when advice has changed.
|
boolean |
adviceIncluded(Advice advice)
Is the given advice included in any advisor within this proxy configuration?
|
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 given object.
|
protected void |
copyConfigurationFrom(AdvisedSupport other,
TargetSource targetSource,
java.util.List<Advisor> advisors)
Copy the AOP configuration from the given AdvisedSupport object,
but allow substitution of a fresh TargetSource and a given interceptor chain.
|
int |
countAdvicesOfType(java.lang.Class adviceClass)
Count advices of the given class.
|
AdvisorChainFactory |
getAdvisorChainFactory()
Return the advisor chain factory to use (never
null ). |
Advisor[] |
getAdvisors()
Return the advisors applying to this proxy.
|
protected java.util.List<Advisor> |
getAdvisorsInternal()
Allows uncontrolled access to the
List of Advisors . |
(package private) AdvisedSupport |
getConfigurationOnlyCopy()
Build a configuration-only copy of this AdvisedSupport,
replacing the TargetSource
|
java.util.List<java.lang.Object> |
getInterceptorsAndDynamicInterceptionAdvice(java.lang.reflect.Method method,
java.lang.Class targetClass)
Determine a list of
org.aopalliance.intercept.MethodInterceptor objects
for the given method, based on this configuration. |
java.lang.Class[] |
getProxiedInterfaces()
Return the interfaces proxied by the AOP proxy.
|
java.lang.Class<?> |
getTargetClass()
Return the target class behind the implementing object
(typically a proxy configuration or an actual proxy).
|
TargetSource |
getTargetSource()
Return the TargetSource used by this Advised object.
|
int |
indexOf(Advice advice)
Return the index (from 0) of the given advisor,
or -1 if no such advisor applies to 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.
|
private void |
initMethodCache()
Initialize the method cache.
|
boolean |
isInterfaceProxied(java.lang.Class intf)
Determine whether the given interface is proxied.
|
boolean |
isPreFiltered()
Return whether this proxy configuration is pre-filtered so that it only
contains applicable advisors (matching this proxy's target class).
|
private void |
readObject(java.io.ObjectInputStream ois) |
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 |
removeInterface(java.lang.Class intf)
Remove a proxied interface.
|
boolean |
replaceAdvisor(Advisor a,
Advisor b)
Replace the given advisor.
|
void |
setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)
Set the advisor chain factory to use.
|
void |
setInterfaces(java.lang.Class[] interfaces)
Set the interfaces to be proxied.
|
void |
setPreFiltered(boolean preFiltered)
Set whether this proxy configuration is pre-filtered so that it only
contains applicable advisors (matching this proxy's target class).
|
void |
setTarget(java.lang.Object target)
Set the given object as target.
|
void |
setTargetClass(java.lang.Class targetClass)
Set a target class to be proxied, indicating that the proxy
should be castable to the given class.
|
void |
setTargetSource(TargetSource targetSource)
Change the TargetSource used by this Advised object.
|
java.lang.String |
toProxyConfigString()
As
toString() will normally be delegated to the target,
this returns the equivalent for the AOP proxy. |
java.lang.String |
toString()
For debugging/diagnostic use.
|
protected void |
updateAdvisorArray()
Bring the array up to date with the list.
|
private void |
validateIntroductionAdvisor(IntroductionAdvisor advisor) |
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isExposeProxy, isFrozen, isProxyTargetClass, setExposeProxy
private static final long serialVersionUID
public static final TargetSource EMPTY_TARGET_SOURCE
TargetSource targetSource
private boolean preFiltered
AdvisorChainFactory advisorChainFactory
private transient java.util.Map<AdvisedSupport.MethodCacheKey,java.util.List<java.lang.Object>> methodCache
private java.util.List<java.lang.Class> interfaces
private java.util.List<Advisor> advisors
private Advisor[] advisorArray
public AdvisedSupport()
public AdvisedSupport(java.lang.Class[] interfaces)
interfaces
- the proxied interfacesprivate void initMethodCache()
public void setTarget(java.lang.Object target)
public void setTargetSource(TargetSource targetSource)
Advised
setTargetSource
in interface Advised
targetSource
- new TargetSource to usepublic TargetSource getTargetSource()
Advised
getTargetSource
in interface Advised
public void setTargetClass(java.lang.Class targetClass)
Internally, an EmptyTargetSource
for the given target class will be used. The kind of proxy needed
will be determined on actual creation of the proxy.
This is a replacement for setting a "targetSource" or "target", for the case where we want a proxy based on a target class (which can be an interface or a concrete class) without having a fully capable TargetSource available.
public java.lang.Class<?> getTargetClass()
TargetClassAware
getTargetClass
in interface TargetClassAware
null
if not knownpublic void setPreFiltered(boolean preFiltered)
Advised
Default is "false". Set this to "true" if the advisors have been pre-filtered already, meaning that the ClassFilter check can be skipped when building the actual advisor chain for proxy invocations.
setPreFiltered
in interface Advised
ClassFilter
public boolean isPreFiltered()
Advised
isPreFiltered
in interface Advised
public void setAdvisorChainFactory(AdvisorChainFactory advisorChainFactory)
Default is a DefaultAdvisorChainFactory
.
public AdvisorChainFactory getAdvisorChainFactory()
null
).public void setInterfaces(java.lang.Class[] interfaces)
public void addInterface(java.lang.Class intf)
intf
- the additional interface to proxypublic boolean removeInterface(java.lang.Class intf)
Does nothing if the given interface isn't proxied.
intf
- the interface to remove from the proxytrue
if the interface was removed; false
if the interface was not found and hence could not be removedpublic java.lang.Class[] getProxiedInterfaces()
Advised
getProxiedInterfaces
in interface Advised
public boolean isInterfaceProxied(java.lang.Class intf)
Advised
isInterfaceProxied
in interface Advised
intf
- the interface to checkpublic final Advisor[] getAdvisors()
Advised
getAdvisors
in interface Advised
null
)public void addAdvisor(Advisor advisor)
Advised
The Advisor may be an IntroductionAdvisor
,
in which new interfaces will be available when a proxy is next obtained
from the relevant factory.
addAdvisor
in interface Advised
advisor
- the advisor to add to the end of the chainpublic void addAdvisor(int pos, Advisor advisor) throws AopConfigException
Advised
addAdvisor
in interface Advised
pos
- position in chain (0 is head). Must be valid.advisor
- the advisor to add at the specified position in the chainAopConfigException
- in case of invalid advicepublic boolean removeAdvisor(Advisor advisor)
Advised
removeAdvisor
in interface Advised
advisor
- the advisor to removetrue
if the advisor was removed; false
if the advisor was not found and hence could not be removedpublic void removeAdvisor(int index) throws AopConfigException
Advised
removeAdvisor
in interface Advised
index
- index of advisor to removeAopConfigException
- if the index is invalidpublic int indexOf(Advisor advisor)
Advised
The return value of this method can be used to index into the advisors array.
public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException
Advised
Note: 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.
replaceAdvisor
in interface Advised
a
- the advisor to replaceb
- the advisor to replace it withfalse
and does nothing.AopConfigException
- in case of invalid advicepublic void addAdvisors(Advisor... advisors)
advisors
- the advisors to registerpublic void addAdvisors(java.util.Collection<Advisor> advisors)
advisors
- the advisors to registerprivate void validateIntroductionAdvisor(IntroductionAdvisor advisor)
private void addAdvisorInternal(int pos, Advisor advisor) throws AopConfigException
AopConfigException
protected final void updateAdvisorArray()
protected final java.util.List<Advisor> getAdvisorsInternal()
List
of Advisors
.
Use with care, and remember to refresh the advisor array
and fire advice changed events
when making any modifications.
public void addAdvice(Advice advice) throws AopConfigException
Advised
This will be wrapped in a DefaultPointcutAdvisor with a pointcut that always
applies, and returned from the getAdvisors()
method in this wrapped form.
Note that the given advice will apply to all invocations on the proxy,
even to the toString()
method! Use appropriate advice implementations
or specify appropriate pointcuts to apply to a narrower set of methods.
addAdvice
in interface Advised
advice
- advice to add to the tail of the chainAopConfigException
- in case of invalid adviceAdvised.addAdvice(int, Advice)
,
DefaultPointcutAdvisor
public void addAdvice(int pos, Advice advice) throws AopConfigException
addAdvice
in interface Advised
pos
- index from 0 (head)advice
- advice to add at the specified position in the advice chainAopConfigException
- in case of invalid advicepublic boolean removeAdvice(Advice advice) throws AopConfigException
Advised
removeAdvice
in interface Advised
advice
- the advice to removetrue
of the advice was found and removed;
false
if there was no such adviceAopConfigException
public int indexOf(Advice advice)
Advised
The return value of this method can be used to index into the advisors array.
public boolean adviceIncluded(Advice advice)
advice
- the advice to check inclusion ofpublic int countAdvicesOfType(java.lang.Class adviceClass)
adviceClass
- the advice class to checkpublic java.util.List<java.lang.Object> getInterceptorsAndDynamicInterceptionAdvice(java.lang.reflect.Method method, java.lang.Class targetClass)
org.aopalliance.intercept.MethodInterceptor
objects
for the given method, based on this configuration.method
- the proxied methodtargetClass
- the target classprotected void adviceChanged()
protected void copyConfigurationFrom(AdvisedSupport other)
other
- the AdvisedSupport object to copy configuration fromprotected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, java.util.List<Advisor> advisors)
other
- the AdvisedSupport object to take proxy configuration fromtargetSource
- the new TargetSourceadvisors
- the Advisors for the chainAdvisedSupport getConfigurationOnlyCopy()
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.String toProxyConfigString()
Advised
toString()
will normally be delegated to the target,
this returns the equivalent for the AOP proxy.toProxyConfigString
in interface Advised
public java.lang.String toString()
toString
in class ProxyConfig