typecodeimpl.java
来自「java jdk 1.4的源码」· Java 代码 · 共 2,106 行 · 第 1/5 页
JAVA
2,106 行
for (int i = 0 ; i < _memberCount ; i++) { _memberNames[i] = members[i].name; _memberTypes[i] = convertToNative(_orb, members[i].type); _memberTypes[i].setParent(this); _unionLabels[i] = new AnyImpl(_orb, members[i].label); // check whether this is the default branch. if (_unionLabels[i].type().kind() == TCKind.tk_octet) { if (_unionLabels[i].extract_octet() == (byte)0) { _defaultIndex = i; } } } } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, String id, String name, short type_modifier, TypeCode concrete_base, ValueMember[] members) // for value types{ // the orb object _orb = orb; if (creationKind == TCKind._tk_value) { _kind = creationKind; setId(id); _name = name; _type_modifier = type_modifier; if (_concrete_base != null) { _concrete_base = convertToNative(_orb, concrete_base); } _memberCount = members.length; _memberNames = new String[_memberCount]; _memberTypes = new TypeCodeImpl[_memberCount]; _memberAccess = new short[_memberCount]; for (int i = 0 ; i < _memberCount ; i++) { _memberNames[i] = members[i].name; _memberTypes[i] = convertToNative(_orb, members[i].type); _memberTypes[i].setParent(this); _memberAccess[i] = members[i].access; } } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, String id, String name, String[] members) // for enums{ // the orb object _orb = orb; if (creationKind == TCKind._tk_enum) { _kind = creationKind; setId(id); _name = name; _memberCount = members.length; _memberNames = new String[_memberCount]; for (int i = 0 ; i < _memberCount ; i++) _memberNames[i] = members[i]; } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, String id, String name, TypeCode original_type) // for aliases and value boxes{ // the orb object _orb = orb; if ( creationKind == TCKind._tk_alias || creationKind == TCKind._tk_value_box ) { _kind = creationKind; setId(id); _name = name; _contentType = convertToNative(_orb, original_type); } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, String id, String name){ // the orb object _orb = orb; if (creationKind == TCKind._tk_objref || creationKind == TCKind._tk_native || creationKind == TCKind._tk_abstract_interface) { _kind = creationKind; setId(id); _name = name; } // else initializes to null} public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, int bound) // for strings{ if (bound < 0) throw new BAD_PARAM("bound can not be negative!"); // the orb object _orb = orb; if ((creationKind == TCKind._tk_string) || (creationKind == TCKind._tk_wstring)) { _kind = creationKind; _length = bound; } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, int creationKind, int bound, TypeCode element_type) // for sequences and arrays{ // the orb object _orb = 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(org.omg.CORBA.ORB orb, int creationKind, int bound, int offset) // for recursive sequences{ // the orb object _orb = orb; if (creationKind == TCKind._tk_sequence) { _kind = creationKind; _length = bound; _parentOffset = offset; } // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, String id) // for recursive type codes{ // the orb object _orb = 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(org.omg.CORBA.ORB orb, int creationKind, short digits, short scale) // for fixed{ // the orb object _orb = 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...public static TypeCodeImpl get_primitive_tc(TCKind tcKind){ try { return primitiveConstants[tcKind.value()]; } catch (Throwable t) { throw new BAD_OPERATION("Invalid or unavailable typecode for kind = "+tcKind.value()); }}public static TypeCodeImpl get_primitive_tc(int val){ try { return primitiveConstants[val]; } catch (Throwable t) { throw new BAD_OPERATION("Invalid or unavailable typecode for kind = "+val); }}// 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(org.omg.CORBA.ORB orb, TypeCode tc) { if (tc instanceof TypeCodeImpl) return (TypeCodeImpl) tc; else return new TypeCodeImpl(orb, tc);}public static CDROutputStream newOutputStream(org.omg.CORBA.ORB orb) { TypeCodeOutputStream tcos = new TypeCodeOutputStream(orb); //if (debug) System.out.println("Created TypeCodeOutputStream " + tcos + " with no parent"); return tcos;}// Support for indirect/recursive type codesprivate TypeCodeImpl indirectType() { _indirectType = tryIndirectType(); if (_indirectType == null) { // Nothing we can do about that. throw new BAD_TYPECODE("Invoked operation on unresolved recursive type code!"); } return _indirectType;}private TypeCodeImpl tryIndirectType() { // Assert that _kind == tk_indirect if (_indirectType != null) return _indirectType; if (_orb instanceof TypeCodeFactory) { setIndirectType(((TypeCodeFactory)_orb).getTypeCode(_id)); } else { throw new BAD_TYPECODE("ORB not supporting recursive type codes!"); } return _indirectType;}private void setIndirectType(TypeCodeImpl newType) { _indirectType = newType; if (_indirectType != null) { try { _id = _indirectType.id(); } catch (BadKind e) {} // can't happen }}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 new BAD_TYPECODE("Invoked operation on unresolved recursive type code!"); 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, realParent._id); } } } return _contentType;}// Other private functionsprivate 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 } return realType;}///////////////////////////////////////////////////////////////////////////// TypeCode operationspublic 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(get_primitive_tc(_kind).id()) == 0) { return true; } if (tc.id().compareTo(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: {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?