package org.theonefx.wcframework.aop; import java.lang.reflect.Method; /** * @File : ExactlyPointcut.java * @ClassName : ExactlyPointcut * @Author : TheoneFx * @Date : 2013-3-11 下午10:36:53 * @Version : v1.0 * @Description : 明确的切入点,唯一指定一个method */ public class ExactlyPointcut implements Pointcut { private final Class<?> clazz; private final Method method; public ExactlyPointcut(Class<?> clazz, Method method) { this.clazz = clazz; this.method = method; } @Override public ClassFilter getClassFilter() { return classFilter; } @Override public MethodMatcher getMethodMatcher() { return methodMatcher; } private final ClassFilter classFilter = new ClassFilter() { @Override public boolean matches(Class<?> clazz) { return clazz.getCanonicalName().equals(ExactlyPointcut.this.clazz.getCanonicalName()); } }; private final MethodMatcher methodMatcher = new MethodMatcher() { @Override public boolean match(Method method) { if (method == ExactlyPointcut.this.method) { return true; } if (method.getName().equals(ExactlyPointcut.this.method.getName())) { Class<?>[] types1 = method.getParameterTypes(); Class<?>[] types2 = ExactlyPointcut.this.method.getParameterTypes(); if (types1.length != types2.length) { return false; } for (int i = 0; i < types1.length; i++) { if (!types1[i].getCanonicalName().equals(types2[i].getCanonicalName())) { return false; } } return true; } else { return false; } } }; }