01: package org.mockejb.interceptor;
02:
03: import org.apache.oro.text.regex.*;
04:
05: /**
06: * Helper class used to isolate pointcuts that use regexp from the
07: * concrete regexp API. Currently we use Jakarta ORO but may
08: * switch to the java regexp package in the future
09: *
10: * @author Alexander Ananiev
11: */
12: class RegexpWrapper {
13:
14: private Pattern pattern;
15: private String patternString;
16:
17: private PatternCompiler compiler = new Perl5Compiler();;
18: private PatternMatcher matcher = new Perl5Matcher();
19:
20: public RegexpWrapper(final String patternString) {
21: this .patternString = patternString;
22: try {
23: pattern = compiler.compile(patternString);
24: } catch (MalformedPatternException mpe) {
25: throw new PointcutException(mpe.getMessage(), mpe);
26: }
27:
28: }
29:
30: /**
31: * Tests if this regexp pattern is contained by the given string.
32: * @param stringToMatch string where to search for the occurences of this regexp
33: * @return true if the string contains the patternprovided method should be intercepted
34: */
35: public boolean containedInString(String stringToMatch) {
36:
37: return matcher.contains(stringToMatch, pattern);
38:
39: }
40:
41: /**
42: * Returns true if the given object is of the same type and
43: * it has the same pattern.
44: */
45: public boolean equals(Object obj) {
46: if (!(obj instanceof RegexpWrapper))
47: return false;
48:
49: RegexpWrapper regexpWrapper = (RegexpWrapper) obj;
50:
51: return (patternString.equals(regexpWrapper.patternString));
52: }
53:
54: public int hashCode() {
55: int result = 17;
56: result = 37 * result + patternString.hashCode();
57:
58: return result;
59: }
60:
61: }
|