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.objectserver.managedobject.bytecode;
06:
07: import com.tc.object.LiteralValues;
08:
09: public class FieldType {
10:
11: public static final LiteralValues literalValues = (LiteralValues) new LiteralValues();
12:
13: private final String localFieldName;
14: private final String fullName;
15: private final int type;
16: private final boolean isReference;
17:
18: public FieldType(String name, String fullName, int type,
19: boolean isReference) {
20: this .localFieldName = name;
21: this .fullName = fullName;
22: this .type = type;
23: this .isReference = isReference;
24: }
25:
26: public static FieldType create(String fullyQualifiedName,
27: Object value, boolean isReference, int id) {
28: String localName = getLocalFieldName(fullyQualifiedName, id);
29: if (value == null) {
30: return new FieldType(localName, fullyQualifiedName,
31: LiteralValues.OBJECT, isReference);
32: }
33: return new FieldType(localName, fullyQualifiedName,
34: literalValues.valueFor(value), isReference);
35: }
36:
37: // TODO:: field Names are currently fully qualified unnecessarily.
38: public static String getLocalFieldName(String fullyQualifiedName,
39: int id) {
40: int lastIdx = fullyQualifiedName.lastIndexOf('.');
41: if (lastIdx < 0) {
42: return fullyQualifiedName + "_" + id;
43: } else if (lastIdx < fullyQualifiedName.length() - 1) {
44: return fullyQualifiedName.substring(lastIdx + 1) + "_" + id;
45: } else {
46: throw new AssertionError("Field Name " + fullyQualifiedName
47: + " is not a valid Field Name !");
48: }
49:
50: }
51:
52: public String getLocalFieldName() {
53: return localFieldName;
54: }
55:
56: public String getQualifiedName() {
57: return fullName;
58: }
59:
60: public int getType() {
61: if (isReference)
62: return LiteralValues.OBJECT_ID;
63: return type;
64: }
65:
66: public boolean canBeReferenced() {
67: return isReference;
68: }
69:
70: public String toString() {
71: return "FieldType [ localFieldName = " + this .localFieldName
72: + ", fullName = " + this .fullName + ", type = "
73: + this .type + ", isReference = " + this .isReference
74: + "]";
75: }
76:
77: }
|