org.mozilla.javascript

Class Delegator

Implemented Interfaces:
Callable, Function, Scriptable
Known Direct Subclasses:
Synchronizer

public class Delegator
extends java.lang.Object
implements Function

This is a helper class for implementing wrappers around Scriptable objects. It implements the Function interface and delegates all invocations to a delegee Scriptable object. The normal use of this class involves creating a sub-class and overriding one or more of the methods. A useful application is the implementation of interceptors, pre/post conditions, debugging.
Author:
Matthias Radestock
See Also:
Function, Scriptable

Field Summary

protected Scriptable
obj

Fields inherited from interface org.mozilla.javascript.Scriptable

NOT_FOUND

Constructor Summary

Delegator()
Create a Delegator prototype.
Delegator(Scriptable obj)
Create a new Delegator that forwards requests to a delegee Scriptable object.

Method Summary

Object
call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
Scriptable
construct(Context cx, Scriptable scope, Object[] args)
Note that if the delegee is null, this method creates a new instance of the Delegator itself rathert than forwarding the call to the delegee.
void
delete(String name)
void
delete(int index)
Object
get(String name, Scriptable start)
Object
get(int index, Scriptable start)
String
getClassName()
Object
getDefaultValue(Class hint)
Note that this method does not get forwarded to the delegee if the hint parameter is null, ScriptRuntime.ScriptableClass or ScriptRuntime.FunctionClass.
Scriptable
getDelegee()
Retrieve the delegee.
Object[]
getIds()
Scriptable
getParentScope()
Scriptable
getPrototype()
boolean
has(String name, Scriptable start)
boolean
has(int index, Scriptable start)
boolean
hasInstance(Scriptable instance)
protected Delegator
newInstance()
Crete new Delegator instance.
void
put(String name, Scriptable start, Object value)
void
put(int index, Scriptable start, Object value)
void
setDelegee(Scriptable obj)
Set the delegee.
void
setParentScope(Scriptable parent)
void
setPrototype(Scriptable prototype)

Field Details

obj

protected Scriptable obj

Constructor Details

Delegator

public Delegator()
Create a Delegator prototype. This constructor should only be used for creating prototype objects of Delegator.

Delegator

public Delegator(Scriptable obj)
Create a new Delegator that forwards requests to a delegee Scriptable object.
Parameters:
obj - the delegee
See Also:
Scriptable

Method Details

call

public Object call(Context cx,
                   Scriptable scope,
                   Scriptable thisObj,
                   Object[] args)
Specified by:
call in interface Function
call in interface Callable

construct

public Scriptable construct(Context cx,
                            Scriptable scope,
                            Object[] args)
Note that if the delegee is null, this method creates a new instance of the Delegator itself rathert than forwarding the call to the delegee. This permits the use of Delegator prototypes.
Specified by:
construct in interface Function
Parameters:
cx - the current Context for this thread
scope - an enclosing scope of the caller except when the function is called from a closure.
args - the array of arguments
Returns:
the allocated object

delete

public void delete(String name)
Specified by:
delete in interface Scriptable

delete

public void delete(int index)
Specified by:
delete in interface Scriptable

get

public Object get(String name,
                  Scriptable start)
Specified by:
get in interface Scriptable

get

public Object get(int index,
                  Scriptable start)
Specified by:
get in interface Scriptable

getClassName

public String getClassName()
Specified by:
getClassName in interface Scriptable

getDefaultValue

public Object getDefaultValue(Class hint)
Note that this method does not get forwarded to the delegee if the hint parameter is null, ScriptRuntime.ScriptableClass or ScriptRuntime.FunctionClass. Instead the object itself is returned.
Specified by:
getDefaultValue in interface Scriptable
Parameters:
hint - the type hint
Returns:
the default value

getDelegee

public Scriptable getDelegee()
Retrieve the delegee.
Returns:
the delegee

getIds

public Object[] getIds()
Specified by:
getIds in interface Scriptable

getParentScope

public Scriptable getParentScope()
Specified by:
getParentScope in interface Scriptable

getPrototype

public Scriptable getPrototype()
Specified by:
getPrototype in interface Scriptable

has

public boolean has(String name,
                   Scriptable start)
Specified by:
has in interface Scriptable

has

public boolean has(int index,
                   Scriptable start)
Specified by:
has in interface Scriptable

hasInstance

public boolean hasInstance(Scriptable instance)
Specified by:
hasInstance in interface Scriptable

newInstance

protected Delegator newInstance()
Crete new Delegator instance. The default implementation calls this.getClass().newInstance().
See Also:
construct(Context cx, Scriptable scope, Object[] args)

put

public void put(String name,
                Scriptable start,
                Object value)
Specified by:
put in interface Scriptable

put

public void put(int index,
                Scriptable start,
                Object value)
Specified by:
put in interface Scriptable

setDelegee

public void setDelegee(Scriptable obj)
Set the delegee.
Parameters:
obj - the delegee
See Also:
Scriptable

setParentScope

public void setParentScope(Scriptable parent)
Specified by:
setParentScope in interface Scriptable

setPrototype

public void setPrototype(Scriptable prototype)
Specified by:
setPrototype in interface Scriptable