|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.mozilla.javascript.FlattenedObject
Manipulate a Scriptable object as if its prototype chain were flattened.
Compared to the Scriptable interface, FlattenedObject provides a view of Scriptable objects that is easier to use and more closely matches a script writer's view of a JavaScript object.
A FlattenedObject is "flattened" in the sense that multiple objects in a prototype chain appear to have their properties all appear in the FlattenedObject.
Another convenience provided by Flattened object is the ability to access properties by a single java.lang.Object id. This id is then converted into a String or an int before methods of the Scriptable object are called.
Scriptable
Constructor Summary | |
FlattenedObject(Scriptable object)
Construct a new FlattenedObject. |
Method Summary | |
java.lang.Object |
call(Context cx,
Scriptable thisObj,
java.lang.Object[] args)
Consider this object to be a function, and call it. |
java.lang.Object |
callMethod(java.lang.Object id,
java.lang.Object[] args)
Get the property indicated by the id, and invoke it with the specified arguments. |
Scriptable |
construct(Context cx,
java.lang.Object[] args)
Consider this object to be a function, and invoke it as a constructor call. |
boolean |
deleteProperty(java.lang.Object id)
Remove a property. |
java.lang.Object[] |
getIds()
Return an array that contains the ids of the properties. |
Scriptable |
getObject()
Get the associated Scriptable object. |
java.lang.Object |
getProperty(java.lang.Object id)
Get a property of an object. |
boolean |
hasProperty(java.lang.Object id)
Determine if a property exists in an object. |
void |
putProperty(java.lang.Object id,
java.lang.Object value)
Set a property of an object. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public FlattenedObject(Scriptable object)
object
- the object to be viewed with flattened propertiesMethod Detail |
public Scriptable getObject()
public boolean hasProperty(java.lang.Object id)
Scriptable.has()
.
It returns true if and only if the property
exists in this object or any of the objects in its prototype
chain.id
- the property index, which may be either a String or a
NumberScriptable.has(java.lang.String, org.mozilla.javascript.Scriptable)
public java.lang.Object getProperty(java.lang.Object id)
This is a more convenient (and less efficient) form than
Scriptable.get()
. It corresponds exactly to the
expression obj[id]
in JavaScript. This method
will traverse the prototype chain of an object to find the
property.
If the property does not exist in the object or its prototype chain, the undefined value will be returned.
id
- the property index; can be a String or a Number; the
String may contain characters representing a numberScriptable.get(java.lang.String, org.mozilla.javascript.Scriptable)
,
Context.getUndefinedValue()
public void putProperty(java.lang.Object id, java.lang.Object value)
obj[id] = val
in JavaScript.id
- the property index, which may be either a String or
a Numbervalue
- the value of the propertyScriptable.put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)
public boolean deleteProperty(java.lang.Object id)
delete
operator in JavaScript.id
- the property index, which may be either a String or
a NumberScriptable.delete(java.lang.String)
public java.lang.Object[] getIds()
This method will walk the prototype chain and collect the ids of all objects in the prototype chain.
If an id appears in more than one object in the prototype chain, it will only be in the array once. (So all the entries in the array will be unique respective to equals().)
Scriptable.getIds()
public java.lang.Object call(Context cx, Scriptable thisObj, java.lang.Object[] args) throws NotAFunctionException, JavaScriptException
cx
- the current Context for this threadthisObj
- the JavaScript 'this' for the callargs
- the arguments for the callFunction.call(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, org.mozilla.javascript.Scriptable, java.lang.Object[])
public Scriptable construct(Context cx, java.lang.Object[] args) throws NotAFunctionException, JavaScriptException
cx
- the current Context for this threadargs
- the arguments for the constructor callFunction.construct(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object[])
public java.lang.Object callMethod(java.lang.Object id, java.lang.Object[] args) throws PropertyException, NotAFunctionException, JavaScriptException
For example, for a FlattenedObject obj
,
and a Java array a
consisting of a single string
"hi"
, the call
obj.callMethod("m", a)is equivalent to the JavaScript code
obj.m("hi")
.If the property is not found or is not a function, an exception will be thrown.
id
- the Number or String to use to find the function property
to callargs
- the arguments for the constructor callFunction.call(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, org.mozilla.javascript.Scriptable, java.lang.Object[])
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |