1 7 8 16 17 package com.sun.corba.se.impl.io; 18 19 import java.lang.reflect.Field ; 20 import java.lang.Comparable ; 21 import java.util.Hashtable ; 22 23 import sun.corba.Bridge ; 24 import java.security.AccessController ; 25 import java.security.PrivilegedAction ; 26 27 33 public class ObjectStreamField implements Comparable 34 { 35 private static final Bridge bridge = 36 (Bridge)AccessController.doPrivileged( 37 new PrivilegedAction () { 38 public Object run() { 39 return Bridge.get() ; 40 } 41 } 42 ) ; 43 44 47 ObjectStreamField(String n, Class clazz) { 48 name = n; 49 this.clazz = clazz; 50 51 if (clazz.isPrimitive()) { 53 if (clazz == Integer.TYPE) { 54 type = 'I'; 55 } else if (clazz == Byte.TYPE) { 56 type = 'B'; 57 } else if (clazz == Long.TYPE) { 58 type = 'J'; 59 } else if (clazz == Float.TYPE) { 60 type = 'F'; 61 } else if (clazz == Double.TYPE) { 62 type = 'D'; 63 } else if (clazz == Short.TYPE) { 64 type = 'S'; 65 } else if (clazz == Character.TYPE) { 66 type = 'C'; 67 } else if (clazz == Boolean.TYPE) { 68 type = 'Z'; 69 } 70 } else if (clazz.isArray()) { 71 type = '['; 72 typeString = ObjectStreamClass.getSignature(clazz); 73 } else { 74 type = 'L'; 75 typeString = ObjectStreamClass.getSignature(clazz); 76 } 77 78 if (typeString != null) 79 signature = typeString; 80 else 81 signature = String.valueOf(type); 82 83 } 84 85 ObjectStreamField(Field field) { 86 this(field.getName(), field.getType()); 87 setField( field ) ; 88 } 89 90 93 ObjectStreamField(String n, char t, Field f, String ts) 94 { 95 name = n; 96 type = t; 97 setField( f ) ; 98 typeString = ts; 99 100 if (typeString != null) 101 signature = typeString; 102 else 103 signature = String.valueOf(type); 104 105 } 106 107 110 public String getName() { 111 return name; 112 } 113 114 117 public Class getType() { 118 if (clazz != null) 119 return clazz; 120 switch (type) { 121 case 'B': clazz = Byte.TYPE; 122 break; 123 case 'C': clazz = Character.TYPE; 124 break; 125 case 'S': clazz = Short.TYPE; 126 break; 127 case 'I': clazz = Integer.TYPE; 128 break; 129 case 'J': clazz = Long.TYPE; 130 break; 131 case 'F': clazz = Float.TYPE; 132 break; 133 case 'D': clazz = Double.TYPE; 134 break; 135 case 'Z': clazz = Boolean.TYPE; 136 break; 137 case '[': 138 case 'L': 139 clazz = Object .class; 140 break; 141 } 142 143 return clazz; 144 } 145 146 public char getTypeCode() { 147 return type; 148 } 149 150 public String getTypeString() { 151 return typeString; 152 } 153 154 Field getField() { 155 return field; 156 } 157 158 void setField(Field field) { 159 this.field = field; 160 this.fieldID = bridge.objectFieldOffset( field ) ; 161 } 162 163 167 ObjectStreamField() { 168 } 169 170 173 public boolean isPrimitive() { 174 return (type != '[' && type != 'L'); 175 } 176 177 183 public int compareTo(Object o) { 184 ObjectStreamField f2 = (ObjectStreamField)o; 185 boolean thisprim = (this.typeString == null); 186 boolean otherprim = (f2.typeString == null); 187 188 if (thisprim != otherprim) { 189 return (thisprim ? -1 : 1); 190 } 191 return this.name.compareTo(f2.name); 192 } 193 194 199 public boolean typeEquals(ObjectStreamField other) { 200 if (other == null || type != other.type) 201 return false; 202 203 204 if (typeString == null && other.typeString == null) 205 return true; 206 207 return ObjectStreamClass.compareClassNames(typeString, 208 other.typeString, 209 '/'); 210 } 211 212 215 public String getSignature() { 216 217 return signature; 218 219 } 220 221 224 public String toString() { 225 if (typeString != null) 226 return typeString + " " + name; 227 else 228 return type + " " + name; 229 } 230 231 public Class getClazz() { 232 return clazz; 233 } 234 235 238 public long getFieldID() { 239 return fieldID ; 240 } 241 242 private String name; private char type; private Field field; private String typeString; private Class clazz; 248 253 private String signature; private long fieldID = Bridge.INVALID_FIELD_OFFSET ; 255 } 256 | Popular Tags |