[Enterprise Extensions only]

Defining the interface for a CORBA servant class

Use this task to define the public interface of a CORBA servant class that is to provide the business logic to be used by clients. This defines the information that a client must know to call and use servant objects of that class, and forms one stage of the tasks to develop a CORBA server or client.

To specify the public interface for a CORBA servant class, you create an IDL (interface definition language) file that contains an interface declaration:

  1. Create an IDL file, servant.idl, where servant is the name of the server implementation class.

    This steps results in a fully-specified servant.idl file.

  2. Edit the servant.idl file to add an interface definition.
    The interface definition declares the interface name (and optionally its base interface names), and the methods (operations), and any constants, type definitions, and exception structures that the interface exports.

    The following information is an overview of the format of an interface declaration, and provides links to the reference topics that provide details about parts of the IDL declaration and IDL syntax. For reference information about IDL interface declarations, and the component declarations that they can contain, see IDL interface declarations.

    An interface declaration has the following syntax:

    interface  interface-name
     [: base-interface1, base-interface2, ...]
      {
       [constant declarations]
       [type declarations]
       [exception declarations]
       [attribute declarations]
       [operation declarations]
     };
    
    interface-name
    The name of the public interface for the servant object, this should match the servant class name.
    [: base-interface1, base-interface2, ...]
    The base-interface names for one or more parent interfaces from which this interface, interface-name, is derived.

    You need to specify base-interface names only if this interface is derived from one or more parent interfaces. Each base interface is specified in the form : interface_name and can be named only once in the interface statement header. If you specify a base-interface name, you must also add an include statement for the base-interface IDL file to the top of the servant.idl file.

    [constant declarations] and [type declarations]
    An interface declaration can include constant declarations and type declarations as in C and C++, with some restrictions and extensions. For more information about these declaration types, see IDL type and constant declarations.
    [exception declarations]
    An interface declaration can include exception declarations, which define data structures to be returned when an exception occurs during the execution of an operation. Each exception declaration specifies a name and, optionally, a struct-like data structure for holding error information. For more information about these declaration types, see IDL exception declarations.
    [attribute declarations]
    Declaring an attribute as part of an interface is equivalent to declaring one or two accessor operations: one to retrieve the value of the attribute (a get or read operation) and (unless the attribute specifies readonly) one to set the value of the attribute (a set or write operation). For more information about these declaration types, see IDL attribute declarations.
    [operation declarations]
    Operation declarations define the interface of each operation introduced by the interface. (An IDL operation is typically implemented by a method in the implementation programming language. Hence, the terms operation and method are often used interchangeably.). For more information about these declaration types, see IDL operation declarations.

    The order in which these declarations are specified is usually optional, and declarations of different kinds can be intermixed. Although all of the declarations are listed above as optional, in some cases using one declaration can mandate another. For example, if an operation raises an exception, the exception structure must be defined beforehand. In general, types, constants, and exceptions, as well as interface declarations, must be defined before they are referenced, as in C or C++.

This task results in a fully-specified IDL file, servant.idl, that contains a declaration for the public interface to a servant class, servant.

For example, for a servant class called WSLogger, the IDL file, WSLogger.idl, was created and edited to add the following interface definition:
interface WSLogger
{
  void setFileName(in string newFileName);
  string getFileName();
  void setMethodName( in string newMethodName );
  string getMethodName();
  short openLogFile();
  short closeLogFile();
  short writeLogMessage(in string newMessage, in short newSeverity);
  enum mdyFormat { DMY_DATE_FORMAT,
                   MDY_DATE_FORMAT };
  void setDateFormat(in unsigned short newDateFormat);
  unsigned short getDateFormat();
};

You can next compile the servant.idl to create the usage bindings and other files needed to complete the implementation, as described in Compiling the servant IDL (using idlc).

This task is one step of the parent task, Developing a CORBA server.