KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > walker > FieldData


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

5 package com.tc.object.walker;
6
7 import java.lang.reflect.Field JavaDoc;
8
9 class FieldData implements Comparable JavaDoc {
10
11   private final Field JavaDoc field;
12   private boolean isShadowed;
13
14   FieldData(Field JavaDoc field) {
15     this.field = field;
16     this.field.setAccessible(true);
17   }
18
19   boolean isShadowed() {
20     return isShadowed;
21   }
22
23   void setShadowed(boolean b) {
24     this.isShadowed = b;
25   }
26
27   Object JavaDoc getValue(Object JavaDoc instance) {
28     try {
29       return field.get(instance);
30     } catch (Exception JavaDoc e) {
31       throw new RuntimeException JavaDoc(e);
32     }
33   }
34
35   public int compareTo(Object JavaDoc o) {
36     if (o == null) { throw new NullPointerException JavaDoc(); }
37     if (!(o instanceof FieldData)) { throw new ClassCastException JavaDoc(o.getClass().getName()); }
38
39     FieldData other = (FieldData) o;
40
41     String JavaDoc thisFieldName = field.getName();
42     String JavaDoc otherFieldName = other.field.getName();
43
44     int i = thisFieldName.compareTo(otherFieldName);
45     if (i == 0) {
46       return field.getDeclaringClass().getName().compareTo(other.field.getDeclaringClass().getName());
47     } else {
48       return i;
49     }
50   }
51
52   Field JavaDoc getField() {
53     return field;
54   }
55 }
Popular Tags