KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > managedobject > bytecode > FieldType


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

4 package com.tc.objectserver.managedobject.bytecode;
5
6 import com.tc.object.LiteralValues;
7
8 public class FieldType {
9
10   public static final LiteralValues literalValues = new LiteralValues();
11
12   private final String JavaDoc localFieldName;
13   private final String JavaDoc fullName;
14   private final int type;
15   private final boolean isReference;
16
17   public FieldType(String JavaDoc name, String JavaDoc fullName, int type, boolean isReference) {
18     this.localFieldName = name;
19     this.fullName = fullName;
20     this.type = type;
21     this.isReference = isReference;
22   }
23
24   public static FieldType create(String JavaDoc fullyQualifiedName, Object JavaDoc value, boolean isReference, int id) {
25     String JavaDoc localName = getLocalFieldName(fullyQualifiedName , id);
26     if(value == null) {
27       return new FieldType(localName, fullyQualifiedName, LiteralValues.OBJECT, isReference);
28     }
29     return new FieldType(localName, fullyQualifiedName, literalValues.valueFor(value), isReference);
30   }
31
32   // TODO:: field Names are currently fully qualified unnecessarily.
33
public static String JavaDoc getLocalFieldName(String JavaDoc fullyQualifiedName, int id) {
34     int lastIdx = fullyQualifiedName.lastIndexOf('.');
35     if(lastIdx < 0 ) {
36       return fullyQualifiedName + "_" + id;
37     } else if(lastIdx < fullyQualifiedName.length() - 1) {
38       return fullyQualifiedName.substring(lastIdx + 1) + "_" + id;
39     } else {
40       throw new AssertionError JavaDoc("Field Name " + fullyQualifiedName + " is not a valid Field Name !");
41     }
42
43   }
44
45   public String JavaDoc getLocalFieldName() {
46     return localFieldName;
47   }
48
49   public String JavaDoc getQualifiedName() {
50     return fullName;
51   }
52
53   public int getType() {
54     if(isReference) return LiteralValues.OBJECT_ID;
55     return type;
56   }
57
58 }
59
Popular Tags