I have a class that extends Swing JFrame. In order for this class to receive a callback and call a method in this class, the class should extend the POA class. I don't know how to do that. What about multiple inheritance? Should I make another class that extends the POA class?
Code
public final class JFSECorbaClient extends javax.swing.JFrame {
//
// init and other method
//
public static void main(final String args[]) throws ClassNotFoundException, IllegalAccessException, InstantiationException{
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
frame = new JFSECorbaClient().setVisible(true);
try {
//initialize orb
Properties props = System.getProperties();
props.put("org.omg.CORBA.ORBInitialPort", "1050");
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
ORB orb = ORB.init(args, props);
System.out.println("Initialized ORB");
//Instantiate Servant and create reference
POA rootPOA = POAHelper.narrow(
orb.resolve_initial_references("RootPOA"));
rootPOA.activate_object(this.frame); //this.frame should extends jfseCallbackPOA
ref = jfseCallbackHelper.narrow(
rootPOA.servant_to_reference(callbackListener));
//Resolve MessageServer
jfseServer = jfseORBHelper.narrow(
orb.string_to_object("corbaname:iiop:1.2@localhost:1050#MessageServer"));
//Activate rootpoa
rootPOA.the_POAManager().activate();
//thread for receive callback in other class thread
JFSECorrbaListener th = new JFSECorrbaListener();
th.setOrb(orb);
th.start();
} catch (Exception e) {
System.out.println(e);
}
}
});
}
It doesn't have to extend the POA class if you are in control of the IDL: you can define your callback via RMI/IIOP, generate the IDL from the remote interface when generating the stub (rmic -iiop), and use PortableRemoteObject.exportObject() to export it. No need to extend any specific class.
Having said all that, it's the wrong answer. Your JFrame-extending class has no need to also be a CORBA callback. Define your CORBA callback as a completely separate class, and provide it with hooks into your JFrame-extending class to do whatever is required when the callback occurs.