[Previous] [Contents] [Next] [IONA Technologies]


Chapter 17
TypeCode


Contents

17.1 The IDL Type TypeCode
17.2 Implementation of TypeCode in OrbixWeb
17.2.1 The TypeCode.IT_create() Method
17.3 Use of TypeCode
17.3.1 Use of TypeCode in Type any
17.3.2 Use of TypeCode when Interrogating the Interface Repository



This chapter describes the IDL pseudo type TypeCode and how this is represented in OrbixWeb. TypeCode is used to describe arbitrary complex IDL types at runtime.

TypeCode is used for many purposes in the system:

The TypeCode interface is available in an IDL file only if it includes the directive:

Note that the file orb.idl is not generally available–it is known internally to OrbixWeb.

In an IDL specification, a TypeCode can be used as an attribute type, or as the type of a parameter or return value to an operation. The IDL TypeCode interface is implemented by the Java class TypeCode (defined in package IE.Iona.Orbix2.CORBA).

The class TypeCode is particularly useful when querying the type of an instance of Any. The class Any has a public member variable, type, of type TypeCode. This variable can be queried at runtime to determine the type of the Any.

17.1 The IDL Type TypeCode

This section describes the standard IDL interface TypeCode, as well as the Java class TypeCode.

Each TypeCode consists of a kind and a sequence of parameters. The kind specifies the overall classification of the TypeCode: for example, whether it is a basic type, a struct, a sequence, and so on. The parameters give the details of the type definition. For example, the IDL type sequence<long,20> has the kind tk_sequence and has two parameters–the first parameter is a TypeCode for long, the second parameter is 20.

The IDL interface for TypeCode is defined as follows:

This interface includes an operation kind() to query the kind of a TypeCode and an operation parameter() to access individual parameters of a TypeCode. The generated signatures of these IDL operations are as follows:

An IDL enumerated type maps to a Java int, with an associated class which defines a constant value for each member of the enumeration. Class TypeCode's kind is therefore a value of type int, which may take any of the values defined in class TCKind. The parameter() operation raises the exception Bounds if an attempt is made to access a non-existent parameter.

The number of parameters which a TypeCode has varies with the kind of the TypeCode. This number is returned by the param_count() operation of the TypeCode interface. The generated signature of this operation is as follows:

The parameters of each kind of TypeCode are listed in detail in the description of class TypeCode in Part II, "Class and Interface Reference" of the OrbixWeb Reference Guide. Some examples follow:

17.2 Implementation of TypeCode in OrbixWeb

The IDL type TypeCode is implemented by the Java class TypeCode. An IDL operation with a parameter of type TypeCode is translated into a Java method which takes a parameter of Java class TypeCode.

The IDL compiler can generate constant declarations for TypeCode pseudo object references from named type definitions that appear in an IDL file–that is from the following types:

Thus, for each user-defined type which appears in an IDL file, a TypeCode constant may be generated. This is of the form _tc_<type>, scoped within the generated Java class for <type>, where <type> is the user-defined type. For example, consider the following IDL specification:

The following TypeCode constant will be generated:

This definition will only be generated if the -A switch to the IDL compiler is used.

In addition, a number of predefined TypeCode pseudo object reference constants are always available to allow the user to access TypeCodes for standard types. These are exhaustively listed in Part II, "Class and Interface Reference" of the OrbixWeb Reference Guide, under the entry for TypeCode.

Each constant is defined in the Java class _CORBA (in package IE.Iona.Orbix2), and is named after the convention _tc_<type>. For example:

The Java class TypeCode defines the following public members:

17.2.1 The TypeCode.IT_create() Method

In addition to the public members listed above, the following methods are provided in the public interface to class TypeCode:

These methods allow the programmer to initialise a TypeCode object reference.

17.3 Use of TypeCode

Examples of using TypeCode are shown in the following subsections.

17.3.1 Use of TypeCode in Type any

Consider an example IDL definition:

Use of the -A switch will cause the TypeCode for type Example to be generated. Now, assume that a client program invokes the IDL operation op():

On the server side, or at a later point in the client code, we may wish to query the actual type of the Any. For example:

This is one of the most common uses of TypeCodes–namely, the runtime querying of type information from a Any.

Use of TypeCode in type Any is explained fully in Chapter 18, "Type any".

17.3.2 Use of TypeCode when Interrogating the Interface Repository

The kind() and parameter() methods of class TypeCode are frequently useful when using the Interface Repository functions. For example, when finding information about an operation of an interface, the number of its arguments can be found, and then the TypeCode of each argument can be determined. The functions kind() and parameter() can be used on each TypeCode to determine the details of the type of each argument. We will take a detailed look, with examples, at the Interface Repository in Chapter 20, "Interface Repository".



[Roadmap] [Introduction] [GS: Applications] [GS: Applets]
[IDL] [Mapping] [Programming OrbixWeb] [Publishing Objects] [Retrieving Objects] [IIOP]
[Running Clients] [Running Servers] [Exceptions] [Inheritance] [Callbacks] [Contexts]
[API Configuration] [TypeCode] [Any] [DII] [IR] [Filters] [Smart Proxies] [Loaders] [Locators]
[Index]