package org.mockejb.interceptor;
import java.lang.reflect.Method;
public class ClassPointcut implements Pointcut {
private Class clazz;
private boolean matchSubclasses = false;
public ClassPointcut( final Class clazz ){
this.clazz = clazz;
}
public ClassPointcut( final Class clazz, final boolean matchSubclasses ){
this.clazz = clazz;
this.matchSubclasses = matchSubclasses;
}
public boolean matchesJointpoint( Method method ) {
boolean matches = false;
if ( matchSubclasses ) {
matches = clazz.isAssignableFrom( method.getDeclaringClass() );
}
else {
matches = method.getDeclaringClass().equals( clazz );
}
return matches;
}
public boolean equals( Object obj ){
if ( ! (obj instanceof ClassPointcut) )
return false;
ClassPointcut classPointcut = (ClassPointcut ) obj;
return ( clazz.equals( classPointcut.clazz ) &&
matchSubclasses == classPointcut.matchSubclasses );
}
public int hashCode() {
int result = 17;
result = 37*result+clazz.hashCode();
result = 37*result+(matchSubclasses ? 0 : 1);
return result;
}
}