HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Developing Distributed Applications in CORBA:
 A Tutorial"
Vol. 3, Issue 5, p. 52

	

Listing 1: Arith.idl
  
 module Arith {  
     interface Add {  
         const unsigned short SIZE = 10;  
         typedef long array[SIZE];  
         void sum_arrays(in array a, in array b, out array c);  
     }  
 }  

Listing 2: % idl2java Arith.idl
  
 Creating: Arith  
 Creating: Arith/AddPackage  
 Creating: Arith/AddPackage/SIZE.java  
 Creating: Arith/AddPackage/arrayHolder.java  
 Creating: Arith/AddPackage/arrayHelper.java  
 Creating: Arith/Add.java  
 Creating: Arith/AddHolder.java  
 Creating: Arith/AddHelper.java  
 Creating: Arith/_st_Add.java  
 Creating: Arith/_sk_Add.java  
 Creating: Arith/_AddImplBase.java  
 Creating: Arith/AddOperations.java  
 Creating: Arith/_tie_Add.java  
 Creating: Arith/_example_Add.java  
 %  

Listing 3: Add.java
  
 public interface Add extends org.omg.CORBA.Object {  
    public void sum_arrays(  
       int[] a;  
       int[] b;  
       Arith.AddPackage.arrayHolder c  
    );  
 }  

Listing 4: AddImpl.java
  
 public class AddImpl extends Arith._AddImplBase {  
     /** Construct a persistently named object. */  
     public AddImpl(java.lang.String name) {  
           super(name);  
     }  
     /** Construct a transient object. */  
     public void sum_arrays() {  
         super();  
     }  
      public void sum_arrays(  
           int[] a,  
           int[] b,  
           Arith.AddPackage.arrayHolder c  
      ) {  
            c.value = new int[10];  
          for (int i = 0; i < Arith.AddPackage.SIZE.value; i++) {  
              c.value[i] = a[i] + b[i];  
          }  
      }  
 }  
   
Listing 5: Server.java
  
import org.omg.CORBA.*;  

public class Server {  
   public static void main(String argv[]) {  
 try {  
    // initialize the ORB  
    ORB orb = ORB.init();  
    // initialize the BOA  
    BOA boa = orb.BOA_init();  
    // create the AddImpl object  
    AddImpl arr = new AddImpl(“Arithmetic Server”);  
    // export the newly created object  
    boa.obj_is_ready(arr);  
    System.out.println(arr + “ is ready.”);  
    // wait for incoming requests  
    boa.impl_is_ready();  
 } catch(SystemException se) {  
    se.printStackTrace();  
 }  
   }  
}  

Listing 6: Client.java
  
import org.omg.CORBA.*;  

public class Client {  
   public static void main(String argv[]) {  
 int a[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2};  
 int b[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4};  
 Arith.AddPackage.arrayHolder result = new  
 Arith.AddPackage.arrayHolder();  
 try {  
    // initialize the ORB  
    ORB orb = ORB.init();  
    // Locate an Add object  
    Arith.Add add = Arith.AddHelper.bind(orb, “Arithmetic Server”);  
    add.sum_arrays(a, b, result);  
    System.out.print(“The sum is: “);  
    for (int i = 0; i < Arith.AddPackage.SIZE.value; i++) {  
  System.out.println(result.value[i];  
    }  
 } catch(SystemException se) {  
    se.printStackTrace();  
 }  
   }  
}
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.