1 28 29 package com.caucho.iiop; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import org.omg.CORBA.Any ; 35 import org.omg.CORBA.TCKind ; 36 import org.omg.CORBA.TypeCode ; 37 import org.omg.CORBA.TypeCodePackage.BadKind ; 38 import org.omg.CORBA.TypeCodePackage.Bounds ; 39 40 import java.io.IOException ; 41 import java.util.ArrayList ; 42 import java.util.logging.Logger ; 43 44 public class TypeCodeImpl extends TypeCode { 45 protected static final L10N L = new L10N(TypeCodeImpl.class); 46 protected static final Logger log = Log.open(TypeCodeImpl.class); 47 48 public static final TypeCode TK_NULL = new TypeCodeImpl(TCKind.tk_null); 49 50 public static final int TK_VOID = 1; 51 public static final int TK_SHORT = 2; 52 53 public static final TypeCode TK_LONG = new TypeCodeImpl(TCKind.tk_long); 54 55 public static final int TK_USHORT = 4; 56 public static final int TK_ULONG = 5; 57 public static final int TK_FLOAT = 6; 58 public static final int TK_DOUBLE = 7; 59 public static final int TK_BOOLEAN = 8; 60 public static final int TK_CHAR = 9; 61 62 public static final TypeCode TK_OCTET = new TypeCodeImpl(TCKind.tk_octet); 63 64 public static final int TK_ANY = 11; 65 public static final int TK_TYPE_CODE = 12; 66 public static final int TK_PRINCIPAL = 13; 67 public static final int TK_OBJREF = 14; 68 public static final int TK_UNION = 16; 69 public static final int TK_ENUM = 17; 70 public static final int TK_STRING = 18; 71 public static final int TK_SEQUENCE = 19; 72 public static final int TK_ARRAY = 20; 73 public static final int TK_ALIAS = 21; 74 public static final int TK_EXCEPT = 22; 75 public static final int TK_LONGLONG = 23; 76 public static final int TK_ULONGLONG = 24; 77 public static final int TK_LONGDOUBLE = 25; 78 public static final int TK_WCHAR = 26; 79 public static final int TK_WSTRING = 27; 80 public static final int TK_FIXED = 28; 81 public static final int TK_VALUE = 29; 82 public static final int TK_VALUE_BOX = 30; 83 public static final int TK_NATIVE = 31; 84 public static final int TK_ABSTRACT_INTERFACE = 32; 85 86 private TCKind _kind; 87 88 private String _id; 89 90 private short _typeModifier; 91 private TypeCode _concreteBaseType; 92 private ArrayList <Member> _members = new ArrayList <Member>(); 93 94 private TypeCode _contentType; 95 private int _length; 96 97 TypeCodeImpl(TCKind kind) 98 { 99 if (kind == null) 100 throw new NullPointerException (); 101 102 _kind = kind; 103 } 104 105 private TypeCodeImpl(TCKind kind, String repId, short modifier) 106 { 107 _kind = kind; 108 _id = repId; 109 _typeModifier = modifier; 110 } 111 112 private TypeCodeImpl(TCKind kind, String repId) 113 { 114 _kind = kind; 115 _id = repId; 116 } 117 118 static TypeCodeImpl createValue(String repId, String name, short modifier) 119 { 120 return new TypeCodeImpl(TCKind.tk_value, repId, modifier); 121 } 122 123 static TypeCodeImpl createValueBox(String repId, String name) 124 { 125 return new TypeCodeImpl(TCKind.tk_value_box, repId); 126 } 127 128 static TypeCodeImpl createAbstractInterface(String repId, String name) 129 { 130 return new TypeCodeImpl(TCKind.tk_abstract_interface, repId); 131 } 132 133 static TypeCodeImpl createSequence() 134 { 135 return new TypeCodeImpl(TCKind.tk_sequence); 136 } 137 138 141 public boolean equal(TypeCode tc) 142 { 143 return tc == this; 144 } 145 146 149 public boolean equivalent(TypeCode tc) 150 { 151 return tc == this; 152 } 153 154 157 public TypeCode get_compact_typecode() 158 { 159 return this; 160 } 161 162 165 public TCKind kind() 166 { 167 return _kind; 168 } 169 170 173 public String id() 174 throws BadKind 175 { 176 return _id; 177 } 178 179 182 public String name() 183 throws BadKind 184 { 185 return ""; 186 } 187 188 191 public short type_modifier() 192 throws BadKind 193 { 194 return _typeModifier; 195 } 196 197 200 void setConcreteBaseType(TypeCode baseType) 201 { 202 _concreteBaseType = baseType; 203 } 204 205 208 public TypeCode concrete_base_type() 209 throws BadKind 210 { 211 return _concreteBaseType; 212 } 213 214 215 218 public int member_count() 219 throws BadKind 220 { 221 return _members.size(); 222 } 223 224 void addMember(String name, TypeCode type, short visibility) 225 { 226 _members.add(new Member(name, type, visibility)); 227 } 228 229 232 public String member_name(int index) 233 throws BadKind , Bounds 234 { 235 return _members.get(index).getName(); 236 } 237 238 241 public TypeCode member_type(int index) 242 throws BadKind , Bounds 243 { 244 return _members.get(index).getType(); 245 } 246 247 250 public short member_visibility(int index) 251 throws BadKind , Bounds 252 { 253 throw new UnsupportedOperationException (); 254 } 255 256 259 public Any member_label(int index) 260 throws BadKind , Bounds 261 { 262 return null; 263 } 264 265 268 public TypeCode discriminator_type() 269 throws BadKind 270 { 271 throw new UnsupportedOperationException (); 272 } 273 274 277 public int default_index() 278 throws BadKind 279 { 280 throw new UnsupportedOperationException (); 281 } 282 283 void setLength(int length) 284 { 285 _length = length; 286 } 287 288 291 public int length() 292 throws BadKind 293 { 294 return _length; 295 } 296 297 300 void setContentType(TypeCode type) 301 { 302 _contentType = type; 303 } 304 305 308 public TypeCode content_type() 309 throws BadKind 310 { 311 return _contentType; 312 } 313 314 317 public short fixed_digits() 318 throws BadKind 319 { 320 throw new UnsupportedOperationException (); 321 } 322 323 326 public short fixed_scale() 327 throws BadKind 328 { 329 throw new UnsupportedOperationException (); 330 } 331 332 335 public static TypeCodeImpl read(IiopReader reader) 336 throws IOException 337 { 338 int tcKind = reader.readInt(); 339 340 switch (tcKind) { 342 case TK_VALUE_BOX: 343 { 344 int len = reader.read_sequence_length(); 345 int endian = reader.read_octet(); 346 347 String repId = reader.readString(); 348 String name = reader.readString(); 349 TypeCode typeCode = reader.read_TypeCode(); 350 351 return new ValueBoxTypeCode(TCKind.from_int(tcKind), typeCode); 352 } 353 354 case TK_ABSTRACT_INTERFACE: 355 { 356 int len = reader.read_sequence_length(); 357 358 int offset = reader.getOffset(); 359 int tail = offset + len; 360 361 int endian = reader.read_octet(); 362 363 String repId = reader.readString(); 364 String name = reader.readString(); 365 366 372 373 return new AbstractBaseTypeCode(TCKind.from_int(tcKind)); 374 } 375 376 case TK_STRING: 377 { 378 int maxLen = reader.read_ulong(); 379 log.info("string len: " + maxLen); 380 return new TypeCodeImpl(TCKind.from_int(tcKind)); 381 } 382 383 case 0xffffffff: 384 throw new UnsupportedOperationException ("INDIRECTION"); 385 386 default: 387 throw new UnsupportedOperationException (); 388 } 389 } 390 391 394 public Object readValue(IiopReader reader) 395 throws IOException 396 { 397 log.fine("READ: " + this); 398 399 switch (_kind.value()) { 400 case TCKind._tk_null: 401 case TCKind._tk_void: 402 return null; 403 404 case TCKind._tk_long: 405 return new Integer (reader.read_long()); 406 407 case TCKind._tk_ulong: 408 return new Integer (reader.read_ulong()); 409 410 case TCKind._tk_string: 411 return reader.read_string(); 412 413 case TCKind._tk_wstring: 414 return reader.read_wstring(); 415 416 case TK_ABSTRACT_INTERFACE: 417 return reader.read_abstract_interface(); 418 419 case TCKind._tk_value: 420 return reader.read_value(); 421 422 case TCKind._tk_value_box: 423 return reader.read_value(); 424 425 default: 426 throw new UnsupportedOperationException (String.valueOf(this)); 427 } 428 } 429 430 public String toString() 431 { 432 return "TypeCodeImpl[" + _kind.value() + "]"; 433 } 434 435 static class Member { 436 private String _name; 437 private TypeCode _type; 438 private short _visibility; 439 440 Member(String name, TypeCode type, short visibility) 441 { 442 _name = name; 443 _type = type; 444 _visibility = visibility; 445 } 446 447 String getName() 448 { 449 return _name; 450 } 451 452 TypeCode getType() 453 { 454 return _type; 455 } 456 457 short getVisibility() 458 { 459 return _visibility; 460 } 461 } 462 463 } 464 | Popular Tags |