📄 anyimpl.java
字号:
case TCKind._tk_char: return (myStream.read_char() == otherStream.read_char()); case TCKind._tk_wchar: return (myStream.read_wchar() == otherStream.read_wchar()); case TCKind._tk_octet: return (myStream.read_octet() == otherStream.read_octet()); case TCKind._tk_any: return myStream.read_any().equal(otherStream.read_any()); case TCKind._tk_TypeCode: return myStream.read_TypeCode().equal(otherStream.read_TypeCode()); case TCKind._tk_string: return myStream.read_string().equals(otherStream.read_string()); case TCKind._tk_wstring: return (myStream.read_wstring().equals(otherStream.read_wstring())); case TCKind._tk_longlong: return (myStream.read_longlong() == otherStream.read_longlong()); case TCKind._tk_ulonglong: return (myStream.read_ulonglong() == otherStream.read_ulonglong()); case TCKind._tk_objref: return (myStream.read_Object().equals(otherStream.read_Object())); case TCKind._tk_Principal: return (myStream.read_Principal().equals(otherStream.read_Principal())); case TCKind._tk_enum: return (myStream.read_long() == otherStream.read_long()); case TCKind._tk_fixed: return (myStream.read_fixed().compareTo(otherStream.read_fixed()) == 0); case TCKind._tk_except: case TCKind._tk_struct: { int length = realType.member_count(); for (int i=0; i<length; i++) { if ( ! equalMember(realType.member_type(i), myStream, otherStream)) { return false; } } return true; } case TCKind._tk_union: { Any myDiscriminator = orb.create_any(); Any otherDiscriminator = orb.create_any(); myDiscriminator.read_value(myStream, realType.discriminator_type()); otherDiscriminator.read_value(otherStream, realType.discriminator_type()); if ( ! myDiscriminator.equal(otherDiscriminator)) { return false; } TypeCodeImpl realTypeCodeImpl = TypeCodeImpl.convertToNative(orb, realType); int memberIndex = realTypeCodeImpl.currentUnionMemberIndex(myDiscriminator); if (memberIndex == -1) throw new MARSHAL(); if ( ! equalMember(realType.member_type(memberIndex), myStream, otherStream)) { return false; } return true; } case TCKind._tk_sequence: { int length = myStream.read_long(); otherStream.read_long(); // just so that the two stream are in sync for (int i=0; i<length; i++) { if ( ! equalMember(realType.content_type(), myStream, otherStream)) { return false; } } return true; } case TCKind._tk_array: { int length = realType.member_count(); for (int i=0; i<length; i++) { if ( ! equalMember(realType.content_type(), myStream, otherStream)) { return false; } } return true; } // Too complicated to handle value types the way we handle // other complex types above. Don't try to decompose it here // for faster comparison, just use Object.equals(). case TCKind._tk_value: case TCKind._tk_value_box: org.omg.CORBA_2_3.portable.InputStream mine = (org.omg.CORBA_2_3.portable.InputStream)myStream; org.omg.CORBA_2_3.portable.InputStream other = (org.omg.CORBA_2_3.portable.InputStream)otherStream; return mine.read_value().equals(other.read_value()); case TCKind._tk_alias: // error resolving alias above throw new org.omg.CORBA.INTERNAL(); case TCKind._tk_longdouble: // Unspecified for Java throw new org.omg.CORBA.NO_IMPLEMENT(); default: throw new org.omg.CORBA.NO_IMPLEMENT(); } } catch (BadKind badKind) { // impossible } catch (Bounds bounds) { // impossible } return false;}///////////////////////////////////////////////////////////////////////////// accessors for marshaling/unmarshaling/** * returns an output stream that an Any value can be marshaled into. * * @result the OutputStream to marshal value of Any into */ public org.omg.CORBA.portable.OutputStream create_output_stream(){ //debug.log ("create_output_stream"); return new AnyOutputStream(orb, DEFAULT_BUFFER_SIZE);}/** * returns an input stream that an Any value can be marshaled out of. * * @result the InputStream to marshal value of Any out of. *///// We create a new InputStream so that multiple threads can call here// and read the streams in parallel without thread safety problems.//public org.omg.CORBA.portable.InputStream create_input_stream(){ //debug.log ("create_input_stream"); if (AnyImpl.isStreamed[realType().kind().value()]) { return stream.dup(); } else { OutputStream os = (OutputStream)orb.create_output_stream(); TCUtility.marshalIn(os, realType(), value, object); return os.create_input_stream(); }}///////////////////////////////////////////////////////////////////////////// marshaling/unmarshaling routines//// If the InputStream is a CDRInputStream then we can copy the bytes// since it is in our format and does not have alignment issues.//public void read_value(org.omg.CORBA.portable.InputStream in, TypeCode tc){ //debug.log ("read_value"); // // Assume that someone isn't going to think they can keep reading // from this stream after calling us. That would be likely for // an IIOPInputStream but if it is an AnyInputStream then they // presumably obtained it via our create_output_stream() so they could // write the contents of an IDL data type to it and then call // create_input_stream() for us to read it. This is how Helper classes // typically implement the insert() method. // We should probably document this behavior in the 1.1 revision // task force. // typeCode = TypeCodeImpl.convertToNative(orb, tc); int kind = realType().kind().value(); if (kind >= isStreamed.length) { throw new INTERNAL("Unknown isStreamed kind value: " + kind, MinorCodes.INVALID_ISSTREAMED_TCKIND, CompletionStatus.COMPLETED_MAYBE); } if (AnyImpl.isStreamed[kind]) { if ( in instanceof AnyInputStream ) { // could only have been created here stream = (CDRInputStream)in; } else { org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream)orb.create_output_stream(); typeCode.copy((org.omg.CORBA_2_3.portable.InputStream)in, out); stream = (CDRInputStream)out.create_input_stream(); } } else { java.lang.Object[] objholder = new java.lang.Object[1]; objholder[0] = object; long[] longholder = new long[1]; TCUtility.unmarshalIn(in, typeCode, longholder, objholder); value = longholder[0]; object = objholder[0]; stream = null; } isInitialized = true;}//// We could optimize this by noticing whether the target stream// has ever had anything marshaled on it that required an// alignment of greater than 4 (was write_double() ever called on it).// If not, then we can just do a byte array copy without having to// drive the remarshaling through typecode interpretation.//public void write_value(OutputStream out){ //debug.log ("write_value"); if (AnyImpl.isStreamed[realType().kind().value()]) { typeCode.copy(stream.dup(), out); } else { // _REVISIT_ check isInitialized whether all we write is TypeCode! TCUtility.marshalIn(out, realType(), value, object); }}/** * takes a streamable and inserts its reference into the any * * @param s the streamable to insert */public void insert_Streamable(Streamable s){ //debug.log ("insert_Streamable"); typeCode = TypeCodeImpl.convertToNative(orb, s._type()); object = s; isInitialized = true;} public Streamable extract_Streamable(){ //debug.log( "extract_Streamable" ) ; return (Streamable)object;}///////////////////////////////////////////////////////////////////////////// insertion/extraction/replacement for all basic types/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_short(short s){ //debug.log ("insert_short"); typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_short); value = s; isInitialized = true;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public short extract_short(){ //debug.log ("extract_short"); if (!isInitialized || !(realType().kind().value() == TCKind._tk_short)) throw new BAD_OPERATION(); return (short)value;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_long(int l){ //debug.log ("insert_long"); // A long value is applicable to enums as well, so don't erase the enum type code // in case it was initialized that way before. int kind = realType().kind().value(); if (kind != TCKind._tk_long && kind != TCKind._tk_enum) { typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_long); } value = l; isInitialized = true;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public int extract_long(){ //debug.log ("extract_long"); int kind = realType().kind().value(); if ( ! isInitialized) { throw new BAD_OPERATION(); } if ( ! (kind == TCKind._tk_long || kind == TCKind._tk_enum)) throw new BAD_OPERATION(); return (int)value;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_ushort(short s){ //debug.log ("insert_ushort"); typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_ushort); value = s; isInitialized = true;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public short extract_ushort(){ //debug.log ("extract_ushort"); if (!isInitialized || !(realType().kind().value() == TCKind._tk_ushort)) throw new BAD_OPERATION(); return (short)value;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_ulong(int l){ //debug.log ("insert_ulong"); typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_ulong); value = l; isInitialized = true;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public int extract_ulong(){ //debug.log ("extract_ulong"); if (!isInitialized || !(realType().kind().value() == TCKind._tk_ulong)) throw new BAD_OPERATION(); return (int)value;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_float(float f){ //debug.log ("insert_float"); typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_float); value = Float.floatToIntBits(f); isInitialized = true;}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public float extract_float(){ //debug.log ("extract_float"); if (!isInitialized || !(realType().kind().value() == TCKind._tk_float)) throw new BAD_OPERATION(); return Float.intBitsToFloat((int)value);}/** * See the description of the <a href="#anyOps">general Any operations.</a> */public void insert_double(double d){ //debug.log ("insert_double"); typeCode = TypeCodeImpl.get_primitive_tc(TCKind.tk_double); value = Double.doubleToLongBits(d); isInitialized = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -