01: package org.mockejb.interceptor;
02:
03: import java.lang.reflect.Method;
04:
05: /**
06: * Tests if the class name of the provided method matches the regexp.
07: *
08: * @author Alexander Ananiev
09: */
10: public class ClassPatternPointcut implements Pointcut {
11:
12: private RegexpWrapper regexpWrapper;
13:
14: /**
15: * Creates a new instance of ClassPatternPoincut
16: * @param regexpPattern regexp pattern that will be matched against the fully qualified class name
17: *
18: */
19: public ClassPatternPointcut(String regexpPattern) {
20:
21: regexpWrapper = new RegexpWrapper(regexpPattern);
22:
23: }
24:
25: /**
26: * Tests if the fully qualified class name of the given method
27: *
28: * @return true if the provided method should be intercepted
29: */
30: public boolean matchesJointpoint(Method method) {
31:
32: return regexpWrapper.containedInString(method.toString());
33:
34: }
35:
36: /**
37: * Returns true if the given object is of the same type and
38: * it has the same pattern.
39: */
40: public boolean equals(Object obj) {
41: if (!(obj instanceof ClassPatternPointcut))
42: return false;
43:
44: ClassPatternPointcut classPatternPointcut = (ClassPatternPointcut) obj;
45:
46: return (regexpWrapper
47: .equals(classPatternPointcut.regexpWrapper));
48: }
49:
50: public int hashCode() {
51: return regexpWrapper.hashCode();
52: }
53:
54: }
|