1 7 15 16 package com.sun.corba.se.impl.corba; 17 18 import java.io.Serializable ; 19 import java.math.BigDecimal ; 20 import java.util.List ; 21 import java.util.ArrayList ; 22 23 import org.omg.CORBA.Principal ; 24 import org.omg.CORBA.TypeCode ; 25 import org.omg.CORBA.Any ; 26 import org.omg.CORBA.CompletionStatus ; 27 import org.omg.CORBA.TCKind ; 28 29 import org.omg.CORBA.portable.Streamable ; 30 import org.omg.CORBA.portable.InputStream ; 31 import org.omg.CORBA.portable.OutputStream ; 32 import org.omg.CORBA.TypeCodePackage.BadKind ; 33 import org.omg.CORBA.TypeCodePackage.Bounds ; 34 35 import com.sun.corba.se.spi.orb.ORB; 36 import com.sun.corba.se.spi.orb.ORBVersionFactory; 37 import com.sun.corba.se.spi.logging.CORBALogDomains; 38 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 39 40 import com.sun.corba.se.impl.encoding.CDRInputStream; 41 import com.sun.corba.se.impl.encoding.EncapsInputStream; 42 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 43 import com.sun.corba.se.impl.io.ValueUtility; 44 import com.sun.corba.se.impl.orbutil.RepositoryIdFactory; 45 import com.sun.corba.se.impl.orbutil.RepositoryIdStrings; 46 import com.sun.corba.se.impl.orbutil.ORBUtility; 47 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 48 49 public class AnyImpl extends Any 51 { 52 private static final class AnyInputStream extends EncapsInputStream 53 { 54 public AnyInputStream(EncapsInputStream theStream ) 55 { 56 super( theStream ); 57 } 58 } 59 60 private static final class AnyOutputStream extends EncapsOutputStream 61 { 62 public AnyOutputStream(ORB orb) 63 { 64 super((ORB)orb); 65 } 66 67 public org.omg.CORBA.portable.InputStream create_input_stream() 68 { 69 return new AnyInputStream( 70 (com.sun.corba.se.impl.encoding.EncapsInputStream) 71 super.create_input_stream()); 72 } 73 } 74 75 private TypeCodeImpl typeCode; 79 protected ORB orb; 80 private ORBUtilSystemException wrapper ; 81 82 private CDRInputStream stream; 91 private long value; 92 private java.lang.Object object; 93 94 private boolean isInitialized = false; 98 99 private static final int DEFAULT_BUFFER_SIZE = 32; 100 101 105 static boolean isStreamed[] = { 106 false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, true, false, false, true, true, true, true, false, false, false, false, false, false, false, false, false, false }; 140 141 static AnyImpl convertToNative(ORB orb, Any any) { 142 if (any instanceof AnyImpl) { 143 return (AnyImpl)any; 144 } else { 145 AnyImpl anyImpl = new AnyImpl(orb, any); 146 anyImpl.typeCode = TypeCodeImpl.convertToNative(orb, anyImpl.typeCode); 147 return anyImpl; 148 } 149 } 150 151 154 159 public AnyImpl(ORB orb) 160 { 161 this.orb = orb; 162 wrapper = ORBUtilSystemException.get( (com.sun.corba.se.spi.orb.ORB)orb, 163 CORBALogDomains.RPC_PRESENTATION ) ; 164 165 typeCode = orb.get_primitive_tc(TCKind._tk_null); 166 stream = null; 167 object = null; 168 value = 0; 169 isInitialized = true; 171 } 172 173 public AnyImpl(ORB orb, Any obj) { 177 this(orb); 178 179 if ((obj instanceof AnyImpl)) { 180 AnyImpl objImpl = (AnyImpl)obj; 181 typeCode = objImpl.typeCode; 182 value = objImpl.value; 183 object = objImpl.object; 184 isInitialized = objImpl.isInitialized; 185 186 if (objImpl.stream != null) 187 stream = objImpl.stream.dup(); 188 189 } else { 190 read_value(obj.create_input_stream(), obj.type()); 191 } 192 } 193 194 197 202 public TypeCode type() { 203 return typeCode; 204 } 205 206 private TypeCode realType() { 207 return realType(typeCode); 208 } 209 210 private TypeCode realType(TypeCode aType) { 211 TypeCode realType = aType; 212 try { 213 while (realType.kind().value() == TCKind._tk_alias) { 215 realType = realType.content_type(); 216 } 217 } catch (BadKind bad) { throw wrapper.badkindCannotOccur( bad ) ; 219 } 220 return realType; 221 } 222 223 228 public void type(TypeCode tc) 229 { 230 typeCode = TypeCodeImpl.convertToNative(orb, tc); 233 234 stream = null; 235 value = 0; 236 object = null; 237 isInitialized = (tc.kind().value() == TCKind._tk_null); 239 } 240 241 247 public boolean equal(Any otherAny) 248 { 249 251 if (otherAny == this) 252 return true; 253 254 if (!typeCode.equal(otherAny.type())) 257 return false; 258 259 TypeCode realType = realType(); 261 262 switch (realType.kind().value()) { 275 case TCKind._tk_null: 277 case TCKind._tk_void: 278 return true; 279 case TCKind._tk_short: 280 return (extract_short() == otherAny.extract_short()); 281 case TCKind._tk_long: 282 return (extract_long() == otherAny.extract_long()); 283 case TCKind._tk_ushort: 284 return (extract_ushort() == otherAny.extract_ushort()); 285 case TCKind._tk_ulong: 286 return (extract_ulong() == otherAny.extract_ulong()); 287 case TCKind._tk_float: 288 return (extract_float() == otherAny.extract_float()); 289 case TCKind._tk_double: 290 return (extract_double() == otherAny.extract_double()); 291 case TCKind._tk_boolean: 292 return (extract_boolean() == otherAny.extract_boolean()); 293 case TCKind._tk_char: 294 return (extract_char() == otherAny.extract_char()); 295 case TCKind._tk_wchar: 296 return (extract_wchar() == otherAny.extract_wchar()); 297 case TCKind._tk_octet: 298 return (extract_octet() == otherAny.extract_octet()); 299 case TCKind._tk_any: 300 return extract_any().equal(otherAny.extract_any()); 301 case TCKind._tk_TypeCode: 302 return extract_TypeCode().equal(otherAny.extract_TypeCode()); 303 case TCKind._tk_string: 304 return extract_string().equals(otherAny.extract_string()); 305 case TCKind._tk_wstring: 306 return (extract_wstring().equals(otherAny.extract_wstring())); 307 case TCKind._tk_longlong: 308 return (extract_longlong() == otherAny.extract_longlong()); 309 case TCKind._tk_ulonglong: 310 return (extract_ulonglong() == otherAny.extract_ulonglong()); 311 312 case TCKind._tk_objref: 313 return (extract_Object().equals(otherAny.extract_Object())); 314 case TCKind._tk_Principal: 315 return (extract_Principal().equals(otherAny.extract_Principal())); 316 317 case TCKind._tk_enum: 318 return (extract_long() == otherAny.extract_long()); 319 case TCKind._tk_fixed: 320 return (extract_fixed().compareTo(otherAny.extract_fixed()) == 0); 321 case TCKind._tk_except: 322 case TCKind._tk_struct: 323 case TCKind._tk_union: 324 case TCKind._tk_sequence: 325 case TCKind._tk_array: 326 InputStream copyOfMyStream = this.create_input_stream(); 327 InputStream copyOfOtherStream = otherAny.create_input_stream(); 328 return equalMember(realType, copyOfMyStream, copyOfOtherStream); 329 330 case TCKind._tk_value: 334 case TCKind._tk_value_box: 335 return extract_Value().equals(otherAny.extract_Value()); 336 337 case TCKind._tk_alias: 338 throw wrapper.errorResolvingAlias() ; 339 340 case TCKind._tk_longdouble: 341 throw wrapper.tkLongDoubleNotSupported() ; 343 344 default: 345 throw wrapper.typecodeNotSupported() ; 346 } 347 } 348 349 private boolean equalMember(TypeCode memberType, InputStream myStream, InputStream otherStream) { 352 TypeCode realType = realType(memberType); 354 355 try { 356 switch (realType.kind().value()) { 357 case TCKind._tk_null: 359 case TCKind._tk_void: 360 return true; 361 case TCKind._tk_short: 362 return (myStream.read_short() == otherStream.read_short()); 363 case TCKind._tk_long: 364 return (myStream.read_long() == otherStream.read_long()); 365 case TCKind._tk_ushort: 366 return (myStream.read_ushort() == otherStream.read_ushort()); 367 case TCKind._tk_ulong: 368 return (myStream.read_ulong() == otherStream.read_ulong()); 369 case TCKind._tk_float: 370 return (myStream.read_float() == otherStream.read_float()); 371 case TCKind._tk_double: 372 return (myStream.read_double() == otherStream.read_double()); 373 case TCKind._tk_boolean: 374 return (myStream.read_boolean() == otherStream.read_boolean()); 375 case TCKind._tk_char: 376 return (myStream.read_char() == otherStream.read_char()); 377 case TCKind._tk_wchar: 378 return (myStream.read_wchar() == otherStream.read_wchar()); 379 case TCKind._tk_octet: 380 return (myStream.read_octet() == otherStream.read_octet()); 381 case TCKind._tk_any: 382 return myStream.read_any().equal(otherStream.read_any()); 383 case TCKind._tk_TypeCode: 384 return myStream.read_TypeCode().equal(otherStream.read_TypeCode()); 385 case TCKind._tk_string: 386 return myStream.read_string().equals(otherStream.read_string()); 387 case TCKind._tk_wstring: 388 return (myStream.read_wstring().equals(otherStream.read_wstring())); 389 case TCKind._tk_longlong: 390 return (myStream.read_longlong() == otherStream.read_longlong()); 391 case TCKind._tk_ulonglong: 392 return (myStream.read_ulonglong() == otherStream.read_ulonglong()); 393 394 case TCKind._tk_objref: 395 return (myStream.read_Object().equals(otherStream.read_Object())); 396 case TCKind._tk_Principal: 397 return (myStream.read_Principal().equals(otherStream.read_Principal())); 398 399 case TCKind._tk_enum: 400 return (myStream.read_long() == otherStream.read_long()); 401 case TCKind._tk_fixed: 402 return (myStream.read_fixed().compareTo(otherStream.read_fixed()) == 0); 403 case TCKind._tk_except: 404 case TCKind._tk_struct: { 405 int length = realType.member_count(); 406 for (int i=0; i<length; i++) { 407 if ( ! equalMember(realType.member_type(i), myStream, otherStream)) { 408 return false; 409 } 410 } 411 return true; 412 } 413 case TCKind._tk_union: { 414 Any myDiscriminator = orb.create_any(); 415 Any otherDiscriminator = orb.create_any(); 416 myDiscriminator.read_value(myStream, realType.discriminator_type()); 417 otherDiscriminator.read_value(otherStream, realType.discriminator_type()); 418 419 if ( ! myDiscriminator.equal(otherDiscriminator)) { 420 return false; 421 } 422 TypeCodeImpl realTypeCodeImpl = TypeCodeImpl.convertToNative(orb, realType); 423 int memberIndex = realTypeCodeImpl.currentUnionMemberIndex(myDiscriminator); 424 if (memberIndex == -1) 425 throw wrapper.unionDiscriminatorError() ; 426 427 if ( ! equalMember(realType.member_type(memberIndex), myStream, otherStream)) { 428 return false; 429 } 430 return true; 431 } 432 case TCKind._tk_sequence: { 433 int length = myStream.read_long(); 434 otherStream.read_long(); for (int i=0; i<length; i++) { 436 if ( ! equalMember(realType.content_type(), myStream, otherStream)) { 437 return false; 438 } 439 } 440 return true; 441 } 442 case TCKind._tk_array: { 443 int length = realType.member_count(); 444 for (int i=0; i<length; i++) { 445 if ( ! equalMember(realType.content_type(), myStream, otherStream)) { 446 return false; 447 } 448 } 449 return true; 450 } 451 452 case TCKind._tk_value: 456 case TCKind._tk_value_box: 457 org.omg.CORBA_2_3.portable.InputStream mine = 458 (org.omg.CORBA_2_3.portable.InputStream )myStream; 459 org.omg.CORBA_2_3.portable.InputStream other = 460 (org.omg.CORBA_2_3.portable.InputStream )otherStream; 461 return mine.read_value().equals(other.read_value()); 462 463 case TCKind._tk_alias: 464 throw wrapper.errorResolvingAlias() ; 466 467 case TCKind._tk_longdouble: 468 throw wrapper.tkLongDoubleNotSupported() ; 469 470 default: 471 throw wrapper.typecodeNotSupported() ; 472 } 473 } catch (BadKind badKind) { throw wrapper.badkindCannotOccur() ; 475 } catch (Bounds bounds) { throw wrapper.boundsCannotOccur() ; 477 } 478 } 479 480 483 488 public org.omg.CORBA.portable.OutputStream create_output_stream() 489 { 490 return new AnyOutputStream(orb); 492 } 493 494 499 public org.omg.CORBA.portable.InputStream create_input_stream() 500 { 501 if (AnyImpl.isStreamed[realType().kind().value()]) { 507 return stream.dup(); 508 } else { 509 OutputStream os = (OutputStream )orb.create_output_stream(); 510 TCUtility.marshalIn(os, realType(), value, object); 511 512 return os.create_input_stream(); 513 } 514 } 515 516 519 public void read_value(org.omg.CORBA.portable.InputStream in, TypeCode tc) 524 { 525 538 typeCode = TypeCodeImpl.convertToNative(orb, tc); 539 int kind = realType().kind().value(); 540 if (kind >= isStreamed.length) { 541 throw wrapper.invalidIsstreamedTckind( CompletionStatus.COMPLETED_MAYBE, 542 new Integer (kind)) ; 543 } 544 545 if (AnyImpl.isStreamed[kind]) { 546 if ( in instanceof AnyInputStream ) { 547 stream = (CDRInputStream)in; 549 } else { 550 org.omg.CORBA_2_3.portable.OutputStream out = 551 (org.omg.CORBA_2_3.portable.OutputStream )orb.create_output_stream(); 552 typeCode.copy((org.omg.CORBA_2_3.portable.InputStream )in, out); 553 stream = (CDRInputStream)out.create_input_stream(); 554 } 555 } else { 556 java.lang.Object [] objholder = new java.lang.Object [1]; 557 objholder[0] = object; 558 long[] longholder = new long[1]; 559 TCUtility.unmarshalIn(in, realType(), longholder, objholder); 560 value = longholder[0]; 561 object = objholder[0]; 562 stream = null; 563 } 564 isInitialized = true; 565 } 566 567 568 public void write_value(OutputStream out) 576 { 577 if (AnyImpl.isStreamed[realType().kind().value()]) { 579 typeCode.copy(stream.dup(), out); 580 } else { 581 TCUtility.marshalIn(out, realType(), value, object); 583 } 584 } 585 586 591 public void insert_Streamable(Streamable s) 592 { 593 typeCode = TypeCodeImpl.convertToNative(orb, s._type()); 595 object = s; 596 isInitialized = true; 597 } 598 599 public Streamable extract_Streamable() 600 { 601 return (Streamable )object; 603 } 604 605 608 611 public void insert_short(short s) 612 { 613 typeCode = orb.get_primitive_tc(TCKind._tk_short); 615 value = s; 616 isInitialized = true; 617 } 618 619 private String getTCKindName( int tc ) 620 { 621 if ((tc >= 0) && (tc < TypeCodeImpl.kindNames.length)) 622 return TypeCodeImpl.kindNames[tc] ; 623 else 624 return "UNKNOWN(" + tc + ")" ; 625 } 626 627 private void checkExtractBadOperation( int expected ) 628 { 629 if (!isInitialized) 630 throw wrapper.extractNotInitialized() ; 631 632 int tc = realType().kind().value() ; 633 if (tc != expected) { 634 String tcName = getTCKindName( tc ) ; 635 String expectedName = getTCKindName( expected ) ; 636 throw wrapper.extractWrongType( expectedName, tcName ) ; 637 } 638 } 639 640 private void checkExtractBadOperationList( int[] expected ) 641 { 642 if (!isInitialized) 643 throw wrapper.extractNotInitialized() ; 644 645 int tc = realType().kind().value() ; 646 for (int ctr=0; ctr<expected.length; ctr++) 647 if (tc == expected[ctr]) 648 return ; 649 650 List list = new ArrayList () ; 651 for (int ctr=0; ctr<expected.length; ctr++) 652 list.add( getTCKindName( expected[ctr] ) ) ; 653 654 String tcName = getTCKindName( tc ) ; 655 throw wrapper.extractWrongTypeList( list, tcName ) ; 656 } 657 658 661 public short extract_short() 662 { 663 checkExtractBadOperation( TCKind._tk_short ) ; 665 return (short)value; 666 } 667 668 671 public void insert_long(int l) 672 { 673 int kind = realType().kind().value(); 677 if (kind != TCKind._tk_long && kind != TCKind._tk_enum) { 678 typeCode = orb.get_primitive_tc(TCKind._tk_long); 679 } 680 value = l; 681 isInitialized = true; 682 } 683 684 687 public int extract_long() 688 { 689 checkExtractBadOperationList( new int[] { TCKind._tk_long, TCKind._tk_enum } ) ; 691 return (int)value; 692 } 693 694 697 public void insert_ushort(short s) 698 { 699 typeCode = orb.get_primitive_tc(TCKind._tk_ushort); 701 value = s; 702 isInitialized = true; 703 } 704 705 708 public short extract_ushort() 709 { 710 checkExtractBadOperation( TCKind._tk_ushort ) ; 712 return (short)value; 713 } 714 715 718 public void insert_ulong(int l) 719 { 720 typeCode = orb.get_primitive_tc(TCKind._tk_ulong); 722 value = l; 723 isInitialized = true; 724 } 725 726 729 public int extract_ulong() 730 { 731 checkExtractBadOperation( TCKind._tk_ulong ) ; 733 return (int)value; 734 } 735 736 739 public void insert_float(float f) 740 { 741 typeCode = orb.get_primitive_tc(TCKind._tk_float); 743 value = Float.floatToIntBits(f); 744 isInitialized = true; 745 } 746 747 750 public float extract_float() 751 { 752 checkExtractBadOperation( TCKind._tk_float ) ; 754 return Float.intBitsToFloat((int)value); 755 } 756 757 760 public void insert_double(double d) 761 { 762 typeCode = orb.get_primitive_tc(TCKind._tk_double); 764 value = Double.doubleToLongBits(d); 765 isInitialized = true; 766 } 767 768 771 public double extract_double() 772 { 773 checkExtractBadOperation( TCKind._tk_double ) ; 775 return Double.longBitsToDouble(value); 776 } 777 778 781 public void insert_longlong(long l) 782 { 783 typeCode = orb.get_primitive_tc(TCKind._tk_longlong); 785 value = l; 786 isInitialized = true; 787 } 788 789 792 public long extract_longlong() 793 { 794 checkExtractBadOperation( TCKind._tk_longlong ) ; 796 return value; 797 } 798 799 802 public void insert_ulonglong(long l) 803 { 804 typeCode = orb.get_primitive_tc(TCKind._tk_ulonglong); 806 value = l; 807 isInitialized = true; 808 } 809 810 813 public long extract_ulonglong() 814 { 815 checkExtractBadOperation( TCKind._tk_ulonglong ) ; 817 return value; 818 } 819 820 823 public void insert_boolean(boolean b) 824 { 825 typeCode = orb.get_primitive_tc(TCKind._tk_boolean); 827 value = (b)? 1:0; 828 isInitialized = true; 829 } 830 831 834 public boolean extract_boolean() 835 { 836 checkExtractBadOperation( TCKind._tk_boolean ) ; 838 return (value == 0)? false: true; 839 } 840 841 844 public void insert_char(char c) 845 { 846 typeCode = orb.get_primitive_tc(TCKind._tk_char); 848 value = c; 849 isInitialized = true; 850 } 851 852 855 public char extract_char() 856 { 857 checkExtractBadOperation( TCKind._tk_char ) ; 859 return (char)value; 860 } 861 862 865 public void insert_wchar(char c) 866 { 867 typeCode = orb.get_primitive_tc(TCKind._tk_wchar); 869 value = c; 870 isInitialized = true; 871 } 872 873 876 public char extract_wchar() 877 { 878 checkExtractBadOperation( TCKind._tk_wchar ) ; 880 return (char)value; 881 } 882 883 884 887 public void insert_octet(byte b) 888 { 889 typeCode = orb.get_primitive_tc(TCKind._tk_octet); 891 value = b; 892 isInitialized = true; 893 } 894 895 898 public byte extract_octet() 899 { 900 checkExtractBadOperation( TCKind._tk_octet ) ; 902 return (byte)value; 903 } 904 905 908 public void insert_string(String s) 909 { 910 if (typeCode.kind() == TCKind.tk_string) { 913 int length = 0; 914 try { 915 length = typeCode.length(); 916 } catch (BadKind bad) { 917 throw wrapper.badkindCannotOccur() ; 918 } 919 920 if (length != 0 && s != null && s.length() > length) { 922 throw wrapper.badStringBounds( new Integer (s.length()), 923 new Integer (length) ) ; 924 } 925 } else { 926 typeCode = orb.get_primitive_tc(TCKind._tk_string); 927 } 928 object = s; 929 isInitialized = true; 930 } 931 932 935 public String extract_string() 936 { 937 checkExtractBadOperation( TCKind._tk_string ) ; 939 return (String )object; 940 } 941 942 945 public void insert_wstring(String s) 946 { 947 if (typeCode.kind() == TCKind.tk_wstring) { 950 int length = 0; 951 try { 952 length = typeCode.length(); 953 } catch (BadKind bad) { 954 throw wrapper.badkindCannotOccur() ; 955 } 956 957 if (length != 0 && s != null && s.length() > length) { 959 throw wrapper.badStringBounds( new Integer (s.length()), 960 new Integer (length) ) ; 961 } 962 } else { 963 typeCode = orb.get_primitive_tc(TCKind._tk_wstring); 964 } 965 object = s; 966 isInitialized = true; 967 } 968 969 972 public String extract_wstring() 973 { 974 checkExtractBadOperation( TCKind._tk_wstring ) ; 976 return (String )object; 977 } 978 979 982 public void insert_any(Any a) 983 { 984 typeCode = orb.get_primitive_tc(TCKind._tk_any); 986 object = a; 987 stream = null; 988 isInitialized = true; 989 } 990 991 994 public Any extract_any() 995 { 996 checkExtractBadOperation( TCKind._tk_any ) ; 998 return (Any )object; 999 } 1000 1001 1004 public void insert_Object(org.omg.CORBA.Object o) 1005 { 1006 if ( o == null ) { 1008 typeCode = orb.get_primitive_tc(TCKind._tk_objref); 1009 } else { 1010 if (StubAdapter.isStub(o)) { 1011 String [] ids = StubAdapter.getTypeIds( o ) ; 1012 typeCode = new TypeCodeImpl(orb, TCKind._tk_objref, ids[0], ""); 1013 } else { 1014 throw wrapper.badInsertobjParam( 1015 CompletionStatus.COMPLETED_MAYBE, o.getClass().getName() ) ; 1016 } 1017 } 1018 1019 object = o; 1020 isInitialized = true; 1021 } 1022 1023 1027 public void insert_Object(org.omg.CORBA.Object o, TypeCode tc) 1028 { 1029 try { 1031 if ( tc.id().equals("IDL:omg.org/CORBA/Object:1.0") || o._is_a(tc.id()) ) 1032 { 1033 typeCode = TypeCodeImpl.convertToNative(orb, tc); 1034 object = o; 1035 } 1036 else { 1037 throw wrapper.insertObjectIncompatible() ; 1038 } 1039 } catch ( Exception ex ) { 1040 throw wrapper.insertObjectFailed(ex) ; 1041 } 1042 isInitialized = true; 1043 } 1044 1045 1048 public org.omg.CORBA.Object extract_Object() 1049 { 1050 if (!isInitialized) 1052 throw wrapper.extractNotInitialized() ; 1053 1054 org.omg.CORBA.Object obj = null; 1056 try { 1057 obj = (org.omg.CORBA.Object ) object; 1058 if (typeCode.id().equals("IDL:omg.org/CORBA/Object:1.0") || obj._is_a(typeCode.id())) { 1059 return obj; 1060 } else { 1061 throw wrapper.extractObjectIncompatible() ; 1062 } 1063 } catch ( Exception ex ) { 1064 throw wrapper.extractObjectFailed(ex); 1065 } 1066 } 1067 1068 1071 public void insert_TypeCode(TypeCode tc) 1072 { 1073 typeCode = orb.get_primitive_tc(TCKind._tk_TypeCode); 1075 object = tc; 1076 isInitialized = true; 1077 } 1078 1079 1082 public TypeCode extract_TypeCode() 1083 { 1084 checkExtractBadOperation( TCKind._tk_TypeCode ) ; 1086 return (TypeCode )object; 1087 } 1088 1089 1092 @Deprecated 1093 public void insert_Principal(Principal p) 1094 { 1095 typeCode = orb.get_primitive_tc(TCKind._tk_Principal); 1096 object = p; 1097 isInitialized = true; 1098 } 1099 1100 1103 @Deprecated 1104 public Principal extract_Principal() 1105 { 1106 checkExtractBadOperation( TCKind._tk_Principal ) ; 1107 return (Principal )object; 1108 } 1109 1110 1116 public Serializable extract_Value() 1117 { 1118 checkExtractBadOperationList( new int[] { TCKind._tk_value, 1120 TCKind._tk_value_box, TCKind._tk_abstract_interface } ) ; 1121 return (Serializable )object; 1122 } 1123 1124 public void insert_Value(Serializable v) 1125 { 1126 object = v; 1128 1129 TypeCode tc; 1130 1131 if ( v == null ) { 1132 tc = orb.get_primitive_tc (TCKind.tk_value); 1133 } else { 1134 tc = createTypeCodeForClass (v.getClass(), (ORB)ORB.init()); 1144 } 1145 1146 typeCode = TypeCodeImpl.convertToNative(orb, tc); 1147 isInitialized = true; 1148 } 1149 1150 public void insert_Value(Serializable v, org.omg.CORBA.TypeCode t) 1151 { 1152 object = v; 1154 typeCode = TypeCodeImpl.convertToNative(orb, t); 1155 isInitialized = true; 1156 } 1157 1158 public void insert_fixed(java.math.BigDecimal value) { 1159 typeCode = TypeCodeImpl.convertToNative(orb, 1160 orb.create_fixed_tc(TypeCodeImpl.digits(value), TypeCodeImpl.scale(value))); 1161 object = value; 1162 isInitialized = true; 1163 } 1164 1165 public void insert_fixed(java.math.BigDecimal value, org.omg.CORBA.TypeCode type) 1166 { 1167 try { 1168 if (TypeCodeImpl.digits(value) > type.fixed_digits() || 1169 TypeCodeImpl.scale(value) > type.fixed_scale()) 1170 { 1171 throw wrapper.fixedNotMatch() ; 1172 } 1173 } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) { 1174 throw wrapper.fixedBadTypecode( bk ) ; 1176 } 1177 typeCode = TypeCodeImpl.convertToNative(orb, type); 1178 object = value; 1179 isInitialized = true; 1180 } 1181 1182 public java.math.BigDecimal extract_fixed() { 1183 checkExtractBadOperation( TCKind._tk_fixed ) ; 1184 return (BigDecimal )object; 1185 } 1186 1187 1193 public TypeCode createTypeCodeForClass (java.lang.Class c, ORB tcORB) 1194 { 1195 TypeCodeImpl classTC = tcORB.getTypeCodeForClass(c); 1197 if (classTC != null) 1198 return classTC; 1199 1200 RepositoryIdStrings repStrs 1205 = RepositoryIdFactory.getRepIdStringsFactory(tcORB); 1206 1207 1208 1210 if ( c.isArray() ) { 1211 Class componentClass = c.getComponentType(); 1213 TypeCode embeddedType; 1214 if ( componentClass.isPrimitive() ) { 1215 embeddedType = getPrimitiveTypeCodeForClass(componentClass, 1216 tcORB); 1217 } else { 1218 embeddedType = createTypeCodeForClass (componentClass, 1219 tcORB); 1220 } 1221 TypeCode t = tcORB.create_sequence_tc (0, embeddedType); 1222 1223 String id = repStrs.createForJavaType(c); 1224 1225 return tcORB.create_value_box_tc (id, "Sequence", t); 1226 } else if ( c == java.lang.String .class ) { 1227 TypeCode t = tcORB.create_string_tc (0); 1229 1230 String id = repStrs.createForJavaType(c); 1231 1232 return tcORB.create_value_box_tc (id, "StringValue", t); 1233 } 1234 1235 classTC = (TypeCodeImpl)ValueUtility.createTypeCodeForClass( 1238 tcORB, c, ORBUtility.createValueHandler(tcORB)); 1239 classTC.setCaching(true); 1241 tcORB.setTypeCodeForClass(c, classTC); 1243 return classTC; 1244 } 1245 1246 1254 private TypeCode getPrimitiveTypeCodeForClass (Class c, ORB tcORB) 1255 { 1256 1258 if (c == Integer.TYPE) { 1259 return tcORB.get_primitive_tc (TCKind.tk_long); 1260 } else if (c == Byte.TYPE) { 1261 return tcORB.get_primitive_tc (TCKind.tk_octet); 1262 } else if (c == Long.TYPE) { 1263 return tcORB.get_primitive_tc (TCKind.tk_longlong); 1264 } else if (c == Float.TYPE) { 1265 return tcORB.get_primitive_tc (TCKind.tk_float); 1266 } else if (c == Double.TYPE) { 1267 return tcORB.get_primitive_tc (TCKind.tk_double); 1268 } else if (c == Short.TYPE) { 1269 return tcORB.get_primitive_tc (TCKind.tk_short); 1270 } else if (c == Character.TYPE) { 1271 if (ORBVersionFactory.getFOREIGN().compareTo(tcORB.getORBVersion()) == 0 || 1283 ORBVersionFactory.getNEWER().compareTo(tcORB.getORBVersion()) <= 0) 1284 return tcORB.get_primitive_tc(TCKind.tk_wchar); 1285 else 1286 return tcORB.get_primitive_tc(TCKind.tk_char); 1287 } else if (c == Boolean.TYPE) { 1288 return tcORB.get_primitive_tc (TCKind.tk_boolean); 1289 } else { 1290 return tcORB.get_primitive_tc (TCKind.tk_any); 1292 } 1293 } 1294 1295 public Any extractAny(TypeCode memberType, ORB orb) { 1299 Any returnValue = orb.create_any(); 1300 OutputStream out = returnValue.create_output_stream(); 1301 TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream )stream, out); 1302 returnValue.read_value(out.create_input_stream(), memberType); 1303 return returnValue; 1304 } 1305 1306 static public Any extractAnyFromStream(TypeCode memberType, InputStream input, ORB orb) { 1309 Any returnValue = orb.create_any(); 1310 OutputStream out = returnValue.create_output_stream(); 1311 TypeCodeImpl.convertToNative(orb, memberType).copy(input, out); 1312 returnValue.read_value(out.create_input_stream(), memberType); 1313 return returnValue; 1314 } 1315 1316 public boolean isInitialized() { 1318 return isInitialized; 1319 } 1320} 1321 1322 | Popular Tags |