Path: blob/master/test/jdk/javax/script/DummyScriptEngineFactory.java
41145 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*25*26* This is script engine factory for dummy engine.27*/2829import javax.script.*;30import java.util.*;3132public class DummyScriptEngineFactory implements ScriptEngineFactory {33public String getEngineName() {34return "dummy";35}3637public String getEngineVersion() {38return "-1.0";39}4041public List<String> getExtensions() {42return extensions;43}4445public String getLanguageName() {46return "dummy";47}4849public String getLanguageVersion() {50return "-1.0";51}5253public String getMethodCallSyntax(String obj, String m, String... args) {54StringBuffer buf = new StringBuffer();55buf.append("call " + m + " ");56buf.append(" on " + obj + " with ");57for (int i = 0; i < args.length; i++) {58buf.append(args[i] + ", ");59}60buf.append(";");61return buf.toString();62}6364public List<String> getMimeTypes() {65return mimeTypes;66}6768public List<String> getNames() {69return names;70}7172public String getOutputStatement(String str) {73return "output " + str;74}7576public String getParameter(String key) {77if (key.equals(ScriptEngine.ENGINE)) {78return getEngineName();79} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {80return getEngineVersion();81} else if (key.equals(ScriptEngine.NAME)) {82return getEngineName();83} else if (key.equals(ScriptEngine.LANGUAGE)) {84return getLanguageName();85} else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {86return getLanguageVersion();87} else {88return null;89}90}9192public String getProgram(String... statements) {93Objects.requireNonNull(statements);94StringBuffer buf = new StringBuffer();95for (String stat : statements) {96buf.append(Objects.requireNonNull(stat));97}98return buf.toString();99}100101public ScriptEngine getScriptEngine() {102return new DummyScriptEngine();103}104105private static List<String> names;106private static List<String> extensions;107private static List<String> mimeTypes;108static {109names = new ArrayList<String>(1);110names.add("dummy");111names = Collections.unmodifiableList(names);112extensions = names;113mimeTypes = new ArrayList<String>(0);114mimeTypes = Collections.unmodifiableList(mimeTypes);115}116}117118119