Class AdvisedSupport
- All Implemented Interfaces:
- Serializable, Advised, TargetClassAware
- Direct Known Subclasses:
- ProxyCreatorSupport
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, Juergen Hoeller, Sam Brannen
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final TargetSourceCanonical TargetSource when there's no target, and behavior is supplied by the advisors.
- 
Constructor SummaryConstructorsConstructorDescriptionNo-arg constructor for use as a JavaBean.AdvisedSupport(Class<?>... interfaces) Create anAdvisedSupportinstance with the given parameters.
- 
Method SummaryModifier and TypeMethodDescriptionvoidCannot add introductions this way unless the advice implements IntroductionInfo.voidAdd the given AOP Alliance advice to the tail of the advice (interceptor) chain.voidaddAdvisor(int pos, Advisor advisor) Add an Advisor at the specified position in the chain.voidaddAdvisor(Advisor advisor) Add an advisor at the end of the advisor chain.voidaddAdvisors(Collection<Advisor> advisors) Add all the given advisors to this proxy configuration.voidaddAdvisors(Advisor... advisors) Add all the given advisors to this proxy configuration.voidaddInterface(Class<?> ifc) Add a new proxied interface.protected voidInvoked when advice has changed.booleanadviceIncluded(@Nullable Advice advice) Is the given advice included in any advisor within this proxy configuration?protected voidCall 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 voidcopyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) Copy the AOP configuration from the givenAdvisedSupportobject, but allow substitution of a freshTargetSourceand a given interceptor chain.intcountAdvicesOfType(@Nullable Class<?> adviceClass) Count advices of the given class.Return the advisor chain factory to use (nevernull).intReturn the number of advisors applying to this proxy.final Advisor[]Return the advisors applying to this proxy.getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) Determine a list ofMethodInterceptorobjects for the given method, based on this configuration.Class<?>[]Return the interfaces proxied by the AOP proxy.Return the target class behind the implementing object (typically a proxy configuration or an actual proxy).Return theTargetSourceused by thisAdvisedobject.intReturn the index (from 0) of the given AOP Alliance Advice, or -1 if no such advice is an advice for this proxy.intReturn the index (from 0) of the given advisor, or -1 if no such advisor applies to this proxy.booleanisInterfaceProxied(Class<?> ifc) Determine whether the given interface is proxied.booleanReturn whether this proxy configuration is pre-filtered so that it only contains applicable advisors (matching this proxy's target class).booleanremoveAdvice(Advice advice) Remove the Advisor containing the given advice.voidremoveAdvisor(int index) Remove the advisor at the given index.booleanremoveAdvisor(Advisor advisor) Remove the given advisor.booleanremoveInterface(Class<?> ifc) Remove a proxied interface.booleanreplaceAdvisor(Advisor a, Advisor b) Replace the given advisor.voidsetAdvisorChainFactory(AdvisorChainFactory advisorChainFactory) Set the advisor chain factory to use.voidsetInterfaces(Class<?>... interfaces) Set the interfaces to be proxied.voidsetPreFiltered(boolean preFiltered) Set whether this proxy configuration is pre-filtered so that it only contains applicable advisors (matching this proxy's target class).voidSet the given object as target.voidsetTargetClass(@Nullable Class<?> targetClass) Set a target class to be proxied, indicating that the proxy should be castable to the given class.voidsetTargetSource(@Nullable TargetSource targetSource) Change theTargetSourceused by thisAdvisedobject.AstoString()will normally be delegated to the target, this returns the equivalent for the AOP proxy.toString()For debugging/diagnostic use.Methods inherited from class ProxyConfigcopyDefault, copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClassMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AdvisedisExposeProxy, isFrozen, isProxyTargetClass, setExposeProxy
- 
Field Details- 
EMPTY_TARGET_SOURCECanonical TargetSource when there's no target, and behavior is supplied by the advisors.
 
- 
- 
Constructor Details- 
AdvisedSupportpublic AdvisedSupport()No-arg constructor for use as a JavaBean.
- 
AdvisedSupportCreate anAdvisedSupportinstance with the given parameters.- Parameters:
- interfaces- the proxied interfaces
 
 
- 
- 
Method Details- 
setTargetSet the given object as target.Will create a SingletonTargetSource for the object. - See Also:
 
- 
setTargetSourceDescription copied from interface:Advised- Specified by:
- setTargetSourcein interface- Advised
- Parameters:
- targetSource- new TargetSource to use
 
- 
getTargetSourceDescription copied from interface:AdvisedReturn theTargetSourceused by thisAdvisedobject.- Specified by:
- getTargetSourcein interface- Advised
 
- 
setTargetClassSet a target class to be proxied, indicating that the proxy should be castable to the given class.Internally, an EmptyTargetSourcefor 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. - See Also:
 
- 
getTargetClassDescription copied from interface:TargetClassAwareReturn the target class behind the implementing object (typically a proxy configuration or an actual proxy).- Specified by:
- getTargetClassin interface- TargetClassAware
- Returns:
- the target Class, or nullif not known
 
- 
setPreFilteredpublic void setPreFiltered(boolean preFiltered) Description copied from interface:AdvisedSet whether this proxy configuration is pre-filtered so that it only contains applicable advisors (matching this proxy's target class).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. - Specified by:
- setPreFilteredin interface- Advised
- See Also:
 
- 
isPreFilteredpublic boolean isPreFiltered()Description copied from interface:AdvisedReturn whether this proxy configuration is pre-filtered so that it only contains applicable advisors (matching this proxy's target class).- Specified by:
- isPreFilteredin interface- Advised
 
- 
setAdvisorChainFactorySet the advisor chain factory to use.Default is a DefaultAdvisorChainFactory.
- 
getAdvisorChainFactoryReturn the advisor chain factory to use (nevernull).
- 
setInterfacesSet the interfaces to be proxied.
- 
addInterfaceAdd a new proxied interface.- Parameters:
- ifc- the additional interface to proxy
 
- 
removeInterfaceRemove a proxied interface.Does nothing if the given interface isn't proxied. - Parameters:
- ifc- the interface to remove from the proxy
- Returns:
- trueif the interface was removed;- falseif the interface was not found and hence could not be removed
 
- 
getProxiedInterfacesDescription copied from interface:AdvisedReturn the interfaces proxied by the AOP proxy.Will not include the target class, which may also be proxied. - Specified by:
- getProxiedInterfacesin interface- Advised
 
- 
isInterfaceProxiedDescription copied from interface:AdvisedDetermine whether the given interface is proxied.- Specified by:
- isInterfaceProxiedin interface- Advised
- Parameters:
- ifc- the interface to check
 
- 
getAdvisorsDescription copied from interface:AdvisedReturn the advisors applying to this proxy.- Specified by:
- getAdvisorsin interface- Advised
- Returns:
- a list of Advisors applying to this proxy (never null)
 
- 
getAdvisorCountpublic int getAdvisorCount()Description copied from interface:AdvisedReturn the number of advisors applying to this proxy.The default implementation delegates to getAdvisors().length.- Specified by:
- getAdvisorCountin interface- Advised
 
- 
addAdvisorDescription copied from interface:AdvisedAdd 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:
- addAdvisorin interface- Advised
- Parameters:
- advisor- the advisor to add to the end of the chain
 
- 
addAdvisorDescription copied from interface:AdvisedAdd an Advisor at the specified position in the chain.- Specified by:
- addAdvisorin interface- Advised
- Parameters:
- pos- position in chain (0 is head). Must be valid.
- advisor- the advisor to add at the specified position in the chain
- Throws:
- AopConfigException- in case of invalid advice
 
- 
removeAdvisorDescription copied from interface:AdvisedRemove the given advisor.- Specified by:
- removeAdvisorin interface- Advised
- Parameters:
- advisor- the advisor to remove
- Returns:
- trueif the advisor was removed;- falseif the advisor was not found and hence could not be removed
 
- 
removeAdvisorDescription copied from interface:AdvisedRemove the advisor at the given index.- Specified by:
- removeAdvisorin interface- Advised
- Parameters:
- index- the index of advisor to remove
- Throws:
- AopConfigException- if the index is invalid
 
- 
indexOfDescription copied from interface:AdvisedReturn 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. 
- 
replaceAdvisorDescription copied from interface:AdvisedReplace the given advisor.Note: If the advisor is an IntroductionAdvisorand 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:
- replaceAdvisorin interface- Advised
- Parameters:
- a- the advisor to replace
- b- the advisor to replace it with
- Returns:
- whether it was replaced. If the advisor wasn't found in the
list of advisors, this method returns falseand does nothing.
- Throws:
- AopConfigException- in case of invalid advice
 
- 
addAdvisorsAdd all the given advisors to this proxy configuration.- Parameters:
- advisors- the advisors to register
 
- 
addAdvisorsAdd all the given advisors to this proxy configuration.- Parameters:
- advisors- the advisors to register
 
- 
getAdvisorsInternalAllows uncontrolled access to theListofAdvisors.Use with care, and remember to fire advice changed eventswhen making any modifications.
- 
addAdviceDescription copied from interface:AdvisedAdd 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.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.- Specified by:
- addAdvicein interface- Advised
- Parameters:
- advice- the advice to add to the tail of the chain
- Throws:
- AopConfigException- in case of invalid advice
- See Also:
 
- 
addAdviceCannot add introductions this way unless the advice implements IntroductionInfo.- Specified by:
- addAdvicein interface- Advised
- Parameters:
- pos- index from 0 (head)
- advice- the advice to add at the specified position in the advice chain
- Throws:
- AopConfigException- in case of invalid advice
 
- 
removeAdviceDescription copied from interface:AdvisedRemove the Advisor containing the given advice.- Specified by:
- removeAdvicein interface- Advised
- Parameters:
- advice- the advice to remove
- Returns:
- trueof the advice was found and removed;- falseif there was no such advice
- Throws:
- AopConfigException
 
- 
indexOfDescription copied from interface:AdvisedReturn 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. 
- 
adviceIncluded
- 
countAdvicesOfType
- 
getInterceptorsAndDynamicInterceptionAdvicepublic List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) Determine a list ofMethodInterceptorobjects for the given method, based on this configuration.- Parameters:
- method- the proxied method
- targetClass- the target class
- Returns:
- a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
 
- 
adviceChangedprotected void adviceChanged()Invoked when advice has changed.
- 
copyConfigurationFromCall this method on a new instance created by the no-arg constructor to create an independent copy of the configuration from the given object.- Parameters:
- other- the AdvisedSupport object to copy configuration from
 
- 
copyConfigurationFromprotected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) Copy the AOP configuration from the givenAdvisedSupportobject, but allow substitution of a freshTargetSourceand a given interceptor chain.- Parameters:
- other- the- AdvisedSupportobject to take proxy configuration from
- targetSource- the new TargetSource
- advisors- the Advisors for the chain
 
- 
toProxyConfigStringDescription copied from interface:AdvisedAstoString()will normally be delegated to the target, this returns the equivalent for the AOP proxy.- Specified by:
- toProxyConfigStringin interface- Advised
- Returns:
- a string description of the proxy configuration
 
- 
toString
 
-