1 /* |
1 /* |
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
33 import java.io.File; |
33 import java.io.File; |
34 import java.io.FileInputStream; |
34 import java.io.FileInputStream; |
35 |
35 |
36 import java.security.AccessController; |
36 import java.security.AccessController; |
37 import java.security.PrivilegedAction; |
37 import java.security.PrivilegedAction; |
|
38 |
|
39 import sun.reflect.misc.ReflectUtil; |
38 |
40 |
39 /** |
41 /** |
40 * A class providing APIs for the CORBA Object Request Broker |
42 * A class providing APIs for the CORBA Object Request Broker |
41 * features. The <code>ORB</code> class also provides |
43 * features. The <code>ORB</code> class also provides |
42 * "pluggable ORB implementation" APIs that allow another vendor's ORB |
44 * "pluggable ORB implementation" APIs that allow another vendor's ORB |
159 * ORB orb = ORB.init(myApplet, null); |
161 * ORB orb = ORB.init(myApplet, null); |
160 * </PRE> |
162 * </PRE> |
161 * <P> |
163 * <P> |
162 * An application or applet can be initialized in one or more ORBs. |
164 * An application or applet can be initialized in one or more ORBs. |
163 * ORB initialization is a bootstrap call into the CORBA world. |
165 * ORB initialization is a bootstrap call into the CORBA world. |
|
166 * |
|
167 * |
|
168 * @implNote |
|
169 * As described above it is possible to specify, at runtime, an alternative ORBSingleton class and |
|
170 * an alternative ORB implementation class, via the system properties {@code org.omg.CORBA.ORBSingletonClass} |
|
171 * and {@code org.omg.CORBA.ORBClass} respectively. |
|
172 * The class loading strategy is organized, such that, in the case of the ORBSingleton |
|
173 * the system class loader is used to load the alternative singleton ORB. |
|
174 * Thus, it is necessary that an application's CLASSPATH |
|
175 * includes the classes for this alternative ORBSingleton, when specified. |
|
176 * |
|
177 * In the case of specifying an alternative ORB implementation class, the loading |
|
178 * strategy will use the thread context class loader, as appropriate. |
|
179 * |
164 * @since JDK1.2 |
180 * @since JDK1.2 |
165 */ |
181 */ |
166 abstract public class ORB { |
182 abstract public class ORB { |
167 |
183 |
168 // |
184 // |
287 className = getPropertyFromFile(ORBSingletonClassKey); |
303 className = getPropertyFromFile(ORBSingletonClassKey); |
288 if ((className == null) || |
304 if ((className == null) || |
289 (className.equals("com.sun.corba.se.impl.orb.ORBSingleton"))) { |
305 (className.equals("com.sun.corba.se.impl.orb.ORBSingleton"))) { |
290 singleton = new com.sun.corba.se.impl.orb.ORBSingleton(); |
306 singleton = new com.sun.corba.se.impl.orb.ORBSingleton(); |
291 } else { |
307 } else { |
292 singleton = create_impl(className); |
308 singleton = create_impl_with_systemclassloader(className); |
293 } |
309 } |
294 } |
310 } |
295 return singleton; |
311 return singleton; |
296 } |
312 } |
297 |
313 |
|
314 private static ORB create_impl_with_systemclassloader(String className) { |
|
315 |
|
316 try { |
|
317 ReflectUtil.checkPackageAccess(className); |
|
318 ClassLoader cl = ClassLoader.getSystemClassLoader(); |
|
319 Class<org.omg.CORBA.ORB> orbBaseClass = org.omg.CORBA.ORB.class; |
|
320 Class<?> singletonOrbClass = Class.forName(className, true, cl).asSubclass(orbBaseClass); |
|
321 return (ORB)singletonOrbClass.newInstance(); |
|
322 } catch (Throwable ex) { |
|
323 SystemException systemException = new INITIALIZE( |
|
324 "can't instantiate default ORB implementation " + className); |
|
325 systemException.initCause(ex); |
|
326 throw systemException; |
|
327 } |
|
328 } |
|
329 |
298 private static ORB create_impl(String className) { |
330 private static ORB create_impl(String className) { |
299 |
|
300 ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
331 ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
301 if (cl == null) |
332 if (cl == null) |
302 cl = ClassLoader.getSystemClassLoader(); |
333 cl = ClassLoader.getSystemClassLoader(); |
303 |
334 |
304 try { |
335 try { |
305 return (ORB) Class.forName(className, true, cl).newInstance(); |
336 ReflectUtil.checkPackageAccess(className); |
|
337 Class<org.omg.CORBA.ORB> orbBaseClass = org.omg.CORBA.ORB.class; |
|
338 Class<?> orbClass = Class.forName(className, true, cl).asSubclass(orbBaseClass); |
|
339 return (ORB)orbClass.newInstance(); |
306 } catch (Throwable ex) { |
340 } catch (Throwable ex) { |
307 SystemException systemException = new INITIALIZE( |
341 SystemException systemException = new INITIALIZE( |
308 "can't instantiate default ORB implementation " + className); |
342 "can't instantiate default ORB implementation " + className); |
309 systemException.initCause(ex); |
343 systemException.initCause(ex); |
310 throw systemException; |
344 throw systemException; |
571 // so lets check if it has a create_operation_list(OperationDef oper) |
603 // so lets check if it has a create_operation_list(OperationDef oper) |
572 // method. |
604 // method. |
573 try { |
605 try { |
574 // First try to load the OperationDef class |
606 // First try to load the OperationDef class |
575 String opDefClassName = "org.omg.CORBA.OperationDef"; |
607 String opDefClassName = "org.omg.CORBA.OperationDef"; |
576 Class opDefClass = null; |
608 Class<?> opDefClass = null; |
577 |
609 |
578 ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
610 ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
579 if ( cl == null ) |
611 if ( cl == null ) |
580 cl = ClassLoader.getSystemClassLoader(); |
612 cl = ClassLoader.getSystemClassLoader(); |
581 // if this throws a ClassNotFoundException, it will be caught below. |
613 // if this throws a ClassNotFoundException, it will be caught below. |
582 opDefClass = Class.forName(opDefClassName, true, cl); |
614 opDefClass = Class.forName(opDefClassName, true, cl); |
583 |
615 |
584 // OK, we loaded OperationDef. Now try to get the |
616 // OK, we loaded OperationDef. Now try to get the |
585 // create_operation_list(OperationDef oper) method. |
617 // create_operation_list(OperationDef oper) method. |
586 Class[] argc = { opDefClass }; |
618 Class<?>[] argc = { opDefClass }; |
587 java.lang.reflect.Method meth = |
619 java.lang.reflect.Method meth = |
588 this.getClass().getMethod("create_operation_list", argc); |
620 this.getClass().getMethod("create_operation_list", argc); |
589 |
621 |
590 // OK, the method exists, so invoke it and be happy. |
622 // OK, the method exists, so invoke it and be happy. |
591 java.lang.Object[] argx = { oper }; |
623 java.lang.Object[] argx = { oper }; |