KickJava   Java API By Example, From Geeks To Geeks.

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


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
6 package com.tc.object.walker;
7
8 import java.lang.reflect.Field JavaDoc;
9
10 public class MemberValue {
11
12   private final Object JavaDoc value;
13   private int id = -1;
14   private boolean isRepeated = false;
15   private boolean isMapKey = false;
16   private boolean isMapValue = false;
17   private boolean isShadowed = false;
18   private boolean isElement = false;
19   private int index;
20   private FieldData fd;
21
22   static MemberValue fieldValue(FieldData fd, Object JavaDoc instance) {
23     MemberValue rv = new MemberValue(fd.getValue(instance));
24     rv.fd = fd;
25     rv.isShadowed = fd.isShadowed();
26     return rv;
27   }
28
29   static MemberValue rootValue(Object JavaDoc root) {
30     return new MemberValue(root);
31   }
32
33   static MemberValue mapKey(Object JavaDoc o) {
34     MemberValue rv = new MemberValue(o);
35     rv.isMapKey = true;
36     return rv;
37   }
38
39   static MemberValue mapValue(Object JavaDoc o) {
40     MemberValue rv = new MemberValue(o);
41     rv.isMapValue = true;
42     return rv;
43   }
44
45   static MemberValue elementValue(int index, Object JavaDoc val) {
46     MemberValue rv = new MemberValue(val);
47     rv.index = index;
48     rv.isElement = true;
49     return rv;
50   }
51
52   protected MemberValue(Object JavaDoc value) {
53     this.value = value;
54   }
55
56   public int getIndex() {
57     return index;
58   }
59
60   public Field JavaDoc getSourceField() {
61     if (fd == null) { return null; }
62     return fd.getField();
63   }
64
65   public Object JavaDoc getValueObject() {
66     return this.value;
67   }
68
69   public boolean isElement() {
70     return isElement;
71   }
72
73   public boolean isRepeated() {
74     return isRepeated;
75   }
76
77   public boolean isShadowed() {
78     return isShadowed;
79   }
80
81   public boolean isMapKey() {
82     return isMapKey;
83   }
84
85   public boolean isMapValue() {
86     return isMapValue;
87   }
88
89   public int getId() {
90     if (id < 0) throw new AssertionError JavaDoc("id: " + id);
91     return id;
92   }
93
94   void setId(int newId) {
95     if (newId < 0) throw new AssertionError JavaDoc("id: " + newId);
96     this.id = newId;
97   }
98
99   void setRepeated(boolean b) {
100     this.isRepeated = b;
101   }
102
103 }
104
Popular Tags