org.apache.bsf.debug.meta
Class JsObjectStub

java.lang.Object
  extended by org.apache.bsf.debug.util.Stub
      extended by org.apache.bsf.debug.meta.JsObjectStub
All Implemented Interfaces:
java.rmi.Remote, JsObject, RemoteService
Direct Known Subclasses:
JsCodeStub

public class JsObjectStub
extends Stub
implements JsObject


Field Summary
 
Fields inherited from class org.apache.bsf.debug.util.Stub
m_con, m_revoked, m_tid, m_uid, NOT_FOUND, UNDEFINED
 
Fields inherited from interface org.apache.bsf.debug.jsdi.JsObject
DONTDELETE, DONTENUM, EMPTY, INTERNAL, READONLY
 
Constructor Summary
JsObjectStub(SocketConnection con, int tid, int uid)
           
 
Method Summary
 void define(java.lang.String propertyName, java.lang.Object value, int attributes)
          The value can be any of the following type: java.lang.Boolean java.lang.Number java.lang.String org.apache.bsf.debug.jsdi.JsObject
 void delete(int index)
          Removes a property from this object.
 void delete(java.lang.String name)
          Removes a property from this object.
 java.lang.Object get(int index)
           
 java.lang.Object get(java.lang.String name)
          Get a named property from the object.
 java.lang.String getClassName()
          Get the name of the set of objects implemented by this Java class.
 java.lang.Object getDefaultValue(java.lang.Class hint)
          Get the default value of the object with a given hint.
 java.lang.Object[] getIds(boolean all)
          Returns an array of property ids defined on this object.
 JsObject getPrototype()
          Get the prototype of the object.
 JsObject getScope()
          The scope is for supporting two things.
 boolean has(int index)
          Indicates whether or not an indexed property is defined in an object.
 boolean has(java.lang.String name)
          Indicates whether or not a named property is defined in an object.
 boolean hasInstance(JsObject instance)
          The instanceof operator.
 boolean isA(int cmd)
           
 boolean isFunction()
           
 boolean isNotFound()
          True if this object represents the "NOT_FOUND" value for a code.
 boolean isScript()
           
 boolean isUndefined()
          Value returned when a property is undefined.
 void put(int index, java.lang.Object value)
          Sets an indexed property in this object.
 void put(java.lang.String name, java.lang.Object value)
          Sets a named property in this object.
 void setPrototype(JsObject prototype)
          Set the prototype of the object.
 void setScope(JsObject scope)
          Set the prototype of the object.
 
Methods inherited from class org.apache.bsf.debug.util.Stub
addListener, completeFuture, createFuture, equals, getConnection, getTid, getUid, Init, removeListener, revoked, revokeFuture, suspendFuture, swizzle
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsObjectStub

public JsObjectStub(SocketConnection con,
                    int tid,
                    int uid)
Method Detail

isNotFound

public boolean isNotFound()
True if this object represents the "NOT_FOUND" value for a code. This is potentially returned from get if the property is not found.


isUndefined

public boolean isUndefined()
Value returned when a property is undefined.


define

public void define(java.lang.String propertyName,
                   java.lang.Object value,
                   int attributes)
            throws java.rmi.RemoteException
The value can be any of the following type: java.lang.Boolean java.lang.Number java.lang.String org.apache.bsf.debug.jsdi.JsObject

Specified by:
define in interface JsObject
Throws:
java.rmi.RemoteException

delete

public void delete(int index)
            throws java.rmi.RemoteException
Removes a property from this object. The prototype chain is not walked to find the property. This operation corresponds to the ECMA [[Delete]] except that the no result is returned. The runtime will guarantee that this method is called only if the property exists. After this method is called, the runtime will call Scriptable.has to see if the property has been removed in order to determine the boolean result of the delete operator as defined by ECMA 11.4.1.

A property can be made permanent by ignoring calls to remove it. The property is specified by an integral index as defined for get.

To delete properties defined in a prototype chain, first find the owner object of the property and then call deleteProperty on that owner object. Identical to delete(String) except that an integral index is used to select the property.

Specified by:
delete in interface JsObject
Parameters:
index - the numeric index for the property
Throws:
java.rmi.RemoteException
See Also:
Scriptable.get(java.lang.String, org.mozilla.javascript.Scriptable), ScriptableObject.deleteProperty(org.mozilla.javascript.Scriptable, java.lang.String)

delete

public void delete(java.lang.String name)
            throws java.rmi.RemoteException
Removes a property from this object. This operation corresponds to the ECMA [[Delete]] except that the no result is returned. The runtime will guarantee that this method is called only if the property exists. After this method is called, the runtime will call Scriptable.has to see if the property has been removed in order to determine the boolean result of the delete operator as defined by ECMA 11.4.1.

A property can be made permanent by ignoring calls to remove it.

The property is specified by a String name as defined for get.

To delete properties defined in a prototype chain, first find the owner object of the property and then call deleteProperty on that owner object.

Specified by:
delete in interface JsObject
Parameters:
name - the identifier for the property
Throws:
java.rmi.RemoteException
See Also:
Scriptable.get(java.lang.String, org.mozilla.javascript.Scriptable), ScriptableObject.deleteProperty(org.mozilla.javascript.Scriptable, java.lang.String)

get

public java.lang.Object get(java.lang.String name)
                     throws java.rmi.RemoteException
Get a named property from the object. Does not walk the prototype chain. Looks property up in this object and returns the associated value if found. Returns NOT_FOUND if not found. Note that this method is not expected to traverse the prototype chain. This is different from the ECMA [[Get]] operation. Depending on the property selector, the runtime will call this method or the form of get that takes an integer:
JavaScript codeJava code
a.b a.get("b", a)
a["foo"] a.get("foo", a)
a[3] a.get(3, a)
a["3"] a.get(3, a)
a[3.0] a.get(3, a)
a["3.0"] a.get("3.0", a)
a[1.1] a.get("1.1", a)
a[-4] a.get(-4, a)

The values that may be returned are limited to the following:

Specified by:
get in interface JsObject
Parameters:
name - the name of the property
Returns:
the value of the property (may be null), or NOT_FOUND
Throws:
java.rmi.RemoteException

get

public java.lang.Object get(int index)
                     throws java.rmi.RemoteException
Specified by:
get in interface JsObject
Throws:
java.rmi.RemoteException

getClassName

public java.lang.String getClassName()
                              throws java.rmi.RemoteException
Get the name of the set of objects implemented by this Java class. This corresponds to the [[Class]] operation in ECMA and is used by Object.prototype.toString() in ECMA.

See ECMA 8.6.2 and 15.2.4.2.

Specified by:
getClassName in interface JsObject
Throws:
java.rmi.RemoteException

getDefaultValue

public java.lang.Object getDefaultValue(java.lang.Class hint)
                                 throws java.rmi.RemoteException
Get the default value of the object with a given hint. The hints are String.class for type String, Number.class for type Number, Scriptable.class for type Object, and Boolean.class for type Boolean.

A hint of null means "no hint". See ECMA 8.6.2.6.

Specified by:
getDefaultValue in interface JsObject
Parameters:
hint - the type hint
Returns:
the default value
Throws:
java.rmi.RemoteException

getIds

public java.lang.Object[] getIds(boolean all)
                          throws java.rmi.RemoteException
Returns an array of property ids defined on this object. The prototype chain is not walked. However, modified properties that were prototype properties will be seen. The parameter indicates to enumerate the "DONTENUM" properties or not.

Specified by:
getIds in interface JsObject
Returns:
an array of all ids from all object in the prototype chain. If a given id occurs multiple times in the prototype chain, it will occur only once in this list. The elements are limited to: - java.lang.String for the property name if it has one. - java.lang.Integer for properties without a name, it is their index.
Throws:
java.rmi.RemoteException
Since:
1.5R2

getPrototype

public JsObject getPrototype()
                      throws java.rmi.RemoteException
Get the prototype of the object.

Specified by:
getPrototype in interface JsObject
Returns:
the prototype
Throws:
java.rmi.RemoteException

getScope

public JsObject getScope()
                  throws java.rmi.RemoteException
The scope is for supporting two things. If the object is a function, the scope is the "execution" scope of the function. It will be used when calling the function to initialize the Context scope. If the object is not a function, the scope is used for the scope chain of execution context.

Specified by:
getScope in interface JsObject
Throws:
java.rmi.RemoteException

has

public boolean has(int index)
            throws java.rmi.RemoteException
Indicates whether or not an indexed property is defined in an object. Does not traverse the prototype chain.

The property is specified by an integral index as defined for the get method.

Specified by:
has in interface JsObject
Parameters:
index - the numeric index for the property
Returns:
true if and only if the indexed property is found in the object
Throws:
java.rmi.RemoteException
See Also:
Scriptable.get(java.lang.String, org.mozilla.javascript.Scriptable), ScriptableObject.getProperty(org.mozilla.javascript.Scriptable, java.lang.String)

has

public boolean has(java.lang.String name)
            throws java.rmi.RemoteException
Indicates whether or not a named property is defined in an object. Does not traverse the prototype chain.

The property is specified by a String name as defined for the get method.

Specified by:
has in interface JsObject
Parameters:
name - the name of the property
Returns:
true if and only if the named property is found in the object
Throws:
java.rmi.RemoteException
See Also:
Scriptable.get(java.lang.String, org.mozilla.javascript.Scriptable), ScriptableObject.getProperty(org.mozilla.javascript.Scriptable, java.lang.String)

hasInstance

public boolean hasInstance(JsObject instance)
                    throws java.rmi.RemoteException
The instanceof operator.

The JavaScript code "lhs instanceof rhs" causes rhs.hasInstance(lhs) to be called.

The return value is implementation dependent so that embedded host objects can return an appropriate value. See the JS 1.3 language documentation for more detail.

This operator corresponds to the proposed EMCA [[HasInstance]] operator.

Specified by:
hasInstance in interface JsObject
Parameters:
instance - The value that appeared on the LHS of the instanceof operator
Returns:
an implementation dependent value
Throws:
java.rmi.RemoteException

isA

public boolean isA(int cmd)
            throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

isFunction

public boolean isFunction()
                   throws java.rmi.RemoteException
Specified by:
isFunction in interface JsObject
Throws:
java.rmi.RemoteException

isScript

public boolean isScript()
                 throws java.rmi.RemoteException
Specified by:
isScript in interface JsObject
Throws:
java.rmi.RemoteException

put

public void put(int index,
                java.lang.Object value)
         throws java.rmi.RemoteException
Sets an indexed property in this object.

The property is specified by an integral index as defined for get.

Specified by:
put in interface JsObject
Parameters:
index - the numeric index for the property
value - value to set the property to
Throws:
java.rmi.RemoteException

put

public void put(java.lang.String name,
                java.lang.Object value)
         throws java.rmi.RemoteException
Sets a named property in this object.

The property is specified by a string name as defined for get.

Note that if a property a is defined in the prototype p of an object o, then evaluating o.a = 23 will cause set to be called on the prototype p with o as the start parameter. To preserve JavaScript semantics, it is the Scriptable object's responsibility to modify o.

This design allows properties to be defined in prototypes and implemented in terms of getters and setters of Java values without consuming slots in each instance.

The values that may be set are limited to the following:

IMPORTANT: JAVA OBJECTS. The wrapping is not yet supported.

Specified by:
put in interface JsObject
Throws:
java.rmi.RemoteException

setPrototype

public void setPrototype(JsObject prototype)
                  throws java.rmi.RemoteException
Set the prototype of the object.

Specified by:
setPrototype in interface JsObject
Parameters:
prototype - the prototype to set
Throws:
java.rmi.RemoteException

setScope

public void setScope(JsObject scope)
              throws java.rmi.RemoteException
Set the prototype of the object.

Specified by:
setScope in interface JsObject
Parameters:
prototype - the prototype to set
Throws:
java.rmi.RemoteException