org.springframework.aop.framework.adapter
public class: DefaultAdvisorAdapterRegistry [javadoc |
source]
java.lang.Object
org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry
All Implemented Interfaces:
Serializable, AdvisorAdapterRegistry
Default implementation of the
AdvisorAdapterRegistry interface.
Supports
org.aopalliance.intercept.MethodInterceptor ,
org.springframework.aop.MethodBeforeAdvice ,
org.springframework.aop.AfterReturningAdvice ,
org.springframework.aop.ThrowsAdvice .
- author:
Rod - Johnson
- author:
Rob - Harrop
- author:
Juergen - Hoeller
| Method from org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry Detail: |
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
List interceptors = new ArrayList(3);
Advice advice = advisor.getAdvice();
if (advice instanceof MethodInterceptor) {
interceptors.add(advice);
}
for (int i = 0; i < this.adapters.size(); i++) {
AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i);
if (adapter.supportsAdvice(advice)) {
interceptors.add(adapter.getInterceptor(advisor));
}
}
if (interceptors.isEmpty()) {
throw new UnknownAdviceTypeException(advisor.getAdvice());
}
return (MethodInterceptor[]) interceptors.toArray(new MethodInterceptor[interceptors.size()]);
}
|
public void registerAdvisorAdapter(AdvisorAdapter adapter) {
this.adapters.add(adapter);
}
|
public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {
if (adviceObject instanceof Advisor) {
return (Advisor) adviceObject;
}
if (!(adviceObject instanceof Advice)) {
throw new UnknownAdviceTypeException(adviceObject);
}
Advice advice = (Advice) adviceObject;
if (advice instanceof MethodInterceptor) {
// So well-known it doesn't even need an adapter.
return new DefaultPointcutAdvisor(advice);
}
for (int i = 0; i < this.adapters.size(); i++) {
// Check that it is supported.
AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i);
if (adapter.supportsAdvice(advice)) {
return new DefaultPointcutAdvisor(advice);
}
}
throw new UnknownAdviceTypeException(advice);
}
|