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