📄 anyimpl.java
字号:
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 wrapper.errorResolvingAlias() ; case TCKind._tk_longdouble: throw wrapper.tkLongDoubleNotSupported() ; default: throw wrapper.typecodeNotSupported() ; } } catch (BadKind badKind) { // impossible throw wrapper.badkindCannotOccur() ; } catch (Bounds bounds) { // impossible throw wrapper.boundsCannotOccur() ; } } /////////////////////////////////////////////////////////////////////////// // 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); } /** * returns an input stream that an Any value can be marshaled out of. * * @result the InputStream to marshal value of Any out of. */ public org.omg.CORBA.portable.InputStream create_input_stream() { // // We create a new InputStream so that multiple threads can call here // and read the streams in parallel without thread safety problems. // //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 wrapper.invalidIsstreamedTckind( CompletionStatus.COMPLETED_MAYBE, new Integer(kind)) ; } 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, realType(), 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 = orb.get_primitive_tc(TCKind._tk_short); value = s; isInitialized = true; } private String getTCKindName( int tc ) { if ((tc >= 0) && (tc < TypeCodeImpl.kindNames.length)) return TypeCodeImpl.kindNames[tc] ; else return "UNKNOWN(" + tc + ")" ; } private void checkExtractBadOperation( int expected ) { if (!isInitialized) throw wrapper.extractNotInitialized() ; int tc = realType().kind().value() ; if (tc != expected) { String tcName = getTCKindName( tc ) ; String expectedName = getTCKindName( expected ) ; throw wrapper.extractWrongType( expectedName, tcName ) ; } } private void checkExtractBadOperationList( int[] expected ) { if (!isInitialized) throw wrapper.extractNotInitialized() ; int tc = realType().kind().value() ; for (int ctr=0; ctr<expected.length; ctr++) if (tc == expected[ctr]) return ; List list = new ArrayList() ; for (int ctr=0; ctr<expected.length; ctr++) list.add( getTCKindName( expected[ctr] ) ) ; String tcName = getTCKindName( tc ) ; throw wrapper.extractWrongTypeList( list, tcName ) ; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public short extract_short() { //debug.log ("extract_short"); checkExtractBadOperation( TCKind._tk_short ) ; 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 = orb.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"); checkExtractBadOperationList( new int[] { TCKind._tk_long, TCKind._tk_enum } ) ; 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 = orb.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"); checkExtractBadOperation( TCKind._tk_ushort ) ; 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 = orb.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"); checkExtractBadOperation( TCKind._tk_ulong ) ; 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 = orb.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"); checkExtractBadOperation( TCKind._tk_float ) ; 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 = orb.get_primitive_tc(TCKind._tk_double); value = Double.doubleToLongBits(d); isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public double extract_double() { //debug.log ("extract_double"); checkExtractBadOperation( TCKind._tk_double ) ; return Double.longBitsToDouble(value); } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_longlong(long l) { //debug.log ("insert_longlong"); typeCode = orb.get_primitive_tc(TCKind._tk_longlong); value = l; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public long extract_longlong() { //debug.log ("extract_longlong"); checkExtractBadOperation( TCKind._tk_longlong ) ; return value; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_ulonglong(long l) { //debug.log ("insert_ulonglong"); typeCode = orb.get_primitive_tc(TCKind._tk_ulonglong); value = l; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public long extract_ulonglong() { //debug.log ("extract_ulonglong"); checkExtractBadOperation( TCKind._tk_ulonglong ) ; return value; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_boolean(boolean b) { //debug.log ("insert_boolean"); typeCode = orb.get_primitive_tc(TCKind._tk_boolean); value = (b)? 1:0; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public boolean extract_boolean() { //debug.log ("extract_boolean"); checkExtractBadOperation( TCKind._tk_boolean ) ; return (value == 0)? false: true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_char(char c) { //debug.log ("insert_char"); typeCode = orb.get_primitive_tc(TCKind._tk_char); value = c; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public char extract_char() { //debug.log ("extract_char"); checkExtractBadOperation( TCKind._tk_char ) ; return (char)value; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_wchar(char c) { //debug.log ("insert_wchar"); typeCode = orb.get_primitive_tc(TCKind._tk_wchar); value = c; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public char extract_wchar() { //debug.log ("extract_wchar"); checkExtractBadOperation( TCKind._tk_wchar ) ; return (char)value; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -