KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > script > ScriptEngineFactory


1 /*
2  * @(#)ScriptEngineFactory.java 1.3 05/11/17 14:24:14
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTAIL. Use is subject to license terms.
6  */

7
8 package javax.script;
9
10 import java.util.List JavaDoc;
11
12 /**
13  * <code>ScriptEngineFactory</code> is used to describe and instantiate
14  * <code>ScriptEngines</code>.
15  * <br><br>
16  * Each class implementing <code>ScriptEngine</code> has a corresponding factory
17  * that exposes metadata describing the engine class.
18  * <br><br>The <code>ScriptEngineManager</code>
19  * uses the service provider mechanism described in the <i>Jar File Specification</i> to obtain
20  * instances of all <code>ScriptEngineFactories</code> available in
21  * the current ClassLoader.
22  *
23  * @since 1.6
24  */

25 public interface ScriptEngineFactory {
26     /**
27      * Returns the full name of the <code>ScriptEngine</code>. For
28      * instance an implementation based on the Mozilla Rhino Javascript engine
29      * might return <i>Rhino Mozilla Javascript Engine</i>.
30      * @return The name of the engine implementation.
31      */

32     public String JavaDoc getEngineName();
33     
34     /**
35      * Returns the version of the <code>ScriptEngine</code>.
36      * @return The <code>ScriptEngine</code> implementation version.
37      */

38     public String JavaDoc getEngineVersion();
39     
40     
41     /**
42      * Returns an immutable list of filename extensions, which generally identify scripts
43      * written in the language supported by this <code>ScriptEngine</code>.
44      * The array is used by the <code>ScriptEngineManager</code> to implement its
45      * <code>getEngineByExtension</code> method.
46      * @return The list of extensions.
47      */

48     public List JavaDoc<String JavaDoc> getExtensions();
49     
50     
51     /**
52      * Returns an immutable list of mimetypes, associated with scripts that
53      * can be executed by the engine. The list is used by the
54      * <code>ScriptEngineManager</code> class to implement its
55      * <code>getEngineByMimetype</code> method.
56      * @return The list of mime types.
57      */

58     public List JavaDoc<String JavaDoc> getMimeTypes();
59     
60     /**
61      * Returns an immutable list of short names for the <code>ScriptEngine</code>, which may be used to
62      * identify the <code>ScriptEngine</code> by the <code>ScriptEngineManager</code>.
63      * For instance, an implementation based on the Mozilla Rhino Javascript engine might
64      * return list containing {&quot;javascript&quot;, &quot;rhino&quot;}.
65      */

66     public List JavaDoc<String JavaDoc> getNames();
67     
68     /**
69      * Returns the name of the scripting langauge supported by this
70      * <code>ScriptEngine</code>.
71      * @return The name of the supported language.
72      */

73     public String JavaDoc getLanguageName();
74     
75     /**
76      * Returns the version of the scripting language supported by this
77      * <code>ScriptEngine</code>.
78      * @return The version of the supported language.
79      */

80     public String JavaDoc getLanguageVersion();
81     
82     /**
83      * Returns the value of an attribute whose meaning may be implementation-specific.
84      * Keys for which the value is defined in all implementations are:
85      * <ul>
86      * <li>ScriptEngine.ENGINE</li>
87      * <li>ScriptEngine.ENGINE_VERSION</li>
88      * <li>ScriptEngine.NAME</li>
89      * <li>ScriptEngine.LANGUAGE</li>
90      * <li>ScriptEngine.LANGUAGE_VERSION</li>
91      * </ul>
92      * <p>
93      * The values for these keys are the Strings returned by <code>getEngineName</code>,
94      * <code>getEngineVersion</code>, <code>getName</code>, <code>getLanguageName</code> and
95      * <code>getLanguageVersion</code> respectively.<br><br>
96      * A reserved key, <code><b>THREADING</b></code>, whose value describes the behavior of the engine
97      * with respect to concurrent execution of scripts and maintenance of state is also defined.
98      * These values for the <code><b>THREADING</b></code> key are:<br><br>
99      * <ul>
100      * <p><code>null</code> - The engine implementation is not thread safe, and cannot
101      * be used to execute scripts concurrently on multiple threads.
102      * <p><code>&quot;MULTITHREADED&quot;</code> - The engine implementation is internally
103      * thread-safe and scripts may execute concurrently although effects of script execution
104      * on one thread may be visible to scripts on other threads.
105      * <p><code>&quot;THREAD-ISOLATED&quot;</code> - The implementation satisfies the requirements
106      * of &quot;MULTITHREADED&quot;, and also, the engine maintains independent values
107      * for symbols in scripts executing on different threads.
108      * <p><code>&quot;STATELESS&quot;</code> - The implementation satisfies the requirements of
109      * <code>&quot;THREAD-ISOLATED&quot;</code>. In addition, script executions do not alter the
110      * mappings in the <code>Bindings</code> which is the engine scope of the
111      * <code>ScriptEngine</code>. In particular, the keys in the <code>Bindings</code>
112      * and their associated values are the same before and after the execution of the script.
113      * </li>
114      * </ul>
115      * <br><br>
116      * Implementations may define implementation-specific keys.
117      *
118      * @param key The name of the parameter
119      * @return The value for the given parameter. Returns <code>null</code> if no
120      * value is assigned to the key.
121      *
122      */

123     public Object JavaDoc getParameter(String JavaDoc key);
124     
125     /**
126      * Returns a String which can be used to invoke a method of a Java object using the syntax
127      * of the supported scripting language. For instance, an implementaton for a Javascript
128      * engine might be;
129      * <p>
130      * <code><pre>
131      * public String getMethodCallSyntax(String obj,
132      * String m, String... args) {
133      * String ret = obj;
134      * ret += "." + m + "(";
135      * for (int i = 0; i < args.length; i++) {
136      * ret += args[i];
137      * if (i == args.length - 1) {
138      * ret += ")";
139      * } else {
140      * ret += ",";
141      * }
142      * }
143      * return ret;
144      * }
145      *</pre></code>
146      * <p>
147      *
148      * @param obj The name representing the object whose method is to be invoked. The
149      * name is the one used to create bindings using the <code>put</code> method of
150      * <code>ScriptEngine</code>, the <code>put</code> method of an <code>ENGINE_SCOPE</code>
151      * <code>Bindings</code>,or the <code>setAttribute</code> method
152      * of <code>ScriptContext</code>. The identifier used in scripts may be a decorated form of the
153      * specified one.
154      *
155      * @param m The name of the method to invoke.
156      * @param args names of the arguments in the method call.
157      *
158      * @return The String used to invoke the method in the syntax of the scripting language.
159      */

160     public String JavaDoc getMethodCallSyntax(String JavaDoc obj, String JavaDoc m, String JavaDoc... args);
161     
162     /**
163      * Returns a String that can be used as a statement to display the specified String using
164      * the syntax of the supported scripting language. For instance, the implementaton for a Perl
165      * engine might be;
166      * <p>
167      * <pre><code>
168      * public String getOutputStatement(String toDisplay) {
169      * return "print(" + toDisplay + ")";
170      * }
171      * </code></pre>
172      *
173      * @param toDisplay The String to be displayed by the returned statement.
174      * @return The string used to display the String in the syntax of the scripting language.
175      *
176      *
177      */

178     public String JavaDoc getOutputStatement(String JavaDoc toDisplay);
179     
180     
181     /**
182      * Returns A valid scripting language executable progam with given statements.
183      * For instance an implementation for a PHP engine might be:
184      * <p>
185      * <pre><code>
186      * public String getProgram(String... statements) {
187      * $retval = "&lt;?\n";
188      * int len = statements.length;
189      * for (int i = 0; i < len; i++) {
190      * $retval += statements[i] + ";\n";
191      * }
192      * $retval += "?&gt;";
193      *
194      * }
195      * </code></pre>
196      *
197      * @param statements The statements to be executed. May be return values of
198      * calls to the <code>getMethodCallSyntax</code> and <code>getOutputStatement</code> methods.
199      * @return The Program
200      */

201     
202     public String JavaDoc getProgram(String JavaDoc... statements);
203     
204     /**
205      * Returns an instance of the <code>ScriptEngine</code> associated with this
206      * <code>ScriptEngineFactory</code>. A new ScriptEngine is generally
207      * returned, but implementations may pool, share or reuse engines.
208      *
209      * @return A new <code>ScriptEngine</code> instance.
210      */

211     public ScriptEngine getScriptEngine();
212 }
213
Popular Tags