changeset 25550:ac3aa9f51e28

8050869: Convert runtime dependency to Applet to a static dependency in cosnaming Reviewed-by: chegar, alanb
author prappo
date Wed, 16 Jul 2014 16:16:32 +0100
parents a2f898967541
children 62ad60d30644 1792c213f870
files jdk/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java
diffstat 1 files changed, 4 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java	Tue May 20 16:02:57 2014 +0200
+++ b/jdk/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java	Wed Jul 16 16:16:32 2014 +0100
@@ -28,12 +28,11 @@
 // Needed for RMI/IIOP
 import java.rmi.Remote;
 
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
 import java.rmi.RemoteException;
 import java.util.Hashtable;
 import java.util.Properties;
 import java.util.Enumeration;
+import java.applet.Applet;
 
 import org.omg.CORBA.ORB;
 
@@ -167,47 +166,13 @@
 
         // Get Applet from environment
         if (env != null) {
-            Object applet = env.get(Context.APPLET);
+            Applet applet = (Applet) env.get(Context.APPLET);
             if (applet != null) {
-                // Create ORBs for an applet
-                return initAppletORB(applet, orbProp);
+            // Create ORBs using applet and orbProp
+                return ORB.init(applet, orbProp);
             }
         }
 
-        // Create ORBs using orbProp for a standalone application
         return ORB.init(new String[0], orbProp);
     }
-
-    /**
-     * This method returns a new ORB instance for the given applet
-     * without creating a static dependency on java.applet.
-     */
-    private static ORB initAppletORB(Object applet, Properties orbProp) {
-        try {
-            Class<?> appletClass  = Class.forName("java.applet.Applet", true, null);
-            if (!appletClass.isInstance(applet)) {
-                throw new ClassCastException(applet.getClass().getName());
-            }
-
-            // invoke the static method ORB.init(applet, orbProp);
-            Method method = ORB.class.getMethod("init", appletClass, Properties.class);
-            return (ORB) method.invoke(null, applet, orbProp);
-        } catch (ClassNotFoundException e) {
-            // java.applet.Applet doesn't exist and the applet parameter is
-            // non-null; so throw CCE
-            throw new ClassCastException(applet.getClass().getName());
-        } catch (NoSuchMethodException e) {
-            throw new AssertionError(e);
-        } catch (InvocationTargetException e) {
-            Throwable cause = e.getCause();
-            if (cause instanceof RuntimeException) {
-                throw (RuntimeException) cause;
-            } else if (cause instanceof Error) {
-                throw (Error) cause;
-            }
-            throw new AssertionError(e);
-        } catch (IllegalAccessException iae) {
-            throw new AssertionError(iae);
-        }
-    }
 }