[omniORB] Missing Java source

Glenn A. Hochberg ghochberg@att.com
Wed, 01 Mar 2000 17:38:14 -0500


This is a multi-part message in MIME format.
--------------AA2CA204B932F10AA5989E2D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

On Tuesday 29 February, Duncan Grisby wrote:

> On Monday 28 February, Fred Cook wrote:
>
> > Looking at your src/jave/../../../.. dirs from an omniORB_280 NT
> > install, we find no source code present.  Where can one find the source
> > for the java equal of eg3_clt?
>

[...]

> The examples last existed in the omniORB 2.6.1 release. If someone
> wants to volunteer to resurrect them, and write some proper
> documentation, then we'll happily make them available from our site.

I have a Java version of the eg3_clnt, with a README, a simple makefile, and
a Bourne shell script to run it.

Since they are relatively small, I have attached them below.  Just snip into
the indicated files.

    Cheers,
        Glenn

------- EchoClnt3.java ---------------
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;

public class EchoClnt3 {

  public static void main(String[] args) {

 try {
   // initialize orb
   org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

   org.omg.CORBA.Object obj = getObjectReference(orb);
   if (obj == null) {
  System.err.println("Couldn't get object reference.");
  return;
   }
   hello(obj);
 }
 catch (org.omg.CORBA.SystemException ex) {
  System.out.println("EchoClnt3: got a system exception.");
  System.out.println(ex);
 }
  }

  static org.omg.CORBA.Object getObjectReference(org.omg.CORBA.ORB orb) {

 NamingContext rootContext;

 try {
   // Obtain a reference to the root context of the Name service:
   org.omg.CORBA.Object initServ;
   initServ = orb.resolve_initial_references("NameService");

   // Narrow the object returned by resolve_initial_references()
   // to a CosNaming.NamingContext object:
   rootContext = NamingContextHelper.narrow(initServ);
   if (rootContext == null)
   {
  System.err.println("Failed to narrow naming context.");
  return null;
   }
 }
 catch(org.omg.CORBA.ORBPackage.InvalidName ex) {
   System.err.println("Service required is invalid [does not exist].");
   return null;
 }

 // Create a name object, containing the name test/context:
 NameComponent[] name = new NameComponent[2];
 name[0] = new NameComponent("test", "my_context");
 name[1] = new NameComponent("Echo", "Object");

 org.omg.CORBA.Object obj;
 try {
   // Resolve the name to an object reference, and assign the reference
   // returned to a CORBA.Object:
   obj = rootContext.resolve(name);
 }
 catch(NotFound ex) {
   // This exception is thrown if any of the components of the
   // path [contexts or the object] aren't found:
   System.err.println("Context not found.");
   return null;
 }
 catch(org.omg.CORBA.COMM_FAILURE ex) {
   System.err.println("Caught system exception COMM_FAILURE, unable to" +
  " contact the naming service.");
   return null;
 }
 catch(Exception ex) {
   System.err.println("Exception caught: " + ex);
   return null;
 }
 return obj;
  }

  static void hello(org.omg.CORBA.Object obj)
  {
 Echo e = EchoHelper.narrow(obj);

 if (e == null) {
   System.err.println("hello: cannot invoke on a nil object reference.");
   return;
 }

 String src = "Hello!";
 String dest;

 dest = e.echoString(src);

 System.err.println("I said,\"" + src + "\"." +
   " The Object said,\"" + dest + "\"");
  }
}
--------- end of EchoClnt3.java ----------
--------- echo.idl -------------------
#ifndef __ECHO_IDL__
#define __ECHO_IDL__

interface Echo {
  string echoString(in string mesg);
};

#endif
-------- end of echo.idl ------------
-------- README -----------------
EchoClnt3 - Java port of eg3_clnt from omniORB 2.8.0.

Files:
 EchoClnt3.java - the source code
 makefile - simple makefile
 README  - this file
 run.sh  - Bourne shell script to run the class


Instructions:

1)  Note you must use JDK 1.2.x.

    Make sure you have the JDK 1.2 idltojava compiler in your path.

    As of the last time I checked, this was not delivered as part of the base

    JDK, but was an add-on that you have to download.

    Note also that you shouldn't have to set your CLASSPATH to anything as
    the ORB classes are in the standard JDK places, but make sure you don't
    have a different Java ORB's jars in your CLASSPATH.


2)  Compile the client:

 make

    or without the makefile:

 mkdir work
 idltojava -j work echo.idl
 javac -classpath work -d work EchoClnt3.java


3)  Now you can run the client, assuming you have the corresponding eg3_impl
    server and the Naming Service already running.

    java -Dorg.omg.CORBA.ORBInitialHost=<host-of-NamingService> \
      -Dorg.omg.CORBA.ORBInitialPort=<port-of-NamingService> EchoClnt3

    or you can use the run.sh script:

 sh run.sh

-------------- end of README ----------------
-------------- makefile -------------------

WORK = work

ECHOCLNT3 = $(WORK)/EchoClnt3.class

GENNED = $(WORK)/Echo.java $(WORK)/EchoHelper.java $(WORK)/EchoHolder.java
$(WORK)/_EchoImplBase.java $(WORK)/_EchoStub.java

all: make-work $(ECHOCLNT3)

make-work:
 if [ ! -d $(WORK) ]; then mkdir $(WORK); fi

$(ECHOCLNT3): EchoClnt3.java $(GENNED)
 javac -classpath $(WORK) -d $(WORK) EchoClnt3.java

$(GENNED): echo.idl
 idltojava -j $(WORK) echo.idl

clean:
 -rm -rf $(WORK)

------------- end of makefile --------------
------------- run.sh ------------------
HOST=   # Fill in host of COS Naming Service
PORT=   # Fill in port of COS Naming Service
WORK=work

if [ -z "$HOST" ]
then echo "Enter Naming Service host: \c"; read HOST
fi
if [ -z "$PORT" ]
then echo "Enter Naming Service port: \c"; read PORT
fi

java -classpath ${WORK} -Dorg.omg.CORBA.ORBInitialHost=${HOST:?} \
  -Dorg.omg.CORBA.ORBInitialPort=${PORT:?} EchoClnt3
-------------- end of run.sh ----------------

--
Glenn A. Hochberg  | "Any activity becomes creative when the doer
AT&T Labs          |  cares about doing it right, or doing it better."
ghochberg@att.com  |      -John Updike

--------------AA2CA204B932F10AA5989E2D
Content-Type: text/x-vcard; charset=us-ascii;
 name="ghochberg.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Glenn A. Hochberg
Content-Disposition: attachment;
 filename="ghochberg.vcf"

begin:vcard 
n:Hochberg;Glenn
tel;fax:973 236-6019
tel;work:973 236-6638
x-mozilla-html:TRUE
org:<div align=center><img src="http://www.att.com/images/attlogo_n9050.gif" width=90 height=50></div>;Software Practices & Technology
version:2.1
email;internet:ghochberg@att.com
title:Senior Technical Staff<br><b>AT&T Labs
adr;quoted-printable:;;AT&T Labs - Shannon Laboratory<br>=0D=0ARoom 2A21, Building 104<br>=0D=0A180 Park Avenue<br>=0D=0AP.O. Box 971;Florham Park;N.J.;07932-0971;USA
x-mozilla-cpt:;-10720
fn:Glenn Hochberg
end:vcard

--------------AA2CA204B932F10AA5989E2D--