KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > reflect > MetaDataInspector


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.reflect;
5
6 /**
7  * Inspects info.
8  *
9  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
10  */

11 public class MetaDataInspector {
12   /**
13    * Checks if a class has a certain field.
14    *
15    * @param classInfo
16    * @param fieldName
17    * @return
18    */

19   public static boolean hasField(final ClassInfo classInfo, final String JavaDoc fieldName) {
20     for (int i = 0; i < classInfo.getFields().length; i++) {
21       FieldInfo fieldMetaData = classInfo.getFields()[i];
22       if (fieldMetaData.getName().equals(fieldName)) {
23         return true;
24       }
25     }
26     return false;
27   }
28
29   /**
30    * Checks if a class implements a certain interface.
31    *
32    * @param classInfo
33    * @param interfaceName
34    * @return
35    */

36   public static boolean hasInterface(final ClassInfo classInfo, final String JavaDoc interfaceName) {
37     for (int i = 0; i < classInfo.getInterfaces().length; i++) {
38       ClassInfo interfaceMetaData = classInfo.getInterfaces()[i];
39       if (interfaceMetaData.getName().equals(interfaceName)) {
40         return true;
41       }
42     }
43     return false;
44   }
45 }
Popular Tags