|
From: <ls...@us...> - 2007-05-17 20:41:06
|
Revision: 3222
http://jnode.svn.sourceforge.net/jnode/?rev=3222&view=rev
Author: lsantha
Date: 2007-05-17 13:41:04 -0700 (Thu, 17 May 2007)
Log Message:
-----------
Openjdk patches.
Added Paths:
-----------
trunk/core/src/openjdk/javax/javax/
trunk/core/src/openjdk/javax/javax/script/
trunk/core/src/openjdk/javax/javax/script/AbstractScriptEngine.java
trunk/core/src/openjdk/javax/javax/script/Bindings.java
trunk/core/src/openjdk/javax/javax/script/Compilable.java
trunk/core/src/openjdk/javax/javax/script/CompiledScript.java
trunk/core/src/openjdk/javax/javax/script/Invocable.java
trunk/core/src/openjdk/javax/javax/script/ScriptContext.java
trunk/core/src/openjdk/javax/javax/script/ScriptEngine.java
trunk/core/src/openjdk/javax/javax/script/ScriptEngineFactory.java
trunk/core/src/openjdk/javax/javax/script/ScriptEngineManager.java
trunk/core/src/openjdk/javax/javax/script/ScriptException.java
trunk/core/src/openjdk/javax/javax/script/SimpleBindings.java
trunk/core/src/openjdk/javax/javax/script/SimpleScriptContext.java
trunk/core/src/openjdk/javax/javax/script/package.html
Added: trunk/core/src/openjdk/javax/javax/script/AbstractScriptEngine.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/AbstractScriptEngine.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/AbstractScriptEngine.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,312 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * Provides a standard implementation for several of the variants of the <code>eval</code>
+ * method.
+ * <br><br>
+ * <code><b>eval(Reader)</b></code><p><code><b>eval(String)</b></code><p>
+ * <code><b>eval(String, Bindings)</b></code><p><code><b>eval(Reader, Bindings)</b></code>
+ * <br><br> are implemented using the abstract methods
+ * <br><br>
+ * <code><b>eval(Reader,ScriptContext)</b></code> or
+ * <code><b>eval(String, ScriptContext)</b></code>
+ * <br><br>
+ * with a <code>SimpleScriptContext</code>.
+ * <br><br>
+ * A <code>SimpleScriptContext</code> is used as the default <code>ScriptContext</code>
+ * of the <code>AbstractScriptEngine</code>..
+ *
+ * @author Mike Grogan
+ * @version 1.0
+ * @since 1.6
+ */
+public abstract class AbstractScriptEngine implements ScriptEngine {
+
+ /**
+ * The default <code>ScriptContext</code> of this <code>AbstractScriptEngine</code>.
+ */
+
+ protected ScriptContext context;
+
+ /**
+ * Creates a new instance of AbstractScriptEngine using a <code>SimpleScriptContext</code>
+ * as its default <code>ScriptContext</code>.
+ */
+ public AbstractScriptEngine() {
+
+ context = new SimpleScriptContext();
+
+ }
+
+ /**
+ * Creates a new instance using the specified <code>Bindings</code> as the
+ * <code>ENGINE_SCOPE</code> <code>Bindings</code> in the protected <code>context</code> field.
+ *
+ * @param n The specified <code>Bindings</code>.
+ * @throws NullPointerException if n is null.
+ */
+ public AbstractScriptEngine(Bindings n) {
+
+ this();
+ if (n == null) {
+ throw new NullPointerException("n is null");
+ }
+ context.setBindings(n, ScriptContext.ENGINE_SCOPE);
+ }
+
+ /**
+ * Sets the value of the protected <code>context</code> field to the specified
+ * <code>ScriptContext</code>.
+ *
+ * @param ctxt The specified <code>ScriptContext</code>.
+ * @throws NullPointerException if ctxt is null.
+ */
+ public void setContext(ScriptContext ctxt) {
+ if (ctxt == null) {
+ throw new NullPointerException("null context");
+ }
+ context = ctxt;
+ }
+
+ /**
+ * Returns the value of the protected <code>context</code> field.
+ *
+ * @return The value of the protected <code>context</code> field.
+ */
+ public ScriptContext getContext() {
+ return context;
+ }
+
+ /**
+ * Returns the <code>Bindings</code> with the specified scope value in
+ * the protected <code>context</code> field.
+ *
+ * @param scope The specified scope
+ *
+ * @return The corresponding <code>Bindings</code>.
+ *
+ * @throws IllegalArgumentException if the value of scope is
+ * invalid for the type the protected <code>context</code> field.
+ */
+ public Bindings getBindings(int scope) {
+
+ if (scope == ScriptContext.GLOBAL_SCOPE) {
+ return context.getBindings(ScriptContext.GLOBAL_SCOPE);
+ } else if (scope == ScriptContext.ENGINE_SCOPE) {
+ return context.getBindings(ScriptContext.ENGINE_SCOPE);
+ } else {
+ throw new IllegalArgumentException("Invalid scope value.");
+ }
+ }
+
+ /**
+ * Sets the <code>Bindings</code> with the corresponding scope value in the
+ * <code>context</code> field.
+ *
+ * @param bindings The specified <code>Bindings</code>.
+ * @param scope The specified scope.
+ *
+ * @throws IllegalArgumentException if the value of scope is
+ * invalid for the type the <code>context</code> field.
+ * @throws NullPointerException if the bindings is null and the scope is
+ * <code>ScriptContext.ENGINE_SCOPE</code>
+ */
+ public void setBindings(Bindings bindings, int scope) {
+
+ if (scope == ScriptContext.GLOBAL_SCOPE) {
+ context.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);;
+ } else if (scope == ScriptContext.ENGINE_SCOPE) {
+ context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);;
+ } else {
+ throw new IllegalArgumentException("Invalid scope value.");
+ }
+ }
+
+ /**
+ * Sets the specified value with the specified key in the <code>ENGINE_SCOPE</code>
+ * <code>Bindings</code> of the protected <code>context</code> field.
+ *
+ * @param key The specified key.
+ * @param value The specified value.
+ *
+ * @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key is empty.
+ */
+ public void put(String key, Object value) {
+
+ Bindings nn = getBindings(ScriptContext.ENGINE_SCOPE);
+ if (nn != null) {
+ nn.put(key, value);
+ }
+
+ }
+
+ /**
+ * Gets the value for the specified key in the <code>ENGINE_SCOPE</code> of the
+ * protected <code>context</code> field.
+ *
+ * @return The value for the specified key.
+ *
+ * @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key is empty.
+ */
+ public Object get(String key) {
+
+ Bindings nn = getBindings(ScriptContext.ENGINE_SCOPE);
+ if (nn != null) {
+ return nn.get(key);
+ }
+
+ return null;
+ }
+
+
+ /**
+ * <code>eval(Reader, Bindings)</code> calls the abstract
+ * <code>eval(Reader, ScriptContext)</code> method, passing it a <code>ScriptContext</code>
+ * whose Reader, Writers and Bindings for scopes other that <code>ENGINE_SCOPE</code>
+ * are identical to those members of the protected <code>context</code> field. The specified
+ * <code>Bindings</code> is used instead of the <code>ENGINE_SCOPE</code>
+ *
+ * <code>Bindings</code> of the <code>context</code> field.
+ *
+ * @param reader A <code>Reader</code> containing the source of the script.
+ * @param bindings A <code>Bindings</code> to use for the <code>ENGINE_SCOPE</code>
+ * while the script executes.
+ *
+ * @return The return value from <code>eval(Reader, ScriptContext)</code>
+ * @throws ScriptException if an error occurs in script.
+ * @throws NullPointerException if any of the parameters is null.
+ */
+ public Object eval(Reader reader, Bindings bindings ) throws ScriptException {
+
+ ScriptContext ctxt = getScriptContext(bindings);
+
+ return eval(reader, ctxt);
+ }
+
+
+ /**
+ * Same as <code>eval(Reader, Bindings)</code> except that the abstract
+ * <code>eval(String, ScriptContext)</code> is used.
+ *
+ * @param script A <code>String</code> containing the source of the script.
+ *
+ * @param bindings A <code>Bindings</code> to use as the <code>ENGINE_SCOPE</code>
+ * while the script executes.
+ *
+ * @return The return value from <code>eval(String, ScriptContext)</code>
+ * @throws ScriptException if an error occurs in script.
+ * @throws NullPointerException if any of the parameters is null.
+ */
+ public Object eval(String script, Bindings bindings) throws ScriptException {
+
+ ScriptContext ctxt = getScriptContext(bindings);
+
+ return eval(script , ctxt);
+ }
+
+ /**
+ * <code>eval(Reader)</code> calls the abstract
+ * <code>eval(Reader, ScriptContext)</code> passing the value of the <code>context</code>
+ * field.
+ *
+ * @param reader A <code>Reader</code> containing the source of the script.
+ * @return The return value from <code>eval(Reader, ScriptContext)</code>
+ * @throws ScriptException if an error occurs in script.
+ * @throws NullPointerException if any of the parameters is null.
+ */
+ public Object eval(Reader reader) throws ScriptException {
+
+
+ return eval(reader, context);
+ }
+
+ /**
+ * Same as <code>eval(Reader)</code> except that the abstract
+ * <code>eval(String, ScriptContext)</code> is used.
+ *
+ * @param script A <code>String</code> containing the source of the script.
+ * @return The return value from <code>eval(String, ScriptContext)</code>
+ * @throws ScriptException if an error occurrs in script.
+ * @throws NullPointerException if any of the parameters is null.
+ */
+ public Object eval(String script) throws ScriptException {
+
+
+ return eval(script, context);
+ }
+
+ /**
+ * Returns a <code>SimpleScriptContext</code>. The <code>SimpleScriptContext</code>:
+ *<br><br>
+ * <ul>
+ * <li>Uses the specified <code>Bindings</code> for its <code>ENGINE_SCOPE</code>
+ * </li>
+ * <li>Uses the <code>Bindings</code> returned by the abstract <code>getGlobalScope</code>
+ * method as its <code>GLOBAL_SCOPE</code>
+ * </li>
+ * <li>Uses the Reader and Writer in the default <code>ScriptContext</code> of this
+ * <code>ScriptEngine</code>
+ * </li>
+ * </ul>
+ * <br><br>
+ * A <code>SimpleScriptContext</code> returned by this method is used to implement eval methods
+ * using the abstract <code>eval(Reader,Bindings)</code> and <code>eval(String,Bindings)</code>
+ * versions.
+ *
+ * @param nn Bindings to use for the <code>ENGINE_SCOPE</code>
+ * @return The <code>SimpleScriptContext</code>
+ */
+ protected ScriptContext getScriptContext(Bindings nn) {
+
+ SimpleScriptContext ctxt = new SimpleScriptContext();
+ Bindings gs = getBindings(ScriptContext.GLOBAL_SCOPE);
+
+ if (gs != null) {
+ ctxt.setBindings(gs, ScriptContext.GLOBAL_SCOPE);
+ }
+
+ if (nn != null) {
+ ctxt.setBindings(nn,
+ ScriptContext.ENGINE_SCOPE);
+ } else {
+ throw new NullPointerException("Engine scope Bindings may not be null.");
+ }
+
+ ctxt.setReader(context.getReader());
+ ctxt.setWriter(context.getWriter());
+ ctxt.setErrorWriter(context.getErrorWriter());
+
+ return ctxt;
+
+ }
+}
Added: trunk/core/src/openjdk/javax/javax/script/Bindings.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/Bindings.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/Bindings.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+import java.util.Map;
+
+/**
+ * A mapping of key/value pairs, all of whose keys are
+ * <code>Strings</code>.
+ *
+ * @version 1.0
+ * @author Mike Grogan
+ * @since 1.6
+ */
+public interface Bindings extends Map<String, Object> {
+ /**
+ * Set a named value.
+ *
+ * @param name The name associated with the value.
+ * @param value The value associated with the name.
+ *
+ * @return The value previously associated with the given name.
+ * Returns null if no value was previously associated with the name.
+ *
+ * @throws NullPointerException if the name is null.
+ * @throws IllegalArgumentException if the name is empty String.
+ */
+ public Object put(String name, Object value);
+
+ /**
+ * Adds all the mappings in a given <code>Map</code> to this <code>Bindings</code>.
+ * @param toMerge The <code>Map</code> to merge with this one.
+ *
+ * @throws NullPointerException
+ * if toMerge map is null or if some key in the map is null.
+ * @throws IllegalArgumentException
+ * if some key in the map is an empty String.
+ */
+ public void putAll(Map<? extends String, ? extends Object> toMerge);
+
+ /**
+ * Returns <tt>true</tt> if this map contains a mapping for the specified
+ * key. More formally, returns <tt>true</tt> if and only if
+ * this map contains a mapping for a key <tt>k</tt> such that
+ * <tt>(key==null ? k==null : key.equals(k))</tt>. (There can be
+ * at most one such mapping.)
+ *
+ * @param key key whose presence in this map is to be tested.
+ * @return <tt>true</tt> if this map contains a mapping for the specified
+ * key.
+ *
+ * @throws NullPointerException if key is null
+ * @throws ClassCastException if key is not String
+ * @throws IllegalArgumentException if key is empty String
+ */
+ public boolean containsKey(Object key);
+
+ /**
+ * Returns the value to which this map maps the specified key. Returns
+ * <tt>null</tt> if the map contains no mapping for this key. A return
+ * value of <tt>null</tt> does not <i>necessarily</i> indicate that the
+ * map contains no mapping for the key; it's also possible that the map
+ * explicitly maps the key to <tt>null</tt>. The <tt>containsKey</tt>
+ * operation may be used to distinguish these two cases.
+ *
+ * <p>More formally, if this map contains a mapping from a key
+ * <tt>k</tt> to a value <tt>v</tt> such that <tt>(key==null ? k==null :
+ * key.equals(k))</tt>, then this method returns <tt>v</tt>; otherwise
+ * it returns <tt>null</tt>. (There can be at most one such mapping.)
+ *
+ * @param key key whose associated value is to be returned.
+ * @return the value to which this map maps the specified key, or
+ * <tt>null</tt> if the map contains no mapping for this key.
+ *
+ * @throws NullPointerException if key is null
+ * @throws ClassCastException if key is not String
+ * @throws IllegalArgumentException if key is empty String
+ */
+ public Object get(Object key);
+
+ /**
+ * Removes the mapping for this key from this map if it is present
+ * (optional operation). More formally, if this map contains a mapping
+ * from key <tt>k</tt> to value <tt>v</tt> such that
+ * <code>(key==null ? k==null : key.equals(k))</code>, that mapping
+ * is removed. (The map can contain at most one such mapping.)
+ *
+ * <p>Returns the value to which the map previously associated the key, or
+ * <tt>null</tt> if the map contained no mapping for this key. (A
+ * <tt>null</tt> return can also indicate that the map previously
+ * associated <tt>null</tt> with the specified key if the implementation
+ * supports <tt>null</tt> values.) The map will not contain a mapping for
+ * the specified key once the call returns.
+ *
+ * @param key key whose mapping is to be removed from the map.
+ * @return previous value associated with specified key, or <tt>null</tt>
+ * if there was no mapping for key.
+ *
+ * @throws NullPointerException if key is null
+ * @throws ClassCastException if key is not String
+ * @throws IllegalArgumentException if key is empty String
+ */
+ public Object remove(Object key);
+}
Added: trunk/core/src/openjdk/javax/javax/script/Compilable.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/Compilable.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/Compilable.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+
+import java.util.Map;
+import java.io.Reader;
+
+/**
+ * The optional interface implemented by ScriptEngines whose methods compile scripts
+ * to a form that can be executed repeatedly without recompilation.
+ *
+ * @author Mike Grogan
+ * @version 1.0
+ * @since 1.6
+ */
+public interface Compilable {
+ /**
+ * Compiles the script (source represented as a <code>String</code>) for
+ * later execution.
+ *
+ * @param script The source of the script, represented as a <code>String</code>.
+ *
+ * @return An subclass of <code>CompiledScript</code> to be executed later using one
+ * of the <code>eval</code> methods of <code>CompiledScript</code>.
+ *
+ * @throws ScriptException if compilation fails.
+ * @throws NullPointerException if the argument is null.
+ *
+ */
+
+ public CompiledScript compile(String script) throws
+ ScriptException;
+
+ /**
+ * Compiles the script (source read from <code>Reader</code>) for
+ * later execution. Functionality is identical to
+ * <code>compile(String)</code> other than the way in which the source is
+ * passed.
+ *
+ * @param script The reader from which the script source is obtained.
+ *
+ * @return An implementation of <code>CompiledScript</code> to be executed
+ * later using one of its <code>eval</code> methods of <code>CompiledScript</code>.
+ *
+ * @throws ScriptException if compilation fails.
+ * @throws NullPointerException if argument is null.
+ */
+ public CompiledScript compile(Reader script) throws
+ ScriptException;
+}
Added: trunk/core/src/openjdk/javax/javax/script/CompiledScript.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/CompiledScript.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/CompiledScript.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+
+import java.util.Map;
+
+/**
+ * Extended by classes that store results of compilations. State
+ * might be stored in the form of Java classes, Java class files or scripting
+ * language opcodes. The script may be executed repeatedly
+ * without reparsing.
+ * <br><br>
+ * Each <code>CompiledScript</code> is associated with a <code>ScriptEngine</code> -- A call to an <code>eval</code>
+ * method of the <code>CompiledScript</code> causes the execution of the script by the
+ * <code>ScriptEngine</code>. Changes in the state of the <code>ScriptEngine</code> caused by execution
+ * of tne <code>CompiledScript</code> may visible during subsequent executions of scripts by the engine.
+ *
+ * @author Mike Grogan
+ * @version 1.0
+ * @since 1.6
+ */
+public abstract class CompiledScript {
+
+ /**
+ * Executes the program stored in this <code>CompiledScript</code> object.
+ *
+ * @param context A <code>ScriptContext</code> that is used in the same way as
+ * the <code>ScriptContext</code> passed to the <code>eval</code> methods of
+ * <code>ScriptEngine</code>.
+ *
+ * @return The value returned by the script execution, if any. Should return <code>null</code>
+ * if no value is returned by the script execution.
+ *
+ * @throws ScriptException if an error occurs.
+ * @throws NullPointerException if context is null.
+ */
+
+ public abstract Object eval(ScriptContext context) throws ScriptException;
+
+ /**
+ * Executes the program stored in the <code>CompiledScript</code> object using
+ * the supplied <code>Bindings</code> of attributes as the <code>ENGINE_SCOPE</code> of the
+ * associated <code>ScriptEngine</code> during script execution. If bindings is null,
+ * then the effect of calling this method is same as that of eval(getEngine().getContext()).
+ * <p>.
+ * The <code>GLOBAL_SCOPE</code> <code>Bindings</code>, <code>Reader</code> and <code>Writer</code>
+ * associated with the default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> are used.
+ *
+ * @param bindings The bindings of attributes used for the <code>ENGINE_SCOPE</code>.
+ *
+ * @return The return value from the script execution
+ *
+ * @throws ScriptException if an error occurs.
+ */
+ public Object eval(Bindings bindings) throws ScriptException {
+
+ ScriptContext ctxt = getEngine().getContext();
+
+ if (bindings != null) {
+ SimpleScriptContext tempctxt = new SimpleScriptContext();
+ tempctxt.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
+ tempctxt.setBindings(ctxt.getBindings(ScriptContext.GLOBAL_SCOPE),
+ ScriptContext.GLOBAL_SCOPE);
+ tempctxt.setWriter(ctxt.getWriter());
+ tempctxt.setReader(ctxt.getReader());
+ tempctxt.setErrorWriter(ctxt.getErrorWriter());
+ ctxt = tempctxt;
+ }
+
+ return eval(ctxt);
+ }
+
+
+ /**
+ * Executes the program stored in the <code>CompiledScript</code> object. The
+ * default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> is used.
+ * The effect of calling this method is same as that of eval(getEngine().getContext()).
+ *
+ * @return The return value from the script execution
+ *
+ * @throws ScriptException if an error occurs.
+ */
+ public Object eval() throws ScriptException {
+ return eval(getEngine().getContext());
+ }
+
+ /**
+ * Returns the <code>ScriptEngine</code> wbose <code>compile</code> method created this <code>CompiledScript</code>.
+ * The <code>CompiledScript</code> will execute in this engine.
+ *
+ * @return The <code>ScriptEngine</code> that created this <code>CompiledScript</code>
+ */
+ public abstract ScriptEngine getEngine();
+
+}
Added: trunk/core/src/openjdk/javax/javax/script/Invocable.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/Invocable.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/Invocable.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+
+/**
+ * The optional interface implemented by ScriptEngines whose methods allow the invocation of
+ * procedures in scripts that have previously been executed.
+ *
+ * @version 1.0
+ * @author Mike Grogan
+ * @author A. Sundararajan
+ * @since 1.6
+ */
+public interface Invocable {
+ /**
+ * Calls a method on a script object compiled during a previous script execution,
+ * which is retained in the state of the <code>ScriptEngine</code>.
+ *
+ * @param name The name of the procedure to be called.
+ *
+ * @param thiz If the procedure is a member of a class
+ * defined in the script and thiz is an instance of that class
+ * returned by a previous execution or invocation, the named method is
+ * called through that instance.
+ *
+ * @param args Arguments to pass to the procedure. The rules for converting
+ * the arguments to scripting variables are implementation-specific.
+ *
+ * @return The value returned by the procedure. The rules for converting the scripting
+ * variable returned by the script method to a Java Object are implementation-specific.
+ *
+ * @throws ScriptException if an error occurrs during invocation of the method.
+ * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
+ * @throws NullPointerException if the method name is null.
+ * @throws IllegalArgumentException if the specified thiz is null or the specified Object is
+ * does not represent a scripting object.
+ */
+ public Object invokeMethod(Object thiz, String name, Object... args)
+ throws ScriptException, NoSuchMethodException;
+
+ /**
+ * Used to call top-level procedures and functions defined in scripts.
+ *
+ * @param args Arguments to pass to the procedure or function
+ * @return The value returned by the procedure or function
+ *
+ * @throws ScriptException if an error occurrs during invocation of the method.
+ * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
+ * @throws NullPointerException if method name is null.
+ */
+ public Object invokeFunction(String name, Object... args)
+ throws ScriptException, NoSuchMethodException;
+
+
+ /**
+ * Returns an implementation of an interface using functions compiled in
+ * the interpreter. The methods of the interface
+ * may be implemented using the <code>invokeFunction</code> method.
+ *
+ * @param clasz The <code>Class</code> object of the interface to return.
+ *
+ * @return An instance of requested interface - null if the requested interface is unavailable,
+ * i. e. if compiled functions in the <code>ScriptEngine</code> cannot be found matching
+ * the ones in the requested interface.
+ *
+ * @throws IllegalArgumentException if the specified <code>Class</code> object
+ * is null or is not an interface.
+ */
+ public <T> T getInterface(Class<T> clasz);
+
+ /**
+ * Returns an implementation of an interface using member functions of
+ * a scripting object compiled in the interpreter. The methods of the
+ * interface may be implemented using the <code>invokeMethod</code> method.
+ *
+ * @param thiz The scripting object whose member functions are used to implement the methods of the interface.
+ * @param clasz The <code>Class</code> object of the interface to return.
+ *
+ * @return An instance of requested interface - null if the requested interface is unavailable,
+ * i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching
+ * the ones in the requested interface.
+ *
+ * @throws IllegalArgumentException if the specified <code>Class</code> object
+ * is null or is not an interface, or if the specified Object is
+ * null or does not represent a scripting object.
+ */
+ public <T> T getInterface(Object thiz, Class<T> clasz);
+
+}
Added: trunk/core/src/openjdk/javax/javax/script/ScriptContext.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/ScriptContext.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/ScriptContext.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+import java.util.List;
+import java.io.Writer;
+import java.io.Reader;
+
+/**
+ * The interface whose implementing classes are used to connect Script Engines
+ * with objects, such as scoped Bindings, in hosting applications. Each scope is a set
+ * of named attributes whose values can be set and retrieved using the
+ * <code>ScriptContext</code> methods. ScriptContexts also expose Readers and Writers
+ * that can be used by the ScriptEngines for input and output.
+ *
+ * @author Mike Grogan
+ * @version 1.0
+ * @since 1.6
+ */
+public interface ScriptContext {
+
+
+ /**
+ * EngineScope attributes are visible during the lifetime of a single
+ * <code>ScriptEngine</code> and a set of attributes is maintained for each
+ * engine.
+ */
+ public static final int ENGINE_SCOPE = 100;
+
+ /**
+ * GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
+ */
+ public static final int GLOBAL_SCOPE = 200;
+
+
+ /**
+ * Associates a <code>Bindings</code> instance with a particular scope in this
+ * <code>ScriptContext</code>. Calls to the <code>getAttribute</code> and
+ * <code>setAttribute</code> methods must map to the <code>get</code> and
+ * <code>put</code> methods of the <code>Bindings</code> for the specified scope.
+ *
+ * @param bindings The <code>Bindings</code> to associate with the given scope
+ * @param scope The scope
+ *
+ * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
+ * specified scope value in ScriptContexts of this type.
+ * @throws NullPointerException if value of scope is <code>ENGINE_SCOPE</code> and
+ * the specified <code>Bindings</code> is null.
+ *
+ */
+ public void setBindings(Bindings bindings, int scope);
+
+ /**
+ * Gets the <code>Bindings</code> associated with the given scope in this
+ * <code>ScriptContext</code>.
+ *
+ * @return The associated <code>Bindings</code>. Returns <code>null</code> if it has not
+ * been set.
+ *
+ * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
+ * specified scope value in <code>ScriptContext</code> of this type.
+ */
+ public Bindings getBindings(int scope);
+
+ /**
+ * Sets the value of an attribute in a given scope.
+ *
+ * @param name The name of the attribute to set
+ * @param value The value of the attribute
+ * @param scope The scope in which to set the attribute
+ *
+ * @throws IllegalArgumentException
+ * if the name is empty or if the scope is invalid.
+ * @throws NullPointerException if the name is null.
+ */
+ public void setAttribute(String name, Object value, int scope);
+
+ /**
+ * Gets the value of an attribute in a given scope.
+ *
+ * @param name The name of the attribute to retrieve.
+ * @param scope The scope in which to retrieve the attribute.
+ * @return The value of the attribute. Returns <code>null</code> is the name
+ * does not exist in the given scope.
+ *
+ * @throws IllegalArgumentException
+ * if the name is empty or if the value of scope is invalid.
+ * @throws NullPointerException if the name is null.
+ */
+ public Object getAttribute(String name, int scope);
+
+ /**
+ * Remove an attribute in a given scope.
+ *
+ * @param name The name of the attribute to remove
+ * @param scope The scope in which to remove the attribute
+ *
+ * @return The removed value.
+ * @throws IllegalArgumentException
+ * if the name is empty or if the scope is invalid.
+ * @throws NullPointerException if the name is null.
+ */
+ public Object removeAttribute(String name, int scope);
+
+ /**
+ * Retrieves the value of the attribute with the given name in
+ * the scope occurring earliest in the search order. The order
+ * is determined by the numeric value of the scope parameter (lowest
+ * scope values first.)
+ *
+ * @param name The name of the the attribute to retrieve.
+ * @return The value of the attribute in the lowest scope for
+ * which an attribute with the given name is defined. Returns
+ * null if no attribute with the name exists in any scope.
+ * @throws NullPointerException if the name is null.
+ * @throws IllegalArgumentException if the name is empty.
+ */
+ public Object getAttribute(String name);
+
+
+ /**
+ * Get the lowest scope in which an attribute is defined.
+ * @param name Name of the attribute
+ * .
+ * @return The lowest scope. Returns -1 if no attribute with the given
+ * name is defined in any scope.
+ * @throws NullPointerException if name is null.
+ * @throws IllegalArgumentException if name is empty.
+ */
+ public int getAttributesScope(String name);
+
+ /**
+ * Returns the <code>Writer</code> for scripts to use when displaying output.
+ *
+ * @return The <code>Writer</code>.
+ */
+ public Writer getWriter();
+
+
+ /**
+ * Returns the <code>Writer</code> used to display error output.
+ *
+ * @return The <code>Writer</code>
+ */
+ public Writer getErrorWriter();
+
+ /**
+ * Sets the <code>Writer</code> for scripts to use when displaying output.
+ *
+ * @param writer The new <code>Writer</code>.
+ */
+ public void setWriter(Writer writer);
+
+
+ /**
+ * Sets the <code>Writer</code> used to display error output.
+ *
+ * @param writer The <code>Writer</code>.
+ */
+ public void setErrorWriter(Writer writer);
+
+ /**
+ * Returns a <code>Reader</code> to be used by the script to read
+ * input.
+ *
+ * @return The <code>Reader</code>.
+ */
+ public Reader getReader();
+
+
+ /**
+ * Sets the <code>Reader</code> for scripts to read input
+ * .
+ * @param reader The new <code>Reader</code>.
+ */
+ public void setReader(Reader reader);
+
+ /**
+ * Returns immutable <code>List</code> of all the valid values for
+ * scope in the ScriptContext.
+ *
+ * @return list of scope values
+ */
+ public List<Integer> getScopes();
+}
Added: trunk/core/src/openjdk/javax/javax/script/ScriptEngine.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/ScriptEngine.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/ScriptEngine.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,324 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+
+import java.io.Reader;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <code>ScriptEngine</code> is the fundamental interface whose methods must be
+ * fully functional in every implementation of this specification.
+ * <br><br>
+ * These methods provide basic scripting functionality. Applications written to this
+ * simple interface are expected to work with minimal modifications in every implementation.
+ * It includes methods that execute scripts, and ones that set and get values.
+ * <br><br>
+ * The values are key/value pairs of two types. The first type of pairs consists of
+ * those whose keys are reserved and defined in this specification or by individual
+ * implementations. The values in the pairs with reserved keys have specified meanings.
+ * <br><br>
+ * The other type of pairs consists of those that create Java language Bindings, the values are
+ * usually represented in scripts by the corresponding keys or by decorated forms of them.
+ *
+ * @author Mike Grogan
+ * @version 1.0
+ * @since 1.6
+ */
+
+public interface ScriptEngine {
+
+ /**
+ * Reserved key for a named value that passes
+ * an array of positional arguments to a script.
+ */
+ public static final String ARGV="javax.script.argv";
+
+ /**
+ * Reserved key for a named value that is
+ * the name of the file being executed.
+ */
+ public static final String FILENAME = "javax.script.filename";
+
+ /**
+ * Reserved key for a named value that is
+ * the name of the <code>ScriptEngine</code> implementation.
+ */
+ public static final String ENGINE = "javax.script.engine";
+
+ /**
+ * Reserved key for a named value that identifies
+ * the version of the <code>ScriptEngine</code> implementation.
+ */
+ public static final String ENGINE_VERSION = "javax.script.engine_version";
+
+ /**
+ * Reserved key for a named value that identifies
+ * the short name of the scripting language. The name is used by the
+ * <code>ScriptEngineManager</code> to locate a <code>ScriptEngine</code>
+ * with a given name in the <code>getEngineByName</code> method.
+ */
+ public static final String NAME = "javax.script.name";
+
+ /**
+ * Reserved key for a named value that is
+ * the full name of Scripting Language supported by the implementation.
+ */
+ public static final String LANGUAGE = "javax.script.language";
+
+ /**
+ * Reserved key for the named value that identifies
+ * the version of the scripting language supported by the implementation.
+ */
+ public static final String LANGUAGE_VERSION ="javax.script.language_version";
+
+
+ /**
+ * Causes the immediate execution of the script whose source is the String
+ * passed as the first argument. The script may be reparsed or recompiled before
+ * execution. State left in the engine from previous executions, including
+ * variable values and compiled procedures may be visible during this execution.
+ *
+ * @param script The script to be executed by the script engine.
+ *
+ * @param context A <code>ScriptContext</code> exposing sets of attributes in
+ * different scopes. The meanings of the scopes <code>ScriptContext.GLOBAL_SCOPE</code>,
+ * and <code>ScriptContext.ENGINE_SCOPE</code> are defined in the specification.
+ * <br><br>
+ * The <code>ENGINE_SCOPE</code> <code>Bindings</code> of the <code>ScriptContext</code> contains the
+ * bindings of scripting variables to application objects to be used during this
+ * script execution.
+ *
+ *
+ * @return The value returned from the execution of the script.
+ *
+ * @throws ScriptException if an error occurrs in script. ScriptEngines should create and throw
+ * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
+ * implementations.
+ * @throws NullPointerException if either argument is null.
+ */
+ public Object eval(String script, ScriptContext context) throws ScriptException;
+
+
+ /**
+ * Same as <code>eval(String, ScriptContext)</code> where the source of the script
+ * is read from a <code>Reader</code>.
+ *
+ * @param reader The source of the script to be executed by the script engine.
+ *
+ * @param context The <code>ScriptContext</code> passed to the script engine.
+ *
+ * @return The value returned from the execution of the script.
+ *
+ * @throws ScriptException if an error occurrs in script.
+ * @throws NullPointerException if either argument is null.
+ */
+ public Object eval(Reader reader , ScriptContext context) throws ScriptException;
+
+ /**
+ * Executes the specified script. The default <code>ScriptContext</code> for the <code>ScriptEngine</code>
+ * is used.
+ *
+ * @param script The script language source to be executed.
+ *
+ * @return The value returned from the execution of the script.
+ *
+ * @throws ScriptException if error occurrs in script.
+ * @throws NullPointerException if the argument is null.
+ */
+ public Object eval(String script) throws ScriptException;
+
+ /**
+ * Same as <code>eval(String)</code> except that the source of the script is
+ * provided as a <code>Reader</code>
+ *
+ * @param reader The source of the script.
+ *
+ * @return The value returned by the script.
+ *
+ * @throws ScriptException if an error occurrs in script.
+ * @throws NullPointerException if the argument is null.
+ */
+ public Object eval(Reader reader) throws ScriptException;
+
+ /**
+ * Executes the script using the <code>Bindings</code> argument as the <code>ENGINE_SCOPE</code>
+ * <code>Bindings</code> of the <code>ScriptEngine</code> during the script execution. The
+ * <code>Reader</code>, <code>Writer</code> and non-<code>ENGINE_SCOPE</code> <code>Bindings</code> of the
+ * default <code>ScriptContext</code> are used. The <code>ENGINE_SCOPE</code>
+ * <code>Bindings</code> of the <code>ScriptEngine</code> is not changed, and its
+ * mappings are unaltered by the script execution.
+ *
+ * @param script The source for the script.
+ *
+ * @param n The <code>Bindings</code> of attributes to be used for script execution.
+ *
+ * @return The value returned by the script.
+ *
+ * @throws ScriptException if an error occurrs in script.
+ * @throws NullPointerException if either argument is null.
+ */
+ public Object eval(String script, Bindings n) throws ScriptException;
+
+ /**
+ * Same as <code>eval(String, Bindings)</code> except that the source of the script
+ * is provided as a <code>Reader</code>.
+ *
+ * @param reader The source of the script.
+ * @param n The <code>Bindings</code> of attributes.
+ *
+ * @return The value returned by the script.
+ *
+ * @throws ScriptException if an error occurrs.
+ * @throws NullPointerException if either argument is null.
+ */
+ public Object eval(Reader reader , Bindings n) throws ScriptException;
+
+
+
+ /**
+ * Sets a key/value pair in the state of the ScriptEngine that may either create
+ * a Java Language Binding to be used in the execution of scripts or be used in some
+ * other way, depending on whether the key is reserved. Must have the same effect as
+ * <code>getBindings(ScriptContext.ENGINE_SCOPE).put</code>.
+ *
+ * @param key The name of named value to add
+ * @param value The value of named value to add.
+ *
+ * @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key is empty.
+ */
+ public void put(String key, Object value);
+
+
+ /**
+ * Retrieves a value set in the state of this engine. The value might be one
+ * which was set using <code>setValue</code> or some other value in the state
+ * of the <code>ScriptEngine</code>, depending on the implementation. Must have the same effect
+ * as <code>getBindings(ScriptContext.ENGINE_SCOPE).get</code>
+ *
+ * @param key The key whose value is to be returned
+ * @return the value for the given key
+ *
+ * @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key is empty.
+ */
+ public Object get(String key);
+
+
+ /**
+ * Returns a scope of named values. The possible scopes are:
+ * <br><br>
+ * <ul>
+ * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The set of named values representing global
+ * scope. If this <code>ScriptEngine</code> is created by a <code>ScriptEngineManager</code>,
+ * then the manager sets global scope bindings. This may be <code>null</code> if no global
+ * scope is associated with this <code>ScriptEngine</code></li>
+ * <li><code>ScriptContext.ENGINE_SCOPE</code> - The set of named values representing the state of
+ * this <code>ScriptEngine</code>. The values are generally visible in scripts using
+ * the associated keys as variable names.</li>
+ * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
+ * </li>
+ * </ul>
+ * <br><br>
+ * The <code>Bindings</code> instances that are returned must be identical to those returned by the
+ * <code>getBindings</code> method of <code>ScriptContext</code> called with corresponding arguments on
+ * the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
+ *
+ * @param scope Either <code>ScriptContext.ENGINE_SCOPE</code> or <code>ScriptContext.GLOBAL_SCOPE</code>
+ * which specifies the <code>Bindings</code> to return. Implementations of <code>ScriptContext</code>
+ * may define additional scopes. If the default <code>ScriptContext</code> of the <code>ScriptEngine</code>
+ * defines additional scopes, any of them can be passed to get the corresponding <code>Bindings</code>.
+ *
+ * @return The <code>Bindings</code> with the specified scope.
+ *
+ * @throws IllegalArgumentException if specified scope is invalid
+ *
+ */
+ public Bindings getBindings(int scope);
+
+ /**
+ * Sets a scope of named values to be used by scripts. The possible scopes are:
+ *<br><br>
+ * <ul>
+ * <li><code>ScriptContext.ENGINE_SCOPE</code> - The specified <code>Bindings</code> replaces the
+ * engine scope of the <code>ScriptEngine</code>.
+ * </li>
+ * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The specified <code>Bindings</code> must be visible
+ * as the <code>GLOBAL_SCOPE</code>.
+ * </li>
+ * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
+ *</li>
+ * </ul>
+ * <br><br>
+ * The method must have the same effect as calling the <code>setBindings</code> method of
+ * <code>ScriptContext</code> with the corresponding value of <code>scope</code> on the default
+ * <code>ScriptContext</code> of the <code>ScriptEngine</code>.
+ *
+ * @param bindings The <code>Bindings</code> for the specified scope.
+ * @param scope The specified scope. Either <code>ScriptContext.ENGINE_SCOPE</code>,
+ * <code>ScriptContext.GLOBAL_SCOPE</code>, or any other valid value of scope.
+ *
+ * @throws IllegalArgumentException if the scope is invalid
+ * @throws NullPointerException if the bindings is null and the scope is
+ * <code>ScriptContext.ENGINE_SCOPE</code>
+ */
+ public void setBindings(Bindings bindings, int scope);
+
+
+ /**
+ * Returns an uninitialized <code>Bindings</code>.
+ *
+ * @return A <code>Bindings</code> that can be used to replace the state of this <code>ScriptEngine</code>.
+ **/
+ public Bindings createBindings();
+
+
+ /**
+ * Returns the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
+ * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
+ *
+ * @return The default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
+ */
+ public ScriptContext getContext();
+
+ /**
+ * Sets the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
+ * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
+ *
+ * @param context A <code>ScriptContext</code> that will replace the default <code>ScriptContext</code> in
+ * the <code>ScriptEngine</code>.
+ * @throws NullPointerException if context is null.
+ */
+ public void setContext(ScriptContext context);
+
+ /**
+ * Returns a <code>ScriptEngineFactory</code> for the class to which this <code>ScriptEngine</code> belongs.
+ *
+ * @return The <code>ScriptEngineFactory</code>
+ */
+ public ScriptEngineFactory getFactory();
+}
Added: trunk/core/src/openjdk/javax/javax/script/ScriptEngineFactory.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/script/ScriptEngineFactory.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/script/ScriptEngineFactory.java 2007-05-17 20:41:04 UTC (rev 3222)
@@ -0,0 +1,230 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.script;
+
+import java.util.List;
+
+/**
+ * <code>ScriptEngineFactory</code> is used to describe and instantiate
+ * <code>ScriptEngines</code>.
+ * <br><br>
+ * Each class implementing <code>ScriptEngine</code> has a corresponding factory
+ * that exposes metadata describing the engine class.
+ * <br><br>The <code>ScriptEngineManager</code>
+ * uses the service provider mechanism described in the <i>Jar File Specification</i> to obtain
+ * instances of all <code>ScriptEngineFactories</code> available in
+ * the current ClassLoader.
+ *
+ * @since 1.6
+ */
+public interface ScriptEngineFactory {
+ /**
+ * Returns the full name of the <code>ScriptEngine</code>. For
+ * instance an implementation based on the Mozilla Rhino Javascript engine
+ * might return <i>Rhino Mozilla Javascript Engine</i>.
+ * @return The name of the engine implementation.
+ */
+ public String getEngineName();
+
+ /**
+ * Returns the version of the <code>ScriptEngine</code>.
+ * @return The <code>ScriptEngine</code> 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</code>.
+ * The array is used by the <code>ScriptEngineManager</code> to implement its
+ * <code>getEngineByExtension</code> 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</code> class to implement its
+ * <code>getEngineByMimetype</code> method.
+ * @return The list of mime types.
+ */
+ public List<String> getMimeTypes();
+
+ /**
+ * Returns an immutable list of short names for the <code>ScriptEngine</code>, which may be used to
+ * identify the <code>ScriptEngine</code> by the <code>ScriptEngineManager</code>.
+ * For instance, an implementation based on the Mozilla Rhino Javascript engine might
+ * return list containing {"javascript", "rhino"}.
+ */
+ public List<String> getNames();
+
+ /**
+ * Returns the name of the scripting langauge supported by this
+ * <code>ScriptEngine</code>.
+ * @return The name of the supported language.
+ */
+ public String getLanguageName();
+
+ /**
+ * Returns the version of the scripting language supported by this
+ * <code>ScriptEngine</code>.
+ * @return The version of the supported language.
+ */
+ public String getLanguageVersion();
+
+ /**
+ ...
[truncated message content] |