/*
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;
import org.springframework.aop.TargetClassAware;
import org.springframework.aop.TargetSource;
Interface to be implemented by classes that hold the configuration
of a factory of AOP proxies. This configuration includes the
Interceptors and other advice, Advisors, and the proxied interfaces.
Any AOP proxy obtained from Spring can be cast to this interface to
allow manipulation of its AOP advice.
Author: Rod Johnson, Juergen Hoeller See Also: Since: 13.03.2003
/**
* Interface to be implemented by classes that hold the configuration
* of a factory of AOP proxies. This configuration includes the
* Interceptors and other advice, Advisors, and the proxied interfaces.
*
* <p>Any AOP proxy obtained from Spring can be cast to this interface to
* allow manipulation of its AOP advice.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 13.03.2003
* @see org.springframework.aop.framework.AdvisedSupport
*/
public interface Advised extends TargetClassAware {
Return whether the Advised configuration is frozen,
in which case no advice changes can be made.
/**
* Return whether the Advised configuration is frozen,
* in which case no advice changes can be made.
*/
boolean isFrozen();
Are we proxying the full target class instead of specified interfaces?
/**
* Are we proxying the full target class instead of specified interfaces?
*/
boolean isProxyTargetClass();
Return the interfaces proxied by the AOP proxy.
Will not include the target class, which may also be proxied.
/**
* Return the interfaces proxied by the AOP proxy.
* <p>Will not include the target class, which may also be proxied.
*/
Class<?>[] getProxiedInterfaces();
Determine whether the given interface is proxied.
Params: - intf – the interface to check
/**
* Determine whether the given interface is proxied.
* @param intf the interface to check
*/
boolean isInterfaceProxied(Class<?> intf);
Params: - targetSource – new TargetSource to use
/**
* Change the {@code TargetSource} used by this {@code Advised} object.
* <p>Only works if the configuration isn't {@linkplain #isFrozen frozen}.
* @param targetSource new TargetSource to use
*/
void setTargetSource(TargetSource targetSource);
Return the TargetSource
used by this Advised
object. /**
* Return the {@code TargetSource} used by this {@code Advised} object.
*/
TargetSource getTargetSource();
Set whether the proxy should be exposed by the AOP framework as a ThreadLocal
for retrieval via the AopContext
class. It can be necessary to expose the proxy if an advised object needs to invoke a method on itself with advice applied. Otherwise, if an advised object invokes a method on this
, no advice will be applied.
Default is false
, for optimal performance.
/**
* Set whether the proxy should be exposed by the AOP framework as a
* {@link ThreadLocal} for retrieval via the {@link AopContext} class.
* <p>It can be necessary to expose the proxy if an advised object needs
* to invoke a method on itself with advice applied. Otherwise, if an
* advised object invokes a method on {@code this}, no advice will be applied.
* <p>Default is {@code false}, for optimal performance.
*/
void setExposeProxy(boolean exposeProxy);
Return whether the factory should expose the proxy as a ThreadLocal
. It can be necessary to expose the proxy if an advised object needs to invoke a method on itself with advice applied. Otherwise, if an advised object invokes a method on this
, no advice will be applied.
Getting the proxy is analogous to an EJB calling getEJBObject()
.
See Also:
/**
* Return whether the factory should expose the proxy as a {@link ThreadLocal}.
* <p>It can be necessary to expose the proxy if an advised object needs
* to invoke a method on itself with advice applied. Otherwise, if an
* advised object invokes a method on {@code this}, no advice will be applied.
* <p>Getting the proxy is analogous to an EJB calling {@code getEJBObject()}.
* @see AopContext
*/
boolean isExposeProxy();
Set 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.
See Also: - ClassFilter
/**
* Set whether this proxy configuration is pre-filtered so that it only
* contains applicable advisors (matching this proxy's target class).
* <p>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.
* @see org.springframework.aop.ClassFilter
*/
void setPreFiltered(boolean preFiltered);
Return whether this proxy configuration is pre-filtered so that it only
contains applicable advisors (matching this proxy's target class).
/**
* Return whether this proxy configuration is pre-filtered so that it only
* contains applicable advisors (matching this proxy's target class).
*/
boolean isPreFiltered();
Return the advisors applying to this proxy.
Returns: a list of Advisors applying to this proxy (never null
)
/**
* Return the advisors applying to this proxy.
* @return a list of Advisors applying to this proxy (never {@code null})
*/
Advisor[] getAdvisors();
Return the number of advisors applying to this proxy.
The default implementation delegates to getAdvisors().length
.
Since: 5.3.1
/**
* Return the number of advisors applying to this proxy.
* <p>The default implementation delegates to {@code getAdvisors().length}.
* @since 5.3.1
*/
default int getAdvisorCount() {
return getAdvisors().length;
}
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.
Params: - advisor – the advisor to add to the end of the chain
Throws: - AopConfigException – in case of invalid advice
/**
* Add an advisor at the end of the advisor chain.
* <p>The Advisor may be an {@link org.springframework.aop.IntroductionAdvisor},
* in which new interfaces will be available when a proxy is next obtained
* from the relevant factory.
* @param advisor the advisor to add to the end of the chain
* @throws AopConfigException in case of invalid advice
*/
void addAdvisor(Advisor advisor) throws AopConfigException;
Add an Advisor at the specified position in the chain.
Params: - advisor – the advisor to add at the specified position in the chain
- pos – position in chain (0 is head). Must be valid.
Throws: - AopConfigException – in case of invalid advice
/**
* Add an Advisor at the specified position in the chain.
* @param advisor the advisor to add at the specified position in the chain
* @param pos position in chain (0 is head). Must be valid.
* @throws AopConfigException in case of invalid advice
*/
void addAdvisor(int pos, Advisor advisor) throws AopConfigException;
Remove the given advisor.
Params: - advisor – the advisor to remove
Returns: true
if the advisor was removed; false
if the advisor was not found and hence could not be removed
/**
* Remove the given advisor.
* @param advisor the advisor to remove
* @return {@code true} if the advisor was removed; {@code false}
* if the advisor was not found and hence could not be removed
*/
boolean removeAdvisor(Advisor advisor);
Remove the advisor at the given index.
Params: - index – the index of advisor to remove
Throws: - AopConfigException – if the index is invalid
/**
* Remove the advisor at the given index.
* @param index the index of advisor to remove
* @throws AopConfigException if the index is invalid
*/
void removeAdvisor(int index) throws AopConfigException;
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.
Params: - advisor – the advisor to search for
Returns: index from 0 of this advisor, or -1 if there's no such advisor
/**
* Return the index (from 0) of the given advisor,
* or -1 if no such advisor applies to this proxy.
* <p>The return value of this method can be used to index into the advisors array.
* @param advisor the advisor to search for
* @return index from 0 of this advisor, or -1 if there's no such advisor
*/
int indexOf(Advisor advisor);
Replace the given advisor.
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.
Params: - a – the advisor to replace
- b – the advisor to replace it with
Throws: - AopConfigException – in case of invalid advice
Returns: whether it was replaced. If the advisor wasn't found in the list of advisors, this method returns false
and does nothing.
/**
* Replace the given advisor.
* <p><b>Note:</b> If the advisor is an {@link org.springframework.aop.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.
* @param a the advisor to replace
* @param b the advisor to replace it with
* @return whether it was replaced. If the advisor wasn't found in the
* list of advisors, this method returns {@code false} and does nothing.
* @throws AopConfigException in case of invalid advice
*/
boolean replaceAdvisor(Advisor a, Advisor b) 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.
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.
Params: - advice – the advice to add to the tail of the chain
Throws: - AopConfigException – in case of invalid advice
See Also:
/**
* Add the given AOP Alliance advice to the tail of the advice (interceptor) chain.
* <p>This will be wrapped in a DefaultPointcutAdvisor with a pointcut that always
* applies, and returned from the {@code getAdvisors()} method in this wrapped form.
* <p>Note that the given advice will apply to all invocations on the proxy,
* even to the {@code toString()} method! Use appropriate advice implementations
* or specify appropriate pointcuts to apply to a narrower set of methods.
* @param advice the advice to add to the tail of the chain
* @throws AopConfigException in case of invalid advice
* @see #addAdvice(int, Advice)
* @see org.springframework.aop.support.DefaultPointcutAdvisor
*/
void addAdvice(Advice advice) throws AopConfigException;
Add the given AOP Alliance Advice at the specified position in the advice 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: 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.
Params: - 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
/**
* Add the given AOP Alliance Advice at the specified position in the advice chain.
* <p>This will be wrapped in a {@link org.springframework.aop.support.DefaultPointcutAdvisor}
* with a pointcut that always applies, and returned from the {@link #getAdvisors()}
* method in this wrapped form.
* <p>Note: The given advice will apply to all invocations on the proxy,
* even to the {@code toString()} method! Use appropriate advice implementations
* or specify appropriate pointcuts to apply to a narrower set of methods.
* @param pos index from 0 (head)
* @param advice the advice to add at the specified position in the advice chain
* @throws AopConfigException in case of invalid advice
*/
void addAdvice(int pos, Advice advice) throws AopConfigException;
Remove the Advisor containing the given advice.
Params: - advice – the advice to remove
Returns: true
of the advice was found and removed; false
if there was no such advice
/**
* Remove the Advisor containing the given advice.
* @param advice the advice to remove
* @return {@code true} of the advice was found and removed;
* {@code false} if there was no such advice
*/
boolean removeAdvice(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.
Params: - advice – the AOP Alliance advice to search for
Returns: index from 0 of this advice, or -1 if there's no such advice
/**
* Return the index (from 0) of the given AOP Alliance Advice,
* or -1 if no such advice is an advice for this proxy.
* <p>The return value of this method can be used to index into
* the advisors array.
* @param advice the AOP Alliance advice to search for
* @return index from 0 of this advice, or -1 if there's no such advice
*/
int indexOf(Advice advice);
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
/**
* As {@code toString()} will normally be delegated to the target,
* this returns the equivalent for the AOP proxy.
* @return a string description of the proxy configuration
*/
String toProxyConfigString();
}