1 16 17 package org.springframework.beans.factory.support; 18 19 import java.lang.reflect.Method ; 20 import java.util.LinkedList ; 21 import java.util.List ; 22 23 import org.springframework.util.Assert; 24 import org.springframework.util.ObjectUtils; 25 26 37 public class ReplaceOverride extends MethodOverride { 38 39 private final String methodReplacerBeanName; 40 41 44 private List typeIdentifiers = new LinkedList (); 45 46 47 52 public ReplaceOverride(String methodName, String methodReplacerBeanName) { 53 super(methodName); 54 Assert.notNull(methodName, "Method replacer bean name must not be null"); 55 this.methodReplacerBeanName = methodReplacerBeanName; 56 } 57 58 61 public String getMethodReplacerBeanName() { 62 return this.methodReplacerBeanName; 63 } 64 65 70 public void addTypeIdentifier(String identifier) { 71 this.typeIdentifiers.add(identifier); 72 } 73 74 75 public boolean matches(Method method) { 76 if (!method.getName().equals(getMethodName())) { 78 return false; 80 } 81 82 if (!isOverloaded()) { 83 return true; 85 } 86 87 if (this.typeIdentifiers.size() != method.getParameterTypes().length) { 89 return false; 90 } 91 for (int i = 0; i < this.typeIdentifiers.size(); i++) { 92 String identifier = (String ) this.typeIdentifiers.get(i); 93 if (method.getParameterTypes()[i].getName().indexOf(identifier) == -1) { 94 return false; 96 } 97 } 98 return true; 99 } 100 101 102 public String toString() { 103 return "Replace override for method '" + getMethodName() + "; will call bean '" + 104 this.methodReplacerBeanName + "'"; 105 } 106 107 public boolean equals(Object other) { 108 if (!(other instanceof ReplaceOverride) || !super.equals(other)) { 109 return false; 110 } 111 ReplaceOverride that = (ReplaceOverride) other; 112 return (ObjectUtils.nullSafeEquals(this.methodReplacerBeanName, that.methodReplacerBeanName) && 113 ObjectUtils.nullSafeEquals(this.typeIdentifiers, that.typeIdentifiers)); 114 } 115 116 public int hashCode() { 117 int hashCode = super.hashCode(); 118 hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.methodReplacerBeanName); 119 hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.typeIdentifiers); 120 return hashCode; 121 } 122 123 } 124 | Popular Tags |