1 16 17 package org.springframework.aop.support; 18 19 import java.io.Serializable ; 20 import java.lang.reflect.Method ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 import org.springframework.util.ObjectUtils; 25 import org.springframework.util.PatternMatchUtils; 26 27 37 public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable { 38 39 private List mappedNames = new LinkedList (); 40 41 42 47 public void setMappedName(String mappedName) { 48 setMappedNames(new String [] { mappedName }); 49 } 50 51 56 public void setMappedNames(String [] mappedNames) { 57 this.mappedNames = new LinkedList (); 58 if (mappedNames != null) { 59 for (int i = 0; i < mappedNames.length; i++) { 60 this.mappedNames.add(mappedNames[i]); 61 } 62 } 63 } 64 65 74 public NameMatchMethodPointcut addMethodName(String name) { 75 this.mappedNames.add(name); 78 return this; 79 } 80 81 82 public boolean matches(Method method, Class targetClass) { 83 for (int i = 0; i < this.mappedNames.size(); i++) { 84 String mappedName = (String ) this.mappedNames.get(i); 85 if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) { 86 return true; 87 } 88 } 89 return false; 90 } 91 92 101 protected boolean isMatch(String methodName, String mappedName) { 102 return PatternMatchUtils.simpleMatch(mappedName, methodName); 103 } 104 105 106 public boolean equals(Object other) { 107 if (this == other) { 108 return true; 109 } 110 return (other instanceof NameMatchMethodPointcut && 111 ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames)); 112 } 113 114 public int hashCode() { 115 return (this.mappedNames != null ? this.mappedNames.hashCode() : 0); 116 } 117 118 } 119 | Popular Tags |