Java Programming  «Prev  Next»
Lesson 7 Mapping methods with out and inout
Objective Describe the mapping of IDL operations with out and inout parameters.

Mapping Methods with out and inout in Corba

Not every operation you will want to declare will be satisfied by one return value or immutable parameters. The declarators
  1. in,
  2. out, and
  3. inout
refer to how the parameter is copied over the wire. Parameters marked as in are copied and reconstructed on the server. Parameters marked as out work just like return values, in that there is no information copied from the client, but a brand new object is copied from the server and reconstructed on the client. Parameters marked as out work just like return values, in that there is no information copied from the client, but a brand new object is copied from the server and reconstructed on the client. Parameters marked inout are just like having one in parameter and one out parameter. The in side parameter is copied and reconstructed on the server side. The server can do whatever it wants with the local copy or create a new one. It then sends the out side of the parameter back when the method returns. On the client side, a wholly new object is created, just like a return value, and the reference is replaced as the stub method returns. In C++ or Pascal, where pass by reference or VAR parameters are allowed, the idea that the parameter reference is replaced with a new object reference or pointer is obvious. In Java, it requires a little work. The IDL-to-Java mapping creates, for each new class generated, a reference class so that objects can be passed by reference.

Mapped Methods with Holders

This holder class is simply a class named MyTypeHolder for every MyType created and has one public instance variable of type MyType named value.
The series of images below illustrates mapped methods with holders.

1) All elements defined in a module are in the same package
MyIdl.idl:
module MyMod {
    interface MyInterface {
        string myMethod(in string arg1, out long arg2, inout string arg3);
    };
};

MyInterface.java:
package MyMod;

public interface MyInterface extends org.omg.CORBA.Object {
    public String myMethod(String arg1, IntHolder arg2, StringHolder arg3);
}

Notes:
  • IDL to Java Mapping
    • The module in IDL corresponds to a package in Java.
    • The interface in IDL is mapped to a Java interface.
  • Parameter Mapping
    • IDL in parameters become regular Java method parameters.
    • IDL out parameters are represented as holders (e.g., IntHolder).
    • IDL inout parameters are also represented as holders (e.g., StringHolder).

Explanation: All elements defined in an IDL module are mapped to the same Java package.
2) The interface definition results in a class for the interface containing all the elements defined in the IDL interface
The interface definition results in a class for the interface containing all the elements defined in the IDL interface

3) Each operation maps to a single method in the Java Interface generated for the IDL interface. The method name and operation name are the same.
Each operation maps to a single method in the Java Interface generated for the IDL interface. The method name and operation name are the same.
4) The return value is mapped as the primitive type rules define
The return value is mapped as the primitive type rules define

5) The parameter type of an in parameter is mapped according to the primitive type mapping rules
The parameter type of an in parameter is mapped according to the primitive type mapping rules

6) The parameter type of an out parameter is mapped to a holder type of the resulting mapped primitive type.
The parameter type of an out parameter is mapped to a holder type of the resulting mapped primitive type.

7) An inout parameter is mapped exactly like an out parameter to a holder type of the resulting mapped primitive type.
An inout parameter is mapped exactly like an out parameter to a holder type of the resulting mapped primitive type.

Mapped Methods with Corba Holders

The basic C++ mappings defines how IDL types are represented in C++. It covers:
  1. mapping for identifiers
  2. scoping rules
  3. mapping for built-in types
  4. mapping for constructed types
  5. memory management rules
For each C++ construct, the compiler generates a definition into the client-side header file, and an implementation into the client-side stub file. General definitions (in the CORBA module) are imported with
#include < OB/CORBA.h>

In the next lesson, you will learn how to use holder objects.

SEMrush Software