public final class

JSAdapter

extends Object
implements Function Scriptable
java.lang.Object
   ↳ com.sun.script.javascript.JSAdapter

Class Overview

JSAdapter is java.lang.reflect.Proxy equivalent for JavaScript. JSAdapter calls specially named JavaScript methods on an adaptee object when property access is attempted on it. Example: var y = { __get__ : function (name) { ... } __has__ : function (name) { ... } __put__ : function (name, value) {...} __delete__ : function (name) { ... } __getIds__ : function () { ... } }; var x = new JSAdapter(y); x.i; // calls y.__get__ i in x; // calls y.__has__ x.p = 10; // calls y.__put__ delete x.p; // calls y.__delete__ for (i in x) { print(i); } // calls y.__getIds__ If a special JavaScript method is not found in the adaptee, then JSAdapter forwards the property access to the adaptee itself. JavaScript caller of adapter object is isolated from the fact that the property access/mutation/deletion are really calls to JavaScript methods on adaptee. Use cases include 'smart' properties, property access tracing/debugging, encaptulation with easy client access - in short JavaScript becomes more "Self" like. Note that Rhino already supports special properties like __proto__ (to set, get prototype), __parent__ (to set, get parent scope). We follow the same double underscore nameing convention here. Similarly the name JSAdapter is derived from JavaAdapter -- which is a facility to extend, implement Java classes/interfaces by JavaScript.

Summary

[Expand]
Inherited Fields
From interface sun.org.mozilla.javascript.internal.Scriptable
Public Methods
Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
Scriptable construct(Context cx, Scriptable scope, Object[] args)
void delete(int index)
void delete(String name)
Object get(String name, Scriptable start)
Object get(int index, Scriptable start)
Scriptable getAdaptee()
String getClassName()
Object getDefaultValue(Class hint)
Object[] getIds()
Scriptable getParentScope()
Scriptable getPrototype()
boolean has(String name, Scriptable start)
boolean has(int index, Scriptable start)
boolean hasInstance(Scriptable scriptable)
static void init(Context cx, Scriptable scope, boolean sealed)
void put(String name, Scriptable start, Object value)
void put(int index, Scriptable start, Object value)
void setAdaptee(Scriptable adaptee)
void setParentScope(Scriptable parent)
void setPrototype(Scriptable prototype)
[Expand]
Inherited Methods
From class java.lang.Object
From interface sun.org.mozilla.javascript.internal.Callable
From interface sun.org.mozilla.javascript.internal.Function
From interface sun.org.mozilla.javascript.internal.Scriptable

Public Methods

public Object call (Context cx, Scriptable scope, Scriptable thisObj, Object[] args)

Throws
RhinoException

public Scriptable construct (Context cx, Scriptable scope, Object[] args)

Throws
RhinoException

public void delete (int index)

public void delete (String name)

public Object get (String name, Scriptable start)

public Object get (int index, Scriptable start)

public Scriptable getAdaptee ()

public String getClassName ()

public Object getDefaultValue (Class hint)

public Object[] getIds ()

public Scriptable getParentScope ()

public Scriptable getPrototype ()

public boolean has (String name, Scriptable start)

public boolean has (int index, Scriptable start)

public boolean hasInstance (Scriptable scriptable)

public static void init (Context cx, Scriptable scope, boolean sealed)

Throws
RhinoException

public void put (String name, Scriptable start, Object value)

public void put (int index, Scriptable start, Object value)

public void setAdaptee (Scriptable adaptee)

public void setParentScope (Scriptable parent)

public void setPrototype (Scriptable prototype)