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.
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:
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:
<identifier>
::<identifier>
<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
The interface body may contain the following types of declarations, though it can also be empty:
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;
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;
Type declarations associate an identifier with a type for naming data types.
IDL supports the following basic types.
Type | Identifier |
floating point |
|
integer | long |
character | char |
boolean | boolean |
octet | octet |
any | any |
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); };
Type declarations have one of the following syntaxes:
typedef <type_declarator>
where <type_declarator>
is defined as follows:
<type_spec> <declarators>
<struct_type>
<union_type>
<enum_type>
The following sections describe constructed types, template types, and the complex declarator.
IDL provides three constructed types:
struct
union
enum
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; };
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.
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 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 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.
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:"
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>
[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>
<identifier>
<parameter_dcls>
in | The parameter is passed from client to server |
out | The parameter is passed from server to client |
inout | The 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>
<context_expr>
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.