Class HopObject

java.lang.Object
org.mozilla.javascript.ScriptableObject
helma.scripting.rhino.HopObject
All Implemented Interfaces:
PropertyRecorder, Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable, org.mozilla.javascript.SymbolScriptable, org.mozilla.javascript.Wrapper

public class HopObject extends org.mozilla.javascript.ScriptableObject implements org.mozilla.javascript.Wrapper, PropertyRecorder
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject

    org.mozilla.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields inherited from class org.mozilla.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from interface org.mozilla.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    HopObject(String className, RhinoCore core)
    Creates a new HopObject prototype.
    protected
    HopObject(String className, RhinoCore core, NodeHandle handle, org.mozilla.javascript.Scriptable proto)
    Creates a new HopObject.
    protected
    HopObject(String className, RhinoCore core, INode node, org.mozilla.javascript.Scriptable proto)
    Creates a new HopObject.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the set of changed properties.
    void
    defineProperty(String propertyName, Object value, int attributes)
    Overwritten to not define constructor property as constant - we need to have the constructor property resettable in Helma.
    void
    delete(String name)
     
    protected Object
    Custom == operator.
    get(int idx, org.mozilla.javascript.Scriptable start)
     
    get(String name, org.mozilla.javascript.Scriptable start)
     
    Return all property names of this object.
    Returns a set containing the names of properties changed since the last time startRecording() was called.
    Get the class/prototype name for this HopObject
    Return a primitive representation for this object.
    Return all "ordinary" property ids of this object.
    Return the INode wrapped by this HopObject.
    boolean
    has(int idx, org.mozilla.javascript.Scriptable start)
     
    boolean
    has(String name, org.mozilla.javascript.Scriptable start)
    Check if a property is set in this HopObject
    static HopObject
    Initialize HopObject prototype for Rhino scope.
    boolean
     
    boolean
    jsFunction_addAt(int index, Object child)
     
    void
    Clear the node's cache node.
    int
    Deprecated.
    use indexOf(Object) instead.
    int
     
    Get a childObject by name/id or index
    Get a child object by ID
    Returns a prototype's resource of a given name.
    Returns an array containing the prototype's resource with a given name.
    jsFunction_href(Object action, Object params)
    Get the URL for this object with the application
    int
    Check if node is contained in the subnode collection.
    boolean
    Invalidate the node itself or a subnode
    boolean
    Check whether the wrapped Node is persistent.
    boolean
    Check whether the wrapped Node is transient.
    org.mozilla.javascript.Scriptable
    jsFunction_list(Object startArg, Object lengthArg)
    Return a JS array of child objects with the given start and length.
    Makes the HopObject and all its reachable descendants persistent.
    void
    Prefetch child objects from (relational) database.
    boolean
    Remove this object from the database.
    boolean
    Remove a child node from this node's collection without deleting it from the database.
    boolean
    jsFunction_renderSkin(Object skinobj, Object paramobj)
    Render a skin to the response buffer.
    Render a skin and return its output as string.
    boolean
    Set a property on this HopObject
    int
     
     
    void
    put(String name, org.mozilla.javascript.Scriptable start, Object value)
    Set a property in this HopObject
    void
    Tell this PropertyRecorder to start recording changes to properties
    void
    Tell this PropertyRecorder to stop recording changes to properties
    Return a string representation of this HopObject.
    Returns the wrapped Node.

    Methods inherited from class org.mozilla.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HopObject

      protected HopObject(String className, RhinoCore core)
      Creates a new HopObject prototype.
      Parameters:
      className - the prototype name
      core - the RhinoCore
    • HopObject

      protected HopObject(String className, RhinoCore core, INode node, org.mozilla.javascript.Scriptable proto)
      Creates a new HopObject.
      Parameters:
      className - the className
      core - the RhinoCore
      node - the wrapped node
      proto - the object's prototype
    • HopObject

      protected HopObject(String className, RhinoCore core, NodeHandle handle, org.mozilla.javascript.Scriptable proto)
      Creates a new HopObject.
      Parameters:
      className - the className
      core - the RhinoCore
      handle - the handle for the wrapped node
      proto - the object's prototype
  • Method Details

    • init

      public static HopObject init(RhinoCore core)
      Initialize HopObject prototype for Rhino scope.
      Parameters:
      core - the RhinoCore
      Returns:
      the HopObject prototype
    • getClassName

      public String getClassName()
      Get the class/prototype name for this HopObject
      Specified by:
      getClassName in interface org.mozilla.javascript.Scriptable
      Specified by:
      getClassName in class org.mozilla.javascript.ScriptableObject
      Returns:
      The object's class or prototype name
    • defineProperty

      public void defineProperty(String propertyName, Object value, int attributes)
      Overwritten to not define constructor property as constant - we need to have the constructor property resettable in Helma.
      Overrides:
      defineProperty in class org.mozilla.javascript.ScriptableObject
      Parameters:
      propertyName - the property name
      value - the property value
      attributes - the property attributes
    • getDefaultValue

      public Object getDefaultValue(Class hint)
      Return a primitive representation for this object. FIXME: We always return a string representation.
      Specified by:
      getDefaultValue in interface org.mozilla.javascript.Scriptable
      Overrides:
      getDefaultValue in class org.mozilla.javascript.ScriptableObject
      Parameters:
      hint - the type hint
      Returns:
      the default value for the object
    • getNode

      public INode getNode()
      Return the INode wrapped by this HopObject.
      Returns:
      the wrapped INode instance
    • unwrap

      public Object unwrap()
      Returns the wrapped Node. Implements unwrap() in interface Wrapper.
      Specified by:
      unwrap in interface org.mozilla.javascript.Wrapper
    • jsGet_cache

      public Object jsGet_cache()
      Returns:
      ...
    • jsFunction_renderSkin

      public boolean jsFunction_renderSkin(Object skinobj, Object paramobj) throws UnsupportedEncodingException, IOException
      Render a skin to the response buffer.
      Parameters:
      skinobj - The skin object or name
      paramobj - An optional parameter object
      Returns:
      ...
      Throws:
      UnsupportedEncodingException
      IOException
    • jsFunction_getResource

      public Object jsFunction_getResource(String resourceName)
      Returns a prototype's resource of a given name. Walks up the prototype's inheritance chain if the resource is not found
      Parameters:
      resourceName - the name of the resource, e.g. "type.properties", "messages.properties", "script.js", etc.
      Returns:
      the resource, if found, null otherwise
    • jsFunction_getResources

      public Object jsFunction_getResources(String resourceName)
      Returns an array containing the prototype's resource with a given name.
      Parameters:
      resourceName - the name of the resource, e.g. "type.properties", "messages.properties", "script.js", etc.
      Returns:
      an array of resources with the given name
    • jsFunction_renderSkinAsString

      public String jsFunction_renderSkinAsString(Object skinobj, Object paramobj) throws UnsupportedEncodingException, IOException
      Render a skin and return its output as string.
      Parameters:
      skinobj - The skin object or name
      paramobj - An optional parameter object
      Returns:
      ...
      Throws:
      UnsupportedEncodingException
      IOException
    • jsFunction_href

      public Object jsFunction_href(Object action, Object params) throws UnsupportedEncodingException, IOException
      Get the URL for this object with the application
      Parameters:
      action - optional action name
      params - optional query parameters
      Returns:
      the URL for the object
      Throws:
      UnsupportedEncodingException - if the application's charset property is not a valid encoding name
      IOException
    • jsFunction_get

      public Object jsFunction_get(Object id)
      Get a childObject by name/id or index
      Parameters:
      id - The name/id or index, depending if the argument is a String or Number.
      Returns:
      ...
    • jsFunction_getById

      public Object jsFunction_getById(Object id)
      Get a child object by ID
      Parameters:
      id - the child id.
      Returns:
      ...
    • jsFunction_set

      public boolean jsFunction_set(Object id, Object value)
      Set a property on this HopObject
      Parameters:
      id - The name/id or index, depending if the argument is a String or Number.
      Returns:
      ...
    • jsFunction_count

      public int jsFunction_count()
      Returns:
      ...
    • jsFunction_size

      public int jsFunction_size()
      Returns:
      ...
    • jsFunction_prefetchChildren

      public void jsFunction_prefetchChildren(Object startArg, Object lengthArg)
      Prefetch child objects from (relational) database.
    • jsFunction_clearCache

      public void jsFunction_clearCache()
      Clear the node's cache node.
    • jsFunction_list

      public org.mozilla.javascript.Scriptable jsFunction_list(Object startArg, Object lengthArg)
      Return a JS array of child objects with the given start and length.
      Returns:
      A JavaScript Array containing the specified child objects
    • jsFunction_add

      public boolean jsFunction_add(Object child)
      Parameters:
      child - ...
      Returns:
      ...
    • jsFunction_addAt

      public boolean jsFunction_addAt(int index, Object child)
      Parameters:
      index - ...
      child - ...
      Returns:
      ...
    • jsFunction_remove

      public boolean jsFunction_remove(Object arg)
      Remove this object from the database.
    • jsFunction_removeChild

      public boolean jsFunction_removeChild(Object child)
      Remove a child node from this node's collection without deleting it from the database.
    • jsFunction_persist

      public Object jsFunction_persist()
      Makes the HopObject and all its reachable descendants persistent.
      Returns:
      the ID of the newly persisted HopObject or null if operation failed
    • jsFunction_invalidate

      public boolean jsFunction_invalidate(Object childId)
      Invalidate the node itself or a subnode
    • jsFunction_isPersistent

      public boolean jsFunction_isPersistent()
      Check whether the wrapped Node is persistent. This also returns true if the Node is being inserted in the database, or it has been in database and is in the proces of being deleted.
      Returns:
      true if the the wrapped Node has a valid database id.
    • jsFunction_isTransient

      public boolean jsFunction_isTransient()
      Check whether the wrapped Node is transient. This also returns false if the Node is being inserted in the database, or it has been in database and is in the proces of being deleted.
      Returns:
      true if the the wrapped Node is not stored in a database.
    • jsFunction_indexOf

      public int jsFunction_indexOf(Object obj)
      Check if node is contained in the subnode collection. Return its index position if it is, and -1 otherwise.
    • jsFunction_contains

      @Deprecated public int jsFunction_contains(Object obj)
      Deprecated.
      use indexOf(Object) instead.
      Check if node is contained in the subnode collection. Return its index position if it is, and -1 otherwise.
    • put

      public void put(String name, org.mozilla.javascript.Scriptable start, Object value)
      Set a property in this HopObject
      Specified by:
      put in interface org.mozilla.javascript.Scriptable
      Overrides:
      put in class org.mozilla.javascript.ScriptableObject
      Parameters:
      name - property name
      start -
      value - ...
    • has

      public boolean has(String name, org.mozilla.javascript.Scriptable start)
      Check if a property is set in this HopObject
      Specified by:
      has in interface org.mozilla.javascript.Scriptable
      Overrides:
      has in class org.mozilla.javascript.ScriptableObject
      Parameters:
      name - the property name
      start - the object in which the lookup began
      Returns:
      true if the property was found
    • delete

      public void delete(String name)
      Specified by:
      delete in interface org.mozilla.javascript.Scriptable
      Overrides:
      delete in class org.mozilla.javascript.ScriptableObject
      Parameters:
      name - ...
    • get

      public Object get(String name, org.mozilla.javascript.Scriptable start)
      Specified by:
      get in interface org.mozilla.javascript.Scriptable
      Overrides:
      get in class org.mozilla.javascript.ScriptableObject
      Parameters:
      name - ...
      start - ...
      Returns:
      ...
    • getAllIds

      public Object[] getAllIds()
      Return all property names of this object. This method is used by debugger.
      Specified by:
      getAllIds in interface org.mozilla.javascript.debug.DebuggableObject
      Overrides:
      getAllIds in class org.mozilla.javascript.ScriptableObject
      Returns:
      array containing the names of all properties defined in this object
    • getIds

      public Object[] getIds()
      Return all "ordinary" property ids of this object. This "hides" the prototype methods.
      Specified by:
      getIds in interface org.mozilla.javascript.Scriptable
      Overrides:
      getIds in class org.mozilla.javascript.ScriptableObject
      Returns:
      array containing the names of this object's data properties
    • has

      public boolean has(int idx, org.mozilla.javascript.Scriptable start)
      Specified by:
      has in interface org.mozilla.javascript.Scriptable
      Overrides:
      has in class org.mozilla.javascript.ScriptableObject
      Parameters:
      idx - ...
      start - ...
      Returns:
      ...
    • get

      public Object get(int idx, org.mozilla.javascript.Scriptable start)
      Specified by:
      get in interface org.mozilla.javascript.Scriptable
      Overrides:
      get in class org.mozilla.javascript.ScriptableObject
      Parameters:
      idx - ...
      start - ...
      Returns:
      ...
    • equivalentValues

      protected Object equivalentValues(Object value)
      Custom == operator. Must return Scriptable.NOT_FOUND if this object does not have custom equality operator for the given value, Boolean.TRUE if this object is equivalent to value, Boolean.FALSE if this object is not equivalent to value.
      Overrides:
      equivalentValues in class org.mozilla.javascript.ScriptableObject
    • toString

      public String toString()
      Return a string representation of this HopObject.
      Overrides:
      toString in class Object
      Returns:
      a string representing this HopObject
    • startRecording

      public void startRecording()
      Tell this PropertyRecorder to start recording changes to properties
      Specified by:
      startRecording in interface PropertyRecorder
    • stopRecording

      public void stopRecording()
      Tell this PropertyRecorder to stop recording changes to properties
      Specified by:
      stopRecording in interface PropertyRecorder
    • getChangeSet

      public Set getChangeSet()
      Returns a set containing the names of properties changed since the last time startRecording() was called.
      Specified by:
      getChangeSet in interface PropertyRecorder
      Returns:
      a Set containing the names of changed properties
    • clearChangeSet

      public void clearChangeSet()
      Clear the set of changed properties.
      Specified by:
      clearChangeSet in interface PropertyRecorder