001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005:
006: package com.tc.object.walker;
007:
008: import java.lang.reflect.Field;
009:
010: public class MemberValue {
011:
012: private final Object value;
013: private int id = -1;
014: private boolean isRepeated = false;
015: private boolean isMapKey = false;
016: private boolean isMapValue = false;
017: private boolean isShadowed = false;
018: private boolean isElement = false;
019: private int index;
020: private FieldData fd;
021:
022: static MemberValue fieldValue(FieldData fd, Object instance) {
023: MemberValue rv = new MemberValue(fd.getValue(instance));
024: rv.fd = fd;
025: rv.isShadowed = fd.isShadowed();
026: return rv;
027: }
028:
029: static MemberValue rootValue(Object root) {
030: return new MemberValue(root);
031: }
032:
033: static MemberValue mapKey(Object o) {
034: MemberValue rv = new MemberValue(o);
035: rv.isMapKey = true;
036: return rv;
037: }
038:
039: static MemberValue mapValue(Object o) {
040: MemberValue rv = new MemberValue(o);
041: rv.isMapValue = true;
042: return rv;
043: }
044:
045: static MemberValue elementValue(int index, Object val) {
046: MemberValue rv = new MemberValue(val);
047: rv.index = index;
048: rv.isElement = true;
049: return rv;
050: }
051:
052: protected MemberValue(Object value) {
053: this .value = value;
054: }
055:
056: public int getIndex() {
057: return index;
058: }
059:
060: public Field getSourceField() {
061: if (fd == null) {
062: return null;
063: }
064: return fd.getField();
065: }
066:
067: public Object getValueObject() {
068: return this .value;
069: }
070:
071: public boolean isElement() {
072: return isElement;
073: }
074:
075: public boolean isRepeated() {
076: return isRepeated;
077: }
078:
079: public boolean isShadowed() {
080: return isShadowed;
081: }
082:
083: public boolean isMapKey() {
084: return isMapKey;
085: }
086:
087: public boolean isMapValue() {
088: return isMapValue;
089: }
090:
091: public int getId() {
092: //if (id < 0) throw new AssertionError("id: " + id);
093: return id;
094: }
095:
096: void setId(int newId) {
097: if (newId < 0)
098: throw new AssertionError("id: " + newId);
099: this .id = newId;
100: }
101:
102: void setRepeated(boolean b) {
103: this.isRepeated = b;
104: }
105:
106: }
|