J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005 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. |
| 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any 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 { |
| 34 | public String getEngineName() { |
| 35 | return "dummy"; |
| 36 | } |
| 37 | |
| 38 | public String getEngineVersion() { |
| 39 | return "-1.0"; |
| 40 | } |
| 41 | |
| 42 | public List<String> getExtensions() { |
| 43 | return extensions; |
| 44 | } |
| 45 | |
| 46 | public String getLanguageName() { |
| 47 | return "dummy"; |
| 48 | } |
| 49 | |
| 50 | public String getLanguageVersion() { |
| 51 | return "-1.0"; |
| 52 | } |
| 53 | |
| 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 | |
| 65 | public List<String> getMimeTypes() { |
| 66 | return mimeTypes; |
| 67 | } |
| 68 | |
| 69 | public List<String> getNames() { |
| 70 | return names; |
| 71 | } |
| 72 | |
| 73 | public String getOutputStatement(String str) { |
| 74 | return "output " + str; |
| 75 | } |
| 76 | |
| 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 | |
| 93 | public String getProgram(String... statements) { |
| 94 | StringBuffer buf = new StringBuffer(); |
| 95 | for (int i = 0; i < statements.length; i++) { |
| 96 | buf.append(statements[i]); |
| 97 | } |
| 98 | return buf.toString(); |
| 99 | } |
| 100 | |
| 101 | public ScriptEngine getScriptEngine() { |
| 102 | return new DummyScriptEngine(); |
| 103 | } |
| 104 | |
| 105 | private static List<String> names; |
| 106 | private static List<String> extensions; |
| 107 | private static List<String> mimeTypes; |
| 108 | static { |
| 109 | names = new ArrayList<String>(1); |
| 110 | names.add("dummy"); |
| 111 | names = Collections.unmodifiableList(names); |
| 112 | extensions = names; |
| 113 | mimeTypes = new ArrayList<String>(0); |
| 114 | mimeTypes = Collections.unmodifiableList(mimeTypes); |
| 115 | } |
| 116 | } |