1 8 package org.codehaus.aspectwerkz.reflect.impl.java; 9 10 import org.codehaus.aspectwerkz.annotation.Annotations; 11 import org.codehaus.aspectwerkz.reflect.ClassInfo; 12 import org.codehaus.aspectwerkz.reflect.ConstructorInfo; 13 import org.codehaus.aspectwerkz.reflect.ReflectHelper; 14 import org.codehaus.aspectwerkz.reflect.ReflectHelper; 15 16 import java.lang.reflect.Constructor ; 17 import java.util.List ; 18 19 24 public class JavaConstructorInfo extends JavaMemberInfo implements ConstructorInfo { 25 28 private ClassInfo[] m_parameterTypes = null; 29 30 33 private ClassInfo[] m_exceptionTypes = null; 34 35 38 private String m_signature; 39 40 46 JavaConstructorInfo(final Constructor constructor, final JavaClassInfo declaringType) { 47 super(constructor, declaringType); 48 m_signature = ReflectHelper.getConstructorSignature(constructor); 49 } 50 51 57 public static ConstructorInfo getConstructorInfo(final Constructor constructor) { 58 Class declaringClass = constructor.getDeclaringClass(); 59 JavaClassInfoRepository repository = JavaClassInfoRepository.getRepository(declaringClass.getClassLoader()); 60 ClassInfo classInfo = repository.getClassInfo(declaringClass.getName()); 61 if (classInfo == null) { 62 classInfo = JavaClassInfo.getClassInfo(declaringClass); 63 } 64 return classInfo.getConstructor(ReflectHelper.calculateHash(constructor)); 65 } 66 67 72 public String getSignature() { 73 return m_signature; 74 } 75 76 82 public List getAnnotations() { 83 if (m_annotations == null) { 84 m_annotations = Annotations.getAnnotationInfos((Constructor ) m_member); 85 } 86 return m_annotations; 87 } 88 89 94 public ClassInfo[] getParameterTypes() { 95 if (m_parameterTypes == null) { 96 Class [] parameterTypes = ((Constructor ) m_member).getParameterTypes(); 97 m_parameterTypes = new ClassInfo[parameterTypes.length]; 98 for (int i = 0; i < parameterTypes.length; i++) { 99 Class parameterType = parameterTypes[i]; 100 ClassInfo metaData; 101 if (m_classInfoRepository.hasClassInfo(parameterType.getName())) { 102 metaData = m_classInfoRepository.getClassInfo(parameterType.getName()); 103 } else { 104 metaData = JavaClassInfo.getClassInfo(parameterType); 105 m_classInfoRepository.addClassInfo(metaData); 106 } 107 m_parameterTypes[i] = metaData; 108 } 109 } 110 return m_parameterTypes; 111 } 112 113 118 public ClassInfo[] getExceptionTypes() { 119 if (m_exceptionTypes == null) { 120 Class [] exceptionTypes = ((Constructor ) m_member).getExceptionTypes(); 121 m_exceptionTypes = new ClassInfo[exceptionTypes.length]; 122 for (int i = 0; i < exceptionTypes.length; i++) { 123 Class exceptionType = exceptionTypes[i]; 124 ClassInfo metaData; 125 if (m_classInfoRepository.hasClassInfo(exceptionType.getName())) { 126 metaData = m_classInfoRepository.getClassInfo(exceptionType.getName()); 127 } else { 128 metaData = JavaClassInfo.getClassInfo(exceptionType); 129 m_classInfoRepository.addClassInfo(metaData); 130 } 131 m_exceptionTypes[i] = metaData; 132 } 133 } 134 return m_exceptionTypes; 135 } 136 137 public boolean equals(Object o) { 138 if (this == o) { 139 return true; 140 } 141 if (!(o instanceof ConstructorInfo)) { 142 return false; 143 } 144 ConstructorInfo constructorInfo = (ConstructorInfo) o; 145 if (!m_declaringType.getName().equals(constructorInfo.getDeclaringType().getName())) { 146 return false; 147 } 148 if (!m_member.getName().equals(constructorInfo.getName())) { 149 return false; 150 } 151 Class [] parameterTypes1 = ((Constructor ) m_member).getParameterTypes(); 152 ClassInfo[] parameterTypes2 = constructorInfo.getParameterTypes(); 153 if (parameterTypes1.length != parameterTypes2.length) { 154 return false; 155 } 156 for (int i = 0; i < parameterTypes1.length; i++) { 157 if (!parameterTypes1[i].getName().equals(parameterTypes2[i].getName())) { 158 return false; 159 } 160 } 161 return true; 162 } 163 164 public int hashCode() { 165 int result = 29; 166 result = (29 * result) + m_declaringType.getName().hashCode(); 167 result = (29 * result) + m_member.getName().hashCode(); 168 Class [] parameterTypes = ((Constructor ) m_member).getParameterTypes(); 169 for (int i = 0; i < parameterTypes.length; i++) { 170 result = (29 * result) + parameterTypes[i].getName().hashCode(); 171 } 172 return result; 173 } 174 } | Popular Tags |