1 17 18 package org.apache.geronimo.gbean; 19 20 import java.lang.reflect.Method ; 21 import java.util.List ; 22 23 28 public final class GOperationSignature { 29 private final static String [] NO_TYPES = new String [0]; 30 private final String name; 31 private final String [] argumentTypes; 32 33 public GOperationSignature(Method method) { 34 name = method.getName(); 35 Class [] parameters = method.getParameterTypes(); 36 argumentTypes = new String [parameters.length]; 37 for (int i = 0; i < parameters.length; i++) { 38 argumentTypes[i] = parameters[i].getName(); 39 } 40 } 41 42 public GOperationSignature(String name, String [] argumentTypes) { 43 this.name = name; 44 if (argumentTypes != null) { 45 this.argumentTypes = argumentTypes; 46 } else { 47 this.argumentTypes = NO_TYPES; 48 } 49 } 50 51 public GOperationSignature(String name, List argumentTypes) { 52 this.name = name; 53 if (argumentTypes != null) { 54 this.argumentTypes = new String [argumentTypes.size()]; 55 for (int i = 0; i < argumentTypes.size(); i++) { 56 this.argumentTypes[i] = (String ) argumentTypes.get(i); 57 } 58 } else { 59 this.argumentTypes = NO_TYPES; 60 } 61 } 62 63 public boolean equals(Object object) { 64 if (!(object instanceof GOperationSignature)) { 65 return false; 66 } 67 68 GOperationSignature methodKey = (GOperationSignature) object; 70 if (!methodKey.name.equals(name)) { 71 return false; 72 } 73 74 int length = methodKey.argumentTypes.length; 76 if (length != argumentTypes.length) { 77 return false; 78 } 79 80 for (int i = 0; i < length; i++) { 82 if (!methodKey.argumentTypes[i].equals(argumentTypes[i])) { 83 return false; 84 } 85 } 86 return true; 87 } 88 89 public int hashCode() { 90 int result = 17; 91 result = 37 * result + name.hashCode(); 92 for (int i = 0; i < argumentTypes.length; i++) { 93 result = 37 * result + argumentTypes[i].hashCode(); 94 } 95 return result; 96 } 97 98 public String toString() { 99 StringBuffer buffer = new StringBuffer (name).append("("); 100 for (int i = 0; i < argumentTypes.length; i++) { 101 if (i > 0) { 102 buffer.append(", "); 103 } 104 buffer.append(argumentTypes[i]); 105 } 106 return buffer.append(")").toString(); 107 } 108 } 109 | Popular Tags |