This commit was generated by cvs2svn to compensate for changes in r4,

which included commits to RCS files with non-trunk default branches.
This commit is contained in:
hns 2000-12-29 17:58:10 +00:00
parent af35ca5581
commit ee13186158
148 changed files with 34934 additions and 0 deletions

View file

@ -0,0 +1,122 @@
// JSException.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
import FESI.Exceptions.*;
import java.io.*;
/**
* Thrown when the EcmaScript interpreter detect an error. Package
* the message of the EcmaScriptException (or other exception) which
* was generated.
*/
public class JSException extends Exception {
/** @serial Original exception which caused the current exception */
private Throwable originatingException = null;
/**
* Constructs a <code>JSException</code> with the
* specified detail message.
*
* @param s the detail message.
*/
public JSException(String s) {
super(s);
}
/**
* Constructs a <code>JSException</code> with the
* specified detail message, but refereing to the
* original exception
*
* @param s the detail message.
*/
public JSException(String s, Throwable originatingException) {
super(s);
this.originatingException = originatingException;
}
/**
* Get the originating exception (if any) or null. Look down
* until a true originating exception is found, if possible.
*
* @return originating exception or null.
*/
public Throwable getOriginatingException() {
Throwable previousLevel = null;
Throwable currentLevel = originatingException;
while (currentLevel != null) {
previousLevel = currentLevel;
if (currentLevel instanceof JSException) {
JSException oe = (JSException) originatingException;
currentLevel = oe.getOriginatingException();
} else if (currentLevel instanceof EcmaScriptException) {
EcmaScriptException oe = (EcmaScriptException) originatingException;
currentLevel = oe.getOriginatingException();
//} else if (currentLevel instanceof java.lang.reflect.InvocationTargetException) {
// java.lang.reflect.InvocationTargetException oe = (java.lang.reflect.InvocationTargetException) originatingException;
// currentLevel = oe.getTargetException();
} else {
currentLevel = null;
}
} // while
return previousLevel;
}
/**
* Prints this <code>Throwable</code> and its backtrace to the
* standard error stream.
*/
public void printStackTrace() {
System.err.println(this);
printStackTrace0(new PrintWriter(System.err));
}
/**
* Prints this <code>Throwable</code> and its backtrace to the
* specified print stream.
*/
public void printStackTrace(java.io.PrintStream s) {
s.println(this);
PrintWriter w = new PrintWriter(s);
printStackTrace0(w);
}
/**
* Prints this <code>Throwable</code> and its backtrace to the specified
* print writer.
*/
public void printStackTrace(java.io.PrintWriter w) {
w.println(this);
printStackTrace0(w);
}
private void printStackTrace0(PrintWriter w) {
super.printStackTrace(w);
if (originatingException != null) {
w.println("due to:");
originatingException.printStackTrace(w);
}
w.flush();
}
}

View file

@ -0,0 +1,44 @@
// JSExtension.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
/**
* Interface used to describe EcmaScript extensions with the
* jslib package. An extension must implements this interface
* to be loadable. A new instance of the extension is created
* by FESI at load time.
* <P>As there can be multiple extension (possibly in multiple
* threads) in a single project, an extension should not have
* shared static properties (unless protected and to share
* information between various instances).
*/
abstract public interface JSExtension {
/**
* Called by the FESI interpreter the first time the extension
* is loaded in the evaluator.
*
* @param globalObject The global object of this evaluator
* @exception JSException To be thrown in case of error
*/
abstract public void initializeExtension(JSGlobalObject globalObject)
throws JSException;
}

View file

@ -0,0 +1,60 @@
// JSFunction.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
/**
* Interface that an object must implement to be considered an EcmaScript
* function.
* <P>This interface may be implemented by an object which will then be recognized
* as a function or a constructor if used in EcmaScript.
* <P>Non function objects need not implement any specific interface,
* FESI using introspection to discover their properties.
* <P>The parameters passed to the doCall or doNew arguments are transformed
* as follow:
* <BR>If they are FESI objects they are wrapped as JSObjects.
* <BR>If they are FESI primitive, the corresponding most primitive
* java object is used (for example Integer).
* <BR>Otherwise (native objects) they are passed as native objects.
* <P>
* @see FESI.jslib.JSFunctionAdapter
*/
public interface JSFunction {
/**
* Call the specified EcmaScript method of this object
*
* @param thisObject The object for which the function is called.
* @param args An array of parameters.
* @return The result of the evaluation
* @exception JSException For any error during interpretation
*/
abstract public Object doCall(JSObject thisObject, Object args[]) throws JSException;
/**
* Create a new object, using the specified EcmaScript method of this object
*
* @param thisObject The object for which the function is called.
* @param args An array of parameters.
* @return The result of the evaluation
* @exception JSException For any error during interpretation
*/
abstract public Object doNew(JSObject thisObject, Object args[]) throws JSException;
}

View file

@ -0,0 +1,52 @@
// JSFunctionAdapter.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
/**
* Implements a default class to ease the implementation of
* function objects.
*/
public class JSFunctionAdapter implements JSFunction {
/**
* Call the specified EcmaScript method of this object
*
* @param thisObject The object for which the function is called.
* @param args An array of parameters.
* @return The result of the evaluation
* @exception JSException For any error during interpretation
*/
public Object doCall(JSObject thisObject, Object args[]) throws JSException {
throw new JSException ("No function defined for this object");
}
/**
* Create a new object, using the specified EcmaScript method of this object
*
* @param thisObject The object for which the function is called.
* @param args An array of parameters.
* @return The result of the evaluation
* @exception JSException For any error during interpretation
*/
public Object doNew(JSObject thisObject, Object args[]) throws JSException {
throw new JSException ("No constructor defined for this object");
}
}

View file

@ -0,0 +1,74 @@
// JSGlobalObject.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
/**
* Interface used to represent the GlobalObject wrapper of the interpreter.
* The global object is used for functions which require the evaluator.
* It is possible to get it from any JSObject.
* <P>This interface is exported by FESI objects, it is not intended
* or useful for user objects to extend this interface.
*/
public interface JSGlobalObject extends JSObject {
/**
* Mark an object as a bean, restricting its access by FESI scripts
* to the public bean methods and properties.
*
* @param object The object to wrap as a bean.
*/
public Object makeBeanWrapper(Object object);
/**
* Make a new object based the object prototype object.
* The object is of class Object and has initially no property.
*
* @return A new object
*/
public JSObject makeJSObject();
/**
* Make a new object based on a given prototype (which may be null).
* The object is of class Object and has initially no property.
*
* @param prototype An object to use as prototype for this object
* @return A new object
*/
public JSObject makeJSObject(JSObject prototype);
/**
* Package any object as an EcmaScript object, allowing to use
* it for example with an "eval" function, where it becomes the
* 'this' object.
*
* @param object The object to wrap.
*/
public JSObject makeObjectWrapper(Object object);
/**
* Make a new array object.
* The object is of class Array and is empty (length 0).
*
* @return A new object
*/
public JSObject makeJSArrayObject();
}

View file

@ -0,0 +1,177 @@
// JSObject.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
import java.io.Reader;
/**
* Interface used for interfacing the FESI EcmaScript interpreter
* with Java code. Based and largely compatible with the Netscape
* JavaScript to Java interface.
* <P>This interface is exported by FESI objects, it is not intended
* or useful for user objects to extend this interface.
* <P>Non function objects need not implement any specific interface,
* FESI using introspection to discover their properties. Function
* objects must implement JSFunction.
*/
public interface JSObject {
/**
* Call the specified EcmaScript method of this object
*
* @param methodName The name of the method to call
* @param args An array of parameters.
* @return The result of the evaluation
* @exception JSException For any error during interpretation
*/
abstract public Object call(String methodName,Object args[]) throws JSException;
/**
* Evaluate a string with this object as the 'this' object.
* Consider the string being a main program, not allowing the
* return statement.
*
* @param s The string to evaluate
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
abstract public Object eval(String s) throws JSException;
/**
* Evaluate a Reader stream with this object as the 'this' object.
* Consider the stream being a main program, not allowing the
* return statement.
*
* @param r The Reader stream to evaluate
* @param d A description of the Reader for error messages
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
abstract public Object eval(Reader r, String d) throws JSException;
/**
* Evaluate a string with this object as the 'this' object.
* Consider the string as a function, allowing the return statement.
*
* @param s The string to evaluate
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
abstract public Object evalAsFunction(String s) throws JSException;
/**
* Evaluate a Reader stream with this object as the 'this' object.
* Consider the stream as a function, allowing the return statement.
*
* @param r The Reader stream to evaluate
* @param d A description of the Reader for error messages
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
//abstract public Object evalAsFunction(Reader r, String d) throws JSException;
/**
* Evaluate a string with this object as the 'this' object.
* Consider the string as a function, allowing the return statement.
* Passing the specified parameters (names and values must have the same length)
*
* @param s The string to evaluate
* @param names the names of the parameters
* @param values the values of the parameters
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
abstract public Object evalAsFunction(String s, String [] names, Object values[]) throws JSException;
/**
* Evaluate a Reader stream with this object as the 'this' object.
* Consider the stream as a function, allowing the return statement.
* Passing the specified parameters (names and values must have the same length)
*
* @param r The Reader stream to evaluate
* @param d A description of the Reader for error messages
* @param names the names of the parameters
* @param values the values of the parameters
* @return The result of the evaluation (null if no value returned)
* @exception JSException For any error during interpretation
*/
//abstract public Object evalAsFunction(Reader r, String d, String [] names, Object values[]) throws JSException;
/**
* Get the named property of this object.
*
* @param name The name of the property to get
* @return The value of the property
* @exception JSException For any error during interpretation
*/
abstract public Object getMember(String name) throws JSException;
/**
* Get the indexed property of this object (useful for arrays).
*
* @param index The index value of the property (converted
* to string if not an array)
* @return The value of the property
* @exception JSException For any error during interpretation
*/
abstract public Object getSlot(int index) throws JSException;
// This Netscape function is not implemented
// public static JSObject getWindow(Applet applet) throws JSException;
/**
* Delete a named property of this object
*
* @param name The name of the property to delete
* @exception JSException For any error during interpretation
*/
abstract public void removeMember(String name) throws JSException;
/**
* Set the value of a named property of this object
*
* @param name The name of the property to set
* @param value The value to set the property to.
* @exception JSException For any error during interpretation
*/
abstract public void setMember(String name, Object value) throws JSException;
/**
* Set a property by index value. Useful for arrays.
*
* @param index The index of the property in the array.
* @param value The value to set the property to.
* @exception JSException For any error during interpretation
*/
abstract public void setSlot(int index, Object value) throws JSException;
// FESI extension
/**
* Get the global object of the interpreter
*/
abstract public JSGlobalObject getGlobalObject();
}

View file

@ -0,0 +1,69 @@
// JSUtil.java
// FESI Copyright (c) Jean-Marc Lugrin, 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// This program 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FESI.jslib;
import FESI.Interpreter.Evaluator;
/**
* Abstract class used for interfacing the FESI EcmaScript interpreter
* with Java code. Contains the static utility functions, as the
* evaluator factory and object factory.
*/
abstract public class JSUtil {
/**
* Create a new evaluator, with no extension loaded.
*
* @return The global object of the created evaluator.
* @exception JSException For any error during initialization
*/
static public JSGlobalObject makeEvaluator() throws JSException {
return FESI.Data.JSWrapper.makeEvaluator();
}
/**
* Create a new evaluator, with specfied extensions loaded.
*
* @param extensions The class name of the extensions to load.
* @return The global object of the created evaluator.
* @exception JSException For any error during initialization
*/
static public JSGlobalObject makeEvaluator(String [] extensions) throws JSException {
return FESI.Data.JSWrapper.makeEvaluator(extensions);
}
/**
* Return the version identifier of the interpreter
*/
public static String getVersion() {
return Evaluator.getVersion();
}
/**
* Return the welcome text (including copyright and version)
* of the interpreter (as two lines)
*/
public static String getWelcomeText() {
return Evaluator.getWelcomeText();
}
}