typecodeimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 2,106 行 · 第 1/5 页

JAVA
2,106
字号
    default:	throw new BadKind();    }}public short member_visibility(int index) throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds {    switch (_kind) {    case tk_indirect:        return indirectType().member_visibility(index);    case TCKind._tk_value:        try {            return _memberAccess[index];        } catch (ArrayIndexOutOfBoundsException e) {            throw new org.omg.CORBA.TypeCodePackage.Bounds();        }    default:        throw new BadKind();    }}public short type_modifier() throws BadKind {    switch (_kind) {    case tk_indirect:        return indirectType().type_modifier();    case TCKind._tk_value:        return _type_modifier;    default:        throw new BadKind();    }}public TypeCode concrete_base_type() throws BadKind {    switch (_kind) {    case tk_indirect:        return indirectType().concrete_base_type();    case TCKind._tk_value:        return _concrete_base;    default:        throw new BadKind();    }}public void read_value(InputStream is) {    if (is instanceof TypeCodeReader) {	// hardly possible unless caller knows our "private" stream classes.	if (read_value_kind((TypeCodeReader)is))	    read_value_body(is);    } else if (is instanceof CDRInputStream) {        WrapperInputStream wrapper = new WrapperInputStream((CDRInputStream)is);        //if (debug) System.out.println("Created WrapperInputStream " + wrapper + " with no parent");	if (read_value_kind((TypeCodeReader)wrapper))	    read_value_body(wrapper);    } else {	read_value_kind(is);	read_value_body(is);    }}private void read_value_recursive(TypeCodeInputStream is) {    // don't wrap a CDRInputStream reading "inner" TypeCodes.    if (is instanceof TypeCodeReader) {	if (read_value_kind((TypeCodeReader)is))	    read_value_body(is);    } else {	read_value_kind((InputStream)is);	read_value_body(is);    }}boolean read_value_kind(TypeCodeReader tcis) {    int myPosition = tcis.getTopLevelPosition();    _kind = tcis.read_long();    // check validity of kind    if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) {	throw new MARSHAL();    }    // Don't do any work if this is native    if (_kind == TCKind._tk_native)	throw new MARSHAL();    // We have to remember the stream and position for EVERY type code    // in case some recursive or indirect type code references it.    TypeCodeReader topStream = tcis.getTopLevelStream();    if (_kind == tk_indirect) {	int streamOffset = tcis.read_long();	if (streamOffset > -4)	    throw new MARSHAL("Invalid indirection value " + streamOffset);	// The encoding used for indirection is the same as that used for recursive TypeCodes,	// i.e., a 0xffffffff indirection marker followed by a long offset	// (in units of octets) from the beginning of the long offset.        int topPos = tcis.getTopLevelPosition();        // substract 4 to get back to the beginning of the long offset.	int indirectTypePosition = topPos - 4 + streamOffset;	// Now we have to find the referenced type	// by its indirectTypePosition within topStream.        //if (debug) System.out.println("TypeCodeImpl looking up indirection at position topPos " +            //topPos + " - 4 + offset " + streamOffset + " = " + indirectTypePosition);	TypeCodeImpl type = topStream.getTypeCodeAtPosition(indirectTypePosition);        if (type == null)	    throw new MARSHAL("Referenced type of indirect type not marshaled!");        setIndirectType(type);	return false;    }    topStream.addTypeCodeAtPosition(this, myPosition);    return true;}void read_value_kind(InputStream is) {    // unmarshal the kind    _kind = is.read_long();    // check validity of kind    if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) {	throw new MARSHAL();    }    // Don't do any work if this is native    if (_kind == TCKind._tk_native)	throw new MARSHAL();    if (_kind == tk_indirect) {	throw new MARSHAL("InputStream subtype not supporting recursive type codes!");    }}void read_value_body(InputStream is) {    // start unmarshaling the rest of the typecode, based on the    // encoding (empty, simple or complex).    switch (typeTable[_kind]) {    case EMPTY:	// nothing to unmarshal	break;    case SIMPLE:	switch (_kind) {	case TCKind._tk_string:	case TCKind._tk_wstring:	    _length = is.read_long();	    break;	case TCKind._tk_fixed:	    _digits = is.read_ushort();	    _scale = is.read_short();	    break;	default:	    throw new MARSHAL();	}	break;    case COMPLEX:	{	    TypeCodeInputStream _encap = TypeCodeInputStream.readEncapsulation(is, _orb);	    switch(_kind) {	    case TCKind._tk_objref:	    case TCKind._tk_abstract_interface:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		}		break;	    case TCKind._tk_union:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		    // discriminant typecode		    _discriminator = new TypeCodeImpl(_orb);		    _discriminator.read_value_recursive(_encap);		    // default index		    _defaultIndex = _encap.read_long();		    // get the number of members		    _memberCount = _encap.read_long();		    // create arrays for the label values, names and types of members		    _unionLabels = new AnyImpl[_memberCount];		    _memberNames = new String[_memberCount];		    _memberTypes = new TypeCodeImpl[_memberCount];		    // read off label values, names and types		    for (int i=0; i < _memberCount; i++) {			_unionLabels[i] = new AnyImpl(_orb);			if (i == _defaultIndex) 			    // for the default case, read off the zero octet			    _unionLabels[i].insert_octet(_encap.read_octet());			else {			    switch (realType(_discriminator).kind().value()) {			    case TCKind._tk_short:				_unionLabels[i].insert_short(_encap.read_short());				break;			    case TCKind._tk_long:				_unionLabels[i].insert_long(_encap.read_long());				break;			    case TCKind._tk_ushort:				_unionLabels[i].insert_ushort(_encap.read_short());				break;			    case TCKind._tk_ulong:				_unionLabels[i].insert_ulong(_encap.read_long());				break;			    case TCKind._tk_float:				_unionLabels[i].insert_float(_encap.read_float());				break;			    case TCKind._tk_double:				_unionLabels[i].insert_double(_encap.read_double());				break;			    case TCKind._tk_boolean:				_unionLabels[i].insert_boolean(_encap.read_boolean());				break;			    case TCKind._tk_char:				_unionLabels[i].insert_char(_encap.read_char());				break;			    case TCKind._tk_enum:				_unionLabels[i].type(_discriminator);				_unionLabels[i].insert_long(_encap.read_long());				break;			    case TCKind._tk_longlong:				_unionLabels[i].insert_longlong(_encap.read_longlong());				break;			    case TCKind._tk_ulonglong:				_unionLabels[i].insert_ulonglong(_encap.read_longlong());				break;				// _REVISIT_ figure out long double mapping				// case TCKind.tk_longdouble:				// _unionLabels[i].insert_longdouble(_encap.getDouble());				// break;                            case TCKind._tk_wchar:				_unionLabels[i].insert_wchar(_encap.read_wchar());                                break;			    default:				throw new MARSHAL();			    }			}			_memberNames[i] = _encap.read_string();			_memberTypes[i] = new TypeCodeImpl(_orb);			_memberTypes[i].read_value_recursive(_encap);			_memberTypes[i].setParent(this);		    }		}		break;	    case TCKind._tk_enum:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		    // get the number of members		    _memberCount = _encap.read_long();		    // create arrays for the identifier names		    _memberNames = new String[_memberCount];		    // read off identifier names		    for (int i=0; i < _memberCount; i++)			_memberNames[i] = _encap.read_string();		}		break;	    case TCKind._tk_sequence:		{		    // get the type of the sequence		    _contentType = new TypeCodeImpl(_orb);		    _contentType.read_value_recursive(_encap);	    		    // get the bound on the length of the sequence		    _length = _encap.read_long();		}		break;	    case TCKind._tk_array:		{		    // get the type of the array		    _contentType = new TypeCodeImpl(_orb);		    _contentType.read_value_recursive(_encap);		    // get the length of the array		    _length = _encap.read_long();		}		break;	    case TCKind._tk_alias:	    case TCKind._tk_value_box:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		    // get the type aliased		    _contentType = new TypeCodeImpl(_orb);		    _contentType.read_value_recursive(_encap);		}		break;	    case TCKind._tk_except:	    case TCKind._tk_struct:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		    // get the number of members		    _memberCount = _encap.read_long();		    // create arrays for the names and types of members		    _memberNames = new String[_memberCount];		    _memberTypes = new TypeCodeImpl[_memberCount];		    // read off member names and types		    for (int i=0; i < _memberCount; i++) {			_memberNames[i] = _encap.read_string();			_memberTypes[i] = new TypeCodeImpl(_orb);                        //if (debug) System.out.println("TypeCode " + _name + " reading member " + _memberNames[i]);			_memberTypes[i].read_value_recursive(_encap);			_memberTypes[i].setParent(this);		    }		}		break;	    case TCKind._tk_value:		{		    // get the repository id		    setId(_encap.read_string());		    // get the name		    _name = _encap.read_string();		    // get the type modifier		    _type_modifier = _encap.read_short();		    // get the type aliased		    _concrete_base = new TypeCodeImpl(_orb);		    _concrete_base.read_value_recursive(_encap);		    if (_concrete_base.kind().value() == TCKind._tk_null) {			_concrete_base = null;		    }		    // get the number of members		    _memberCount = _encap.read_long();		    // create arrays for the names, types and visibility of members		    _memberNames = new String[_memberCount];		    _memberTypes = new TypeCodeImpl[_memberCount];		    _memberAccess = new short[_memberCount];		    // read off value member visibilities		    for (int i=0; i < _memberCount; i++) {			_memberNames[i] = _encap.read_string();			_memberTypes[i] = new TypeCodeImpl(_orb);                        //if (debug) System.out.println("TypeCode " + _name + " reading member " + _memberNames[i]);			_memberTypes[i].read_value_recursive(_encap);			_memberTypes[i].setParent(this);			_memberAccess[i] = _encap.read_short();		    }		}		break;	    default:		throw new MARSHAL();	    }	    break;	}    }}public void write_value(OutputStream os) {    // Wrap OutputStream into TypeCodeOutputStream.    // This test shouldn't be necessary according to the Java language spec.    if (os instanceof TypeCodeOutputStream) {	this.write_value((TypeCodeOutputStream)os);    } else {        TypeCodeOutputStream wrapperOutStream = null;        if (outBuffer == null) {            wrapperOutStream = TypeCodeOutputStream.wrapOutputStream(os);            this.write_value(wrapperOutStream);            if (cachingEnabled) {                // Cache the buffer for repeated writes                outBuffer = wrapperOutStream.getTypeCodeBuffer();                //if (outBuffer != null)                    //System.out.println("Caching outBuffer with length = " + outBuffer.length +                                       //" for id = " + _id);            }        } else {            //System.out.println("Using cached outBuffer: length = " + outBuffer.length +                               //", id = " + _id);        }        // Write the first 4 bytes first to trigger alignment.        // We know that it is the kind.        if (cachingEnabled && outBuffer != null) {            os.write_long(_kind);            os.write_octet_array(outBuffer, 0, outBuffer.length);        } else {            //System.out.println("Buffer is empty for " + _id);            wrapperOutStream.writeRawBuffer(os, _kind);        }    }}public void write_value(Ty

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?