alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ScriptEngineFactory.java)

This example Java source code file (ScriptEngineFactory.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

list, object, scriptengine, scriptenginefactory, string, util

The ScriptEngineFactory.java Java example source code

/*
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package javax.script;

import java.util.List;

/**
 * <code>ScriptEngineFactory is used to describe and instantiate
 * <code>ScriptEngines.
 * <br>
* Each class implementing <code>ScriptEngine has a corresponding factory * that exposes metadata describing the engine class. * <br>
The ScriptEngineManager * uses the service provider mechanism described in the <i>Jar File Specification to obtain * instances of all <code>ScriptEngineFactories available in * the current ClassLoader. * * @since 1.6 */ public interface ScriptEngineFactory { /** * Returns the full name of the <code>ScriptEngine. For * instance an implementation based on the Mozilla Rhino Javascript engine * might return <i>Rhino Mozilla Javascript Engine. * @return The name of the engine implementation. */ public String getEngineName(); /** * Returns the version of the <code>ScriptEngine. * @return The <code>ScriptEngine implementation version. */ public String getEngineVersion(); /** * Returns an immutable list of filename extensions, which generally identify scripts * written in the language supported by this <code>ScriptEngine. * The array is used by the <code>ScriptEngineManager to implement its * <code>getEngineByExtension method. * @return The list of extensions. */ public List<String> getExtensions(); /** * Returns an immutable list of mimetypes, associated with scripts that * can be executed by the engine. The list is used by the * <code>ScriptEngineManager class to implement its * <code>getEngineByMimetype method. * @return The list of mime types. */ public List<String> getMimeTypes(); /** * Returns an immutable list of short names for the <code>ScriptEngine, which may be used to * identify the <code>ScriptEngine by the ScriptEngineManager. * For instance, an implementation based on the Mozilla Rhino Javascript engine might * return list containing {"javascript", "rhino"}. * @return an immutable list of short names */ public List<String> getNames(); /** * Returns the name of the scripting langauge supported by this * <code>ScriptEngine. * @return The name of the supported language. */ public String getLanguageName(); /** * Returns the version of the scripting language supported by this * <code>ScriptEngine. * @return The version of the supported language. */ public String getLanguageVersion(); /** * Returns the value of an attribute whose meaning may be implementation-specific. * Keys for which the value is defined in all implementations are: * <ul> * <li>ScriptEngine.ENGINE * <li>ScriptEngine.ENGINE_VERSION * <li>ScriptEngine.NAME * <li>ScriptEngine.LANGUAGE * <li>ScriptEngine.LANGUAGE_VERSION * </ul> * <p> * The values for these keys are the Strings returned by <code>getEngineName, * <code>getEngineVersion, getName, getLanguageName and * <code>getLanguageVersion respectively.

* A reserved key, <code>THREADING, whose value describes the behavior of the engine * with respect to concurrent execution of scripts and maintenance of state is also defined. * These values for the <code>THREADING key are:

* <ul> * <li>null - The engine implementation is not thread safe, and cannot * be used to execute scripts concurrently on multiple threads. * <li>"MULTITHREADED" - The engine implementation is internally * thread-safe and scripts may execute concurrently although effects of script execution * on one thread may be visible to scripts on other threads. * <li>"THREAD-ISOLATED" - The implementation satisfies the requirements * of "MULTITHREADED", and also, the engine maintains independent values * for symbols in scripts executing on different threads. * <li>"STATELESS" - The implementation satisfies the requirements of * <li>"THREAD-ISOLATED". In addition, script executions do not alter the * mappings in the <code>Bindings which is the engine scope of the * <code>ScriptEngine. In particular, the keys in the Bindings * and their associated values are the same before and after the execution of the script. * </ul> * <br>
* Implementations may define implementation-specific keys. * * @param key The name of the parameter * @return The value for the given parameter. Returns <code>null if no * value is assigned to the key. * */ public Object getParameter(String key); /** * Returns a String which can be used to invoke a method of a Java object using the syntax * of the supported scripting language. For instance, an implementation for a Javascript * engine might be; * * <pre>{@code * public String getMethodCallSyntax(String obj, * String m, String... args) { * String ret = obj; * ret += "." + m + "("; * for (int i = 0; i < args.length; i++) { * ret += args[i]; * if (i < args.length - 1) { * ret += ","; * } * } * ret += ")"; * return ret; * } * } </pre> * <p> * * @param obj The name representing the object whose method is to be invoked. The * name is the one used to create bindings using the <code>put method of * <code>ScriptEngine, the put method of an ENGINE_SCOPE * <code>Bindings,or the setAttribute method * of <code>ScriptContext. The identifier used in scripts may be a decorated form of the * specified one. * * @param m The name of the method to invoke. * @param args names of the arguments in the method call. * * @return The String used to invoke the method in the syntax of the scripting language. */ public String getMethodCallSyntax(String obj, String m, String... args); /** * Returns a String that can be used as a statement to display the specified String using * the syntax of the supported scripting language. For instance, the implementation for a Perl * engine might be; * * <pre> * public String getOutputStatement(String toDisplay) { * return "print(" + toDisplay + ")"; * } * </code>
* * @param toDisplay The String to be displayed by the returned statement. * @return The string used to display the String in the syntax of the scripting language. * * */ public String getOutputStatement(String toDisplay); /** * Returns a valid scripting language executable program with given statements. * For instance an implementation for a PHP engine might be: * * <pre>{@code * public String getProgram(String... statements) { * String retval = "<?\n"; * int len = statements.length; * for (int i = 0; i < len; i++) { * retval += statements[i] + ";\n"; * } * return retval += "?>"; * } * }</pre> * * @param statements The statements to be executed. May be return values of * calls to the <code>getMethodCallSyntax and getOutputStatement methods. * @return The Program */ public String getProgram(String... statements); /** * Returns an instance of the <code>ScriptEngine associated with this * <code>ScriptEngineFactory. A new ScriptEngine is generally * returned, but implementations may pool, share or reuse engines. * * @return A new <code>ScriptEngine instance. */ public ScriptEngine getScriptEngine(); }

Other Java examples (source code examples)

Here is a short list of links related to this Java ScriptEngineFactory.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.