typecodeimpl.java

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

JAVA
2,106
字号
		    // check for member count		    if (_memberCount != tc.member_count())			return false;		    // check for repository id		    if (_id.compareTo(tc.id()) != 0)			return false;		    // check for default index		    if (_defaultIndex != tc.default_index())			return false;		    // check for discriminator type		    if (!_discriminator.equal(tc.discriminator_type()))			return false;		    // check for label types and values		    for (int i = 0 ; i < _memberCount ; i++)			if (! _unionLabels[i].equal(tc.member_label(i)))			    return false;		    // check for branch types		    for (int i = 0 ; i < _memberCount ; i++)			if (! _memberTypes[i].equal(tc.member_type(i)))			    return false;		    // ignore id and names since those are optional.		    return true;		}	    case TCKind._tk_enum:		{		    // check for repository id		    if (_id.compareTo(tc.id()) != 0)			return false;		    // check member count		    if (_memberCount != tc.member_count())			return false;		    // ignore names since those are optional.		    return true;		}	    case TCKind._tk_sequence:	    case TCKind._tk_array:		{		    // check bound/length		    if (_length != tc.length()) {			return false;		    }		    // check content type		    if (! lazy_content_type().equal(tc.content_type())) {			return false;		    }		    // ignore id and name since those are optional.		    return true;		}	    case TCKind._tk_value:		{		    // check for member count		    if (_memberCount != tc.member_count())			return false;		    // check for repository id		    if (_id.compareTo(tc.id()) != 0)			return false;		    // check for member types.		    for (int i = 0 ; i < _memberCount ; i++)			if (_memberAccess[i] != tc.member_visibility(i) ||			    ! _memberTypes[i].equal(tc.member_type(i)))			    return false;		    if (_type_modifier == tc.type_modifier())			return false;		    // concrete_base may be null		    TypeCode tccb = tc.concrete_base_type();		    if ((_concrete_base == null && tccb != null) ||			(_concrete_base != null && tccb == null) ||			! _concrete_base.equal(tccb))		    {			return false;		    }		    // ignore id and names since those are optional.		    return true;		}	    case TCKind._tk_alias:	    case TCKind._tk_value_box:		{		    // check for repository id		    if (_id.compareTo(tc.id()) != 0) {			return false;		    }		    // check for equality with the true type		    return _contentType.equal(tc.content_type());		}	    }	}    } catch (org.omg.CORBA.TypeCodePackage.Bounds e) {} catch (BadKind e) {}    // dont have to worry about these since the code ensures these dont    // arise.    return false;}/*** The equivalent operation is used by the ORB when determining type equivalence* for values stored in an IDL any.*/public boolean equivalent(TypeCode tc) {    if (tc == this) {        return true;    }    // If the result of the kind operation on either TypeCode is tk_alias, recursively    // replace the TypeCode with the result of calling content_type, until the kind is no    // longer tk_alias.    // Note: Always resolve indirect types first!    TypeCode myRealType = (_kind == tk_indirect ? indirectType() : this);    myRealType = realType(myRealType);    TypeCode otherRealType = realType(tc);    // If results of the kind operation on each typecode differ, equivalent returns false.    if (myRealType.kind().value() != otherRealType.kind().value()) {        return false;    }    String myID = null;    String otherID = null;    try {        myID = this.id();        otherID = tc.id();        // At this point the id operation is valid for both TypeCodes.        // Return true if the results of id for both TypeCodes are non-empty strings        // and both strings are equal.        // If both ids are non-empty but are not equal, then equivalent returns FALSE.        if (myID != null && otherID != null) {            return (myID.equals(otherID));        }    } catch (BadKind e) {        // id operation is not valid for either or both TypeCodes    }    // If either or both id is an empty string, or the TypeCode kind does not support    // the id operation, perform a structural comparison of the TypeCodes.    int myKind = myRealType.kind().value();    try {        if (myKind == TCKind._tk_struct ||            myKind == TCKind._tk_union ||            myKind == TCKind._tk_enum ||            myKind == TCKind._tk_except ||            myKind == TCKind._tk_value)        {            if (myRealType.member_count() != otherRealType.member_count())                return false;        }        if (myKind == TCKind._tk_union)        {            if (myRealType.default_index() != otherRealType.default_index())                return false;        }        if (myKind == TCKind._tk_string ||            myKind == TCKind._tk_wstring ||            myKind == TCKind._tk_sequence ||            myKind == TCKind._tk_array)        {            if (myRealType.length() != otherRealType.length())                return false;        }        if (myKind == TCKind._tk_fixed)        {            if (myRealType.fixed_digits() != otherRealType.fixed_digits() ||                myRealType.fixed_scale() != otherRealType.fixed_scale())                return false;        }        if (myKind == TCKind._tk_union)        {            for (int i=0; i<myRealType.member_count(); i++) {                if (myRealType.member_label(i) != otherRealType.member_label(i))                    return false;            }            if ( ! myRealType.discriminator_type().equivalent(otherRealType.discriminator_type()))                return false;        }        if (myKind == TCKind._tk_alias ||            myKind == TCKind._tk_value_box ||            myKind == TCKind._tk_sequence ||            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 new INTERNAL();    } catch (org.omg.CORBA.TypeCodePackage.Bounds e) {        // impossible if we checked correctly above        throw new INTERNAL();    }    // 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;

⌨️ 快捷键说明

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