1 package atg.adapter.gsa;
2
3 import java.lang.reflect.Field;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 /***
9 * This class uses reflection to allow access to private member variables
10 * withing a GSA Table class.
11 *
12 * @author adamb
13 */
14 public class AccessibleTableColumns {
15 public Logger mLogger = Logger.getLogger(this.getClass());
16 public TableColumns mTableColumns;
17
18 public AccessibleTableColumns(TableColumns pTable) {
19 mTableColumns = pTable;
20 }
21
22
23 /***
24 * Returns the mHead field of the Table class passed to the constructor of
25 * this class.
26 *
27 * @return
28 */
29 public ColumnDefinitionNode getHead() {
30 String fieldName = "mHead";
31 ColumnDefinitionNode node = (ColumnDefinitionNode) getPrivateField(fieldName);
32 return node;
33 }
34
35
36 /***
37 * Returns the mTail field of the Table class passed to the constructor of
38 * this class.
39 *
40 * @return
41 */
42 public ColumnDefinitionNode getTail() {
43 String fieldName = "mTail";
44 ColumnDefinitionNode node = (ColumnDefinitionNode) getPrivateField(fieldName);
45 return node;
46 }
47
48
49 /***
50 * Returns the mPrimaryKeys field of the Table class passed to the constructor of
51 * this class.
52 *
53 * @return
54 */
55 public List getPrimaryKeys() {
56 String fieldName = "mPrimaryKeys";
57 List node = (List) getPrivateField(fieldName);
58 return node;
59 }
60
61
62 /***
63 * Returns the mForeignKeys field of the Table class passed to the constructor of
64 * this class.
65 *
66 * @return
67 */
68 public List getForeignKeys() {
69 String fieldName = "mForeignKeys";
70 List node = (List) getPrivateField(fieldName);
71 return node;
72 }
73
74
75 /***
76 * Returns the mMultiColumnName field of the Table class passed to the
77 * constructor of this class.
78 *
79 * @return
80 */
81 public String getMultiColumnName() {
82 String fieldName = "mMultiColumnName";
83 String node = (String) getPrivateField(fieldName);
84 return node;
85 }
86
87
88 public Object getPrivateField(String fieldName) {
89 Field columnDefinitionNode = null;
90 Object field = null;
91 try {
92 columnDefinitionNode = mTableColumns.getClass().getDeclaredField(
93 fieldName);
94 columnDefinitionNode.setAccessible(true);
95 field = columnDefinitionNode.get(mTableColumns);
96 } catch (SecurityException e) {
97 mLogger.error(e);
98 } catch (NoSuchFieldException e) {
99 mLogger.error(e);
100 } catch (IllegalArgumentException e) {
101 mLogger.error(e);
102 } catch (IllegalAccessException e) {
103 mLogger.error(e);
104 }
105 return field;
106 }
107
108 }