1 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 localFieldName; 13 private final String fullName; 14 private final int type; 15 private final boolean isReference; 16 17 public FieldType(String name, String 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 fullyQualifiedName, Object value, boolean isReference, int id) { 25 String 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 public static String getLocalFieldName(String 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 ("Field Name " + fullyQualifiedName + " is not a valid Field Name !"); 41 } 42 43 } 44 45 public String getLocalFieldName() { 46 return localFieldName; 47 } 48 49 public String 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 |