📄 typecodeimpl.java
字号:
{ _kind = creationKind; setId(id); _name = name; } // else initializes to null } public TypeCodeImpl(ORB orb, int creationKind, int bound) // for strings { this(orb) ; if (bound < 0) throw wrapper.negativeBounds() ; if ((creationKind == TCKind._tk_string) || (creationKind == TCKind._tk_wstring)) { _kind = creationKind; _length = bound; } // else initializes to null } public TypeCodeImpl(ORB orb, int creationKind, int bound, TypeCode element_type) // for sequences and arrays { this(orb) ; if ( creationKind == TCKind._tk_sequence || creationKind == TCKind._tk_array ) { _kind = creationKind; _length = bound; _contentType = convertToNative(_orb, element_type); } // else initializes to null } public TypeCodeImpl(ORB orb, int creationKind, int bound, int offset) // for recursive sequences { this(orb) ; if (creationKind == TCKind._tk_sequence) { _kind = creationKind; _length = bound; _parentOffset = offset; } // else initializes to null } public TypeCodeImpl(ORB orb, String id) // for recursive type codes { this(orb) ; _kind = tk_indirect; // This is the type code of the type we stand in for, not our own. _id = id; // Try to resolve it now. May return null in which case // we try again later (see indirectType()). tryIndirectType(); } public TypeCodeImpl(ORB orb, int creationKind, short digits, short scale) // for fixed { this(orb) ; //if (digits < 1 || digits > 31) //throw new BAD_TYPECODE(); if (creationKind == TCKind._tk_fixed) { _kind = creationKind; _digits = digits; _scale = scale; } // else initializes to null } /////////////////////////////////////////////////////////////////////////// // Other creation functions... // Optimization: // If we checked for and returned constant primitive typecodes // here we could reduce object creation and also enable more // efficient typecode comparisons for primitive typecodes. // protected static TypeCodeImpl convertToNative(ORB orb, TypeCode tc) { if (tc instanceof TypeCodeImpl) return (TypeCodeImpl) tc; else return new TypeCodeImpl(orb, tc); } public static CDROutputStream newOutputStream(ORB orb) { TypeCodeOutputStream tcos = new TypeCodeOutputStream((ORB)orb); //if (debug) System.out.println("Created TypeCodeOutputStream " + tcos + // " with no parent"); return tcos; } // Support for indirect/recursive type codes private TypeCodeImpl indirectType() { _indirectType = tryIndirectType(); if (_indirectType == null) { // Nothing we can do about that. throw wrapper.unresolvedRecursiveTypecode() ; } return _indirectType; } private TypeCodeImpl tryIndirectType() { // Assert that _kind == tk_indirect if (_indirectType != null) return _indirectType; setIndirectType(_orb.getTypeCode(_id)); return _indirectType; } private void setIndirectType(TypeCodeImpl newType) { _indirectType = newType; if (_indirectType != null) { try { _id = _indirectType.id(); } catch (BadKind e) { // can't happen throw wrapper.badkindCannotOccur() ; } } } private void setId(String newID) { _id = newID; if (_orb instanceof TypeCodeFactory) { ((TypeCodeFactory)_orb).setTypeCode(_id, this); } // check whether return value != this which would indicate that the // repository id isn't unique. } private void setParent(TypeCodeImpl parent) { _parent = parent; } private TypeCodeImpl getParentAtLevel(int level) { if (level == 0) return this; if (_parent == null) throw wrapper.unresolvedRecursiveTypecode() ; return _parent.getParentAtLevel(level - 1); } private TypeCodeImpl lazy_content_type() { if (_contentType == null) { if (_kind == TCKind._tk_sequence && _parentOffset > 0 && _parent != null) { // This is an unresolved recursive sequence tc. // Try to resolve it now if the hierarchy is complete. TypeCodeImpl realParent = getParentAtLevel(_parentOffset); if (realParent != null && realParent._id != null) { // Create a recursive type code object as the content type. // This is when the recursive sequence typecode morphes // into a sequence typecode containing a recursive typecode. _contentType = new TypeCodeImpl((ORB)_orb, realParent._id); } } } return _contentType; } // Other private functions private TypeCode realType(TypeCode aType) { TypeCode realType = aType; try { // Note: Indirect types are handled in kind() method while (realType.kind().value() == TCKind._tk_alias) { realType = realType.content_type(); } } catch (BadKind bad) { // impossible throw wrapper.badkindCannotOccur() ; } return realType; } /////////////////////////////////////////////////////////////////////////// // TypeCode operations public final boolean equal(TypeCode tc) // _REVISIT_ for all optional names/ids, we might want to check that // they are equal in case both are non-nil. { if (tc == this) return true; try { if (_kind == tk_indirect) { //return indirectType().equal(tc); if (_id != null && tc.id() != null) return _id.equals(tc.id()); return (_id == null && tc.id() == null); } // make sure kinds are identical. if (_kind != tc.kind().value()) { return false; } switch (typeTable[_kind]) { case EMPTY: // no parameters to check. return true; case SIMPLE: switch (_kind) { case TCKind._tk_string: case TCKind._tk_wstring: // check for bound. return (_length == tc.length()); case TCKind._tk_fixed: return (_digits == tc.fixed_digits() && _scale == tc.fixed_scale()); default: return false; } case COMPLEX: switch(_kind) { case TCKind._tk_objref: { // check for logical id. if (_id.compareTo(tc.id()) == 0) { return true; } if (_id.compareTo( (_orb.get_primitive_tc(_kind)).id()) == 0) { return true; } if (tc.id().compareTo( (_orb.get_primitive_tc(_kind)).id()) == 0) { return true; } return false; } case TCKind._tk_native: case TCKind._tk_abstract_interface: { // check for logical id. if (_id.compareTo(tc.id()) != 0) { return false; } // ignore name since its optional. return true; } case TCKind._tk_struct: case TCKind._tk_except: { // 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 (! _memberTypes[i].equal(tc.member_type(i))) return false; // ignore id and names since those are optional. return true; } case TCKind._tk_union: { // 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 ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -