org.mozilla.javascript

Class Delegator

public class Delegator extends 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 Scriptableobj
Constructor Summary
Delegator()
Create a Delegator prototype.
Delegator(Scriptable obj)
Create a new Delegator that forwards requests to a delegee Scriptable object.
Method Summary
Objectcall(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
Scriptableconstruct(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.
voiddelete(String name)
voiddelete(int index)
Objectget(String name, Scriptable start)
Objectget(int index, Scriptable start)
StringgetClassName()
ObjectgetDefaultValue(Class hint)
Note that this method does not get forwarded to the delegee if the hint parameter is null, ScriptRuntime.ScriptableClass or ScriptRuntime.FunctionClass.
ScriptablegetDelegee()
Retrieve the delegee.
Object[]getIds()
ScriptablegetParentScope()
ScriptablegetPrototype()
booleanhas(String name, Scriptable start)
booleanhas(int index, Scriptable start)
booleanhasInstance(Scriptable instance)
protected DelegatornewInstance()
Crete new Delegator instance.
voidput(String name, Scriptable start, Object value)
voidput(int index, Scriptable start, Object value)
voidsetDelegee(Scriptable obj)
Set the delegee.
voidsetParentScope(Scriptable parent)
voidsetPrototype(Scriptable prototype)

Field Detail

obj

protected Scriptable obj

Constructor Detail

Delegator

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

See Also: 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 Detail

call

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

See Also: Function

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.

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

See Also: (Context, Scriptable, Object[])

delete

public void delete(String name)

See Also: Scriptable

delete

public void delete(int index)

See Also: Scriptable

get

public Object get(String name, Scriptable start)

See Also: Scriptable

get

public Object get(int index, Scriptable start)

See Also: Scriptable

getClassName

public String getClassName()

See Also: 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.

Parameters: hint the type hint

Returns: the default value

See Also: Scriptable

getDelegee

public Scriptable getDelegee()
Retrieve the delegee.

Returns: the delegee

getIds

public Object[] getIds()

See Also: Scriptable

getParentScope

public Scriptable getParentScope()

See Also: Scriptable

getPrototype

public Scriptable getPrototype()

See Also: Scriptable

has

public boolean has(String name, Scriptable start)

See Also: Scriptable

has

public boolean has(int index, Scriptable start)

See Also: Scriptable

hasInstance

public boolean hasInstance(Scriptable instance)

See Also: Scriptable

newInstance

protected Delegator newInstance()
Crete new Delegator instance. The default implementation calls this.getClass().newInstance().

See Also: (Context cx, Scriptable scope, Object[] args)

put

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

See Also: Scriptable

put

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

See Also: Scriptable

setDelegee

public void setDelegee(Scriptable obj)
Set the delegee.

Parameters: obj the delegee

See Also: Scriptable

setParentScope

public void setParentScope(Scriptable parent)

See Also: Scriptable

setPrototype

public void setPrototype(Scriptable prototype)

See Also: Scriptable