org.omg.CORBA.Object
and inherit from another class. You can use it to work around Java's single-inheritance restriction when it is not convenient or possible to have your implementation class inherit from the ISB for Java skeleton class.
The tie mechanism provides a delegator implementation class that inherits from org.omg.CORBA.Object
. The delegator implementation does not provide any semantics of its own. Instead, it delegates every call to the real implementation class, which can be implemented separately and can inherit from any class it wishes.
The procedures for developing and running a client application or applet are the same whether you use the tie mechanism or not. This sample application was developed under Windows NT 4.0. It assumes that
c:\projects\tieMsg
is its root directory, that some files reside there, some in a subdirectory named SendMsg
. If you recreate this sample application using a different configuration, change code and commands accordingly.SendMsg.idl
) for this example.module SendMsg {The
interface Hello {
string sayHello();
};
};
idl2java
compiler generates files to support the tie mechanism by default. The following command compiles SendMsg.idl
(the -no_comments
flag suppresses comments in generated files, reducing clutter for this example).c:\projects\tieMsg> java2idl -no_comments SendMsg.idl
idl2java
compiler generates a file containing a code framework you can use to implement interfaces (in this example, the file is _example_Hello.java
). After adding your code, save the file using a different name (this example uses the name
HelloImpl.java
). idl2java
also generates an Operations file for each interface in a module. The Operations file provides the Java definition of the interface. To use the tie mechanism, a class implements the corresponding Operations interface. Here, HelloImpl implements HelloOperations. This class is also free to extend another class, if desired; without the tie mechanism, this class would have to extend the skeleton class SendMsg._sk_Hello.// HelloImpl.java
/**
The HelloImpl class implements the HelloOperations interface
defined in the file HelloOperations.java generated by idl2java.
*/
package SendMsg;
/*
With the tie mechanism, this class can extend
a class other than SendMsg._sk_Hello.
Without the tie mechanism:
public class HelloImpl extends SendMsg._sk_Hello {
*/public class HelloImpl implements SendMsg.HelloOperations
{
/* This constructor is included when idl2java generates _example_Hello.java,
but it is not valid in this example.
public HelloImpl(java.lang.String name) {
super(name);
}
*/
public HelloImpl() {
super();
}
public String sayHello() {
// Implement the operation.
System.out.println("Tie Client called sayHello.");
return "Tie Hello!";
}
}
// Using Enterprise Server's ORBThe
// MsgService.java
public class MsgService {
public static void main (String[] args) {
try {
// Initialize the ORB.
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
// Initialize the BOA.
org.omg.CORBA.BOA boa = orb.BOA_init();
// Activate the object implementation.
// Without tie mechanism:
// SendMsg.HelloImpl hi = new SendMsg.HelloImpl("TieExample
");
SendMsg.HelloImpl dlgt = new SendMsg.HelloImpl();
SendMsg.Hello hi = new SendMsg._tie_Hello(dlgt, "TieExample");
// Export the newly created object.
boa.obj_is_ready(hi);
netscape.WAI.Naming.register("http://myHost/TieExample
", hi);
// Or, if using Communicator's ORB, the call would be:
// netscape.WAI.Naming.register("http://myHost/NameService/TieExample", hi);
System.out.println(hi + " is ready.");
// Wait for incoming requests.
boa.impl_is_ready();
}
catch(org.omg.CORBA.SystemException e) {
System.err.println(e);
}
}
}
_tie_Hello.java
file (shown below) is generated by the idl2java
compiler. It implements methods by calling the corresponding method exposed by the member _delegate, an instance of a class that implements the operations defined in HelloOperations. For example, when a client calls the sayHello
method, the _tie_Hello class calls the sayHello
method provided by _delegate. In the server application (MsgService.java), _delegate is initialized with an instance of HelloImpl, which implements the HelloOperations interface.package SendMsg;
public class _tie_Hello extends SendMsg._sk_Hello {
private SendMsg.HelloOperations _delegate;
public _tie_Hello(SendMsg.HelloOperations delegate,
java.lang.String name) {
super(name);
this._delegate = delegate;
}
public _tie_Hello(SendMsg.HelloOperations delegate) {
this._delegate = delegate;
}
public java.lang.String sayHello() {
return this._delegate.sayHello();
}
}
Last Updated: 02/04/98 13:46:59