Notice that in the Makefile, we have set the JNDI Naming Factory for initial contexts to the JNDI/COS provider from JavaSoft.
-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
package jndiCOS2;
import util.Util;
import helloWorld2.Hello;
import helloWorld2.HelloImpl;
import javax.naming.Context;
import javax.naming.InitialContext;
public class helloServer
{
public static void main(String[] args)
{
| try {
| |
| | // create a servant
| | Hello hello = new HelloImpl();
| |
| | // get the root naming context
| | Context ctx = new InitialContext(null);
| |
| | // bind the hello objref using JNDI
| | ctx.rebind("hello", hello);
| |
| | // wait for invocations
| | System.out.println("waiting for invocations ...");
| |
| } catch (Exception ex) {
| | ex.printStackTrace();
| }
}
}
ORB.init() is required.
package jndiCOS2;
import util.Util;
import helloWorld2.Hello;
import javax.naming.Context;
import javax.naming.InitialContext;
public class helloClient
{
public static void main(String[] args)
{
| try {
| |
| | // get the root naming context
| | Context ctx = new InitialContext(null);
| |
| | // lookup the hello objref
| | Hello hello = (Hello) ctx.lookup("hello");
| |
| | // invoke method on the object
| | System.out.println(hello.sayHello());
| |
| } catch (Exception ex) {
| | ex.printStackTrace();
| }
}
}
package jndiCOS2;
import java.awt.Graphics;
import java.util.Hashtable;
import helloWorld2.Hello;
import javax.naming.Context;
import javax.naming.InitialContext;
public class helloApplet extends java.applet.Applet
{
private String _message = "";
public void init() {
| try {
| |
| | // get the root naming context
| | Context ctx = new InitialContext(null);
| |
| | // lookup the hello objref
| | Hello hello = (Hello) ctx.lookup("hello");
| |
| | // invoke method on the object
| | _message = hello.sayHello();
| |
| } catch (Exception ex) {
| | ex.printStackTrace();
| }
}
public void paint(Graphics g)
{
| g.drawString(_message, 25, 50);
}
}
| Copyright © 2000-2003, Novell, Inc. All rights reserved. |