01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.field;
06:
07: import com.tc.object.LiteralValues;
08: import com.tc.object.TCClass;
09: import com.tc.util.Assert;
10:
11: import java.lang.reflect.Field;
12: import java.lang.reflect.Modifier;
13:
14: /**
15: * @author orion
16: */
17: public class GenericTCField implements TCField {
18:
19: private static final LiteralValues literalValues = new LiteralValues();
20:
21: private final TCClass tcClass;
22: private final boolean isPortable;
23: private final String fieldName;
24: private final boolean isFinal;
25: private final boolean isArray;
26: private final boolean canBeReference;
27:
28: protected GenericTCField(TCClass tcClass, Field field,
29: boolean portable) {
30: Assert.eval(tcClass != null);
31: Assert.eval(field != null);
32: this .tcClass = tcClass;
33: this .fieldName = (tcClass.getName() + "." + field.getName())
34: .intern();
35:
36: // special case for synthetic parent field
37: portable = portable
38: || fieldName.equals(tcClass.getParentFieldName());
39: this .isPortable = portable
40: && !field.getType().getName().startsWith("com.tc.");
41:
42: this .isFinal = Modifier.isFinal(field.getModifiers());
43: this .isArray = field.getType().isArray();
44: this .canBeReference = isReferenceField(field);
45: }
46:
47: private static boolean isReferenceField(Field field) {
48: if (Modifier.isStatic(field.getModifiers()))
49: return false;
50: Class type = field.getType();
51:
52: if (literalValues.isLiteral(type.getName())) {
53: return !type.isPrimitive();
54: }
55:
56: return true;
57: }
58:
59: public TCClass getDeclaringTCClass() {
60: return tcClass;
61: }
62:
63: public boolean isFinal() {
64: return isFinal;
65: }
66:
67: public boolean isPortable() {
68: return isPortable;
69: }
70:
71: public boolean isArray() {
72: return this .isArray;
73: }
74:
75: public String getName() {
76: return fieldName;
77: }
78:
79: public boolean canBeReference() {
80: return this .canBeReference;
81: }
82:
83: public String toString() {
84: return getClass().getName() + "(" + getName() + ")";
85: }
86: }
|