/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Contains utilities for performing CORBA-related tasks:
* 1. Get the org.omg.CORBA.Object for a java.rmi.Remote object.
*
* @author Simon Nash
* @author Bryan Atsatt
*/
public class CorbaUtils {
/**
* Returns the CORBA object reference associated with a Remote
* object by using the javax.rmi.CORBA package.
*<p>
* Use reflection to avoid hard dependencies on javax.rmi.CORBA package.
* This method effective does the following:
*<blockquote><pre>
* java.lang.Object stub;
* try {
* stub = PortableRemoteObject.toStub(remoteObj);
* } catch (Exception e) {
* throw new ConfigurationException("Object not exported or not found");
* }
* if (!(stub instanceof javax.rmi.CORBA.Stub)) {
* return null; // JRMP impl or JRMP stub
* }
* try {
* ((javax.rmi.CORBA.Stub)stub).connect(orb); // try to connect IIOP stub
* } catch (RemoteException e) {
* // ignore 'already connected' error
* }
* return (javax.rmi.CORBA.Stub)stub;
*
* @param remoteObj The non-null remote object for
* @param orb The non-null ORB to connect the remote object to
* @return The CORBA Object for remoteObj; null if <tt>remoteObj</tt>
* is a JRMP implementation or JRMP stub.
* @exception ClassNotFoundException The RMI-IIOP package is not available
* @exception ConfigurationException The CORBA Object cannot be obtained
* because of configuration problems.
*/
throws ClassNotFoundException, ConfigurationException {
synchronized (CorbaUtils.class) {
if (toStubMethod == null) {
}
}
// First, get remoteObj's stub
// javax.rmi.CORBA.Stub stub = PortableRemoteObject.toStub(remoteObj);
try {
} catch (InvocationTargetException e) {
// realException.printStackTrace();
"Problem with PortableRemoteObject.toStub(); object not exported or stub not found");
throw ce;
} catch (IllegalAccessException e) {
"Cannot invoke javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote)");
ce.setRootCause(e);
throw ce;
}
// Next, make sure that the stub is javax.rmi.CORBA.Stub
return null; // JRMP implementation or JRMP stub
}
// Next, make sure that the stub is connected
// Invoke stub.connect(orb)
try {
} catch (InvocationTargetException e) {
// realException.printStackTrace();
"Problem invoking javax.rmi.CORBA.Stub.connect()");
throw ce;
}
// ignore RemoteException because stub might have already
// been connected
} catch (IllegalAccessException e) {
"Cannot invoke javax.rmi.CORBA.Stub.connect()");
ce.setRootCause(e);
throw ce;
}
// Finally, return stub
}
/**
* Get ORB using given server and port number, and properties from environment.
*
* @param server Possibly null server; if null means use default;
* For applet, it is the applet host; for app, it is localhost.
* @param port Port number, -1 means default port
* @param env Possibly null environment. Contains environment properties.
* Could contain ORB itself; or applet used for initializing ORB.
* Use all String properties from env for initializing ORB
* @return A non-null ORB.
*/
// See if we can get info from environment
// Extract any org.omg.CORBA properties from environment
if (env instanceof Properties) {
// Already a Properties, just clone
} else {
// Get all String properties
orbProp = new Properties();
}
}
}
} else {
orbProp = new Properties();
}
}
if (port >= 0) {
}
// Get Applet from environment
// Create ORBs for an applet
}
}
// Create ORBs using orbProp for a standalone application
}
/**
* This method returns a new ORB instance for the given applet
* without creating a static dependency on java.applet.
*/
try {
}
// invoke the static method ORB.init(applet, orbProp);
} catch (ClassNotFoundException e) {
// java.applet.Applet doesn't exist and the applet parameter is
// non-null; so throw CCE
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
throw new AssertionError(e);
} catch (IllegalAccessException iae) {
throw new AssertionError(iae);
}
}
// Fields used for reflection of RMI-IIOP
/**
* Initializes reflection method handles for RMI-IIOP.
* @exception ClassNotFoundException javax.rmi.CORBA.* not available
*/
// Get javax.rmi.CORBA.Stub class
// Get javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB) method
try {
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
"No method definition for javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB)");
}
// Get javax.rmi.PortableRemoteObject method
// Get javax.rmi.PortableRemoteObject(java.rmi.Remote) method
try {
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
"No method definition for javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote)");
}
}
}