Class HopObject

  • All Implemented Interfaces:
    PropertyRecorder, java.io.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:
    Serialized Form
    • 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​(java.lang.String className, RhinoCore core)
      Creates a new HopObject prototype.
      protected HopObject​(java.lang.String className, RhinoCore core, NodeHandle handle, org.mozilla.javascript.Scriptable proto)
      Creates a new HopObject.
      protected HopObject​(java.lang.String className, RhinoCore core, INode node, org.mozilla.javascript.Scriptable proto)
      Creates a new HopObject.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void clearChangeSet()
      Clear the set of changed properties.
      void defineProperty​(java.lang.String propertyName, java.lang.Object value, int attributes)
      Overwritten to not define constructor property as constant - we need to have the constructor property resettable in Helma.
      void delete​(java.lang.String name)  
      protected java.lang.Object equivalentValues​(java.lang.Object value)
      Custom == operator.
      java.lang.Object get​(int idx, org.mozilla.javascript.Scriptable start)  
      java.lang.Object get​(java.lang.String name, org.mozilla.javascript.Scriptable start)  
      java.lang.Object[] getAllIds()
      Return all property names of this object.
      java.util.Set getChangeSet()
      Returns a set containing the names of properties changed since the last time startRecording() was called.
      java.lang.String getClassName()
      Get the class/prototype name for this HopObject
      java.lang.Object getDefaultValue​(java.lang.Class hint)
      Return a primitive representation for this object.
      java.lang.Object[] getIds()
      Return all "ordinary" property ids of this object.
      INode getNode()
      Return the INode wrapped by this HopObject.
      boolean has​(int idx, org.mozilla.javascript.Scriptable start)  
      boolean has​(java.lang.String name, org.mozilla.javascript.Scriptable start)
      Check if a property is set in this HopObject
      static HopObject init​(RhinoCore core)
      Initialize HopObject prototype for Rhino scope.
      boolean jsFunction_add​(java.lang.Object child)  
      boolean jsFunction_addAt​(int index, java.lang.Object child)  
      void jsFunction_clearCache()
      Clear the node's cache node.
      int jsFunction_contains​(java.lang.Object obj)
      Deprecated.
      use indexOf(Object) instead.
      int jsFunction_count()  
      java.lang.Object jsFunction_get​(java.lang.Object id)
      Get a childObject by name/id or index
      java.lang.Object jsFunction_getById​(java.lang.Object id)
      Get a child object by ID
      java.lang.Object jsFunction_getResource​(java.lang.String resourceName)
      Returns a prototype's resource of a given name.
      java.lang.Object jsFunction_getResources​(java.lang.String resourceName)
      Returns an array containing the prototype's resource with a given name.
      java.lang.Object jsFunction_href​(java.lang.Object action, java.lang.Object params)
      Get the URL for this object with the application
      int jsFunction_indexOf​(java.lang.Object obj)
      Check if node is contained in the subnode collection.
      boolean jsFunction_invalidate​(java.lang.Object childId)
      Invalidate the node itself or a subnode
      boolean jsFunction_isPersistent()
      Check whether the wrapped Node is persistent.
      boolean jsFunction_isTransient()
      Check whether the wrapped Node is transient.
      org.mozilla.javascript.Scriptable jsFunction_list​(java.lang.Object startArg, java.lang.Object lengthArg)
      Return a JS array of child objects with the given start and length.
      java.lang.Object jsFunction_persist()
      Makes the HopObject and all its reachable descendants persistent.
      void jsFunction_prefetchChildren​(java.lang.Object startArg, java.lang.Object lengthArg)
      Prefetch child objects from (relational) database.
      boolean jsFunction_remove​(java.lang.Object arg)
      Remove this object from the database.
      boolean jsFunction_removeChild​(java.lang.Object child)
      Remove a child node from this node's collection without deleting it from the database.
      boolean jsFunction_renderSkin​(java.lang.Object skinobj, java.lang.Object paramobj)
      Render a skin to the response buffer.
      java.lang.String jsFunction_renderSkinAsString​(java.lang.Object skinobj, java.lang.Object paramobj)
      Render a skin and return its output as string.
      boolean jsFunction_set​(java.lang.Object id, java.lang.Object value)
      Set a property on this HopObject
      int jsFunction_size()  
      java.lang.Object jsGet_cache()  
      void put​(java.lang.String name, org.mozilla.javascript.Scriptable start, java.lang.Object value)
      Set a property in this HopObject
      void startRecording()
      Tell this PropertyRecorder to start recording changes to properties
      void stopRecording()
      Tell this PropertyRecorder to stop recording changes to properties
      java.lang.String toString()
      Return a string representation of this HopObject.
      java.lang.Object unwrap()
      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, 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 Detail

      • HopObject

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

        protected HopObject​(java.lang.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​(java.lang.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 Detail

      • init

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

        public java.lang.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​(java.lang.String propertyName,
                                   java.lang.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 java.lang.Object getDefaultValue​(java.lang.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 java.lang.Object unwrap()
        Returns the wrapped Node. Implements unwrap() in interface Wrapper.
        Specified by:
        unwrap in interface org.mozilla.javascript.Wrapper
      • jsGet_cache

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

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

        public java.lang.Object jsFunction_getResource​(java.lang.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 java.lang.Object jsFunction_getResources​(java.lang.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 java.lang.String jsFunction_renderSkinAsString​(java.lang.Object skinobj,
                                                              java.lang.Object paramobj)
                                                       throws java.io.UnsupportedEncodingException,
                                                              java.io.IOException
        Render a skin and return its output as string.
        Parameters:
        skinobj - The skin object or name
        paramobj - An optional parameter object
        Returns:
        ...
        Throws:
        java.io.UnsupportedEncodingException
        java.io.IOException
      • jsFunction_href

        public java.lang.Object jsFunction_href​(java.lang.Object action,
                                                java.lang.Object params)
                                         throws java.io.UnsupportedEncodingException,
                                                java.io.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:
        java.io.UnsupportedEncodingException - if the application's charset property is not a valid encoding name
        java.io.IOException
      • jsFunction_get

        public java.lang.Object jsFunction_get​(java.lang.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 java.lang.Object jsFunction_getById​(java.lang.Object id)
        Get a child object by ID
        Parameters:
        id - the child id.
        Returns:
        ...
      • jsFunction_set

        public boolean jsFunction_set​(java.lang.Object id,
                                      java.lang.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​(java.lang.Object startArg,
                                                java.lang.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​(java.lang.Object startArg,
                                                                 java.lang.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​(java.lang.Object child)
        Parameters:
        child - ...
        Returns:
        ...
      • jsFunction_addAt

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

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

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

        public java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String name,
                        org.mozilla.javascript.Scriptable start,
                        java.lang.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​(java.lang.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​(java.lang.String name)
        Specified by:
        delete in interface org.mozilla.javascript.Scriptable
        Overrides:
        delete in class org.mozilla.javascript.ScriptableObject
        Parameters:
        name - ...
      • get

        public java.lang.Object get​(java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.Object equivalentValues​(java.lang.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 java.lang.String toString()
        Return a string representation of this HopObject.
        Overrides:
        toString in class java.lang.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 java.util.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