KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > field > GenericTCField


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

5 package com.tc.object.field;
6
7 import com.tc.object.LiteralValues;
8 import com.tc.object.TCClass;
9 import com.tc.util.Assert;
10
11 import java.lang.reflect.Field JavaDoc;
12 import java.lang.reflect.Modifier JavaDoc;
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 JavaDoc fieldName;
24   private final boolean isFinal;
25   private final boolean isArray;
26   private final boolean canBeReference;
27
28   protected GenericTCField(TCClass tcClass, Field JavaDoc field, boolean portable) {
29     Assert.eval(tcClass != null);
30     Assert.eval(field != null);
31     this.tcClass = tcClass;
32     this.fieldName = (tcClass.getName() + "." + field.getName()).intern();
33
34     // special case for synthetic parent field
35
portable = portable || fieldName.equals(tcClass.getParentFieldName());
36     this.isPortable = portable && !field.getType().getName().startsWith("com.tc.");
37
38     this.isFinal = Modifier.isFinal(field.getModifiers());
39     this.isArray = field.getType().isArray();
40     this.canBeReference = isReferenceField(field);
41   }
42
43   private static boolean isReferenceField(Field JavaDoc field) {
44     if (Modifier.isStatic(field.getModifiers())) return false;
45     Class JavaDoc type = field.getType();
46
47     if (literalValues.isLiteral(type.getName())) {
48       return !type.isPrimitive();
49     }
50
51     return true;
52   }
53
54   public TCClass getDeclaringTCClass() {
55     return tcClass;
56   }
57
58   public boolean isFinal() {
59     return isFinal;
60   }
61
62   public boolean isPortable() {
63     return isPortable;
64   }
65
66   public boolean isArray() {
67     return this.isArray;
68   }
69
70   public String JavaDoc getName() {
71     return fieldName;
72   }
73
74   public boolean canBeReference() {
75     return this.canBeReference;
76   }
77
78   public String JavaDoc toString() {
79     return getClass().getName() + "(" + getName() + ")";
80   }
81 }
82
Popular Tags