.$B$3$N%Z!<%8$G$O!"
.$B$3$N%W%m%0%i%`Nc$N%3%s%Q%$%kJ}K!$H .$BsayHello() .$B$H$$$&%*%Z%l!<%7%g%s$,.(B 1 .$B$D$@$14^$^$l$?.(B CORBA .$B%*%V%8%'%/%H$r5-=R$7$?$b$N$G$9!#.(B .$B$3$N.(B IDL .$B%$%s%?%U%'!<%9$O!"
idltojava Hello.idl
.$B$3$l$K$h$j!".(B .$B$3$3$G>R2p$9$k%5!<%P$O!"%5!<%P%s%H$H%5!<%P$N.(B 2 .$B$D$N%/%i%9$G9=@.$5$l$^$9!#.(B
.$B%5!<%P%s%H$G$"$k.(B HelloServant .$B$O!".(B
IDL .$B%$%s%?%U%'!<%9.(B Hello .$B$N .$B%5!<%P%/%i%9$K$O%5!<%P$N.(B main() .$B%a%=%C%I$,4^$^$l$^$9!#.(B .$B$3$N.(B main() .$B%a%=%C%I$G$O!"
.$B$3$N%"%W%j%1!<%7%g%s%/%i%$%"%s%H$G$O!"
.$B$3$N%"%W%l%C%H%/%i%$%"%s%H$G$O!"
.$B$3$N%W%m%0%i%`Nc$N%=!<%9%3!<%I$O!".(B
examples/hello .$B%G%#%l%/%H%j$K$"$j$^$9!#.(B
.$B0J2<$N@bL@$G$O!".(BJava IDL .$B%M!<%`%5!<%PMQ$K%]!<%H.(B 1050 .$B$r;HMQ$G$-$k$3$H$rA0Ds$H$7$F$$$^$9!#I,MW$G$"$l$PJL$N%]!<%H$KJQ99$7$F$/$@$5$$!#$J$*!".(B1024 .$B0J2<$N%]!<%H$r;HMQ$9$k>l9g$O!".(BUNIX .$B%^%7%s$G$"$l$P%9!<%Q!<%f!<%6$N8"8B$,!".(BWindows95 .$B$*$h$S.(B NT .$B$G$"$l$P4IM} .$BCm.(B: Hello World .$B$r9=C[$7
Copyright © 1995-98
Sun Microsystems, Inc.
All Rights Reserved..$B%$%s%?%U%'!<%9Dj5A.(B (
Hello.idl
)
module HelloApp
{
interface Hello
{
string sayHello();
};
};
.$BCm.(B: OMG IDL .$B$G%3!<%I$r5-=R$9$k>l9g!"%b%8%e!<%kL>$K%$%s%?%U%'!<%9L>$r;HMQ$7$J$$$G$/$@$5$$!#.(B .$B%b%8%e!<%kL>$K%$%s%9%?%s%9L>$r;HMQ$9$k$H!"0[$J$k%Y%s%@!<$N%D!<%k$r;H$C$?%3%s%Q%$%kHelloApp
.$B%5%V%G%#%l%/%H%j$K
.$B%"%W%j%1!<%7%g%s$r40@.$5$;$k$K$O!"%5!<%P$H%/%i%$%"%s%H$r!"$=$l$>$l.(B
HelloServer.java
.$B%U%!%$%k$H.(B HelloClient.java
.$B%U%!%$%k$G.$B%5!<%P$N
// Copyright and License
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
class HelloServant extends _HelloImplBase
{
public String sayHello()
{
return "\nHello world !!\n";
}
}
public class HelloServer {
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create servant and register it with the ORB
HelloServant helloRef = new HelloServant();
orb.connect(helloRef);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// bind the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
ncRef.rebind(path, helloRef);
// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync) {
sync.wait();
}
} catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}
.$B%/%i%$%"%s%H$N
// Copyright and License
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class HelloClient
{
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get the root naming context
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));
// call the Hello server object and print results
String hello = helloRef.sayHello();
System.out.println(hello);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}
.$B%"%W%l%C%H%/%i%$%"%s%H$N
// Copyright and License
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.awt.Graphics;
public class HelloApplet extends java.applet.Applet
{
public void init() {
try {
// create and initialize the ORB
ORB orb = ORB.init(this, null);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));
// call the Hello server object and print results
message = helloRef.sayHello();
} catch (Exception e) {
System.out.println("HelloApplet exception: " + e.getMessage());
e.printStackTrace(System.out);
}
}
public void paint(Graphics g)
{
g.drawString(message, 25, 50);
}
String message = "";
}
Hello World .$B$N9=C[J}K!$H
idltojava
.$B$O!".(BJDC (Java Developer Connection) Web .$B%Z!<%8$+$iL5=~$G%@%&%s%m!<%I$G$-$^$9!#$3$N%Z!<%8$K%"%/%;%9$9$k$K$O!".(BJDC .$B$N%a%s%P$G$J$1$l$P$J$j$^$;$s!#.(B JDC .$B$N%a%s%P$G$J$$>l9g$O!".(BJDC .$B$KEPO?$9$kI,MW$,$"$j$^$9!#.(B .$BEPO?NA$OL5NA$G$9!#.(B .$B%@%&%s%m!<%I%Z!<%8$O
http://java.sun.com/j2se/1.5.0/docs/guide/rmi-iiop/toJavaPortableUG.html
.$B3HD%;R!V.(B.bin.$B!W$N%U%!%$%k$,%@%&%s%m!<%I$5$l$k$N$G!".(B .$B$3$N%U%!%$%k$ridltojava
.$B%3%s%Q%$%i$r;HMQ$G$-$^$;$s!#.(B
cd docs/guide/idl/examples/hello
idltojava Hello.idl
javac *.java HelloApp/*.java
tnameserv -ORBInitialPort 1050&
java HelloServer -ORBInitialPort 1050
.$B%[!<%`.(B