Mapping Clients  «Prev  Next»
Lesson 1

Java mapping Clients and Servers

In this module, you will deepen your understanding of the IDL-to-Java mapping by examining how IDL interfaces are mapped to Java stubs and skeletons that are used in clients and servers and how to develop these clients and servers.

Module Objectives

By the end of this module, you will be able to:
  1. Describe how stubs and skeletons in Java correspond to IDL interfaces
  2. Write a CORBA server in Java
  3. Write a CORBA object implementation in Java
  4. Write a client in Java
  5. Describe the purpose and use of the narrow() method for interface helper classes

Deepen understanding of the "IDL-to-Java mapping"

To deepen your understanding of IDL-to-Java mapping in CORBA, especially how IDL interfaces are mapped to Java stubs and skeletons, you should follow a structured approach combining theoretical concepts and hands-on practice. Here's how to proceed:
  1. Understand the IDL (Interface Definition Language) Basics

    • IDL is used in CORBA to define the interfaces that objects present to the outside world.
    • Learn the IDL syntax: module, interface, struct, enum, typedef, attribute, operation.

    Example IDL:

    module HelloApp {
      interface Hello {
        string sayHello();
        oneway void shutdown();
      };
    };
    
  2. Learn the IDL-to-Java Mapping Rules

    Each IDL construct maps to a Java construct as per the CORBA specifications.

    IDL Construct Java Mapping
    interface A Java interface extending org.omg.CORBA.Object
    struct A final Java class with public fields
    enum A Java class with constant fields
    exception A Java class extending org.omg.CORBA.UserException
    typedef No direct mapping (resolved to base type)
    module A Java package
  3. Use the idlj Compiler

    Compile your .idl file using the idlj compiler:

    idlj -fall Hello.idl
    

    This generates:

    • _Hello.java — The client stub interface.
    • HelloHelper.java — Helper class for marshalling/unmarshalling.
    • HelloHolder.java — Used for out/inout parameters.
    • _HelloStub.java — Client-side stub that communicates with the ORB.
    • HelloPOA.java — Abstract server skeleton to be extended for implementation.
  4. Dissect the Generated Files

    • _Hello.java

      An interface for client applications.

    • _HelloStub.java

      Implements _Hello.java, marshals requests to the remote object.

    • HelloPOA.java

      Abstract base class for the servant. You override it to implement business logic.

    • HelloHelper.java

      Provides helper methods like:

      Hello narrow(org.omg.CORBA.Object obj);
      void insert(Any a, Hello that);
      Hello extract(Any a);
      
    • HelloHolder.java

      Used for out and inout parameters.

  5. Implement the Server

    You write a class that extends HelloPOA and implements the sayHello() method.

    public class HelloImpl extends HelloPOA {
      public String sayHello() {
        return "Hello, world!";
      }
      public void shutdown() {
        orb.shutdown(false);
      }
    }
    
  6. Compile and Run Using ORB

    Use ORB.init(args, null) and bind the servant in the CORBA Naming Service. Then, use the stub on the client side.

  7. Review IDL-Java Type Mappings

    IDL Type Java Type
    short short
    long int
    long long long
    float float
    double double
    boolean boolean
    char char
    string java.lang.String
    any org.omg.CORBA.Any
    Object org.omg.CORBA.Object

  8. Use a Visual Diagram

    Create a visual mapping flow:

    IDL Hello.idl
        ↓
    idlj compiler
        ↓
    Java Interfaces + Stubs + Skeletons
        ↓
    Implement HelloPOA.java → Run ORB server
        ↓
    Use _HelloStub.java in the client via Naming Service
    
  9. Deepen by Debugging and Tracing

    Use logging or IDE breakpoints to trace:

    • how the client calls the stub,
    • how the stub uses the ORB,
    • how the ORB routes to the skeleton (servant),
    • how results are marshalled back.
  10. ✅ 10. Suggested Practice Project
    1. Define a simple IDL for a calculator.
    2. Generate Java bindings using `idlj`.
    3. Implement the server logic.
    4. Write a CORBA client to invoke the operations.
    5. Extend the IDL with new operations or structs and regenerate.

Corba Programming C++
Client and Object (Servant) communicate with the ORB interface.
Client and Object (Servant) communicate with the ORB interface.
  1. CORBA shields applications from heterogeneous platform dependencies
  2. for example: languages, operating systems, networking protocols, hardware
  3. It simplifies development of distributed applications by automating/encapsulating
    1. Object location
    2. Connection & memory mgmt.
    3. Parameter (de)marshaling
    4. Event & request demultiplexing
    5. Error handling & fault tolerance
    6. Object/server activation
    7. Concurrency
    8. Security
  4. CORBA defines interfaces, not implementations

In the next lesson, we will review the structure and components of the CORBA programming model.

SEMrush Software