1 27 package ch.ethz.prose.query; 28 29 import java.lang.reflect.Field ; 31 32 38 public 39 class FieldSurrogate extends Surrogate { 40 41 private String fieldName; 42 private String fieldType; 43 private int hashCode; 44 private String declaringClassName; 45 46 47 52 public FieldSurrogate(Field f) 53 { 54 if (f == null) 55 throw new IllegalArgumentException ("specified field must not be null"); 56 57 hashCode = f.hashCode(); 58 fieldName = f.getName(); 59 fieldType = f.getType().getName(); 60 declaringClassName = f.getDeclaringClass().getName(); 61 } 62 63 64 69 public String getName() 70 { 71 return fieldName; 72 } 73 74 75 80 public String getType() 81 { 82 return fieldType; 83 } 84 85 public Object toRealInstance() throws ClassNotFoundException , NoSuchFieldException 86 { 87 return toRealInstance(declaringClassName); 88 } 89 90 97 public Field toRealInstance(String className) throws ClassNotFoundException , NoSuchFieldException 98 { 99 Class c = Class.forName(className); 100 return c.getDeclaredField(fieldName); 101 } 102 103 104 111 public boolean equals(Object o) 112 { 113 if (!(o instanceof FieldSurrogate)) 114 return false; 115 116 FieldSurrogate other = (FieldSurrogate) o; 117 118 if (!this.getName().equals(other.getName())) 119 return false; 120 121 if (!this.getType().equals(other.getType())) 122 return false; 123 124 return true; 125 } 126 127 public int hashCode() 128 { 129 return hashCode; 130 } 131 132 135 public String toString() 136 { 137 return fieldType + " " + fieldName; 138 } 139 } 140 141 142 | Popular Tags |