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

Print this page
rev 10321 : imported patch cosnamingApplet


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.toolkit.corba;
  27 
  28 // Needed for RMI/IIOP
  29 import java.rmi.Remote;
  30 
  31 import java.lang.reflect.Method;
  32 import java.lang.reflect.InvocationTargetException;
  33 import java.rmi.RemoteException;
  34 import java.util.Hashtable;
  35 import java.util.Properties;
  36 import java.util.Enumeration;

  37 
  38 import org.omg.CORBA.ORB;
  39 
  40 import javax.naming.Context;
  41 import javax.naming.ConfigurationException;
  42 import javax.rmi.CORBA.Stub;
  43 import javax.rmi.PortableRemoteObject;
  44 
  45 /**
  46   * Contains utilities for performing CORBA-related tasks:
  47   * 1. Get the org.omg.CORBA.Object for a java.rmi.Remote object.
  48   * 2. Create an ORB to use for a given host/port, and environment properties.
  49   *
  50   * @author Simon Nash
  51   * @author Bryan Atsatt
  52   */
  53 
  54 public class CorbaUtils {
  55     /**
  56       * Returns the CORBA object reference associated with a Remote


 150                     String key = (String)envProp.nextElement();
 151                     Object val = env.get(key);
 152                     if (val instanceof String) {
 153                         orbProp.put(key, val);
 154                     }
 155                 }
 156             }
 157         } else {
 158             orbProp = new Properties();
 159         }
 160 
 161         if (server != null) {
 162             orbProp.put("org.omg.CORBA.ORBInitialHost", server);
 163         }
 164         if (port >= 0) {
 165             orbProp.put("org.omg.CORBA.ORBInitialPort", ""+port);
 166         }
 167 
 168         // Get Applet from environment
 169         if (env != null) {
 170             Object applet = env.get(Context.APPLET);
 171             if (applet != null) {
 172                 // Create ORBs for an applet
 173                 return initAppletORB(applet, orbProp);
 174             }
 175         }
 176 
 177         // Create ORBs using orbProp for a standalone application
 178         return ORB.init(new String[0], orbProp);
 179     }
 180 
 181     /**
 182      * This method returns a new ORB instance for the given applet
 183      * without creating a static dependency on java.applet.
 184      */
 185     private static ORB initAppletORB(Object applet, Properties orbProp) {
 186         try {
 187             Class<?> appletClass  = Class.forName("java.applet.Applet", true, null);
 188             if (!appletClass.isInstance(applet)) {
 189                 throw new ClassCastException(applet.getClass().getName());
 190             }
 191 
 192             // invoke the static method ORB.init(applet, orbProp);
 193             Method method = ORB.class.getMethod("init", appletClass, Properties.class);
 194             return (ORB) method.invoke(null, applet, orbProp);
 195         } catch (ClassNotFoundException e) {
 196             // java.applet.Applet doesn't exist and the applet parameter is
 197             // non-null; so throw CCE
 198             throw new ClassCastException(applet.getClass().getName());
 199         } catch (NoSuchMethodException e) {
 200             throw new AssertionError(e);
 201         } catch (InvocationTargetException e) {
 202             Throwable cause = e.getCause();
 203             if (cause instanceof RuntimeException) {
 204                 throw (RuntimeException) cause;
 205             } else if (cause instanceof Error) {
 206                 throw (Error) cause;
 207             }
 208             throw new AssertionError(e);
 209         } catch (IllegalAccessException iae) {
 210             throw new AssertionError(iae);
 211         }
 212     }
 213 }


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.toolkit.corba;
  27 
  28 // Needed for RMI/IIOP
  29 import java.rmi.Remote;
  30 


  31 import java.rmi.RemoteException;
  32 import java.util.Hashtable;
  33 import java.util.Properties;
  34 import java.util.Enumeration;
  35 import java.applet.Applet;
  36 
  37 import org.omg.CORBA.ORB;
  38 
  39 import javax.naming.Context;
  40 import javax.naming.ConfigurationException;
  41 import javax.rmi.CORBA.Stub;
  42 import javax.rmi.PortableRemoteObject;
  43 
  44 /**
  45   * Contains utilities for performing CORBA-related tasks:
  46   * 1. Get the org.omg.CORBA.Object for a java.rmi.Remote object.
  47   * 2. Create an ORB to use for a given host/port, and environment properties.
  48   *
  49   * @author Simon Nash
  50   * @author Bryan Atsatt
  51   */
  52 
  53 public class CorbaUtils {
  54     /**
  55       * Returns the CORBA object reference associated with a Remote


 149                     String key = (String)envProp.nextElement();
 150                     Object val = env.get(key);
 151                     if (val instanceof String) {
 152                         orbProp.put(key, val);
 153                     }
 154                 }
 155             }
 156         } else {
 157             orbProp = new Properties();
 158         }
 159 
 160         if (server != null) {
 161             orbProp.put("org.omg.CORBA.ORBInitialHost", server);
 162         }
 163         if (port >= 0) {
 164             orbProp.put("org.omg.CORBA.ORBInitialPort", ""+port);
 165         }
 166 
 167         // Get Applet from environment
 168         if (env != null) {
 169             Applet applet = (Applet) env.get(Context.APPLET);
 170             if (applet != null) {
 171             // Create ORBs using applet and orbProp
 172                 return ORB.init(applet, orbProp);
 173             }
 174         }
 175 

 176         return ORB.init(new String[0], orbProp);
 177     }

































 178 }