📄 typecodeimpl.java
字号:
myKind == TCKind._tk_array) { if ( ! myRealType.content_type().equivalent(otherRealType.content_type())) return false; } if (myKind == TCKind._tk_struct || myKind == TCKind._tk_union || myKind == TCKind._tk_except || myKind == TCKind._tk_value) { for (int i=0; i<myRealType.member_count(); i++) { if ( ! myRealType.member_type(i).equivalent( otherRealType.member_type(i))) return false; } } } catch (BadKind e) { // impossible if we checked correctly above throw wrapper.badkindCannotOccur() ; } catch (org.omg.CORBA.TypeCodePackage.Bounds e) { // impossible if we checked correctly above throw wrapper.boundsCannotOccur() ; } // Structural comparison succeeded! return true; } public TypeCode get_compact_typecode() { // _REVISIT_ It isn't clear whether this method should operate on this or a copy. // For now just return this unmodified because the name and member_name fields // aren't used for comparison anyways. return this; } public TCKind kind() { if (_kind == tk_indirect) return indirectType().kind(); return TCKind.from_int(_kind); } public boolean is_recursive() { // Recursive is the only form of indirect type codes right now. // Indirection can also be used for repeated type codes. return (_kind == tk_indirect); } public String id() throws BadKind { switch (_kind) { case tk_indirect: //return indirectType().id(); // same as _id case TCKind._tk_except: case TCKind._tk_objref: case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_enum: case TCKind._tk_alias: case TCKind._tk_value: case TCKind._tk_value_box: case TCKind._tk_native: case TCKind._tk_abstract_interface: // exception and objref typecodes must have a repository id. // structs, unions, enums, and aliases may or may not. return _id; default: // all other typecodes throw the BadKind exception. throw new BadKind(); } } public String name() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().name(); case TCKind._tk_except: case TCKind._tk_objref: case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_enum: case TCKind._tk_alias: case TCKind._tk_value: case TCKind._tk_value_box: case TCKind._tk_native: case TCKind._tk_abstract_interface: return _name; default: throw new BadKind(); } } public int member_count() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().member_count(); case TCKind._tk_except: case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_enum: case TCKind._tk_value: return _memberCount; default: throw new BadKind(); } } public String member_name(int index) throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds { switch (_kind) { case tk_indirect: return indirectType().member_name(index); case TCKind._tk_except: case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_enum: case TCKind._tk_value: try { return _memberNames[index]; } catch (ArrayIndexOutOfBoundsException e) { throw new org.omg.CORBA.TypeCodePackage.Bounds(); } default: throw new BadKind(); } } public TypeCode member_type(int index) throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds { switch (_kind) { case tk_indirect: return indirectType().member_type(index); case TCKind._tk_except: case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_value: try { return _memberTypes[index]; } catch (ArrayIndexOutOfBoundsException e) { throw new org.omg.CORBA.TypeCodePackage.Bounds(); } default: throw new BadKind(); } } public Any member_label(int index) throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds { switch (_kind) { case tk_indirect: return indirectType().member_label(index); case TCKind._tk_union: try { // _REVISIT_ Why create a new Any for this? return new AnyImpl(_orb, _unionLabels[index]); } catch (ArrayIndexOutOfBoundsException e) { throw new org.omg.CORBA.TypeCodePackage.Bounds(); } default: throw new BadKind(); } } public TypeCode discriminator_type() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().discriminator_type(); case TCKind._tk_union: return _discriminator; default: throw new BadKind(); } } public int default_index() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().default_index(); case TCKind._tk_union: return _defaultIndex; default: throw new BadKind(); } } public int length() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().length(); case TCKind._tk_string: case TCKind._tk_wstring: case TCKind._tk_sequence: case TCKind._tk_array: return _length; default: throw new BadKind(); } } public TypeCode content_type() throws BadKind { switch (_kind) { case tk_indirect: return indirectType().content_type(); case TCKind._tk_sequence: return lazy_content_type(); case TCKind._tk_array: case TCKind._tk_alias: case TCKind._tk_value_box: return _contentType; default: throw new BadKind(); } } public short fixed_digits() throws BadKind { switch (_kind) { case TCKind._tk_fixed: return _digits; default: throw new BadKind(); } } public short fixed_scale() throws BadKind { switch (_kind) { case TCKind._tk_fixed: return _scale; 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) { _kind = tcis.read_long(); // Bug fix 5034649: allow for padding that precedes the typecode kind. int myPosition = tcis.getTopLevelPosition()-4; // check validity of kind if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) { throw wrapper.cannotMarshalBadTckind() ; } // Don't do any work if this is native if (_kind == TCKind._tk_native) throw wrapper.cannotMarshalNative() ; // 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 wrapper.invalidIndirection( new Integer(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 wrapper.indirectionNotFound( new Integer(indirectTypePosition) ) ; 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 wrapper.cannotMarshalBadTckind() ; } // Don't do any work if this is native if (_kind == TCKind._tk_native) throw wrapper.cannotMarshalNative() ; if (_kind == tk_indirect) { throw wrapper.recursiveTypecodeError() ; } } 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 wrapper.invalidSimpleTypecode() ; } break; case COMPLEX: { TypeCodeInputStream _encap = TypeCodeInputStream.readEncapsulation(is, 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)is.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)is.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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -