src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java

Print this page




 141                 ConfigurationException ce = new ConfigurationException(
 142                     "Cannot invoke javax.rmi.CORBA.Stub.connect()");
 143                 ce.setRootCause(e);
 144                 throw ce;
 145             }
 146 // Finally, return stub
 147             return (org.omg.CORBA.Object)stub;
 148     }
 149 
 150     /**
 151      * Get ORB using given server and port number, and properties from environment.
 152      *
 153      * @param server Possibly null server; if null means use default;
 154      *               For applet, it is the applet host; for app, it is localhost.
 155      * @param port   Port number, -1 means default port
 156      * @param env    Possibly null environment. Contains environment properties.
 157      *               Could contain ORB itself; or applet used for initializing ORB.
 158      *               Use all String properties from env for initializing ORB
 159      * @return A non-null ORB.
 160      */
 161     public static ORB getOrb(String server, int port, Hashtable env) {
 162         // See if we can get info from environment
 163         Properties orbProp;
 164 
 165         // Extract any org.omg.CORBA properties from environment
 166         if (env != null) {
 167             if (env instanceof Properties) {
 168                 // Already a Properties, just clone
 169                 orbProp = (Properties) env.clone();
 170             } else {
 171                 // Get all String properties
 172                 Enumeration envProp;
 173                 orbProp = new Properties();
 174                 for (envProp = env.keys(); envProp.hasMoreElements();) {
 175                     String key = (String)envProp.nextElement();
 176                     Object val = env.get(key);
 177                     if (val instanceof String) {
 178                         orbProp.put(key, val);
 179                     }
 180                 }
 181             }
 182         } else {
 183             orbProp = new Properties();
 184         }
 185 
 186         if (server != null) {
 187             orbProp.put("org.omg.CORBA.ORBInitialHost", server);
 188         }
 189         if (port >= 0) {
 190             orbProp.put("org.omg.CORBA.ORBInitialPort", ""+port);
 191         }
 192 


 222             // non-null; so throw CCE
 223             throw new ClassCastException(applet.getClass().getName());
 224         } catch (NoSuchMethodException e) {
 225             throw new AssertionError(e);
 226         } catch (InvocationTargetException e) {
 227             Throwable cause = e.getCause();
 228             if (cause instanceof RuntimeException) {
 229                 throw (RuntimeException) cause;
 230             } else if (cause instanceof Error) {
 231                 throw (Error) cause;
 232             }
 233             throw new AssertionError(e);
 234         } catch (IllegalAccessException iae) {
 235             throw new AssertionError(iae);
 236         }
 237     }
 238 
 239     // Fields used for reflection of RMI-IIOP
 240     private static Method toStubMethod = null;
 241     private static Method connectMethod = null;
 242     private static Class corbaStubClass = null;
 243     /**
 244      * Initializes reflection method handles for RMI-IIOP.
 245      * @exception ClassNotFoundException javax.rmi.CORBA.* not available
 246      */
 247     private static void initMethodHandles() throws ClassNotFoundException {
 248         // Get javax.rmi.CORBA.Stub class
 249         corbaStubClass = Class.forName("javax.rmi.CORBA.Stub");
 250 
 251         // Get javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB) method
 252 
 253         try {
 254             connectMethod = corbaStubClass.getMethod("connect",
 255                 new Class[] {org.omg.CORBA.ORB.class});
 256         } catch (NoSuchMethodException e) {
 257             throw new IllegalStateException(
 258         "No method definition for javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB)");
 259         }
 260 
 261         // Get javax.rmi.PortableRemoteObject method
 262         Class proClass = Class.forName("javax.rmi.PortableRemoteObject");
 263 
 264         // Get javax.rmi.PortableRemoteObject(java.rmi.Remote) method
 265         try {
 266             toStubMethod = proClass.getMethod("toStub",
 267                 new Class[] {java.rmi.Remote.class});
 268 
 269         } catch (NoSuchMethodException e) {
 270             throw new IllegalStateException(
 271 "No method definition for javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote)");
 272         }
 273     }
 274 }


 141                 ConfigurationException ce = new ConfigurationException(
 142                     "Cannot invoke javax.rmi.CORBA.Stub.connect()");
 143                 ce.setRootCause(e);
 144                 throw ce;
 145             }
 146 // Finally, return stub
 147             return (org.omg.CORBA.Object)stub;
 148     }
 149 
 150     /**
 151      * Get ORB using given server and port number, and properties from environment.
 152      *
 153      * @param server Possibly null server; if null means use default;
 154      *               For applet, it is the applet host; for app, it is localhost.
 155      * @param port   Port number, -1 means default port
 156      * @param env    Possibly null environment. Contains environment properties.
 157      *               Could contain ORB itself; or applet used for initializing ORB.
 158      *               Use all String properties from env for initializing ORB
 159      * @return A non-null ORB.
 160      */
 161     public static ORB getOrb(String server, int port, Hashtable<?,?> env) {
 162         // See if we can get info from environment
 163         Properties orbProp;
 164 
 165         // Extract any org.omg.CORBA properties from environment
 166         if (env != null) {
 167             if (env instanceof Properties) {
 168                 // Already a Properties, just clone
 169                 orbProp = (Properties) env.clone();
 170             } else {
 171                 // Get all String properties
 172                 Enumeration<?> envProp;
 173                 orbProp = new Properties();
 174                 for (envProp = env.keys(); envProp.hasMoreElements();) {
 175                     String key = (String)envProp.nextElement();
 176                     Object val = env.get(key);
 177                     if (val instanceof String) {
 178                         orbProp.put(key, val);
 179                     }
 180                 }
 181             }
 182         } else {
 183             orbProp = new Properties();
 184         }
 185 
 186         if (server != null) {
 187             orbProp.put("org.omg.CORBA.ORBInitialHost", server);
 188         }
 189         if (port >= 0) {
 190             orbProp.put("org.omg.CORBA.ORBInitialPort", ""+port);
 191         }
 192 


 222             // non-null; so throw CCE
 223             throw new ClassCastException(applet.getClass().getName());
 224         } catch (NoSuchMethodException e) {
 225             throw new AssertionError(e);
 226         } catch (InvocationTargetException e) {
 227             Throwable cause = e.getCause();
 228             if (cause instanceof RuntimeException) {
 229                 throw (RuntimeException) cause;
 230             } else if (cause instanceof Error) {
 231                 throw (Error) cause;
 232             }
 233             throw new AssertionError(e);
 234         } catch (IllegalAccessException iae) {
 235             throw new AssertionError(iae);
 236         }
 237     }
 238 
 239     // Fields used for reflection of RMI-IIOP
 240     private static Method toStubMethod = null;
 241     private static Method connectMethod = null;
 242     private static Class<?> corbaStubClass = null;
 243     /**
 244      * Initializes reflection method handles for RMI-IIOP.
 245      * @exception ClassNotFoundException javax.rmi.CORBA.* not available
 246      */
 247     private static void initMethodHandles() throws ClassNotFoundException {
 248         // Get javax.rmi.CORBA.Stub class
 249         corbaStubClass = Class.forName("javax.rmi.CORBA.Stub");
 250 
 251         // Get javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB) method
 252 
 253         try {
 254             connectMethod = corbaStubClass.getMethod("connect",
 255                 new Class<>[] {org.omg.CORBA.ORB.class});
 256         } catch (NoSuchMethodException e) {
 257             throw new IllegalStateException(
 258         "No method definition for javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB)");
 259         }
 260 
 261         // Get javax.rmi.PortableRemoteObject class
 262         Class<?> proClass = Class.forName("javax.rmi.PortableRemoteObject");
 263 
 264         // Get javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote) method
 265         try {
 266             toStubMethod = proClass.getMethod("toStub",
 267                 new Class<?>[] {java.rmi.Remote.class});
 268 
 269         } catch (NoSuchMethodException e) {
 270             throw new IllegalStateException(
 271 "No method definition for javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote)");
 272         }
 273     }
 274 }