Path: blob/master/src/java.scripting/share/classes/javax/script/package-info.java
41153 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**2627<p>The scripting API consists of interfaces and classes that define28Java Scripting Engines and provides29a framework for their use in Java applications. This API is intended30for use by application programmers who wish to execute programs31written in scripting languages in their Java applications. The32scripting language programs are usually provided by the end-users of33the applications.34</p>35<p>The main areas of functionality of <code>javax.script</code>36package include37</p>38<ol>39<li><p><b>Script execution</b>: Scripts40are streams of characters used as sources for programs executed by41script engines. Script execution uses42{@link javax.script.ScriptEngine#eval eval} methods of43{@link javax.script.ScriptEngine ScriptEngine} and methods of the44{@link javax.script.Invocable Invocable} interface.45</p>46<li><p><b>Binding</b>: This facility47allows Java objects to be exposed to script programs as named48variables. {@link javax.script.Bindings Bindings} and49{@link javax.script.ScriptContext ScriptContext}50classes are used for this purpose.51</p>52<li><p><b>Compilation</b>: This53functionality allows the intermediate code generated by the54front-end of a script engine to be stored and executed repeatedly.55This benefits applications that execute the same script multiple56times. These applications can gain efficiency since the engines'57front-ends only need to execute once per script rather than once per58script execution. Note that this functionality is optional and59script engines may choose not to implement it. Callers need to check60for availability of the {@link javax.script.Compilable Compilable}61interface using an <I>instanceof</I> check.62</p>63<li><p><b>Invocation</b>: This64functionality allows the reuse of intermediate code generated by a65script engine's front-end. Whereas Compilation allows entire scripts66represented by intermediate code to be re-executed, Invocation67functionality allows individual procedures/methods in the scripts to68be re-executed. As in the case with compilation, not all script69engines are required to provide this facility. Caller has to check70for {@link javax.script.Invocable Invocable} availability.71</p>72<li><p><b>Script engine discovery</b>: Applications73written to the Scripting API might have specific requirements on74script engines. Some may require a specific scripting language75and/or version while others may require a specific implementation76engine and/or version. Script engines are packaged in a specified77way so that engines can be discovered at runtime and queried for78attributes. The Engine discovery mechanism is based on the service-provider79loading facility described in the {@link java.util.ServiceLoader} class.80{@link javax.script.ScriptEngineManager ScriptEngineManager}81includes82{@link javax.script.ScriptEngineManager#getEngineFactories getEngineFactories} method to get all83{@link javax.script.ScriptEngineFactory ScriptEngineFactory} instances84discovered using this mechanism. <code>ScriptEngineFactory</code> has85methods to query attributes about script engine.86</p>87</ol>8889@since 1.690*/9192package javax.script;93949596