Client application

A client application definition of the aforementioned communication can be established using the following steps:

  • Initialize the CORBA environment and get the reference to ORB
  • Get the object reference for the object to invoke the operation
  • Invoke the operations and process the result

The following code snippet will generate the Java interface:

package org.admin.hr.employee;
public interface Registry extends RegistyOperations, org.omg.CORBA.object, org.omg.CORBA.portable.IDLEntry
{
}

The RegistryOperations interface is defined as follows:

package org.admin.hr.employee;
public interface RegistryOperations {
public java.lang.String register();
}

ORB can be initialized using the following code snippet:

package org.admin.hr.employee;
import java.io.*;
import org.omg.CORBA.*;
public class Client {
public static void main(String args[]) {
try {
ORB orb = ORB.init (args. Null);
}
Catch(Exception e) {
System.out.println("Exception " + e);
}
}
}

An object reference can be obtained in this ORB setup as follows:

org.omg.CORBA.Object obj = orb.string_to_object (args[0]);

Get the Registry object reference by invoking the narrow () method from the helper class, as follows:

Registry reg = RegistryHelper.narrow(obj);
If (reg == null) {
System.err.println("object reference type fault”);
System.exit(-1);
}

Once the object reference is found from ORB as earlier, its method can be invoked as a local Java method itself:

System.out.println(reg.register());

Compile and execute the Java client program as follows:

prompt > javac Client.java
prompt > java org.admin.hr.employee.Client IOR:0002453..2

This should give the output as follows:

Employee Rohith, is now registered
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset