001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.xbean.finder; 018 019import java.io.InputStream; 020import java.lang.annotation.Annotation; 021import java.lang.reflect.Constructor; 022import java.lang.reflect.Field; 023import java.lang.reflect.Method; 024import java.lang.reflect.Type; 025import java.lang.reflect.TypeVariable; 026import java.net.URL; 027import java.security.ProtectionDomain; 028 029/** 030* @version $Rev$ $Date$ 031*/ 032public class MetaAnnotatedClass<T> extends MetaAnnotatedElement<Class<T>> { 033 034 public MetaAnnotatedClass(Class<T> clazz) { 035 super(clazz, unroll(clazz)); 036 } 037 038 public MetaAnnotatedClass<?> forName(String className) throws ClassNotFoundException { 039 return to(target.forName(className)); 040 } 041 042 private MetaAnnotatedClass<?> to(Class<?> clazz) { 043 return new MetaAnnotatedClass(clazz); 044 } 045 046 public MetaAnnotatedClass<?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException { 047 return to(target.forName(name, initialize, loader)); 048 } 049 050 public T newInstance() throws InstantiationException, IllegalAccessException { 051 return target.newInstance(); 052 } 053 054 public boolean isInstance(Object obj) { 055 return target.isInstance(obj); 056 } 057 058 public boolean isAssignableFrom(Class<?> cls) { 059 return target.isAssignableFrom(cls); 060 } 061 062 public boolean isInterface() { 063 return target.isInterface(); 064 } 065 066 public boolean isArray() { 067 return target.isArray(); 068 } 069 070 public boolean isPrimitive() { 071 return target.isPrimitive(); 072 } 073 074 public boolean isAnnotation() { 075 return target.isAnnotation(); 076 } 077 078 public boolean isSynthetic() { 079 return target.isSynthetic(); 080 } 081 082 public String getName() { 083 return target.getName(); 084 } 085 086 public ClassLoader getClassLoader() { 087 return target.getClassLoader(); 088 } 089 090 public TypeVariable<Class<T>>[] getTypeParameters() { 091 return target.getTypeParameters(); 092 } 093 094 public MetaAnnotatedClass<? super T> getSuperclass() { 095 return new MetaAnnotatedClass(target.getSuperclass()); 096 } 097 098 public Type getGenericSuperclass() { 099 return target.getGenericSuperclass(); 100 } 101 102 public Package getPackage() { 103 return target.getPackage(); 104 } 105 106 public MetaAnnotatedClass<?>[] getInterfaces() { 107 return to(target.getInterfaces()); 108 } 109 110 public Type[] getGenericInterfaces() { 111 return target.getGenericInterfaces(); 112 } 113 114 public MetaAnnotatedClass<?> getComponentType() { 115 return to(target.getComponentType()); 116 } 117 118 public int getModifiers() { 119 return target.getModifiers(); 120 } 121 122 public Object[] getSigners() { 123 return target.getSigners(); 124 } 125 126 public MetaAnnotatedMethod getEnclosingMethod() { 127 return to(target.getEnclosingMethod()); 128 } 129 130 public MetaAnnotatedConstructor<?> getEnclosingConstructor() { 131 return to(target.getEnclosingConstructor()); 132 } 133 134 public MetaAnnotatedClass<?> getDeclaringClass() { 135 return to(target.getDeclaringClass()); 136 } 137 138 public MetaAnnotatedClass<?> getEnclosingClass() { 139 return to(target.getEnclosingClass()); 140 } 141 142 public String getSimpleName() { 143 return target.getSimpleName(); 144 } 145 146 public String getCanonicalName() { 147 return target.getCanonicalName(); 148 } 149 150 public boolean isAnonymousClass() { 151 return target.isAnonymousClass(); 152 } 153 154 public boolean isLocalClass() { 155 return target.isLocalClass(); 156 } 157 158 public boolean isMemberClass() { 159 return target.isMemberClass(); 160 } 161 162 public MetaAnnotatedClass<?>[] getClasses() { 163 return to(target.getClasses()); 164 } 165 166 public MetaAnnotatedField[] getFields() throws SecurityException { 167 return to(target.getFields()); 168 } 169 170 public MetaAnnotatedMethod[] getMethods() throws SecurityException { 171 return to(target.getMethods()); 172 } 173 174 public MetaAnnotatedConstructor<?>[] getConstructors() throws SecurityException { 175 return to(target.getConstructors()); 176 } 177 178 public MetaAnnotatedField getField(String name) throws NoSuchFieldException, SecurityException { 179 return to(target.getField(name)); 180 } 181 182 public MetaAnnotatedMethod getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException { 183 return to(target.getMethod(name, parameterTypes)); 184 } 185 186 public MetaAnnotatedConstructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException { 187 return new MetaAnnotatedConstructor(target.getConstructor(parameterTypes)); 188 } 189 190 public MetaAnnotatedClass<?>[] getDeclaredClasses() throws SecurityException { 191 return to(target.getDeclaredClasses()); 192 } 193 194 public MetaAnnotatedField[] getDeclaredFields() throws SecurityException { 195 return to(target.getDeclaredFields()); 196 } 197 198 public MetaAnnotatedMethod[] getDeclaredMethods() throws SecurityException { 199 return to(target.getDeclaredMethods()); 200 } 201 202 public MetaAnnotatedConstructor<?>[] getDeclaredConstructors() throws SecurityException { 203 return to(target.getDeclaredConstructors()); 204 } 205 206 public MetaAnnotatedField getDeclaredField(String name) throws NoSuchFieldException, SecurityException { 207 return to(target.getDeclaredField(name)); 208 } 209 210 public MetaAnnotatedMethod getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException { 211 return to(target.getDeclaredMethod(name, parameterTypes)); 212 } 213 214 public MetaAnnotatedConstructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException { 215 return new MetaAnnotatedConstructor(target.getDeclaredConstructor(parameterTypes)); 216 } 217 218 public InputStream getResourceAsStream(String name) { 219 return target.getResourceAsStream(name); 220 } 221 222 public URL getResource(String name) { 223 return target.getResource(name); 224 } 225 226 public ProtectionDomain getProtectionDomain() { 227 return target.getProtectionDomain(); 228 } 229 230 public boolean desiredAssertionStatus() { 231 return target.desiredAssertionStatus(); 232 } 233 234 public boolean isEnum() { 235 return target.isEnum(); 236 } 237 238 public T[] getEnumConstants() { 239 return target.getEnumConstants(); 240 } 241 242 public T cast(Object obj) { 243 return target.cast(obj); 244 } 245 246 public <U> Class<? extends U> asSubclass(Class<U> clazz) { 247 return target.asSubclass(clazz); 248 } 249 250 private MetaAnnotatedMethod[] to(Method[] a) { 251 MetaAnnotatedMethod[] b = new MetaAnnotatedMethod[a.length]; 252 for (int i = 0; i < a.length; i++) { 253 b[i] = new MetaAnnotatedMethod(a[i]); 254 } 255 return b; 256 } 257 258 private MetaAnnotatedMethod to(Method method) { 259 return new MetaAnnotatedMethod(method); 260 } 261 262 private MetaAnnotatedConstructor<?>[] to(Constructor<?>[] a) { 263 MetaAnnotatedConstructor<?>[] b = new MetaAnnotatedConstructor[a.length]; 264 for (int i = 0; i < a.length; i++) { 265 b[i] = new MetaAnnotatedConstructor(a[i]); 266 } 267 return b; 268 } 269 270 private MetaAnnotatedConstructor<?> to(Constructor<?> constructor) { 271 return new MetaAnnotatedConstructor(constructor); 272 } 273 274 private MetaAnnotatedClass<?>[] to(Class<?>[] a) { 275 MetaAnnotatedClass<?>[] b = new MetaAnnotatedClass[a.length]; 276 for (int i = 0; i < a.length; i++) { 277 b[i] = to(a[i]); 278 } 279 return b; 280 } 281 282 private MetaAnnotatedField[] to(Field[] a) { 283 MetaAnnotatedField[] b = new MetaAnnotatedField[a.length]; 284 for (int i = 0; i < a.length; i++) { 285 b[i] = new MetaAnnotatedField(a[i]); 286 } 287 return b; 288 } 289 290 private MetaAnnotatedField to(Field field) { 291 return new MetaAnnotatedField(field); 292 } 293 294}