01: package org.uispec4j.utils;
02:
03: public class UIComponentAnalyzer {
04: public static Class[] getSwingClasses(Class uiComponentClass) {
05: Class[] classes;
06: try {
07: classes = (Class[]) uiComponentClass.getDeclaredField(
08: "SWING_CLASSES").get(null);
09: if (classes == null) {
10: throw new RuntimeException(
11: "Field 'static Class[] SWING_CLASSES' in class "
12: + uiComponentClass
13: + " should be initialized");
14: }
15: } catch (NoSuchFieldException e) {
16: throw new RuntimeException(
17: "Class "
18: + uiComponentClass
19: + " should have a field 'static Class[] SWING_CLASSES'");
20: } catch (IllegalAccessException e) {
21: throw new RuntimeException("Invalid UIComponent class "
22: + uiComponentClass, e);
23: }
24: return classes;
25: }
26:
27: public static String getTypeName(Class uiComponentClass) {
28: String typeName = null;
29: try {
30: typeName = (String) uiComponentClass.getDeclaredField(
31: "TYPE_NAME").get(null);
32: } catch (IllegalAccessException e) {
33: throw new RuntimeException("Invalid UIComponent class "
34: + uiComponentClass, e);
35: } catch (NoSuchFieldException e) {
36: throw new RuntimeException("Invalid UIComponent class "
37: + uiComponentClass, e);
38: }
39: return typeName;
40: }
41: }
|