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 */
017 package org.apache.xbean.finder;
018
019 import java.io.InputStream;
020 import java.lang.annotation.Annotation;
021 import java.lang.reflect.Constructor;
022 import java.lang.reflect.Field;
023 import java.lang.reflect.Method;
024 import java.lang.reflect.Type;
025 import java.lang.reflect.TypeVariable;
026 import java.net.URL;
027 import java.security.ProtectionDomain;
028
029 /**
030 * @version $Rev$ $Date$
031 */
032 public class MetaAnnotatedClass<T> extends MetaAnnotatedObject<Class<T>> {
033
034 public MetaAnnotatedClass(Class<T> clazz) {
035 super(clazz, unroll(clazz, clazz));
036 }
037
038 @Override
039 public Annotation[] getDeclaredAnnotations() {
040 return target.getDeclaredAnnotations();
041 }
042
043 public MetaAnnotatedClass<?> forName(String className) throws ClassNotFoundException {
044 return to(target.forName(className));
045 }
046
047 private MetaAnnotatedClass<?> to(Class<?> clazz) {
048 return new MetaAnnotatedClass(clazz);
049 }
050
051 public MetaAnnotatedClass<?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException {
052 return to(target.forName(name, initialize, loader));
053 }
054
055 public T newInstance() throws InstantiationException, IllegalAccessException {
056 return target.newInstance();
057 }
058
059 public boolean isInstance(Object obj) {
060 return target.isInstance(obj);
061 }
062
063 public boolean isAssignableFrom(Class<?> cls) {
064 return target.isAssignableFrom(cls);
065 }
066
067 public boolean isInterface() {
068 return target.isInterface();
069 }
070
071 public boolean isArray() {
072 return target.isArray();
073 }
074
075 public boolean isPrimitive() {
076 return target.isPrimitive();
077 }
078
079 public boolean isAnnotation() {
080 return target.isAnnotation();
081 }
082
083 public boolean isSynthetic() {
084 return target.isSynthetic();
085 }
086
087 public String getName() {
088 return target.getName();
089 }
090
091 public ClassLoader getClassLoader() {
092 return target.getClassLoader();
093 }
094
095 public TypeVariable<Class<T>>[] getTypeParameters() {
096 return target.getTypeParameters();
097 }
098
099 public MetaAnnotatedClass<? super T> getSuperclass() {
100 return new MetaAnnotatedClass(target.getSuperclass());
101 }
102
103 public Type getGenericSuperclass() {
104 return target.getGenericSuperclass();
105 }
106
107 public Package getPackage() {
108 return target.getPackage();
109 }
110
111 public MetaAnnotatedClass<?>[] getInterfaces() {
112 return to(target.getInterfaces());
113 }
114
115 public Type[] getGenericInterfaces() {
116 return target.getGenericInterfaces();
117 }
118
119 public MetaAnnotatedClass<?> getComponentType() {
120 return to(target.getComponentType());
121 }
122
123 public int getModifiers() {
124 return target.getModifiers();
125 }
126
127 public Object[] getSigners() {
128 return target.getSigners();
129 }
130
131 public MetaAnnotatedMethod getEnclosingMethod() {
132 return to(target.getEnclosingMethod());
133 }
134
135 public MetaAnnotatedConstructor<?> getEnclosingConstructor() {
136 return to(target.getEnclosingConstructor());
137 }
138
139 public MetaAnnotatedClass<?> getDeclaringClass() {
140 return to(target.getDeclaringClass());
141 }
142
143 public MetaAnnotatedClass<?> getEnclosingClass() {
144 return to(target.getEnclosingClass());
145 }
146
147 public String getSimpleName() {
148 return target.getSimpleName();
149 }
150
151 public String getCanonicalName() {
152 return target.getCanonicalName();
153 }
154
155 public boolean isAnonymousClass() {
156 return target.isAnonymousClass();
157 }
158
159 public boolean isLocalClass() {
160 return target.isLocalClass();
161 }
162
163 public boolean isMemberClass() {
164 return target.isMemberClass();
165 }
166
167 public MetaAnnotatedClass<?>[] getClasses() {
168 return to(target.getClasses());
169 }
170
171 public MetaAnnotatedField[] getFields() throws SecurityException {
172 return to(target.getFields());
173 }
174
175 public MetaAnnotatedMethod[] getMethods() throws SecurityException {
176 return to(target.getMethods());
177 }
178
179 public MetaAnnotatedConstructor<?>[] getConstructors() throws SecurityException {
180 return to(target.getConstructors());
181 }
182
183 public MetaAnnotatedField getField(String name) throws NoSuchFieldException, SecurityException {
184 return to(target.getField(name));
185 }
186
187 public MetaAnnotatedMethod getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
188 return to(target.getMethod(name, parameterTypes));
189 }
190
191 public MetaAnnotatedConstructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
192 return new MetaAnnotatedConstructor(target.getConstructor(parameterTypes));
193 }
194
195 public MetaAnnotatedClass<?>[] getDeclaredClasses() throws SecurityException {
196 return to(target.getDeclaredClasses());
197 }
198
199 public MetaAnnotatedField[] getDeclaredFields() throws SecurityException {
200 return to(target.getDeclaredFields());
201 }
202
203 public MetaAnnotatedMethod[] getDeclaredMethods() throws SecurityException {
204 return to(target.getDeclaredMethods());
205 }
206
207 public MetaAnnotatedConstructor<?>[] getDeclaredConstructors() throws SecurityException {
208 return to(target.getDeclaredConstructors());
209 }
210
211 public MetaAnnotatedField getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
212 return to(target.getDeclaredField(name));
213 }
214
215 public MetaAnnotatedMethod getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
216 return to(target.getDeclaredMethod(name, parameterTypes));
217 }
218
219 public MetaAnnotatedConstructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
220 return new MetaAnnotatedConstructor(target.getDeclaredConstructor(parameterTypes));
221 }
222
223 public InputStream getResourceAsStream(String name) {
224 return target.getResourceAsStream(name);
225 }
226
227 public URL getResource(String name) {
228 return target.getResource(name);
229 }
230
231 public ProtectionDomain getProtectionDomain() {
232 return target.getProtectionDomain();
233 }
234
235 public boolean desiredAssertionStatus() {
236 return target.desiredAssertionStatus();
237 }
238
239 public boolean isEnum() {
240 return target.isEnum();
241 }
242
243 public T[] getEnumConstants() {
244 return target.getEnumConstants();
245 }
246
247 public T cast(Object obj) {
248 return target.cast(obj);
249 }
250
251 public <U> Class<? extends U> asSubclass(Class<U> clazz) {
252 return target.asSubclass(clazz);
253 }
254
255 private MetaAnnotatedMethod[] to(Method[] a) {
256 MetaAnnotatedMethod[] b = new MetaAnnotatedMethod[a.length];
257 for (int i = 0; i < a.length; i++) {
258 b[i] = new MetaAnnotatedMethod(a[i]);
259 }
260 return b;
261 }
262
263 private MetaAnnotatedMethod to(Method method) {
264 return new MetaAnnotatedMethod(method);
265 }
266
267 private MetaAnnotatedConstructor<?>[] to(Constructor<?>[] a) {
268 MetaAnnotatedConstructor<?>[] b = new MetaAnnotatedConstructor[a.length];
269 for (int i = 0; i < a.length; i++) {
270 b[i] = new MetaAnnotatedConstructor(a[i]);
271 }
272 return b;
273 }
274
275 private MetaAnnotatedConstructor<?> to(Constructor<?> constructor) {
276 return new MetaAnnotatedConstructor(constructor);
277 }
278
279 private MetaAnnotatedClass<?>[] to(Class<?>[] a) {
280 MetaAnnotatedClass<?>[] b = new MetaAnnotatedClass[a.length];
281 for (int i = 0; i < a.length; i++) {
282 b[i] = to(a[i]);
283 }
284 return b;
285 }
286
287 private MetaAnnotatedField[] to(Field[] a) {
288 MetaAnnotatedField[] b = new MetaAnnotatedField[a.length];
289 for (int i = 0; i < a.length; i++) {
290 b[i] = new MetaAnnotatedField(a[i]);
291 }
292 return b;
293 }
294
295 private MetaAnnotatedField to(Field field) {
296 return new MetaAnnotatedField(field);
297 }
298
299 }