[Ericsson AB]

10 IDL to Java language Mapping

10.1 Introduction

This chapter describes the mapping of OMG IDL constructs to the Java programming language for the generation of native Java - Erlang communication.

This language mapping defines the following:

10.2 Specialities in the Mapping

10.2.1 Names Reserved by the Compiler

The IDL compiler reserves all identifiers starting with OE_ and oe_ for internal use.

10.3 Basic OMG IDL Types

The mapping of basic types are according to the standard. All basic types have a special Holder class.

OMG IDL basic types
OMG IDL type Java type
float float
double double
short short
unsigned short short
long int
long long long
unsigned long long
unsigned long long long
char char
wchar char
boolean boolean
octet octet
string java.lang.String
wstring java.lang.String
any Any
long double Not supported
Object Not supported
void void

10.4 Constructed OMG IDL Types

All constructed types are according to the standard with three (3) major exceptions.

10.5 Mapping for Constants

Constants are mapped according to the standard.

10.6 Invocations of Operations

Operation invocation is implemented according to the standard. The implementation is in the class _<nterfacename>Stub.java which implements the interface in <nterfacename>.java.

test._iStub client;

client.op(10);
    

10.6.1 Operation Implementation

The server is implemented through extension of the class _<nterfacename>ImplBase.java and implementation of all the methods in the interface.

public class server extends test._iImplBase {
  
  public void op(int i) throws java.lang.Exception {
    System.out.println("Received call op()");
    o.value = i;
    return i;
  }

}
      

10.7 Exceptions

While exception mapping is not implemented, the stubs will generate some Java exceptions in case of operation failure. No exceptions are propagated through the communication.

10.8 Access to Attributes

Attributes are supported according to the standard.

10.9 Summary of Argument/Result Passing for Java

All types (in, out or inout) of user defined parameters are supported in the Java mapping. This is also the case in the Erlang mappings but not in the C mapping. inout parameters are not supported in the C mapping so if you are going to do calls to or from a C program inout cannot be used in the IDL specifications.

out and inout parameters must be of Holder types. There is a jar file ( ic.jar) with Holder classes for the basic types in the ic application. This library is in the directory $OTPROOT/lib/ic_<version number>/priv.

10.10 Communication Toolbox

The generated client and server stubs use the classes defined in the jinterface package to communicate whith other nodes. The most important classes are :

10.11 The Package com.ericsson.otp.ic

The package com.ericsson.otp.ic contains a number of java classes specially designed for the IC generated java-back-ends :

10.12 The Term Class

The Term class is intended to represent the Erlang term generic type. It extends the Any class and it is basically used in the same way as in the Any type.

The big difference between Term and Any is the use of guard methods instead of TypeCode to determine the data included in the Term. This is especially true when the Term's value class cannot be determinated at compilation time. The guard methods found in Term :

10.13 Stub File Types

For each interface, three (3) stub/skeleton files are generated :

10.14 Client Stub Initialization, Methods Exported

The recommended constructor function for client stubs accepts four (4) parameters :

The methods exported from the generated client stub are :

10.15 Server Skeleton Initialization, Server Stub Implementation, Methods Exported

The constructor function for server skeleton accepts no parameters.

The server skeleton file contains a server switch which decodes messages from the input stream and calls implementation (callback) functions. As the server skeleton is declared abstract, the application programmer will have to create a stub class that extends the skeleton file. In this class, all operations defined in the interface class, generated under compiling the idl file, are implemented.

The server skeleton file exports the following methods:

10.16 A Mapping Example

This is a small example of a simple stack. There are two operations on the stack, push and pop. The example shows some of the generated files.

// The source IDL file: stack.idl

struct s {
      long l;
      string s;
};

interface stack {
    void push(in s val);
    s pop();
};

    

When this file is compiled it produces eight files. Three important files are shown below.

The public interface is in stack.java.


public interface stack {

/****
 * Operation "stack::push" interface functions 
 *
 */

    void push(s val) throws java.lang.Exception;

/****
 * Operation "stack::pop" interface functions 
 *
 */

    s pop() throws java.lang.Exception;

}

    

For the IDL struct s three files are generated, a public class in s.java.


final public class s {
   // instance variables
   public int l;
   public java.lang.String s;

   // constructors
   public s() {};
   public s(int _l, java.lang.String _s) {
     l = _l;
     s = _s;
   };

};

    

A holder class in sHolder.java and a helper class in sHelper.java. The helper class is used for marshalling.


public class sHelper {

   // constructors
   private sHelper() {};

   // methods
   public static s unmarshal(OtpInputStream in) 
      throws java.lang.Exception {
        :
        :
   };

   public static void marshal(OtpOutputStream out, s value) 
      throws java.lang.Exception {
        :
        :
   };

};


    

10.17 Running the Compiled Code

When using the generated java code you must have added $OTPROOT/lib/ic_<version number>/priv and $OTPROOT/lib/jinterface_<version number>/priv to your CLASSPATH variable to get basic Holder types and the communication classes.


ic 4.2.13
Copyright © 1991-2007 Ericsson AB