1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * 26 * 27 * This is script engine factory for dummy engine. 28 */ 29 30 import javax.script.*; 31 import java.util.*; 32 33 public class DummyScriptEngineFactory implements ScriptEngineFactory { getEngineName()34 public String getEngineName() { 35 return "dummy"; 36 } 37 getEngineVersion()38 public String getEngineVersion() { 39 return "-1.0"; 40 } 41 getExtensions()42 public List<String> getExtensions() { 43 return extensions; 44 } 45 getLanguageName()46 public String getLanguageName() { 47 return "dummy"; 48 } 49 getLanguageVersion()50 public String getLanguageVersion() { 51 return "-1.0"; 52 } 53 getMethodCallSyntax(String obj, String m, String... args)54 public String getMethodCallSyntax(String obj, String m, String... args) { 55 StringBuffer buf = new StringBuffer(); 56 buf.append("call " + m + " "); 57 buf.append(" on " + obj + " with "); 58 for (int i = 0; i < args.length; i++) { 59 buf.append(args[i] + ", "); 60 } 61 buf.append(";"); 62 return buf.toString(); 63 } 64 getMimeTypes()65 public List<String> getMimeTypes() { 66 return mimeTypes; 67 } 68 getNames()69 public List<String> getNames() { 70 return names; 71 } 72 getOutputStatement(String str)73 public String getOutputStatement(String str) { 74 return "output " + str; 75 } 76 getParameter(String key)77 public String getParameter(String key) { 78 if (key.equals(ScriptEngine.ENGINE)) { 79 return getEngineName(); 80 } else if (key.equals(ScriptEngine.ENGINE_VERSION)) { 81 return getEngineVersion(); 82 } else if (key.equals(ScriptEngine.NAME)) { 83 return getEngineName(); 84 } else if (key.equals(ScriptEngine.LANGUAGE)) { 85 return getLanguageName(); 86 } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) { 87 return getLanguageVersion(); 88 } else { 89 return null; 90 } 91 } 92 getProgram(String... statements)93 public String getProgram(String... statements) { 94 Objects.requireNonNull(statements); 95 StringBuffer buf = new StringBuffer(); 96 for (String stat : statements) { 97 buf.append(Objects.requireNonNull(stat)); 98 } 99 return buf.toString(); 100 } 101 getScriptEngine()102 public ScriptEngine getScriptEngine() { 103 return new DummyScriptEngine(); 104 } 105 106 private static List<String> names; 107 private static List<String> extensions; 108 private static List<String> mimeTypes; 109 static { 110 names = new ArrayList<String>(1); 111 names.add("dummy"); 112 names = Collections.unmodifiableList(names); 113 extensions = names; 114 mimeTypes = new ArrayList<String>(0); 115 mimeTypes = Collections.unmodifiableList(mimeTypes); 116 } 117 } 118