Coverage Report - com.sun.javafx.runtime.Entry
 
Classes in this File Line Coverage Branch Coverage Complexity
Entry
55%
26/47
50%
5/10
0
Entry$1
0%
0/3
N/A
0
 
 1  
 /*
 2  
  * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 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
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 package com.sun.javafx.runtime;
 26  
 
 27  
 import java.lang.reflect.InvocationTargetException;
 28  
 import java.lang.reflect.Method;
 29  
 import java.security.AccessControlException;
 30  
 import java.util.Iterator;
 31  
 
 32  
 import com.sun.javafx.functions.Function0;
 33  
 import com.sun.javafx.runtime.sequence.Sequence;
 34  
 import com.sun.javafx.runtime.sequence.Sequences;
 35  
 
 36  
 /**
 37  
  * First code that is run to start a JavaFX Script application.
 38  
  * 
 39  
  * @author Tom Ball
 40  
  */
 41  0
 public class Entry {
 42  
     private static RuntimeProvider provider;
 43  
 
 44  
     public static void start(Class<?> app, String[] commandLineArgs) throws Throwable {
 45  236
         Method main = app.getMethod(entryMethodName(), Sequence.class);
 46  236
         Object args = Sequences.make(String.class, commandLineArgs);
 47  
         
 48  
         try {
 49  236
             main.setAccessible(true);
 50  236
             provider = runtimeProviderLocator();
 51  236
             if (provider != null && provider.usesRuntimeLibrary(app)) {
 52  4
                 provider.run(main, commandLineArgs);
 53  
             } else {
 54  
                 try {
 55  232
                     main.invoke(null, args);
 56  1
                 } catch (InvocationTargetException e) {
 57  1
                     throw e.getCause();
 58  231
                 }
 59  
             }
 60  0
         } catch (AccessControlException ex) {
 61  
             // applet or jnlp app security problem:  try just running main
 62  
              try {
 63  0
                 main.invoke(null, args);
 64  0
             } catch (InvocationTargetException e) {
 65  0
                 throw e.getCause();
 66  0
             }
 67  235
         }
 68  235
     }
 69  
 
 70  
     public static void deferTask(final Function0<Void> function) {
 71  0
         deferTask(new Runnable() {
 72  
             public void run() {
 73  0
                 function.invoke();
 74  0
             }
 75  
         });
 76  0
     }
 77  
 
 78  
     public static void deferTask(Runnable function) {
 79  0
         if (provider == null)
 80  0
             provider = runtimeProviderLocator();
 81  0
         provider.deferTask(function);
 82  0
     }
 83  
 
 84  
     private static RuntimeProvider runtimeProviderLocator() {
 85  
         Iterator<?> iterator;
 86  
         Class<?> loaderClass;
 87  
         String loadMethodName;
 88  
         boolean usingServiceLoader;
 89  
 
 90  
         try {
 91  
             // Lookup Java 6 public API first
 92  236
             loaderClass = Class.forName("java.util.ServiceLoader");
 93  236
             loadMethodName = "load";
 94  236
             usingServiceLoader = true;
 95  0
         } catch (ClassNotFoundException cnfe) {
 96  
             try {
 97  
                 // Lookup Java 5 Sun-private API
 98  0
                 loaderClass = Class.forName("sun.misc.Service");
 99  0
                 loadMethodName = "providers";
 100  0
                 usingServiceLoader = false;
 101  0
             } catch (ClassNotFoundException cnfe2) {
 102  0
                 throw new AssertionError("Failed discovering ServiceLoader");
 103  0
             }
 104  236
         }
 105  
 
 106  
         try {
 107  
             // java.util.ServiceLoader.load or sun.misc.Service.providers
 108  236
             Method loadMethod = loaderClass.getMethod(loadMethodName,
 109  
                     Class.class,
 110  
                     ClassLoader.class);
 111  236
             ClassLoader cl = Entry.class.getClassLoader();
 112  236
             Object result = loadMethod.invoke(null, RuntimeProvider.class, cl);
 113  
 
 114  
             // For java.util.ServiceLoader, we have to call another
 115  
             // method to get the iterator.
 116  236
             if (usingServiceLoader) {
 117  236
                 Method m = loaderClass.getMethod("iterator");
 118  236
                 result = m.invoke(result); // serviceLoader.iterator();
 119  
             }
 120  
 
 121  236
             iterator = (Iterator<?>) result;
 122  0
         } catch (Throwable t) {
 123  0
             throw new RuntimeException(t);
 124  236
         }
 125  236
         return iterator.hasNext() ? (RuntimeProvider) iterator.next() : null;
 126  
     }
 127  
     
 128  
     public static String entryMethodName() {
 129  299
         return "javafx$run$";
 130  
     }
 131  
 }