这里有一个例子(英文) Example 4: Hello World with Implementation Inheritance Ordinarily, servant classes must inherit from the ImplBase class generated by the idltojava compiler. This is inadequate for servant classes that need to inherit functionality from another Java class. The Java programming language allows a class only one superclass and the generated ImplBase class occupies this position. Example 4 illustrates how a servant class can inherit (an implementation) from any Java class. In this example, the HelloServant class inherits its entire implementation from another Java class HelloBasic. At runtime, method requests for HelloServant are delegated to another idltojava-generated class. Example 4 is identical to Example 1 except for implementation inheritance enhancements. This page only discusses the code necessary for these enhancements. This section contains: The IDL for a simple "Hello World" program A server implementation that delegates method requests for HelloServant to another Java class. A client program. Instructions for compiling and running the example are provided. Interface Definition (Hello.idl) module HelloApp { interface Hello { string sayHello(); }; };Compile the IDL interface with the command: idltojava -ftie Hello.idlThis generates two additional files in a HelloApp subdirectory: _HelloOperations.java The servant class will implement this interface. _HelloTie.java This class acts as the skeleton, receiving invocations from the ORB and delegating them to the servant that actually does the work. Implementing the Server (HelloServer.java) // Copyright and License import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; class HelloBasic { public String sayHello() { return "\nHello world !!\n"; } }class HelloServant extends HelloBasic implements _HelloOperations { } 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 servant = new HelloServant(); Hello helloRef = new _HelloTie(servant); 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(); }
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); } } } Building and Running Hello World The following instructions assume you can use port 1050 for the Java IDL name server. Substitute a different port if necessary. Note that for ports below 1024, you need root access on UNIX machines, and administrator privileges on Windows95 and NT. Note also that the instructions use a slash (/) for path names. Windows95 and NT users should subtitute a backslash (\).Create source code files as shown above. Run idltojava on the IDL file to create stubs and skeletons: idltojava -ftie Hello.idlCompile the .java files, including the stubs and skeletons: javac *.java HelloApp/*.javaMake sure the name server is running: tnameserv -ORBInitialPort 1050&Start the Hello server: java HelloServer -ORBInitialPort 1050Run the Hello application client from a different shell than the server: java HelloClient -ORBInitialPort 1050
现在已经退一步了,不一定用Weblogic。 我用Java自己带的Tnameserv做NameService。在Win2K环境下,Applet\Application都OK。 并且在其他机器上也能访问这个远程对象。Linux的客户端可以访问Win2K的对象。但是如果Corba Server放在Linux上,就只能在Linux的本机上通过Corba进行访问,如果在其他Win2K的机器上,无论用Application or Applet都不能访问这个远程对象。命令如下:tnameserv -ORBInitialPort 1050Server:java CorbaServer -ORBInitialPort 1050 -ORBInitialHost 109.10.5.100Clientjava ApplicationClient -ORBInitialPort 1050 -ORBInitialHost 109.10.5.100 如果Server、TnameServ在Win2K上,一切OK。 如果在Linux上,就会包如下错误:Error:org.omg.CORBA.COMM_FAILURE: minor code: 1398079490 completed: No org.omg.CORBA.COMM_FAILURE: minor code: 1398079490 completed: No at com.sun.corba.se.internal.iiop.IIOPConnection.writeLock(IIOPConnectio n.java:919) at com.sun.corba.se.internal.iiop.IIOPConnection.send(IIOPConnection.jav a:980) at com.sun.corba.se.internal.iiop.IIOPOutputStream.invoke(IIOPOutputStre am.java:76) at com.sun.corba.se.internal.iiop.ClientRequestImpl.invoke(ClientRequest Impl.java:74) at com.sun.corba.se.internal.corba.ClientDelegate.invoke(ClientDelegate. java:152) at com.sun.corba.se.internal.corba.RequestImpl.doInvocation(RequestImpl. java:304) at com.sun.corba.se.internal.corba.RequestImpl.invoke(RequestImpl.java:2 23) at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java: 156) at unierp.corba.ApplicationClient.getRemoteObject(unierp/corba/Applicati onClient.java:46) 请在Linux\Corba方面有经验的大虾帮助解决。
Example 4: Hello World with Implementation Inheritance
Ordinarily, servant classes must inherit from the ImplBase class generated by the idltojava compiler. This is inadequate for servant classes that need to inherit functionality from another Java class. The Java programming language allows a class only one superclass and the generated ImplBase class occupies this position. Example 4 illustrates how a servant class can inherit (an implementation) from any Java class. In this example, the HelloServant class inherits its entire implementation from another Java class HelloBasic. At runtime, method requests for HelloServant are delegated to another idltojava-generated class. Example 4 is identical to Example 1 except for implementation inheritance enhancements. This page only discusses the code necessary for these enhancements. This section contains: The IDL for a simple "Hello World" program
A server implementation that delegates method requests for HelloServant to another Java class.
A client program.
Instructions for compiling and running the example are provided. Interface Definition (Hello.idl)
module HelloApp
{
interface Hello
{
string sayHello();
};
};Compile the IDL interface with the command: idltojava -ftie Hello.idlThis generates two additional files in a HelloApp subdirectory:
_HelloOperations.java
The servant class will implement this interface.
_HelloTie.java
This class acts as the skeleton, receiving invocations from the ORB and delegating them to the servant that actually does the work.
Implementing the Server (HelloServer.java)
// Copyright and License import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
class HelloBasic
{
public String sayHello()
{
return "\nHello world !!\n";
}
}class HelloServant extends HelloBasic implements _HelloOperations
{
}
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 servant = new HelloServant();
Hello helloRef = new _HelloTie(servant);
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);
}
}
}
Implementing the Client (HelloClient.java)
// 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);
}
}
}
Building and Running Hello World
The following instructions assume you can use port 1050 for the Java IDL name server. Substitute a different port if necessary. Note that for ports below 1024, you need root access on UNIX machines, and administrator privileges on Windows95 and NT. Note also that the instructions use a slash (/) for path names. Windows95 and NT users should subtitute a backslash (\).Create source code files as shown above.
Run idltojava on the IDL file to create stubs and skeletons:
idltojava -ftie Hello.idlCompile the .java files, including the stubs and skeletons:
javac *.java HelloApp/*.javaMake sure the name server is running:
tnameserv -ORBInitialPort 1050&Start the Hello server:
java HelloServer -ORBInitialPort 1050Run the Hello application client from a different shell than the server:
java HelloClient -ORBInitialPort 1050
http://java.sun.com/j2se/1.3.0/docs/guide/rmi-iiop/toJavaPortableUG.html
--没有大用的拉,每个 Corba 都有自己的 IDL 编译器...
--与 Application 有什么大的区别?把 applet 权限问题设定好后,与 application 一样的拉。
我用Java自己带的Tnameserv做NameService。在Win2K环境下,Applet\Application都OK。
并且在其他机器上也能访问这个远程对象。Linux的客户端可以访问Win2K的对象。但是如果Corba Server放在Linux上,就只能在Linux的本机上通过Corba进行访问,如果在其他Win2K的机器上,无论用Application or Applet都不能访问这个远程对象。命令如下:tnameserv -ORBInitialPort 1050Server:java CorbaServer -ORBInitialPort 1050 -ORBInitialHost 109.10.5.100Clientjava ApplicationClient -ORBInitialPort 1050 -ORBInitialHost 109.10.5.100
如果Server、TnameServ在Win2K上,一切OK。
如果在Linux上,就会包如下错误:Error:org.omg.CORBA.COMM_FAILURE: minor code: 1398079490 completed: No
org.omg.CORBA.COMM_FAILURE: minor code: 1398079490 completed: No
at com.sun.corba.se.internal.iiop.IIOPConnection.writeLock(IIOPConnectio
n.java:919)
at com.sun.corba.se.internal.iiop.IIOPConnection.send(IIOPConnection.jav
a:980)
at com.sun.corba.se.internal.iiop.IIOPOutputStream.invoke(IIOPOutputStre
am.java:76)
at com.sun.corba.se.internal.iiop.ClientRequestImpl.invoke(ClientRequest
Impl.java:74)
at com.sun.corba.se.internal.corba.ClientDelegate.invoke(ClientDelegate.
java:152)
at com.sun.corba.se.internal.corba.RequestImpl.doInvocation(RequestImpl.
java:304)
at com.sun.corba.se.internal.corba.RequestImpl.invoke(RequestImpl.java:2
23)
at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:
156)
at unierp.corba.ApplicationClient.getRemoteObject(unierp/corba/Applicati
onClient.java:46)
请在Linux\Corba方面有经验的大虾帮助解决。