Coverage Report - com.sun.tools.javafx.script.JavaFXScriptEngineFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaFXScriptEngineFactory
25%
16/64
0%
0/23
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  
 
 26  
 package com.sun.tools.javafx.script;
 27  
 
 28  
 import javax.script.*;
 29  
 import java.util.*;
 30  
 
 31  
 /**
 32  
  * This is the script engine factory for "JavaFX Script" engines, based on 
 33  
  * JavaScriptEngineFactory from the Scripting project at 
 34  
  * https://scripting.dev.java.net/.
 35  
  * 
 36  
  * @author A. Sundararajan
 37  
  * @author Tom Ball
 38  
  */
 39  28
 public class JavaFXScriptEngineFactory implements ScriptEngineFactory {
 40  
     public String getEngineName() { 
 41  0
         return "JavaFX Script Engine";
 42  
     }
 43  
 
 44  
     public String getEngineVersion() {
 45  0
         return "1.0";
 46  
     }
 47  
 
 48  
     public List<String> getExtensions() {
 49  8
         return extensions;
 50  
     }
 51  
 
 52  
     public String getLanguageName() {
 53  0
         return "javafx";
 54  
     }
 55  
 
 56  
     public String getLanguageVersion() {
 57  0
         return "1.0";
 58  
     }
 59  
 
 60  
     public String getMethodCallSyntax(String obj, String m, String... args) {
 61  0
         StringBuilder buf = new StringBuilder();
 62  0
         buf.append(obj);
 63  0
         buf.append(".");
 64  0
         buf.append(m);
 65  0
         buf.append("(");
 66  0
         if (args.length != 0) {
 67  0
             int i = 0;
 68  0
             for (; i < args.length - 1; i++) {
 69  0
                 buf.append(args[i] + ", ");
 70  
             }
 71  0
             buf.append(args[i]);
 72  
         }        
 73  0
         buf.append(")");
 74  0
         return buf.toString();
 75  
     }
 76  
 
 77  
     public List<String> getMimeTypes() {
 78  0
         return mimeTypes;
 79  
     }
 80  
 
 81  
     public List<String> getNames() {
 82  20
         return names;
 83  
     }
 84  
 
 85  
     public String getOutputStatement(String toDisplay) {
 86  0
         StringBuilder buf = new StringBuilder();
 87  0
         buf.append("java.lang.System.out.print(\"");
 88  0
         int len = toDisplay.length();
 89  0
         for (int i = 0; i < len; i++) {
 90  0
             char ch = toDisplay.charAt(i);
 91  0
             switch (ch) {
 92  
             case '"':
 93  0
                 buf.append("\\\"");
 94  0
                 break;
 95  
             case '\\':
 96  0
                 buf.append("\\\\");
 97  0
                 break;
 98  
             default:
 99  0
                 buf.append(ch);
 100  
                 break;
 101  
             }
 102  
         }
 103  0
         buf.append("\");");
 104  0
         return buf.toString();
 105  
     }
 106  
 
 107  
     public String getParameter(String key) {
 108  0
         if (key.equals(ScriptEngine.ENGINE)) {
 109  0
             return getEngineName();
 110  0
         } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
 111  0
             return getEngineVersion();
 112  0
         } else if (key.equals(ScriptEngine.NAME)) {
 113  0
             return getEngineName();
 114  0
         } else if (key.equals(ScriptEngine.LANGUAGE)) {
 115  0
             return getLanguageName();
 116  0
         } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
 117  0
             return getLanguageVersion();
 118  0
         } else if (key.equals("THREADING")) {
 119  0
             return "MULTITHREADED";
 120  
         } else {
 121  0
             return null;
 122  
         }
 123  
     } 
 124  
 
 125  
     public String getProgram(String... statements) {
 126  0
         StringBuilder sb = new StringBuilder();
 127  0
         for( int i=0; i< statements.length; i++ ) {
 128  0
             sb.append( statements[i] );
 129  0
             sb.append("\n");
 130  
         }
 131  0
         return sb.toString();
 132  
     }
 133  
 
 134  
     public ScriptEngine getScriptEngine() {
 135  26
         JavaFXScriptEngineImpl engine = new JavaFXScriptEngineImpl();
 136  26
         engine.setFactory(this);
 137  26
         return engine;
 138  
     }
 139  
 
 140  4
     private static long nextClassNum = 0L;
 141  
     private static List<String> names;
 142  
     private static List<String> extensions;
 143  
     private static List<String> mimeTypes;
 144  
     static {
 145  4
         names = new ArrayList<String>(1);
 146  4
         names.add("fx");
 147  4
         extensions = Collections.unmodifiableList(names);
 148  4
         names.add("javafx");  // preferred engine name
 149  4
         names = Collections.unmodifiableList(names);
 150  4
         mimeTypes = new ArrayList<String>(0);
 151  4
         mimeTypes.add("application/x-javafx-source");
 152  4
         mimeTypes = Collections.unmodifiableList(mimeTypes);
 153  4
     }
 154  
 }