下面列出了怎么用org.omg.CORBA.TypeCode的API类实例代码及写法,或者点击链接到github查看源代码。
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 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();
}
}
/**
* This is used to create the TypeCode for a null reference.
* It also handles backwards compatibility with JDK 1.3.x.
*
* This method will not return null.
*/
private TypeCode createTypeCodeForNull(org.omg.CORBA.ORB orb)
{
if (orb instanceof ORB) {
ORB ourORB = (ORB)orb;
// Preserve backwards compatibility with Kestrel and Ladybird
// by not fully implementing interop issue resolution 3857,
// and returning a null TypeCode with a tk_value TCKind.
// If we're not talking to Kestrel or Ladybird, fall through
// to the abstract interface case (also used for foreign ORBs).
if (!ORBVersionFactory.getFOREIGN().equals(ourORB.getORBVersion()) &&
ORBVersionFactory.getNEWER().compareTo(ourORB.getORBVersion()) > 0) {
return orb.get_primitive_tc(TCKind.tk_value);
}
}
// Use tk_abstract_interface as detailed in the resolution
// REVISIT: Define this in IDL and get the ID in generated code
String abstractBaseID = "IDL:omg.org/CORBA/AbstractBase:1.0";
return orb.create_abstract_interface_tc(abstractBaseID, "");
}
/**
* When using our own ORB and Any implementations, we need to get
* the ORB version and create the type code appropriately. This is
* to overcome a bug in which the JDK 1.3.x ORBs used a tk_char
* rather than a tk_wchar to describe a Java char field.
*
* This only works in RMI-IIOP with Util.writeAny since we actually
* know what ORB and stream we're writing with when we insert
* the value.
*
* Returns null if it wasn't possible to create the TypeCode (means
* it wasn't our ORB or Any implementation).
*
* This does not handle null objs.
*/
private TypeCode createTypeCode(Serializable obj,
org.omg.CORBA.Any any,
org.omg.CORBA.ORB orb) {
if (any instanceof com.sun.corba.se.impl.corba.AnyImpl &&
orb instanceof ORB) {
com.sun.corba.se.impl.corba.AnyImpl anyImpl
= (com.sun.corba.se.impl.corba.AnyImpl)any;
ORB ourORB = (ORB)orb;
return anyImpl.createTypeCodeForClass(obj.getClass(), ourORB);
} else
return null;
}
public static TypeCode getPrimitiveTypeCodeForClass (ORB orb,
Class c,
ValueHandler vh) {
if (c == Integer.TYPE) {
return orb.get_primitive_tc (TCKind.tk_long);
} else if (c == Byte.TYPE) {
return orb.get_primitive_tc (TCKind.tk_octet);
} else if (c == Long.TYPE) {
return orb.get_primitive_tc (TCKind.tk_longlong);
} else if (c == Float.TYPE) {
return orb.get_primitive_tc (TCKind.tk_float);
} else if (c == Double.TYPE) {
return orb.get_primitive_tc (TCKind.tk_double);
} else if (c == Short.TYPE) {
return orb.get_primitive_tc (TCKind.tk_short);
} else if (c == Character.TYPE) {
return orb.get_primitive_tc (((ValueHandlerImpl)vh).getJavaCharTCKind());
} else if (c == Boolean.TYPE) {
return orb.get_primitive_tc (TCKind.tk_boolean);
} else {
// _REVISIT_ Not sure if this is right.
return orb.get_primitive_tc (TCKind.tk_any);
}
}
public void insert_fixed(java.math.BigDecimal value, org.omg.CORBA.TypeCode type)
{
try {
if (TypeCodeImpl.digits(value) > type.fixed_digits() ||
TypeCodeImpl.scale(value) > type.fixed_scale())
{
throw wrapper.fixedNotMatch() ;
}
} catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
// type isn't even of kind fixed
throw wrapper.fixedBadTypecode( bk ) ;
}
typeCode = TypeCodeImpl.convertToNative(orb, type);
object = value;
isInitialized = true;
}
public static TypeCode getPrimitiveTypeCodeForClass (ORB orb,
Class c,
ValueHandler vh) {
if (c == Integer.TYPE) {
return orb.get_primitive_tc (TCKind.tk_long);
} else if (c == Byte.TYPE) {
return orb.get_primitive_tc (TCKind.tk_octet);
} else if (c == Long.TYPE) {
return orb.get_primitive_tc (TCKind.tk_longlong);
} else if (c == Float.TYPE) {
return orb.get_primitive_tc (TCKind.tk_float);
} else if (c == Double.TYPE) {
return orb.get_primitive_tc (TCKind.tk_double);
} else if (c == Short.TYPE) {
return orb.get_primitive_tc (TCKind.tk_short);
} else if (c == Character.TYPE) {
return orb.get_primitive_tc (((ValueHandlerImpl)vh).getJavaCharTCKind());
} else if (c == Boolean.TYPE) {
return orb.get_primitive_tc (TCKind.tk_boolean);
} else {
// _REVISIT_ Not sure if this is right.
return orb.get_primitive_tc (TCKind.tk_any);
}
}
/**
* This is used to create the TypeCode for a null reference.
* It also handles backwards compatibility with JDK 1.3.x.
*
* This method will not return null.
*/
private TypeCode createTypeCodeForNull(org.omg.CORBA.ORB orb)
{
if (orb instanceof ORB) {
ORB ourORB = (ORB)orb;
// Preserve backwards compatibility with Kestrel and Ladybird
// by not fully implementing interop issue resolution 3857,
// and returning a null TypeCode with a tk_value TCKind.
// If we're not talking to Kestrel or Ladybird, fall through
// to the abstract interface case (also used for foreign ORBs).
if (!ORBVersionFactory.getFOREIGN().equals(ourORB.getORBVersion()) &&
ORBVersionFactory.getNEWER().compareTo(ourORB.getORBVersion()) > 0) {
return orb.get_primitive_tc(TCKind.tk_value);
}
}
// Use tk_abstract_interface as detailed in the resolution
// REVISIT: Define this in IDL and get the ID in generated code
String abstractBaseID = "IDL:omg.org/CORBA/AbstractBase:1.0";
return orb.create_abstract_interface_tc(abstractBaseID, "");
}
private static TypeCode createTypeCodeForClassInternal (ORB orb,
java.lang.Class c,
ValueHandler vh,
IdentityKeyValueStack createdIDs)
{
// This wrapper method is the protection against infinite recursion.
TypeCode tc = null;
String id = (String)createdIDs.get(c);
if (id != null) {
return orb.create_recursive_tc(id);
} else {
id = vh.getRMIRepositoryID(c);
if (id == null) id = "";
// cache the rep id BEFORE creating a new typecode.
// so that recursive tc can look up the rep id.
createdIDs.push(c, id);
tc = createTypeCodeInternal(orb, c, vh, id, createdIDs);
createdIDs.pop();
return tc;
}
}
public static TypeCode getPrimitiveTypeCodeForClass (ORB orb,
Class c,
ValueHandler vh) {
if (c == Integer.TYPE) {
return orb.get_primitive_tc (TCKind.tk_long);
} else if (c == Byte.TYPE) {
return orb.get_primitive_tc (TCKind.tk_octet);
} else if (c == Long.TYPE) {
return orb.get_primitive_tc (TCKind.tk_longlong);
} else if (c == Float.TYPE) {
return orb.get_primitive_tc (TCKind.tk_float);
} else if (c == Double.TYPE) {
return orb.get_primitive_tc (TCKind.tk_double);
} else if (c == Short.TYPE) {
return orb.get_primitive_tc (TCKind.tk_short);
} else if (c == Character.TYPE) {
return orb.get_primitive_tc (((ValueHandlerImpl)vh).getJavaCharTCKind());
} else if (c == Boolean.TYPE) {
return orb.get_primitive_tc (TCKind.tk_boolean);
} else {
// _REVISIT_ Not sure if this is right.
return orb.get_primitive_tc (TCKind.tk_any);
}
}
/**
* This is used to create the TypeCode for a null reference.
* It also handles backwards compatibility with JDK 1.3.x.
*
* This method will not return null.
*/
private TypeCode createTypeCodeForNull(org.omg.CORBA.ORB orb)
{
if (orb instanceof ORB) {
ORB ourORB = (ORB)orb;
// Preserve backwards compatibility with Kestrel and Ladybird
// by not fully implementing interop issue resolution 3857,
// and returning a null TypeCode with a tk_value TCKind.
// If we're not talking to Kestrel or Ladybird, fall through
// to the abstract interface case (also used for foreign ORBs).
if (!ORBVersionFactory.getFOREIGN().equals(ourORB.getORBVersion()) &&
ORBVersionFactory.getNEWER().compareTo(ourORB.getORBVersion()) > 0) {
return orb.get_primitive_tc(TCKind.tk_value);
}
}
// Use tk_abstract_interface as detailed in the resolution
// REVISIT: Define this in IDL and get the ID in generated code
String abstractBaseID = "IDL:omg.org/CORBA/AbstractBase:1.0";
return orb.create_abstract_interface_tc(abstractBaseID, "");
}
public org.omg.CORBA.TypeCode get_typecode()
throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
org.omg.DynamicAny.DynAnyPackage.InvalidValue
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
if (any.type().kind().value() != TCKind._tk_TypeCode)
throw new TypeMismatch();
return any.extract_TypeCode();
}
protected boolean initializeComponentsFromAny() {
// This typeCode is of kind tk_sequence.
TypeCode typeCode = any.type();
int length;
TypeCode contentType = getContentType();
InputStream input;
try {
input = any.create_input_stream();
} catch (BAD_OPERATION e) {
return false;
}
length = input.read_long();
components = new DynAny[length];
anys = new Any[length];
for (int i=0; i<length; i++) {
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
// but only for primitive types
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
try {
// Creates the appropriate subtype without copying the Any
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
} catch (InconsistentTypeCode itc) { // impossible
}
}
return true;
}
public TypeCode concrete_base_type() throws BadKind {
switch (_kind) {
case tk_indirect:
return indirectType().concrete_base_type();
case TCKind._tk_value:
return _concrete_base;
default:
throw new BadKind();
}
}
/**
* See RequestInfoImpl for javadoc.
*/
public TypeCode[] exceptions (){
checkAccess( MID_EXCEPTIONS );
if( cachedExceptions == null ) {
if( request == null ) {
throw stdWrapper.piOperationNotSupported2() ;
}
// Get the list of exceptions from DII request data, If there are
// no exceptions raised then this method will return null.
ExceptionList excList = request.exceptions( );
int count = excList.count();
TypeCode[] excTCList = new TypeCode[count];
try {
for( int i = 0; i < count; i++ ) {
excTCList[i] = excList.item( i );
}
} catch( Exception e ) {
throw wrapper.exceptionInExceptions( e ) ;
}
cachedExceptions = excTCList;
}
// Good citizen: In the interest of efficiency, we assume
// interceptors will be "good citizens" in that they will not
// modify the contents of the TypeCode[] array. We also assume
// they will not change the values of the containing TypeCodes.
return cachedExceptions;
}
public org.omg.CORBA.TypeCode create_value_tc(String id,
String name,
short type_modifier,
TypeCode concrete_base,
ValueMember[] members)
{
return new TypeCodeImpl(this, TCKind._tk_value, id, name,
type_modifier, concrete_base, members);
}
static public Any extractAnyFromStream(TypeCode memberType, InputStream input, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy(input, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
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
}
/**
* See RequestInfoImpl for javadoc.
*/
public TypeCode[] exceptions (){
checkAccess( MID_EXCEPTIONS );
if( cachedExceptions == null ) {
if( request == null ) {
throw stdWrapper.piOperationNotSupported2() ;
}
// Get the list of exceptions from DII request data, If there are
// no exceptions raised then this method will return null.
ExceptionList excList = request.exceptions( );
int count = excList.count();
TypeCode[] excTCList = new TypeCode[count];
try {
for( int i = 0; i < count; i++ ) {
excTCList[i] = excList.item( i );
}
} catch( Exception e ) {
throw wrapper.exceptionInExceptions( e ) ;
}
cachedExceptions = excTCList;
}
// Good citizen: In the interest of efficiency, we assume
// interceptors will be "good citizens" in that they will not
// modify the contents of the TypeCode[] array. We also assume
// they will not change the values of the containing TypeCodes.
return cachedExceptions;
}
/**
* See ServerRequestInfo for javadocs.
*/
public TypeCode[] exceptions (){
checkAccess( MID_EXCEPTIONS );
// _REVISIT_ PI RTF Issue: No exception list on server side.
throw stdWrapper.piOperationNotSupported2() ;
}
protected boolean initializeComponentsFromAny() {
// This typeCode is of kind tk_sequence.
TypeCode typeCode = any.type();
int length;
TypeCode contentType = getContentType();
InputStream input;
try {
input = any.create_input_stream();
} catch (BAD_OPERATION e) {
return false;
}
length = input.read_long();
components = new DynAny[length];
anys = new Any[length];
for (int i=0; i<length; i++) {
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
// but only for primitive types
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
try {
// Creates the appropriate subtype without copying the Any
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
} catch (InconsistentTypeCode itc) { // impossible
}
}
return true;
}
protected DynAnyComplexImpl(ORB orb, TypeCode typeCode) {
// We can be sure that typeCode is of kind tk_struct
super(orb, typeCode);
// For DynAnyComplex, the operation sets the current position to -1
// for empty exceptions and to zero for all other TypeCodes.
// The members (if any) are (recursively) initialized to their default values.
index = 0;
}
/**
* Create a TypeCode for a union.
*
* @param id the logical id for the typecode.
* @param name the name for the typecode.
* @param discriminator_type
* the type of the union discriminator.
* @param members an array describing the members of the TypeCode.
* @return the requested TypeCode.
*/
public synchronized TypeCode create_union_tc(String id,
String name,
TypeCode discriminator_type,
UnionMember[] members)
{
checkShutdownState();
return new TypeCodeImpl(this,
TCKind._tk_union,
id,
name,
discriminator_type,
members);
}
@Test
public void testCreateStreamable() {
QName objName = new QName("object");
QName objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
TypeCode objTypeCode = orb.get_primitive_tc(TCKind.tk_short);
CorbaPrimitiveHandler obj = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
CorbaStreamable streamable = new CorbaStreamableImpl(obj, objName);
assertNotNull(streamable);
}
public synchronized org.omg.CORBA.TypeCode create_abstract_interface_tc(
String id,
String name)
{
checkShutdownState();
return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
}
public org.omg.CORBA.TypeCode get_typecode()
throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
org.omg.DynamicAny.DynAnyPackage.InvalidValue
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
if (index == NO_INDEX)
throw new org.omg.DynamicAny.DynAnyPackage.InvalidValue();
DynAny currentComponent = current_component();
if (DynAnyUtil.isConstructedDynAny(currentComponent))
throw new org.omg.DynamicAny.DynAnyPackage.TypeMismatch();
return currentComponent.get_typecode();
}
public org.omg.CORBA.TypeCode get_typecode()
throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
org.omg.DynamicAny.DynAnyPackage.InvalidValue
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
if (index == NO_INDEX)
throw new org.omg.DynamicAny.DynAnyPackage.InvalidValue();
DynAny currentComponent = current_component();
if (DynAnyUtil.isConstructedDynAny(currentComponent))
throw new org.omg.DynamicAny.DynAnyPackage.TypeMismatch();
return currentComponent.get_typecode();
}
public TypeCode item(int index)
throws Bounds
{
try {
return (TypeCode) _exceptions.elementAt(index);
} catch (ArrayIndexOutOfBoundsException e) {
throw new Bounds();
}
}
/**
* See the description of the <a href="#anyOps">general Any operations.</a>
*/
public void insert_TypeCode(TypeCode tc)
{
//debug.log ("insert_TypeCode");
typeCode = orb.get_primitive_tc(TCKind._tk_TypeCode);
object = tc;
isInitialized = true;
}
/**
* sets the type of the element to be contained in the Any.
*
* @param tc the TypeCode for the element in the Any
*/
public void type(TypeCode tc)
{
//debug.log ("type2");
// set the typecode
typeCode = TypeCodeImpl.convertToNative(orb, tc);
stream = null;
value = 0;
object = null;
// null is the only legal value this Any can have after resetting the type code
isInitialized = (tc.kind().value() == TCKind._tk_null);
}