NonStop Software

IDL Declarations

Previous Topic | Next Topic | Contents | Index
Getting Started Guide | Administration Guide | Programmer's Guide

Subtopics

IDL Module Declaration
IDL Interface Declaration
IDL Forward Declaration
IDL Constant Declaration
IDL Type Declaration
IDL Exception Declaration
IDL Operation Declaration
IDL Attribute Declaration

IDL Module Declaration

Modules group interfaces and IDL type definitions into logical units. To prevent names from clashing, all names defined in the CORBA specification are defined as if they were within a module named CORBA. Likewise, identifiers can be defined only once in a scope, to prevent clashing in the global namespace.

The syntax is as follows:

module <identifier> {<definition>}

For example, you could define the interfaces related to RealEstate within a module RealEstate as follows:

//IDL
module RealEstate {
    interface Commercial {
    . . .
    };
    interface Residential {
    . . .
    };
    interface Rental {
    . . .
    };
};

To identify an interface outside a module, use the fully scoped name of the interface. For example, RealEstate::Commercial, RealEstate::Residential, or RealEstate::Rental.

IDL Interface Declaration

The interface declaration is an important part of IDL code. The interface provides a way to abstract object functionality. An interface consists of the following:

Interface Header

The interface header has the following syntax:

interface <identifier> [<inheritance_spec>]

The <identifier> names the interface. The <inheritance_spec> uses one of the following syntaxes:

Syntax 1:
<identifier>
Syntax 2:
::<identifier>
Syntax 3:
<scoped_name>::<identifier>

The <scoped_name> must denote a previously defined interface. An interface can be derived from another interface, which is then called a base interface of the derived interface. A derived interface, like all interfaces, may declare new elements (constants, types, attributes, exceptions, and operations).

In addition, unless redefined in the derived interface, the elements of a base interface can be referred to as if they were elements of the derived interface. The name resolution operator (::) may be used to refer to a base element explicitly; this permits reference to a name that has been redefined in the derived interface. A derived interface may redefine any of the type, constant, and exception names which have been inherited. Refer to Inheritance for more information.

An example header follows:

interface NewInterface

Interface Body

The interface body may contain the following types of declarations, though it can also be empty:

IDL Forward Declaration

A forward declaration specifies the name of an interface without providing a definition. This allows for the subsequent definition of interfaces that refer to each other. It also allows one interface to refer to object parameter types or return values for as yet undefined interfaces.

The syntax is as follows:

interface <identifier>

You can include multiple forward declarations to the same interface. An example forward declaration follows:

interface NewInterface;

IDL Constant Declaration

A constant can be declared in an interface or module, at file level scope. The syntax is as follows:

const <const_type> <identifier>

The <const_type> is an integer, char, boolean, floating point, string, or scoped name denoting a previously defined type. An example constant declaration follows:

const long MaxUsers = 10000;

IDL Type Declaration

Type declarations associate an identifier with a type for naming data types.

Basic Types

IDL supports the following basic types.

 Type   Identifier
 floating point

float
double

 integer long
short
unsigned long
unsigned short 
 character char
 boolean boolean
 octet octet
 any any

IDL Operation Declaration

The CORBA::Any type allows an interface to specify that a parameter or result type can contain any type of value. For example:

//IDL
interface M {
  void op(in any a);
};

Syntax

Type declarations have one of the following syntaxes:

Syntax 1:
typedef <type_declarator>

where <type_declarator> is defined as follows:

<type_spec> <declarators>
Syntax 2:
<struct_type>
Syntax 3:
<union_type>
Syntax 4:
<enum_type>

The following sections describe constructed types, template types, and the complex declarator.

Constructed Types

IDL provides three constructed types:

Structures

The structure syntax is as follows:

struct <identifier> {<member_list>}

The <identifier> defines a new legal type and must be unique within the structure. The member list consists of one or more type_specs and declarators.

An example of a structure follows:

//IDL
struct Catalog {
  string CDname;
  short number;
};

Unions

The union type in IDL specifies the amount of storage needed to store its largest element. Unions are a cross between the C language union and switch statements. The syntax is as follows:

union <identifier> switch (<switch_type_spec>)
{<switch_body>}

The identifier defines a new legal type. The <switch_type_spec> is a typed tag field that can be an integer, char, boolean, enum, or a scoped name denoting one of these types.

Unions must be discriminated; that is, the union header must include a tag field called the discriminator that determines which union member to use for the current instance of a call.

The <switch_body> consists of a case statement. Expressions following the case keyword must be compatible with the tag type.

An example of a union follows:

//IDL
union label switch (long) {
    case 1 : long x;
    case 2 : float f;
    default: string str;
};

In the example, the union is called label and has a discriminator of type long. The expressions in the case statements must be compatible with the discriminator type. The default statement specifies the default discriminator if none of the case expressions match the switch expression.

Enumerations

An enumerated type is an ordered list of identifiers that defines a new legal type. The syntax is as follows:

enum <identifier> {<enumerator> { , <enumerator>}}

The order of the identifiers determines the relative value of the identifiers.

An example of an enumeration follows:

//IDL
enum Car {sports, sedan, van, truck, convertible};

In the example, Car is the legal type defined by the enumeration.

Template Types

Template types are either sequences or strings. A sequence is a one-dimensional array with a maximum size and length.

For example:

//IDL
sequence<long, 10> test;

This declaration defines a bounded sequence of 10. The sequence is called test and can be any length up to the bound.

Complex Declarator

Complex declarators are multidimensional, fixed-sized arrays with explicit sizes for each dimension.

The syntax for arrays is as follows:

<array_declarator> ::=<identifier> <fixed_array_size>

<fixed_array_size> ::="["<positive_int_const>"]"

The array size in each dimension is fixed at compile time. When an array is passed as a parameter in an operation invocation, all elements of the array are transmitted.

IDL Exception Declaration

Exception declarations are used to specify struct-like data structures that may be returned to indicate that an exception condition occurred during a request. The exception begins with the keyword exception and is followed by an exception type <identifier> and the members of the exception. The members provide additional information about the exception.

The syntax is as follows:

exception <identifier> {<member>}

CORBA defines a set of system exceptions that are similar to standard runtime errors that can occur. Refer to the common Object Request Broker: Architecture and Specification for information on the standard exception definitions. See the Bibliography for details.

For information on NonStop DOM minor codes for system exceptions, refer to the following topics in the section "Exception Handling: Minor Codes:"

IDL Operation Declaration

Operation declarations specify the operations that can be applied to objects of a particular interface. They are similar to class method declarations in C++. They define the publicly accessible methods of a class and can be declared only within an interface definition. An operation is defined with the following syntax:

[<op_attribute>] <op_type_spec> <identifier>
<parameter_dcls>
<raises_expr>[<context_expr>]

where:

<op_attribute>
is an optional operation attribute that specifies which invocation semantics the communication system should provide when the operation is performed. The [oneway] operation attribute specifies that there is no reply to the operation. The operation must not have any output parameters (out or inout), no raises clause, and must specify a void return type.

<op_type_spec>
is the type of the operation's return result, which can be any defined IDL type. Oneway operations must have a return type of void.

<identifier>
names the operation in the scope of the interface.

<parameter_dcls>
is a list of parameter declarations for the operation. The parameter list is similar to that of a C++ method parameter list, with the addition of a parameter attribute. The parameter attribute specifies the direction in which the parameter will be passed to the method. The valid parameter attributes are:

inThe parameter is passed from client to server
outThe parameter is passed from server to client
inoutThe parameter is passed in both directions; for example, it has an input value and an output value

The in parameters are not modified, while out and inout parameters may be changed by the method. Also, inout, out, and return values are undefined if an exception is raised as a result of the method invocation. When an unbounded string or sequence is passed as an inout parameter, the returned value cannot be longer than the input value.

<raises_expr>
is an optional raised expression that indicates which user exceptions can be raised when the operation is invoked. It specifies scoped names that are previously defined exceptions. System exceptions can always be raised by the Object Request Broker.

<context_expr>
is an optional context expression that indicates which elements of the request context the method can check on during the operation.

IDL Attribute Declaration

Attribute definitions specify interface attributes that describe the properties of an object. Attributes are inherited and cannot be redefined to a different type.

The syntax is as follows:

[readonly] attribute <param_type_spec>
<simple_declarator> {,<simple_declarator>}

The attribute declaration represents two accessor functions: one to retrieve the value and the other to set the value of the attribute. Include the readonly keyword to indicate that there is only one accessor function to read the value.

For example:

//IDL
interface Library {
  attribute float total;
  readonly attribute string librarian;
};

Here, total may be both set and retrieved; librarian can only be retrieved; its value is set by the object's implementation.


Previous Topic | Next Topic | Contents | Top
Administration Guide | Programmer's Guide
Bibliography | Glossary | Index
© Tandem, a division of Compaq. All rights reserved. Legal notices.