typecodeimpl.java

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

JAVA
2,106
字号
	TypeCodeOutputStream encap = new TypeCodeOutputStream(_orb, isLittleEndian());	encap.setEnclosingOutputStream(this);        encap.makeEncapsulation();        //if (TypeCodeImpl.debug) System.out.println("Created TypeCodeOutputStream " + encap + " with parent " + this);	return encap;    }    protected void makeEncapsulation() {        // first entry in an encapsulation is the endianess        putEndian();        isEncapsulation = true;    }    public static TypeCodeOutputStream wrapOutputStream(OutputStream os) {        boolean littleEndian = ((os instanceof CDROutputStream) ? ((CDROutputStream)os).isLittleEndian() : false);        TypeCodeOutputStream wrapper = new TypeCodeOutputStream(os.orb(), littleEndian);        wrapper.setEnclosingOutputStream(os);        //if (TypeCodeImpl.debug) System.out.println("Created TypeCodeOutputStream " + wrapper + " with parent " + os);        return wrapper;    }    public int getPosition() {        return getIndex();    }    public int getRealIndex(int index) {        int topPos = getTopLevelPosition();        //if (TypeCodeImpl.debug) System.out.println("TypeCodeOutputStream.getRealIndex using getTopLevelPosition " +            //topPos + " instead of getPosition " + getPosition());	return topPos;    }/*    protected void printBuffer() {        super.printBuffer();    }*/    byte[] getTypeCodeBuffer() {        // Returns the buffer trimmed of the trailing zeros and without the        // known _kind value at the beginning.        byte[] theBuffer = getByteBuffer();        //System.out.println("outBuffer length = " + (getIndex() - 4));        byte[] tcBuffer = new byte[getIndex() - 4];        System.arraycopy(theBuffer, 4, tcBuffer, 0, getIndex() - 4);        return tcBuffer;    }    public void printTypeMap() {        System.out.println("typeMap = {");        Iterator i = typeMap.keySet().iterator();        while (i.hasNext()) {            String id = (String)i.next();            Integer pos = (Integer)typeMap.get(id);            System.out.println("  key = " + id + ", value = " + pos);        }        System.out.println("}");    }}// no chance of subclasses, so no problems with runtime helper lookuppublic final class TypeCodeImpl extends TypeCode {    //static final boolean debug = false;    // the predefined typecode constants    private static final TypeCodeImpl primitiveConstants[] = {	new TypeCodeImpl(TCKind._tk_null),			// tk_null      	new TypeCodeImpl(TCKind._tk_void),			// tk_void      	new TypeCodeImpl(TCKind._tk_short),			// tk_short     	new TypeCodeImpl(TCKind._tk_long),			// tk_long      	new TypeCodeImpl(TCKind._tk_ushort),		// tk_ushort    	new TypeCodeImpl(TCKind._tk_ulong),			// tk_ulong     	new TypeCodeImpl(TCKind._tk_float),			// tk_float     	new TypeCodeImpl(TCKind._tk_double),		// tk_double    	new TypeCodeImpl(TCKind._tk_boolean),		// tk_boolean   	new TypeCodeImpl(TCKind._tk_char),			// tk_char      	new TypeCodeImpl(TCKind._tk_octet),			// tk_octet     	new TypeCodeImpl(TCKind._tk_any),			// tk_any       	new TypeCodeImpl(TCKind._tk_TypeCode),		// tk_typecode  	new TypeCodeImpl(TCKind._tk_Principal),		// tk_principal 	new TypeCodeImpl(TCKind._tk_objref),		// tk_objref    	null,						// tk_struct    	null,						// tk_union     	null,						// tk_enum      	new TypeCodeImpl(TCKind._tk_string),		// tk_string    	null,						// tk_sequence  	null,						// tk_array     	null,						// tk_alias     	null,						// tk_except    	new TypeCodeImpl(TCKind._tk_longlong),		// tk_longlong  	new TypeCodeImpl(TCKind._tk_ulonglong),		// tk_ulonglong 	new TypeCodeImpl(TCKind._tk_longdouble),		// tk_longdouble	new TypeCodeImpl(TCKind._tk_wchar),			// tk_wchar     	new TypeCodeImpl(TCKind._tk_wstring),		// tk_wstring	new TypeCodeImpl(TCKind._tk_fixed),         // tk_fixed	new TypeCodeImpl(TCKind._tk_value),			// tk_value	new TypeCodeImpl(TCKind._tk_value_box),		// tk_value_box	new TypeCodeImpl(TCKind._tk_native),		// tk_native	new TypeCodeImpl(TCKind._tk_abstract_interface)	// tk_abstract_interface       };    // the indirection TCKind, needed for recursive typecodes.     protected static final int tk_indirect = 0xFFFFFFFF;      // typecode encodings have three different categories that determine    // how the encoding should be done.      private static final int EMPTY = 0;	// no parameters    private static final int SIMPLE = 1;	// simple parameters.    private static final int COMPLEX = 2; // complex parameters. need to    // use CDR encapsulation for    // parameters       // a table storing the encoding category for the various typecodes.      private static final int typeTable[] = {	EMPTY,	// tk_null      	EMPTY,	// tk_void      	EMPTY,	// tk_short     	EMPTY,	// tk_long      	EMPTY,	// tk_ushort    	EMPTY,	// tk_ulong     	EMPTY,	// tk_float     	EMPTY,	// tk_double    	EMPTY,	// tk_boolean   	EMPTY,	// tk_char      	EMPTY,	// tk_octet     	EMPTY,	// tk_any       	EMPTY,	// tk_typecode  	EMPTY,	// tk_principal 	COMPLEX,	// tk_objref    	COMPLEX,	// tk_struct    	COMPLEX,	// tk_union     	COMPLEX,	// tk_enum      	SIMPLE,	// tk_string    	COMPLEX,	// tk_sequence  	COMPLEX,	// tk_array     	COMPLEX,	// tk_alias     	COMPLEX,	// tk_except    	EMPTY,	// tk_longlong  	EMPTY,	// tk_ulonglong 	EMPTY,	// tk_longdouble	EMPTY,	// tk_wchar     	SIMPLE,	// tk_wstring	SIMPLE,	// tk_fixed	COMPLEX,	// tk_value	COMPLEX,	// tk_value_box	COMPLEX,	// tk_native	COMPLEX	// tk_abstract_interface    };    // Maps TCKind values to names    private static final String[] kindNames = {        "null",        "void",        "short",        "long",        "ushort",        "ulong",        "float",        "double",        "boolean",        "char",        "octet",        "any",        "typecode",        "principal",        "objref",        "struct",        "union",        "enum",        "string",        "sequence",        "array",        "alias",        "exception",        "longlong",        "ulonglong",        "longdouble",        "wchar",        "wstring",        "fixed",        "value",        "valueBox",        "native",        "abstractInterface"    };private int 		_kind		= 0;	// the typecode kind// data members for representing the various kinds of typecodes. private String          _id             = "";   // the typecode repository idprivate String          _name           = "";   // the typecode nameprivate int             _memberCount    = 0;    // member countprivate String          _memberNames[]  = null; // names of membersprivate TypeCodeImpl    _memberTypes[]  = null; // types of membersprivate AnyImpl         _unionLabels[]  = null; // values of union labelsprivate TypeCodeImpl    _discriminator  = null; // union discriminator typeprivate int             _defaultIndex   = -1;   // union default indexprivate int             _length         = 0;    // string/seq/array lengthprivate TypeCodeImpl    _contentType    = null; // seq/array/alias type// fixedprivate short           _digits         = 0;private short           _scale          = 0;// value type// _REVISIT_ We might want to keep references to the ValueMember classes// passed in at initialization instead of copying the relevant data.// Is the data immutable? What about StructMember, UnionMember etc.?private short           _type_modifier  = -1;   // VM_NONE, VM_CUSTOM,// VM_ABSTRACT, VM_TRUNCATABLEprivate TypeCodeImpl    _concrete_base  = null; // concrete base typeprivate short           _memberAccess[] = null; // visibility of ValueMember// recursive sequence supportprivate TypeCodeImpl    _parent         = null; // the enclosing type codeprivate int             _parentOffset   = 0;    // the level of enclosure// recursive type code supportprivate TypeCodeImpl    _indirectType   = null;// caches the byte buffer written in write_value for quick remarshaling...private byte[] outBuffer                = null;// ... but only if caching is enabledprivate boolean cachingEnabled          = false;// the ORB instance: may be instanceof ORBSingleton or ORBprivate org.omg.CORBA.ORB _orb; 		///////////////////////////////////////////////////////////////////////////// Constructors...public TypeCodeImpl(org.omg.CORBA.ORB orb) {    // initialized to tk_null    _orb = orb;}  public TypeCodeImpl(org.omg.CORBA.ORB orb, TypeCode tc)// to handle conversion of "remote" typecodes into "native" style.// also see the 'convertToNative(ORB orb, TypeCode tc)' function{    // the orb object    _orb = orb;    // This is a protection against misuse of this constructor.    // Should only be used if tc is not an instance of this class!    // Otherwise we run into problems with recursive/indirect type codes.    // _REVISIT_ We should make this constructor private    if (tc instanceof TypeCodeImpl) {	TypeCodeImpl tci = (TypeCodeImpl)tc;	if (tci._kind == tk_indirect)	    throw new BAD_TYPECODE();	if (tci._kind == TCKind._tk_sequence && tci._contentType == null)	    throw new BAD_TYPECODE();    }    // set up kind    _kind 	= tc.kind().value();    try {	// set up parameters	switch (_kind) {	case TCKind._tk_value:	    _type_modifier = tc.type_modifier();	    // concrete base may be null	    TypeCode tccb = tc.concrete_base_type();	    if (tccb != null) {		_concrete_base = convertToNative(_orb, tccb);	    } else {		_concrete_base = null;	    }	    //_memberAccess = tc._memberAccess;	    // Need to reconstruct _memberAccess using member_count() and member_visibility()	    _memberAccess = new short[tc.member_count()];	    for (int i=0; i < tc.member_count(); i++) {		_memberAccess[i] = tc.member_visibility(i);	    }	case TCKind._tk_except:	case TCKind._tk_struct:	case TCKind._tk_union:	    // set up member types	    _memberTypes = new TypeCodeImpl[tc.member_count()];	    for (int i=0; i < tc.member_count(); i++) {	        _memberTypes[i] = convertToNative(_orb, tc.member_type(i));		_memberTypes[i].setParent(this);	    }	case TCKind._tk_enum:	    // set up member names	    _memberNames = new String[tc.member_count()];	    for (int i=0; i < tc.member_count(); i++) {	        _memberNames[i] = tc.member_name(i);	    }	    // set up member count	    _memberCount = tc.member_count();	case TCKind._tk_objref:	case TCKind._tk_alias:	case TCKind._tk_value_box:	case TCKind._tk_native:	case TCKind._tk_abstract_interface:	    setId(tc.id());	    _name = tc.name();	    break;	}      	// set up stuff for unions	switch (_kind) {	case TCKind._tk_union:	    _discriminator = convertToNative(_orb, tc.discriminator_type());	    _defaultIndex  = tc.default_index();	    _unionLabels = new AnyImpl[_memberCount];	    for (int i=0; i < _memberCount; i++)		_unionLabels[i] = new AnyImpl(_orb, tc.member_label(i));	    break;	}      	// set up length	switch (_kind) {	case TCKind._tk_string:	case TCKind._tk_wstring:	case TCKind._tk_sequence:	case TCKind._tk_array:	    _length = tc.length();	}      	// set up content type	switch (_kind) {	case TCKind._tk_sequence:	case TCKind._tk_array:	case TCKind._tk_alias:	case TCKind._tk_value_box:	    _contentType = convertToNative(_orb, tc.content_type());	}    } catch (org.omg.CORBA.TypeCodePackage.Bounds e) {} catch (BadKind e) {}    // dont have to worry about these since code ensures we dont step    // out of bounds.}    public TypeCodeImpl(int creationKind)// for primitive types{    // the orb object    _orb = null;    // private API. dont bother checking that    //     (creationKind < 0 || creationKind > typeTable.length)    _kind = creationKind;    // do initialization for special cases    switch (_kind) {    case TCKind._tk_objref:	{	    // this is being used to create typecode for CORBA::Object	    setId("IDL:omg.org/CORBA/Object:1.0");	    _name = "Object";	    break;	}    case TCKind._tk_string:    case TCKind._tk_wstring:	{	    _length =0;	    break;	}    case TCKind._tk_value:	{	    _concrete_base = null;	    break;	}    }}public TypeCodeImpl(org.omg.CORBA.ORB orb,		    int creationKind,		    String id,		    String name,		    StructMember[] members)		    // for structs and exceptions{    // the orb object    _orb = orb;    if ((creationKind == TCKind._tk_struct) || (creationKind == TCKind._tk_except))	{		    _kind		= creationKind;	    setId(id);	    _name		= name;	    _memberCount	= members.length;		    _memberNames = new String[_memberCount];	    _memberTypes = new TypeCodeImpl[_memberCount];	    for (int i = 0 ; i < _memberCount ; i++) {		_memberNames[i] = members[i].name;		_memberTypes[i] = convertToNative(_orb, members[i].type);		_memberTypes[i].setParent(this);	    }	} // else initializes to null}public TypeCodeImpl(org.omg.CORBA.ORB orb, 		    int creationKind,		    String id,		    String name,		    TypeCode discriminator_type,		    UnionMember[] members)		    // for unions{    // the orb object    _orb = orb;    if (creationKind == TCKind._tk_union) {        _kind		= creationKind;        setId(id);        _name		= name;        _memberCount	= members.length;        _discriminator	= convertToNative(_orb, discriminator_type);        _memberNames = new String[_memberCount];        _memberTypes = new TypeCodeImpl[_memberCount];        _unionLabels = new AnyImpl[_memberCount];

⌨️ 快捷键说明

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