1 package org.neo.swarm.core.aop.silc.comp;
2
3 import java.io.Serializable;
4 import java.lang.reflect.Method;
5
6 import org.neo.swarm.core.aop.AspectComponent;
7
8
9 /***
10 * Matches using String.match()
11 * @see http://java.sun.com/j2se/1.4.1/docs/api/java/util/regex/Pattern.html#sum
12 */
13 public class RegexPointCut implements Serializable, Pointcut {
14 private String regEx;
15
16 public RegexPointCut(String matches) {
17 this.regEx = matches;
18 }
19 public void advise(Perspective perspective, AspectComponent component, MethodInterceptor interceptor) {
20 Method [] methods = component.getInterfaceMethods();
21
22 for (int i = 0; i < methods.length; i++) {
23 if (shouldAdvise(component, methods[i])) {
24 component.addInterceptor(perspective, methods[i], interceptor);
25 }
26 }
27 }
28
29 public boolean shouldAdvise(AspectComponent component, Method method) {
30 return getFullName(method).matches(regEx);
31 }
32
33 private String getFullName(Method method) {
34 return method.getDeclaringClass().getName() + "." + method.getName();
35 }
36 }