A container for information about a specific CORBA data type.
TypeCode objects are used:
- in the Dynamic Invocation Interface -- to indicate the types of the actual arguments or the type of the return value.
NamedValue objects are used to represent arguments and return values. One of their components is an Any object, which in turn has as one of its components a TypeCode object.
- by an Interface Repository to represent the type specifications that are part of many OMG IDL declarations
The representation of a TypeCode object is opaque, but abstractly, a TypeCode object consists of:
- a
kind field, which is set to an instance of the class TCKind
- zero or more additional fields appropriate for the particular kind. For example, the
TypeCode object describing the OMG IDL type 1ong has kind TCKind.tk_long and no additional fields. The TypeCode describing OMG IDL type sequence<boolean, 10> has a kind field with the value TCKind.tk_sequence and also fields with the values boolean and 10 for the type of sequence elements and the length of the sequence.
TypeCode objects can be obtained in various ways:
- from a call to the method
Any.insert_X, where X is a basic IDL type. This method creates a TypeCode object for type X and assigns it to the Any object's type field.
- from invocations of methods in the ORB class
For example, the following creates a TypeCode object for a string with a maximum of 30 characters:
org.omg.CORBA.TypeCode tcString = orb.create_string_tc(30);
The following creates a TypeCode object for an array of five strings:
org.omg.CORBA.TypeCode tcArray = orb.create_array_tc(
5, TCKind.tk_string);
The following creates a TypeCode object for an interface named "Account":
org.omg.CORBA.TypeCode tcInterface = orb.create_interface_tc(
"thisId", "Account");
- as the return value from the
_type method in Holder classes for user-defined IDL types. These Holder classes are generated by the idltojava compiler.
- from a CORBA Interface Repository
Most of the methods in the class TypeCode are accessors, and the information contained in a TypeCode object is specific to a particular type. Therefore, methods must be invoked only on the kind of type codes to which they apply. If an accessor method tries to access information from an inappropriate kind of type code, it will throw the exception TypeCodePackage.BadKind. For example, if the method discriminator_type is called on anything other than a union, it will throw BadKind because only unions have a discriminator. The following list shows which methods apply to which kinds of type codes:
These methods may be invoked on all TypeCode kinds:
These methods may be invoked on objref, struct, union, enum, alias, exception, value, value_box, native, and abstract_interface:
These methods may be invoked on struct, union, enum, and exception:
These methods may be invoked on struct, union, and exception:
These methods may be invoked on union:
-
member_label
-
discriminator_type
-
default_index
These methods may be invoked on string, sequence, and array:
These methods may be invoked on alias, sequence, array, and value_box:
Unlike other CORBA pseudo-objects, TypeCode objects can be passed as general IDL parameters.
The methods parameter and param_count, which are deprecated, are not mapped.
Java IDL extends the CORBA specification to allow all operations permitted on a structTypeCode to be permitted on an exceptionTypeCode as well.