1 7 8 16 17 package com.sun.corba.se.impl.orbutil; 18 19 import java.lang.reflect.Field ; 20 import java.lang.Comparable ; 21 import java.util.Hashtable ; 22 23 28 34 class ObjectStreamField implements Comparable { 35 38 ObjectStreamField(String n, Class clazz) { 39 name = n; 40 this.clazz = clazz; 41 42 if (clazz.isPrimitive()) { 44 if (clazz == Integer.TYPE) { 45 type = 'I'; 46 } else if (clazz == Byte.TYPE) { 47 type = 'B'; 48 } else if (clazz == Long.TYPE) { 49 type = 'J'; 50 } else if (clazz == Float.TYPE) { 51 type = 'F'; 52 } else if (clazz == Double.TYPE) { 53 type = 'D'; 54 } else if (clazz == Short.TYPE) { 55 type = 'S'; 56 } else if (clazz == Character.TYPE) { 57 type = 'C'; 58 } else if (clazz == Boolean.TYPE) { 59 type = 'Z'; 60 } 61 } else if (clazz.isArray()) { 62 type = '['; 63 typeString = ObjectStreamClass_1_3_1.getSignature(clazz); 64 } else { 65 type = 'L'; 66 typeString = ObjectStreamClass_1_3_1.getSignature(clazz); 67 } 68 69 if (typeString != null) 70 signature = typeString; 71 else 72 signature = String.valueOf(type); 73 74 } 75 76 ObjectStreamField(Field field) { 77 this(field.getName(), field.getType()); 78 this.field = field; 79 } 80 81 84 ObjectStreamField(String n, char t, Field f, String ts) 85 { 86 name = n; 87 type = t; 88 field = f; 89 typeString = ts; 90 91 if (typeString != null) 92 signature = typeString; 93 else 94 signature = String.valueOf(type); 95 96 } 97 98 101 public String getName() { 102 return name; 103 } 104 105 108 public Class getType() { 109 if (clazz != null) 110 return clazz; 111 switch (type) { 112 case 'B': clazz = Byte.TYPE; 113 break; 114 case 'C': clazz = Character.TYPE; 115 break; 116 case 'S': clazz = Short.TYPE; 117 break; 118 case 'I': clazz = Integer.TYPE; 119 break; 120 case 'J': clazz = Long.TYPE; 121 break; 122 case 'F': clazz = Float.TYPE; 123 break; 124 case 'D': clazz = Double.TYPE; 125 break; 126 case 'Z': clazz = Boolean.TYPE; 127 break; 128 case '[': 129 case 'L': 130 clazz = Object .class; 131 break; 132 } 133 134 return clazz; 135 } 136 137 public char getTypeCode() { 138 return type; 139 } 140 141 public String getTypeString() { 142 return typeString; 143 } 144 145 Field getField() { 146 return field; 147 } 148 149 void setField(Field field) { 150 this.field = field; 151 this.fieldID = -1; 152 } 153 154 158 ObjectStreamField() { 159 } 160 161 164 public boolean isPrimitive() { 165 return (type != '[' && type != 'L'); 166 } 167 168 174 public int compareTo(Object o) { 175 ObjectStreamField f2 = (ObjectStreamField)o; 176 boolean thisprim = (this.typeString == null); 177 boolean otherprim = (f2.typeString == null); 178 179 if (thisprim != otherprim) { 180 return (thisprim ? -1 : 1); 181 } 182 return this.name.compareTo(f2.name); 183 } 184 185 190 public boolean typeEquals(ObjectStreamField other) { 191 if (other == null || type != other.type) 192 return false; 193 194 195 if (typeString == null && other.typeString == null) 196 return true; 197 198 return ObjectStreamClass_1_3_1.compareClassNames(typeString, 199 other.typeString, 200 '/'); 201 } 202 203 206 public String getSignature() { 207 208 return signature; 209 210 } 211 212 215 public String toString() { 216 if (typeString != null) 217 return typeString + " " + name; 218 else 219 return type + " " + name; 220 } 221 222 public Class getClazz() { 223 return clazz; 224 } 225 226 239 240 private String name; private char type; private Field field; private String typeString; private Class clazz; 246 251 private String signature; private long fieldID = -1; 253 } 255 | Popular Tags |