net.rim.device.api.script
Class ScriptableImpl

java.lang.Object
  extended by net.rim.device.api.script.Scriptable
      extended by net.rim.device.api.script.ScriptableImpl

public class ScriptableImpl
extends Scriptable

A convenience class providing an easy-to-use Scriptable implementation with elements and fields. This class uses Hashtables internally to store elements and fields, providing a "push" wrapper around the "pull" model Scriptable base class. Instead of subclassing Scriptable for every single scriptable object, it may be easier to simply instantiate a ScriptableImpl, populate it with the required fields, and never have to worry about it again. This is particularly true for objects whose fields don't change dynamically very often.

Since:
BlackBerry API 5.0.0

Field Summary
 
Fields inherited from class net.rim.device.api.script.Scriptable
UNDEFINED
 
Constructor Summary
ScriptableImpl()
          Constructor.
 
Method Summary
 void enumerateFields(Vector v)
          Provides a list of elements and fields pushed into this object.
 Object getElement(int index)
          Gets an element pushed into this object.
 int getElementCount()
          Returns the number of elements that have been pushed into this object.
protected  int getElementLength()
          This method calculates the element length of the object.
 Object getField(String name)
          Gets a field pushed into this object.
 boolean putElement(int index, Object value)
          Pushes an element into this object.
 boolean putField(String name, Object value)
          Pushes a field into this object.
 void removeElement(int index)
          Removes a pushed element from this object.
 void removeField(String name)
          Removes a pushed field from this object.
 
Methods inherited from class net.rim.device.api.script.Scriptable
getParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

ScriptableImpl

public ScriptableImpl()
Constructor. Creates a new ScriptableImpl object.

Since:
BlackBerry API 5.0.0


Method Detail

enumerateFields

public void enumerateFields(Vector v)
Provides a list of elements and fields pushed into this object. This method simply iterates over the fields that been pushed into this object via the put method and adds the field names to the provided Vector.

Overrides:
enumerateFields in class Scriptable
Parameters:
v - The vector to which the names should be added. This must not be null.
See Also:
Scriptable.enumerateFields(Vector)
Since:
BlackBerry API 5.0.0

getField

public Object getField(String name)
Gets a field pushed into this object. This method returns the field pushed into this object via the put method. If no field with the given name was pushed, it returns UNDEFINED.
One special case is the length field. When this field is requested, this Scriptable's element length will be returned. The element length is defined as the highest index at which an element has been pushed, plus one. Note that this may provide different values than the getElementCount method. The special-casing of the length field is provided as a convenience to users of this class.

Overrides:
getField in class Scriptable
Parameters:
name - The name of the field being requested. This must not be null.
Returns:
The named field in this scriptable object. This may be null.
See Also:
Scriptable.getField(String)
Since:
BlackBerry API 5.0.0

putField

public boolean putField(String name,
                        Object value)
Pushes a field into this object. This method will always accept the provided value, and store it internally as the value associated with the named field. Therefore, this method will always return true.

Overrides:
putField in class Scriptable
Parameters:
name - The name of the field being modified. This must not be null.
value - The value that the caller wishes to set as the field value. This may be null.
Returns:
true if the field mutation was handled, or false if the caller should handle it instead.
See Also:
Scriptable.putField(String,Object)
Since:
BlackBerry API 5.0.0

getElementCount

public int getElementCount()
Returns the number of elements that have been pushed into this object. This value is the number of distinct indices for which a call to getElement will return something other than UNDEFINED.

Overrides:
getElementCount in class Scriptable
Returns:
The number of indexed elements in this object.
See Also:
Scriptable.getElementCount()
Since:
BlackBerry API 5.0.0

getElement

public Object getElement(int index)
Gets an element pushed into this object. This method returns the element pushed into this object via the putElement method. If no element was pushed at the given index, it returns UNDEFINED.

Overrides:
getElement in class Scriptable
Parameters:
index - The index of the element being requested. This may be any integer, including negative values.
Returns:
The indexed element in this scriptable object. This may be null.
See Also:
Scriptable.getElement(int)
Since:
BlackBerry API 5.0.0

putElement

public boolean putElement(int index,
                          Object value)
Pushes an element into this object. This method will always accept the provided value, and store it internally as the value associated with the indexed element. Therefore, this method will always return true.

Overrides:
putElement in class Scriptable
Parameters:
index - The index of the element being modified. This may be any integer, including negative values.
value - The value that the caller wishes to set as the element value. This may be null.
Returns:
true if the element mutation was handled, or false if the caller should handle it instead.
See Also:
Scriptable.putElement(int,Object)
Since:
BlackBerry API 5.0.0

removeField

public void removeField(String name)
Removes a pushed field from this object. This method removes the value stored internally that is associated with the named field. After this, calls to getField with the same name parameter will return UNDEFINED, until some other value is pushed into this object with the same field name.

Parameters:
name - The name of the field to remove. This must not be null.
Since:
BlackBerry API 5.0.0

removeElement

public void removeElement(int index)
Removes a pushed element from this object. This method removes the value stored internally that is associated with the indexed field. After this, calls to getElement with the same index parameter will return UNDEFINED, until some other value is pushed into this object for that index.

Parameters:
index - The index of the element to remove.
Since:
BlackBerry API 5.0.0

getElementLength

protected final int getElementLength()
This method calculates the element length of the object. See the getField documentation for the definition of the element length.

Since:
BlackBerry API 5.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.