netscape.javascript.JSObject Maven / Gradle / Ivy
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package netscape.javascript;
// FIXME: need URL on java.sun.com for new LiveConnect spec
/**
* Allows Java code to manipulate JavaScript objects.
*
* When a JavaScript object is passed or returned to Java code, it
* is wrapped in an instance of JSObject
. When a
* JSObject
instance is passed to the JavaScript engine,
* it is unwrapped back to its original JavaScript object. The
* JSObject
class provides a way to invoke JavaScript
* methods and examine JavaScript properties.
*
* Any data returned from the JavaScript engine to Java is
* converted to Java data types. Certain data passed to the JavaScript
* engine is converted to JavaScript data types. See the section on
* Data Type Conversions in the LiveConnect Specification
* for details on how values are converted.
*
*/
public abstract class JSObject {
/**
* Constructs a new JSObject. Users should not call this method
* nor subclass JSObject.
*/
protected JSObject() {
}
/**
* Calls a JavaScript method. Equivalent to
* "this.methodName(args[0], args[1], ...)" in JavaScript.
*
*
* @param methodName The name of the JavaScript method to be invoked.
* @param args An array of Java object to be passed as arguments to the method.
* @return Result of the method.
*/
public abstract Object call(String methodName, Object... args) throws JSException;
/**
* Evaluates a JavaScript expression. The expression is a string of
* JavaScript source code which will be evaluated in the context given by
* "this".
*
*
* @param s The JavaScript expression.
* @return Result of the JavaScript evaluation.
*/
public abstract Object eval(String s) throws JSException;
/**
* Retrieves a named member of a JavaScript object. Equivalent to
* "this.name" in JavaScript.
*
*
* @param name The name of the JavaScript property to be accessed.
* @return The value of the propery.
*/
public abstract Object getMember(String name) throws JSException;
/**
* Sets a named member of a JavaScript object. Equivalent to
* "this.name = value" in JavaScript.
*
*
* @param name The name of the JavaScript property to be accessed.
* @param value The value of the propery.
*/
public abstract void setMember(String name, Object value) throws JSException;
/**
* Removes a named member of a JavaScript object. Equivalent
* to "delete this.name" in JavaScript.
*
*
* @param name The name of the JavaScript property to be removed.
*/
public abstract void removeMember(String name) throws JSException;
/**
* Retrieves an indexed member of a JavaScript object. Equivalent to
* "this[index]" in JavaScript.
*
*
* @param index The index of the array to be accessed.
* @return The value of the indexed member.
*/
public abstract Object getSlot(int index) throws JSException;
/**
* Sets an indexed member of a JavaScript object. Equivalent to
* "this[index] = value" in JavaScript.
*
*
* @param index The index of the array to be accessed.
*/
public abstract void setSlot(int index, Object value) throws JSException;
/* *
* Returns a JSObject for the window containing the given applet.
*
*
* @param applet The applet.
* @return JSObject for the window containing the given applet.
* /
public static JSObject getWindow(Applet applet) throws JSException {
try
{
if (applet != null)
{
String obj = (String) applet.getParameter("MAYSCRIPT");
// Comment out MAYSCRIPT check because Internet Explorer doesn't support
// it.
// if (obj != null && (obj.equals("") || (new Boolean(obj).booleanValue() == true)))
{
// MAYSCRIPT is enabled
AppletContext c = applet.getAppletContext();
// The applet context must implement the sun.plugin.javascript.JSContext
// in order for us to get the handle that can be used when evaluating
// JavaScript expression.
//
JSObject ret = null;
if (c instanceof sun.plugin.javascript.JSContext)
{
JSContext j = (JSContext) c;
ret = j.getJSObject();
}
if (ret != null) {
return ret;
}
}
} else {
// new code for CustomProgress to get the JSObject w/o applet
AppContext ac = ToolkitStore.get().getAppContext();
if (ac != null) {
Object context = ac.get(sun.plugin2.applet.Plugin2Manager.APPCONTEXT_PLUGIN2HOST_KEY);
if (context != null && (context instanceof JSContext)) {
JSContext jsc = (JSContext) context;
JSObject ret = jsc.getOneWayJSObject();
if (ret != null) {
return ret;
}
}
}
}
}
catch (Throwable e)
{
throw (JSException) new JSException(JSException.EXCEPTION_TYPE_ERROR, e).initCause(e);
}
throw new JSException();
}
*/
}