Creating and editing interfaces

Interfaces can be added in EAServer Manager, creating a blank interface declaration, or you can declare the interface yourself by editing the module’s IDL definition.

NoteChoosing an interface name Interface names are restricted as follows:

Sybase recommends that you begin interface names with a capital letter, and operation names with a lowercase letter.

NoteSupported preprocessor directives No IDL preprocessor directives other than #include are supported.

StepsCreating new interfaces in EAServer Manager

  1. Highlight the module’s icon and choose File | New IDL Entity.

  2. Type the name of the new interface, choose Interface in the dropdown list of IDL entity types, and click Ok.

  3. Click Ok.

  4. EAServer Manager displays a new, blank interface in the IDL Editor window. Edit the declaration if needed.

  5. When done, choose File | Save, then File | Exit to close the IDL Editor window.

StepsEditing an existing interface

  1. Select the interface’s icon and choose File | Edit IDL.

  2. EAServer Manager extracts the interface definition from the module and displays it in the IDL editor window.

  3. Edit the declaration as needed.

  4. When done, choose File | Save, then File | Exit to close the IDL Editor window.

IDL interface declarations

Interfaces are declared as shown below:

interface InterfaceName [: BaseInterface1, BaseInterface2, ...] {
  operations
};

where:

For example, this interface, StockComponent, inherits from no other interface:

interface StockComponent {
};

This interface, C, inherits from interfaces A and B:

interface C : A, B {
}

Interfaces that inherit definitions from other interfaces are subject to the following constraints:

The sections below describe how to define operations and attributes for the interface.

Interface stub generation directives

You can embed specially formatted comments in IDL to control the generation of Java stubs for IDL interfaces and structures. Directives must appear in a block comment located immediately before the IDL interface or struct declaration.

Imported class name This directive specifies that a structure or interface was imported from a Java class, and that a new version of the imported class must not be generated when stubs are generated. This directive is most commonly used for EJB home and remote interfaces and EJB primary keys that were defined by importing EJB classes or EJB-JAR files.

The format is:

** <!-- imported classname -->

Where classname is the Java class name, in dot notation. For example, foo.bar.MyBeanHome or foo.bar.MyBeanPrimaryKey.

Is home interface This directive identifies an interface as a home interface used by EJB clients and components. If you specify a home interface for a component as described in “Changing the EJB remote or home interface”, EAServer Manager adds this directive. The format is:

** <!-- home -->

Finder method return type Applies to multi-object finder methods in an EJB entity bean’s home interface. If a finder method’s Java form must return java.util.Enumeration, add a doc comment of this form above the IDL finder method declaration:

/*
** <!-- java.util.Enumeration -->
*/
::MyModule::MyRemoteList findByName(in string name);

See “Defining home interface methods” for more information on EJB finder methods.

Operation declarations

Operations in an IDL interface become component methods when the interface is assigned to a component. You can define operations directly in IDL, or graphically as described in “Defining interfaces graphically”. If you define operations in IDL, follow the structure described here.

Operations are declared as follows:

returnType opName 
( 
[ ... parameterList ... ] 
)
[  raises ( ... exceptionList ... ) ] ;

where:

Attribute declarations

Attributes allow you to associate a value with an interface. IDL attributes are similar in concept to structure fields in languages such as C. However, when mapped to a programming language, attribute values can typically be accessed only by generated functions that allow you to set and retrieve the attribute’s value.

NoteAttributes are not supported by ActiveX components and clients.

Attributes are declared as shown below:

[ readonly ] attribute TypeSpec name;

where

In C++ and Java, a read-only attribute maps to a method with the same name that returns the attribute type. A writable attribute maps to a pair of overloaded methods with the same name as the attribute. For example, consider the following IDL declarations:

readonly attribute long days; // readonly
attribute long months;        // writable

In a C++ or Java implementation of the interface, these methods must be declared:

long days();
long months();
void months(long new_months);

NoteCurrently, attributes do not do not display with a component’s methods in EAServer Manager. Use the IDL editor to view attribute definitions.

Datatypes for parameters and return values

To define parameter and return value datatypes, you can use EAServer’s predefined IDL datatypes or your own user-defined IDL types. In addition, EAServer extends IDL to allow the use of Java class names. The sections below describe each option in detail.

Predefined IDL datatypes EAServer ships with predefined datatypes for use in declaring parameter and return value datatypes. Predefined datatypes include all CORBA base types (except for the CORBA::Any type) and equivalents for database result sets and other commonly used database column types such as date, time, and timestamp.

EAServer Manager’s Method Properties dialog box displays the predefined datatypes in the drop-down lists for Parameter and Return types. “Predefined datatypes” lists EAServer’s predefined IDL datatypes, the equivalent display names, and a description of each.

For descriptions of the datatypes defined in the BCD, MJD, or TabularResults modules, see the documentation in the html/ir subdirectory of your EAServer installation. (Or, load the main EAServer HTML page in your Web browser, and click the Interface Repository link). If you use types from these modules, add an include directive for the appropriate module at the top of the module that defines your interface. For example:

#include <TabularResults.idl>

Internally, TabularResults.idl includes both BCD.idl and MJD.idl. You need not include BCD.idl and MJD.idl explicitly if you have already included TabularResults.idl.

User-defined IDL datatypes In addition to EAServer’s predefined datatypes, you can define your own datatypes in IDL and use them to declare return types and parameters.

All IDL type definitions are allowed, with these exceptions:

User-defined types must exist in the EAServer IDL repository before you can use them in interface declarations. For information on defining datatypes, see Chapter 3, “OMG IDL Syntax and Semantics,” in the CORBA 2.3 specification.

In some cases, you must use the full scope name. In a parameter list, use a type’s full scope name if any of the following is true:

For example, consider the IDL:

module MyMod {
    typedef string MyType;
    interface MyIntf {
        typedef double MyOtherType;
        ....
    };
};

With these declarations, MyMod::MyType is the full scope name for MyType and MyMod::MyIntf::MyOtherType is the full scope name for MyOtherType.

Java class names used as IDL datatypes EAServer’s IDL compiler extends IDL to allow Java class names as parameter and return types for methods. This feature provides functionality that is similar to the proposed Objects by Value CORBA extension (OMG TC Document orbos/98-01-18, Objects By Value). Specifically, you can pass a copy of an object rather than passing an interface pointer that refers back to the original object.

You can specify any Java class name for a method input parameter or return type as long as:

Note the following restrictions for methods that are defined using Java datatypes rather than IDL or predefined EAServer Manager types:

User-defined exceptions

Exceptions can be declared in a module or interface. Exceptions are declared as follows:

exception name {
    ... memberList ...
};

where name is the name of the exception and memberList is an optional list of member field declarations. This list has the form:

exception MyException {
    type1 member1;
    type2 member2;
    ...
};

Where type1, type2, and so forth are IDL type names (other than CORBA::Any) and member1, member2, and so forth are the names of the member fields.

Once you have defined an exception, you can use it in the raises clause when defining operations for an interface, as described in “Operation declarations”.

NoteUser-defined exceptions are not supported by ActiveX components and clients.