📄 typecodeimpl.java
字号:
/* * @(#)TypeCodeImpl.java 1.94 04/06/21 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.corba.se.impl.corba;import java.util.HashMap;import java.util.Map;import java.util.Iterator;import java.util.List;import java.util.Collections;import java.util.ArrayList;import java.io.IOException;import java.io.PrintStream;import java.io.ByteArrayOutputStream;import java.math.BigDecimal;import java.math.BigInteger;import org.omg.CORBA.TypeCode ;import org.omg.CORBA.StructMember ;import org.omg.CORBA.UnionMember ;import org.omg.CORBA.ValueMember ;import org.omg.CORBA.TCKind ;import org.omg.CORBA.Any ;import org.omg.CORBA.Principal ;import org.omg.CORBA.BAD_TYPECODE ;import org.omg.CORBA.BAD_PARAM ;import org.omg.CORBA.BAD_OPERATION ;import org.omg.CORBA.INTERNAL ;import org.omg.CORBA.MARSHAL ;import org.omg.CORBA.TypeCodePackage.BadKind ;import org.omg.CORBA_2_3.portable.InputStream;import org.omg.CORBA_2_3.portable.OutputStream;import com.sun.corba.se.spi.ior.iiop.GIOPVersion;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;import com.sun.corba.se.impl.encoding.MarshalInputStream;import com.sun.corba.se.impl.encoding.CodeSetConversion;import com.sun.corba.se.impl.encoding.CDRInputStream;import com.sun.corba.se.impl.encoding.CDROutputStream;import com.sun.corba.se.impl.encoding.TypeCodeInputStream;import com.sun.corba.se.impl.encoding.TypeCodeOutputStream;import com.sun.corba.se.impl.encoding.TypeCodeReader;import com.sun.corba.se.impl.encoding.WrapperInputStream;import com.sun.corba.se.impl.logging.ORBUtilSystemException;// no chance of subclasses, so no problems with runtime helper lookuppublic final class TypeCodeImpl extends TypeCode { //static final boolean debug = false; // 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 // This is also used in AnyImpl. 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 id private String _name = ""; // the typecode name private int _memberCount = 0; // member count private String _memberNames[] = null; // names of members private TypeCodeImpl _memberTypes[] = null; // types of members private AnyImpl _unionLabels[] = null; // values of union labels private TypeCodeImpl _discriminator = null; // union discriminator type private int _defaultIndex = -1; // union default index private int _length = 0; // string/seq/array length private TypeCodeImpl _contentType = null; // seq/array/alias type // fixed private 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_TRUNCATABLE private TypeCodeImpl _concrete_base = null; // concrete base type private short _memberAccess[] = null; // visibility of ValueMember // recursive sequence support private TypeCodeImpl _parent = null; // the enclosing type code private int _parentOffset = 0; // the level of enclosure // recursive type code support private TypeCodeImpl _indirectType = null; // caches the byte buffer written in write_value for quick remarshaling... private byte[] outBuffer = null; // ... but only if caching is enabled private boolean cachingEnabled = false; // the ORB instance: may be instanceof ORBSingleton or ORB private ORB _orb; private ORBUtilSystemException wrapper ; /////////////////////////////////////////////////////////////////////////// // Constructors... public TypeCodeImpl(ORB orb) { // initialized to tk_null _orb = orb; wrapper = ORBUtilSystemException.get( (com.sun.corba.se.spi.orb.ORB)orb, CORBALogDomains.RPC_PRESENTATION ) ; } public TypeCodeImpl(ORB orb, TypeCode tc) // to handle conversion of "remote" typecodes into "native" style. // also see the 'convertToNative(ORB orb, TypeCode tc)' function { this(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 wrapper.badRemoteTypecode() ; if (tci._kind == TCKind._tk_sequence && tci._contentType == null) throw wrapper.badRemoteTypecode() ; } // 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(ORB orb, int creationKind) // for primitive types { this(orb); // 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(ORB orb, int creationKind, String id, String name, StructMember[] members) // for structs and exceptions { this(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(ORB orb, int creationKind, String id, String name, TypeCode discriminator_type, UnionMember[] members) // for unions { this(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]; 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(ORB orb, int creationKind, String id, String name, short type_modifier, TypeCode concrete_base, ValueMember[] members) // for value types { this(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(ORB orb, int creationKind, String id, String name, String[] members) // for enums { this(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(ORB orb, int creationKind, String id, String name, TypeCode original_type) // for aliases and value boxes { this(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(ORB orb, int creationKind, String id, String name) { this(orb) ; if (creationKind == TCKind._tk_objref || creationKind == TCKind._tk_native || creationKind == TCKind._tk_abstract_interface)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -