1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import org.omg.CORBA.TCKind ; 21 22 25 public class Any 26 extends org.omg.CORBA.Any 27 { 28 private org.omg.CORBA.TypeCode _type; 29 30 private byte[] _data; 31 32 36 private void extract_type(TCKind tk, String what) 37 { 38 if (_type.kind().value() != tk.value()) 39 { 40 throw new org.omg.CORBA.BAD_TYPECODE ("org.apache.geronimo.interop.rmi.iiop.Any.extract_" 41 + what + ": type = " + _type); 42 } 43 } 44 45 48 public Any() 49 { 50 _type = TypeCode.NULL; 51 } 52 53 57 public boolean equal(org.omg.CORBA.Any a) 58 { 59 if (!_type.equal(a.type())) 60 { 61 return false; 62 } 63 if (a instanceof org.apache.geronimo.interop.rmi.iiop.Any) 64 { 65 org.apache.geronimo.interop.rmi.iiop.Any _that = (org.apache.geronimo.interop.rmi.iiop.Any) a; 66 String x = org.apache.geronimo.interop.util.Base16Binary.toString(this._data); 67 String y = org.apache.geronimo.interop.util.Base16Binary.toString(_that._data); 68 return x.equals(y); 69 } 70 else 71 { 72 throw new org.omg.CORBA.NO_IMPLEMENT ("org.apache.geronimo.interop.rmi.iiop.Any.equal(" 74 + a.getClass().getName() + ")"); 75 } 76 } 77 78 81 public org.omg.CORBA.TypeCode type() 82 { 83 return _type; 84 } 85 86 89 public void type(org.omg.CORBA.TypeCode type) 90 { 91 _type = type; 92 } 93 94 98 public void read_value(org.omg.CORBA.portable.InputStream input, 99 org.omg.CORBA.TypeCode type) 100 { 101 byte[] buffer = ((CdrInputStream) input)._buffer; 102 int length = ((CdrInputStream) input)._length; 103 _type = type; 104 _data = new byte[length]; 105 System.arraycopy(buffer, 0, _data, 0, length); 106 } 107 108 111 public void write_value(org.omg.CORBA.portable.OutputStream output) 112 { 113 } 115 116 119 public org.omg.CORBA.portable.OutputStream create_output_stream() 120 { 121 _data = null; 122 return CdrOutputStream.getInstance(); 123 } 124 125 128 public org.omg.CORBA.portable.InputStream create_input_stream() 129 { 130 if (_data == null) 131 { 132 throw new org.omg.CORBA.BAD_OPERATION ( 133 "org.apache.geronimo.interop.rmi.Any.create_input_stream"); 134 } 135 return CdrInputStream.getInstance(); 136 } 137 138 141 public short extract_short() 142 { 143 extract_type(TCKind.tk_short, "short"); 144 return create_input_stream().read_short(); 145 } 146 147 150 public void insert_short(short value) 151 { 152 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 153 output.write_short(value); 154 read_value(null, TypeCode.SHORT); 155 } 156 157 160 public int extract_long() 161 { 162 extract_type(TCKind.tk_long, "long"); 163 return create_input_stream().read_long(); 164 } 165 166 169 public void insert_long(int value) 170 { 171 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 172 output.write_long(value); 173 read_value(null, TypeCode.LONG); 174 } 175 176 179 public long extract_longlong() 180 { 181 extract_type(TCKind.tk_longlong, "longlong"); 182 return create_input_stream().read_longlong(); 183 } 184 185 188 public void insert_longlong(long value) 189 { 190 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 191 output.write_longlong(value); 192 read_value(null, TypeCode.LONGLONG); 193 } 194 195 198 public short extract_ushort() 199 { 200 extract_type(TCKind.tk_ushort, "ushort"); 201 return create_input_stream().read_ushort(); 202 } 203 204 207 public void insert_ushort(short value) 208 { 209 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 210 output.write_ushort(value); 211 read_value(null, TypeCode.USHORT); 212 } 213 214 217 public int extract_ulong() 218 { 219 extract_type(TCKind.tk_ulong, "ulong"); 220 return create_input_stream().read_ulong(); 221 } 222 223 226 public void insert_ulong(int value) 227 { 228 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 229 output.write_ulong(value); 230 read_value(null, TypeCode.ULONG); 231 } 232 233 236 public long extract_ulonglong() 237 { 238 extract_type(TCKind.tk_ulonglong, "ulonglong"); 239 return create_input_stream().read_ulonglong(); 240 } 241 242 245 public void insert_ulonglong(long value) 246 { 247 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 248 output.write_ulonglong(value); 249 read_value(null, TypeCode.ULONGLONG); 250 } 251 252 255 public float extract_float() 256 { 257 extract_type(TCKind.tk_float, "float"); 258 return create_input_stream().read_float(); 259 } 260 261 264 public void insert_float(float value) 265 { 266 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 267 output.write_float(value); 268 read_value(null, TypeCode.FLOAT); 269 } 270 271 274 public double extract_double() 275 { 276 extract_type(TCKind.tk_double, "double"); 277 return create_input_stream().read_double(); 278 } 279 280 283 public void insert_double(double value) 284 { 285 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 286 output.write_double(value); 287 read_value(null, TypeCode.DOUBLE); 288 } 289 290 293 public boolean extract_boolean() 294 { 295 extract_type(TCKind.tk_boolean, "boolean"); 296 return create_input_stream().read_boolean(); 297 } 298 299 302 public void insert_boolean(boolean value) 303 { 304 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 305 output.write_boolean(value); 306 read_value(null, TypeCode.BOOLEAN); 307 } 308 309 312 public char extract_char() 313 { 314 extract_type(TCKind.tk_char, "char"); 315 return create_input_stream().read_char(); 316 } 317 318 321 public void insert_char(char value) 322 { 323 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 324 output.write_char(value); 325 read_value(null, TypeCode.CHAR); 326 } 327 328 331 public char extract_wchar() 332 { 333 extract_type(TCKind.tk_wchar, "wchar"); 334 return create_input_stream().read_wchar(); 335 } 336 337 340 public void insert_wchar(char value) 341 { 342 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 343 output.write_wchar(value); 344 read_value(null, TypeCode.WCHAR); 345 } 346 347 350 public byte extract_octet() 351 { 352 extract_type(TCKind.tk_octet, "octet"); 353 return create_input_stream().read_octet(); 354 } 355 356 359 public void insert_octet(byte value) 360 { 361 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 362 output.write_octet(value); 363 read_value(null, TypeCode.OCTET); 364 } 365 366 369 public org.omg.CORBA.Any extract_any() 370 { 371 extract_type(TCKind.tk_any, "any"); 372 return create_input_stream().read_any(); 373 } 374 375 378 public void insert_any(org.omg.CORBA.Any value) 379 { 380 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 381 output.write_any(value); 382 read_value(null, TypeCode.ANY); 383 } 384 385 388 public org.omg.CORBA.Object extract_Object() 389 { 390 extract_type(TCKind.tk_objref, "Object"); 391 org.omg.CORBA.Object obj = create_input_stream().read_Object(); 392 return obj; 393 } 394 395 398 public void insert_Object(org.omg.CORBA.Object value) 399 { 400 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 401 output.write_Object(value); 402 read_value(null, TypeCode.OBJREF); 403 } 404 405 409 public void insert_Object(org.omg.CORBA.Object value, 410 org.omg.CORBA.TypeCode type) 411 { 412 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 413 output.write_Object(value); 414 read_value(null, type); 415 } 416 417 420 public java.io.Serializable extract_Value() 421 { 422 throw new org.omg.CORBA.NO_IMPLEMENT (); 423 } 424 425 428 public void insert_Value(java.io.Serializable v) 429 { 430 throw new org.omg.CORBA.NO_IMPLEMENT (); 431 } 432 433 437 public void insert_Value(java.io.Serializable v, org.omg.CORBA.TypeCode t) 438 { 439 throw new org.omg.CORBA.NO_IMPLEMENT (); 440 } 441 442 445 public String extract_string() 446 { 447 extract_type(TCKind.tk_string, "string"); 448 return create_input_stream().read_string(); 449 } 450 451 454 public void insert_string(String value) 455 { 456 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 457 output.write_string(value); 458 read_value(null, TypeCode.STRING); 459 } 460 461 464 public String extract_wstring() 465 { 466 extract_type(TCKind.tk_wstring, "wstring"); 467 return create_input_stream().read_wstring(); 468 } 469 470 473 public void insert_wstring(String value) 474 { 475 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 476 output.write_wstring(value); 477 read_value(null, TypeCode.WSTRING); 478 } 479 480 483 public org.omg.CORBA.TypeCode extract_TypeCode() 484 { 485 extract_type(TCKind.tk_TypeCode, "TypeCode"); 486 return create_input_stream().read_TypeCode(); 487 } 488 489 492 public void insert_TypeCode(org.omg.CORBA.TypeCode value) 493 { 494 org.omg.CORBA.portable.OutputStream output = create_output_stream(); 495 output.write_TypeCode(value); 496 read_value(null, TypeCode.TYPECODE); 497 } 498 499 502 public org.omg.CORBA.Principal extract_Principal() 503 { 504 throw new org.omg.CORBA.NO_IMPLEMENT ( 505 "org.apache.geronimo.interop.rmi.iiop.Any.extract_Principal"); 506 } 507 508 public void insert_Principal(org.omg.CORBA.Principal value) 509 { 510 throw new org.omg.CORBA.NO_IMPLEMENT ( 511 "org.apache.geronimo.interop.rmi.iiop.Any.insert_Principal"); 512 } 513 514 522 public org.omg.CORBA.portable.Streamable extract_Streamable() 523 throws org.omg.CORBA.BAD_INV_ORDER 524 { 525 throw new org.omg.CORBA.NO_IMPLEMENT (); 526 } 527 528 531 public void insert_Streamable(org.omg.CORBA.portable.Streamable s) 532 { 533 throw new org.omg.CORBA.NO_IMPLEMENT (); 534 } 535 536 540 544 public Any(org.omg.CORBA.TypeCode type, String value) 545 { 546 try 547 { 548 _type = type; 549 switch (_type.kind().value()) 550 { 551 case TCKind._tk_boolean: 552 if (value.equals("0")) 553 { 554 insert_boolean(false); 555 } 556 else if (value.equals("1")) 557 { 558 insert_boolean(true); 559 } 560 else 561 { 562 insert_boolean(Boolean.valueOf(value).booleanValue()); 563 } 564 break; 565 case TCKind._tk_octet: 566 insert_octet((byte) parse(value, 0, 255)); 568 break; 569 case TCKind._tk_short: 570 insert_short((short) parse(value, -32768, 32767)); 572 break; 573 case TCKind._tk_ushort: 574 insert_ushort((short) parse(value, 0, 65535)); 576 break; 577 case TCKind._tk_long: 578 insert_long((int) parse(value, -2147483648, 2147483647)); 579 break; 580 case TCKind._tk_ulong: 581 insert_ulong((int) parse(value, 0, 4294967295L)); 582 break; 583 case TCKind._tk_longlong: 584 insert_longlong(Long.parseLong(value)); 585 break; 586 case TCKind._tk_ulonglong: 587 insert_ulonglong(Long.parseLong(value)); 590 break; 591 case TCKind._tk_float: 592 insert_float(Float.valueOf(value).floatValue()); 593 break; 594 case TCKind._tk_double: 595 insert_double(Double.valueOf(value).doubleValue()); 596 break; 597 default: 598 throw new org.omg.CORBA.BAD_PARAM (value); 599 } 600 } 601 catch (NumberFormatException nfe) 602 { 603 throw new org.omg.CORBA.BAD_PARAM (value + " - " + nfe.toString()); 604 } 605 } 606 607 614 private long parse(String value, long min, long max) 615 throws NumberFormatException 616 { 617 long n = Long.parseLong(value); 618 if (n < min || n > max) 619 { 620 throw new NumberFormatException (value + 621 " is not in range [" 622 + min + ".." + max + "]"); 623 } 624 return n; 625 } 626 627 630 public String toString() 631 { 632 switch (_type.kind().value()) 633 { 634 case TCKind._tk_any: 635 case TCKind._tk_boolean: 636 case TCKind._tk_char: 637 case TCKind._tk_wchar: 638 case TCKind._tk_octet: 639 case TCKind._tk_short: 640 case TCKind._tk_ushort: 641 case TCKind._tk_long: 642 case TCKind._tk_ulong: 643 case TCKind._tk_longlong: 644 case TCKind._tk_ulonglong: 645 case TCKind._tk_float: 646 case TCKind._tk_double: 647 case TCKind._tk_string: 648 case TCKind._tk_wstring: 649 case TCKind._tk_objref: 650 return value(); 651 default: 652 return _type.toString(); 654 } 655 } 656 657 660 private String value() 661 { 662 switch (_type.kind().value()) 663 { 664 case TCKind._tk_any: 665 return "" + extract_any(); 666 case TCKind._tk_boolean: 667 return extract_boolean() ? "TRUE" : "FALSE"; 668 case TCKind._tk_char: 669 return "'" + extract_char() + "'"; 670 case TCKind._tk_wchar: 671 return "'" + extract_wchar() + "'"; 672 case TCKind._tk_octet: 673 return "" + extract_octet(); 674 case TCKind._tk_short: 675 return "" + extract_short(); 676 case TCKind._tk_ushort: 677 return "" + extract_ushort(); 678 case TCKind._tk_long: 679 return "" + extract_long(); 680 case TCKind._tk_ulong: 681 return "" + extract_ulong(); 682 case TCKind._tk_longlong: 683 return "" + extract_longlong(); 684 case TCKind._tk_ulonglong: 685 return "" + extract_ulonglong(); 686 case TCKind._tk_float: 687 return "" + extract_float(); 688 case TCKind._tk_double: 689 return "" + extract_double(); 690 case TCKind._tk_string: 691 return "\"" + extract_string() + "\""; 692 case TCKind._tk_wstring: 693 return "\"" + extract_wstring() + "\""; 694 case TCKind._tk_objref: 695 return extract_Object().toString(); 696 case TCKind._tk_TypeCode: 697 return "" + extract_TypeCode(); 698 default: 699 return "?"; 700 } 701 } 702 } 703 | Popular Tags |