< prev index next >

modules/graphics/src/main/java/com/sun/javafx/application/HostServicesDelegate.java

Print this page
rev 9717 : 8151320: Remove unnecessary addReads from JavaFX


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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.javafx.application;
  27 
  28 import com.sun.javafx.util.ModuleHelper;
  29 import java.lang.reflect.Method;
  30 import java.security.AccessController;
  31 import java.security.PrivilegedActionException;
  32 import java.security.PrivilegedExceptionAction;
  33 import javafx.application.Application;
  34 
  35 public abstract class HostServicesDelegate {
  36 
  37     private static Method getInstanceMeth = null;
  38 
  39     public static HostServicesDelegate getInstance(final Application app) {
  40         // Call into the deploy code to get the delegate class
  41         HostServicesDelegate instance = null;
  42         try {
  43             instance = AccessController.doPrivileged(
  44                     (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
  45                         if (getInstanceMeth == null) {
  46                             try {
  47                                 final String factoryClassName =
  48                                         "com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory";
  49 
  50                                 Class factoryClass = Class.forName(factoryClassName,
  51                                         true,
  52                                         HostServicesDelegate.class.getClassLoader());
  53                                 Object thisModule = ModuleHelper.getModule(HostServicesDelegate.class);
  54                                 Object targetModule = ModuleHelper.getModule(factoryClass);
  55                                 ModuleHelper.addReads(thisModule, targetModule);
  56 
  57                                 getInstanceMeth = factoryClass.getMethod(
  58                                         "getInstance", Application.class);
  59                             } catch (Exception ex) {
  60                                 ex.printStackTrace();
  61                                 return null;
  62                             }
  63                         }
  64                         return (HostServicesDelegate)
  65                                 getInstanceMeth.invoke(null, app);
  66                     }
  67             );
  68         } catch (PrivilegedActionException pae) {
  69             System.err.println(pae.getException().toString());
  70             return null;
  71         }
  72 
  73         return instance;
  74     }
  75 


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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.javafx.application;
  27 

  28 import java.lang.reflect.Method;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedActionException;
  31 import java.security.PrivilegedExceptionAction;
  32 import javafx.application.Application;
  33 
  34 public abstract class HostServicesDelegate {
  35 
  36     private static Method getInstanceMeth = null;
  37 
  38     public static HostServicesDelegate getInstance(final Application app) {
  39         // Call into the deploy code to get the delegate class
  40         HostServicesDelegate instance = null;
  41         try {
  42             instance = AccessController.doPrivileged(
  43                     (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
  44                         if (getInstanceMeth == null) {
  45                             try {
  46                                 final String factoryClassName =
  47                                         "com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory";
  48 
  49                                 Class factoryClass = Class.forName(factoryClassName,
  50                                         true,
  51                                         HostServicesDelegate.class.getClassLoader());



  52 
  53                                 getInstanceMeth = factoryClass.getMethod(
  54                                         "getInstance", Application.class);
  55                             } catch (Exception ex) {
  56                                 ex.printStackTrace();
  57                                 return null;
  58                             }
  59                         }
  60                         return (HostServicesDelegate)
  61                                 getInstanceMeth.invoke(null, app);
  62                     }
  63             );
  64         } catch (PrivilegedActionException pae) {
  65             System.err.println(pae.getException().toString());
  66             return null;
  67         }
  68 
  69         return instance;
  70     }
  71 
< prev index next >