org.mozilla.javascript

Class NativeJavaObject

Implemented Interfaces:
Scriptable, Serializable, Wrapper
Known Direct Subclasses:
NativeJavaArray, NativeJavaClass

public class NativeJavaObject
extends java.lang.Object
implements Scriptable, Wrapper, Serializable

This class reflects non-Array Java objects into the JavaScript environment. It reflect fields directly, and uses NativeJavaMethod objects to reflect (possibly overloaded) methods.

Author:
Mike Shaver
See Also:
NativeJavaArray, NativeJavaPackage, NativeJavaClass

Field Summary

protected Object
javaObject
protected org.mozilla.javascript.JavaMembers
members
protected Scriptable
parent
The parent scope of this object.
protected Scriptable
prototype
The prototype of this object.
protected Class
staticType

Fields inherited from interface org.mozilla.javascript.Scriptable

NOT_FOUND

Constructor Summary

NativeJavaObject()
NativeJavaObject(Scriptable scope, Object javaObject, Class staticType)

Method Summary

static boolean
canConvert(Object fromObj, Class to)
Determine whether we can/should convert between the given type and the desired one.
static Object
coerceType(Class type, Object value)
Deprecated. as of 1.5 Release 4
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)
Object[]
getIds()
Scriptable
getParentScope()
Returns the parent (enclosing) scope of the object.
Scriptable
getPrototype()
boolean
has(String name, Scriptable start)
boolean
has(int index, Scriptable start)
boolean
hasInstance(Scriptable value)
protected void
initMembers()
void
put(String name, Scriptable start, Object value)
void
put(int index, Scriptable start, Object value)
void
setParentScope(Scriptable m)
Sets the parent (enclosing) scope of the object.
void
setPrototype(Scriptable m)
Sets the prototype of the object.
Object
unwrap()
static Object
wrap(Scriptable scope, Object obj, Class staticType)
Deprecated. Use Context.getWrapFactory() together with calling WrapFactory.wrap(Context cx, Scriptable scope, Object obj, Class)

Field Details

javaObject

protected Object javaObject

members

protected org.mozilla.javascript.JavaMembers members

parent

protected Scriptable parent
The parent scope of this object.

prototype

protected Scriptable prototype
The prototype of this object.

staticType

protected Class staticType

Constructor Details

NativeJavaObject

public NativeJavaObject()

NativeJavaObject

public NativeJavaObject(Scriptable scope,
                        Object javaObject,
                        Class staticType)

Method Details

canConvert

public static boolean canConvert(Object fromObj,
                                 Class to)
Determine whether we can/should convert between the given type and the desired one. This should be superceded by a conversion-cost calculation function, but for now I'll hide behind precedent.

coerceType

public static Object coerceType(Class type,
                                Object value)

Deprecated. as of 1.5 Release 4

Not intended for public use. Callers should use the public API Context.toType.

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)
Specified by:
getDefaultValue in interface Scriptable

getIds

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

getParentScope

public Scriptable getParentScope()
Returns the parent (enclosing) scope of the object.
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 value)
Specified by:
hasInstance in interface Scriptable

initMembers

protected void initMembers()

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

setParentScope

public void setParentScope(Scriptable m)
Sets the parent (enclosing) scope of the object.
Specified by:
setParentScope in interface Scriptable

setPrototype

public void setPrototype(Scriptable m)
Sets the prototype of the object.
Specified by:
setPrototype in interface Scriptable

unwrap

public Object unwrap()
Specified by:
unwrap in interface Wrapper

wrap

public static Object wrap(Scriptable scope,
                          Object obj,
                          Class staticType)

Deprecated. Use Context.getWrapFactory() together with calling WrapFactory.wrap(Context cx, Scriptable scope, Object obj, Class)