Coverage Report - javafx.lang.FX
 
Classes in this File Line Coverage Branch Coverage Complexity
Evaluator
71%
5/7
50%
1/2
2.667
FX
20%
1/5
0%
0/2
2.667
 
 1  
 /*
 2  
  * Copyright 2008 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  
 
 26  
 package javafx.lang;
 27  
 import com.sun.javafx.api.JavaFXScriptEngine;
 28  
 import javax.script.ScriptEngine;
 29  
 import javax.script.ScriptEngineManager;
 30  
 import javax.script.ScriptException;
 31  
 
 32  
 // factored out to avoid linkage error for javax.script.* on Java 1.5
 33  0
 class Evaluator {
 34  
     static Object eval(String script) throws ScriptException {
 35  5
         ScriptEngineManager manager = new ScriptEngineManager();
 36  5
         ScriptEngine scrEng = manager.getEngineByExtension("javafx");
 37  5
         JavaFXScriptEngine engine = (JavaFXScriptEngine)scrEng;
 38  5
         if (engine == null)
 39  0
             throw new ScriptException("no scripting engine available");
 40  5
         return engine.eval(script);
 41  
     }
 42  
 }
 43  
 
 44  
 /**
 45  
  * FX, analogous to java.lang.System, is a place to store static utility methods.  
 46  
  *
 47  
  * @author Brian Goetz
 48  
  */
 49  0
 public class FX {
 50  
     public static boolean isSameObject(Object a, Object b) {
 51  0
         return a == b;
 52  
     }
 53  
 
 54  
     /**
 55  
      * Evaluates a JavaFX Script source string and returns its result, if any.
 56  
      * For example, 
 57  
      * <br/>
 58  
      * This method depends upon the JavaFX Script compiler API being accessible
 59  
      * by the application, such as including the <code>javafxc.jar</code> file
 60  
      * in the application's classpath.
 61  
      * <br/>
 62  
      * Note:  this method provides only the simplest scripting functionality;
 63  
      * the script is evaluated without any specified context state, nor can 
 64  
      * any state it creates during evaluation be reused by other scripts.  For
 65  
      * sophisticated scripting applications, use the Java Scripting API
 66  
      * (<code>javax.scripting</code>).
 67  
      * 
 68  
      * @param script the JavaFX Script source to evaluate
 69  
      * @return the results from evaluating the script, or null if no results
 70  
      *         are returned by the script.
 71  
      * @throws javax.script.ScriptException
 72  
      */
 73  
     public static Object eval(String script) {
 74  
         try {
 75  5
             return Evaluator.eval(script);
 76  0
         } catch (Exception e) {
 77  0
             throw new RuntimeException(e);
 78  
         }
 79  
     }
 80  
 }