1161-1163

Previous Table of Contents Next

Page 1161

Interface Definition Language (IDL)

IDL provides a means of defining object types and interfaces in an implementation-independent context. In addition to basic datatypes and interfaces, the CORBA specification defines a number of complex ( constructed ) and special datatypes. The specification also defines language- specific mappings for C, C++, and SmallTalk.

NOTE
Although no Java mapping has been adopted formally as a standard, several Java mappings have been implemented. One of these mappings is described in the next section, "Developing Java-Based CORBA Services." This section focuses on the most commonly used elements of IDL, without regard to any specific mapping. For a more complete description of the Java language, consult the specification.

Table 52.4 lists the OMG IDL basic datatypes and their definitions.

Table 52.4. OMG IDL datatypes.


Datatype Range or Definition
short Integer in the range of _2 15 to (2 15 _ 1)
unsigned short Integer in the range of 0 to (2 16 _ 1)
long Integer in the range of _2 31 to (2 31 _ 1)
unsigned long Integer in the range of 0 to (2 32 _ 1)
float Single-precision floating point number (IEEE 754 standard)
double Double-precision floating point number (IEEE 754 standard)
char 8-bit quantity (meanings and representations based on International Standards Organization (ISO) Latin-1 and ASCII)
boolean True or False
octet 8-bit quantity guaranteed not to undergo conversions in network transmissions
any Used in parameter lists to allow any other valid OMG IDL type to be passed

Page 1162

An OMG string is similar to an array of char, except that it can be unbounded. A unbounded string's length must be identified in a language-dependent manner by the ORB before it can be passed as a parameter to an object implementation. (For C language implementations , the string must be null- terminated , for example.) The following declarations of a string are both valid:

 string<10> bounded; string         unbounded; 

You can define named constant values for any of the basic types by using the const keyword. All the following constant declarations are valid:

 const unsigned short  MAX_ITEMS = 3; const float  RATE = .05; const char   FEMALE = `F'; const string GREETING = "Welcome to Earth"; 

OMG IDL defines three constructed types that consist of basic or previously defined types. An IDL struct consists of one or more members containing types that were previously defined in the same scope. An example of a simple struct follows :

 struct Account {     long acctno;     float balance; }; 

The discriminated union defined by OMG IDL requires a discriminator tag and uses a switch statement to determine which member to use for each instance. A simple discriminated union might be defined as the following:

 union TimeIncrement switch (boolean) {         case TRUE: float  fraction;          default:        long whole; }; 

An IDL enumeration is an ordered list of identifiers used to represent distinct values. An IDL enumeration starts with 0, and values are incremented by 1. Unlike C, an IDL value cannot be assigned to an identifier in an enumeration. An application used to calculate grade-point averages, for example, might define the following enumeration:

 enum Grade {F, D, C, B, A}; 

You can construct arrays from any previously defined type, but they must have fixed sizes for all dimensions in OMG IDL. An array of previously defined Account structs could be included in a second struct, as shown here:

 struct Customer {     Account accounts[10];     short       numopen; }; 

Page 1163

An IDL sequence is similar to an array, except that it can be unbounded. The Customer struct defined earlier could be declared using a sequence, as in this example:

 struct Customer {     sequence<Account, 10> accounts;     short             numopen; }; 

The Customer struct could have virtually unlimited accounts if it were declared as the following:

 struct Customer {     sequence<Account> accounts;     short             numopen; }; 

Like an unbounded string, an unbounded sequence's length must be identified in a language-dependent manner by the ORB before it can be used by an object implementation.

All these datatypes are interesting, but they are not very useful without an interface to do something with them. The IDL interface defines the operations that can be performed on any object that satisfies the interface. In other words, an interface does not specify any particular type of object. An object implementation may implement any number of interfaces to provide polymorphic behavior.

Suppose that a client has access to two interfaces defined as the following:

 interface talker {     void talk(in string statement); }; interface listener {     string listen(); }; 

The client requesting a talker and a listener receives two distinct object references (identifiers). These two references may refer to the same object on the server, however, which implements both interfaces. This process is completely transparent to the client. The client accesses interfaces without regard to implementations, so it must use the separate references to access talk() and listen().

OMG IDL also supports interface inheritance. An interface that extends both talker and listener might be defined as the following:

 interface being: talker, listener {     void converse(inout string q_and_a); }; 

The implementation of the being interface must implement talk() and listen() in addition to converse(). Parameters to interface operations can be defined as in, out, or inout. An interface can have attributes in addition to operations. Defining an interface attribute is equivalent to defining accessor functions to read and write a value. Read-only attributes also can be defined,

Previous Table of Contents Next


Oracle Unleashed
Oracle Development Unleashed (3rd Edition)
ISBN: 0672315750
EAN: 2147483647
Year: 1997
Pages: 391

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net