Package helma.scripting.rhino

# Class JSAdapter

java.lang.Object
helma.scripting.rhino.JSAdapter

All Implemented Interfaces:
  `org.mozilla.javascript.Callable`, `org.mozilla.javascript.Constructable`, `org.mozilla.javascript.Function`, `org.mozilla.javascript.Scriptable`

public final class JSAdapter extends Object implements org.mozilla.javascript.Scriptable, org.mozilla.javascript.Function
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.

Since:
  1.6

## Field Summary

### Fields inherited from interface org.mozilla.javascript.Scriptable

`NOT_FOUND`

## Method Summary

Modifier and Type
Method
Description
`Object`
`call(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObj, Object[] args)`
`org.mozilla.javascript.Scriptable`
`construct(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, Object[] args)`
`void`
`delete(int index)`
`void`
`delete(String name)`
`Object`
`get(int index, org.mozilla.javascript.Scriptable start)`
`Object`
`get(String name, org.mozilla.javascript.Scriptable start)`
`org.mozilla.javascript.Scriptable`
`getAdaptee()`
`String`
`getClassName()`
`Object`
`getDefaultValue(Class hint)`
`Object[]`
`getIds()`
`org.mozilla.javascript.Scriptable`
`getParentScope()`
`org.mozilla.javascript.Scriptable`
`getPrototype()`
`boolean`
`has(int index, org.mozilla.javascript.Scriptable start)`
`boolean`
`has(String name, org.mozilla.javascript.Scriptable start)`
`boolean`
`hasInstance(org.mozilla.javascript.Scriptable scriptable)`
`static void`
`init(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, boolean sealed)`
`void`
`put(int index, org.mozilla.javascript.Scriptable start, Object value)`
`void`
`put(String name, org.mozilla.javascript.Scriptable start, Object value)`
`void`
`setAdaptee(org.mozilla.javascript.Scriptable adaptee)`
`void`
`setParentScope(org.mozilla.javascript.Scriptable parent)`
`void`
`setPrototype(org.mozilla.javascript.Scriptable prototype)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### init

public static void init(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, boolean sealed) throws org.mozilla.javascript.RhinoException

Throws:
  `org.mozilla.javascript.RhinoException`

### getClassName

public String getClassName()

Specified by:
  `getClassName` in interface `org.mozilla.javascript.Scriptable`

### get

public Object get(String name, org.mozilla.javascript.Scriptable start)

Specified by:
  `get` in interface `org.mozilla.javascript.Scriptable`

### get

public Object get(int index, org.mozilla.javascript.Scriptable start)

Specified by:
  `get` in interface `org.mozilla.javascript.Scriptable`

### has

public boolean has(String name, org.mozilla.javascript.Scriptable start)

Specified by:
  `has` in interface `org.mozilla.javascript.Scriptable`

### has

public boolean has(int index, org.mozilla.javascript.Scriptable start)

Specified by:
  `has` in interface `org.mozilla.javascript.Scriptable`

### put

public void put(String name, org.mozilla.javascript.Scriptable start, Object value)

Specified by:
  `put` in interface `org.mozilla.javascript.Scriptable`

### put

public void put(int index, org.mozilla.javascript.Scriptable start, Object value)

Specified by:
  `put` in interface `org.mozilla.javascript.Scriptable`

### delete

public void delete(String name)

Specified by:
  `delete` in interface `org.mozilla.javascript.Scriptable`

### delete

public void delete(int index)

Specified by:
  `delete` in interface `org.mozilla.javascript.Scriptable`

### getPrototype

public org.mozilla.javascript.Scriptable getPrototype()

Specified by:
  `getPrototype` in interface `org.mozilla.javascript.Scriptable`

### setPrototype

public void setPrototype(org.mozilla.javascript.Scriptable prototype)

Specified by:
  `setPrototype` in interface `org.mozilla.javascript.Scriptable`

### getParentScope

public org.mozilla.javascript.Scriptable getParentScope()

Specified by:
  `getParentScope` in interface `org.mozilla.javascript.Scriptable`

### setParentScope

public void setParentScope(org.mozilla.javascript.Scriptable parent)

Specified by:
  `setParentScope` in interface `org.mozilla.javascript.Scriptable`

### getIds

public Object[] getIds()

Specified by:
  `getIds` in interface `org.mozilla.javascript.Scriptable`

### hasInstance

public boolean hasInstance(org.mozilla.javascript.Scriptable scriptable)

Specified by:
  `hasInstance` in interface `org.mozilla.javascript.Scriptable`

### getDefaultValue

public Object getDefaultValue(Class hint)

Specified by:
  `getDefaultValue` in interface `org.mozilla.javascript.Scriptable`

### call

public Object call(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObj, Object[] args) throws org.mozilla.javascript.RhinoException

Specified by:
  `call` in interface `org.mozilla.javascript.Callable`
Specified by:
  `call` in interface `org.mozilla.javascript.Function`
Throws:
  `org.mozilla.javascript.RhinoException`

### construct

public org.mozilla.javascript.Scriptable construct(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, Object[] args) throws org.mozilla.javascript.RhinoException

Specified by:
  `construct` in interface `org.mozilla.javascript.Constructable`
Specified by:
  `construct` in interface `org.mozilla.javascript.Function`
Throws:
  `org.mozilla.javascript.RhinoException`

### getAdaptee

public org.mozilla.javascript.Scriptable getAdaptee()

### setAdaptee

public void setAdaptee(org.mozilla.javascript.Scriptable adaptee)