package org.mockejb.interceptor;
import java.lang.reflect.Method;
import java.util.*;
public class AspectSystemImpl implements AspectSystem {
private List aspectList = Collections.synchronizedList(new LinkedList());
public void add(Aspect aspect) {
removeIfExists( aspect );
aspectList.add( aspect );
}
public void addFirst(Aspect aspect) {
removeIfExists( aspect );
aspectList.add( 0, aspect );
}
public void add(Pointcut pointcut, Interceptor interceptor) {
Aspect aspect = new InterceptorContainerAspect( pointcut, interceptor );
removeIfExists( aspect );
aspectList.add( aspect );
}
public void addFirst(Pointcut pointcut, Interceptor interceptor) {
Aspect aspect = new InterceptorContainerAspect( pointcut, interceptor );
removeIfExists( aspect );
aspectList.add( 0, aspect );
}
protected void removeIfExists( Aspect aspect ){
aspectList.remove( aspect );
}
public List getAspectList() {
return aspectList;
}
public void clear(){
aspectList.clear();
}
public List findInterceptors( Method proxyMethod, Method targetMethod ) {
List resultList = new ArrayList();
for( Iterator i=aspectList.iterator(); i.hasNext();){
Aspect aspect = (Aspect) i.next();
if ( proxyMethod != null && aspect.getPointcut().matchesJointpoint( proxyMethod ) ||
targetMethod!=null && aspect.getPointcut().matchesJointpoint( targetMethod ) ) {
resultList.add( aspect );
}
}
return resultList;
}
}