Class Node

  • All Implemented Interfaces:
    IPathElement, INode, INodeState

    public final class Node
    extends java.lang.Object
    implements INode
    An implementation of INode that can be stored in the internal database or an external relational database.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Node​(long timestamp)
      Creates an empty, uninitialized Node with the given create and modify time.
        Node​(Node home, java.lang.String propname, WrappedNodeManager nmgr, java.lang.String prototype)
      Constructor used for virtual nodes.
      protected Node​(WrappedNodeManager nmgr)
      Creates an empty, uninitialized Node.
        Node​(java.lang.String name, java.lang.String prototype, WrappedNodeManager nmgr)
      Creates a new Node with the given name.
        Node​(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr)
      Creates a new Node with the given name.
        Node​(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr, long created, long lastmodified)
      Constructor used to create a Node with a given name from a embedded database.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      INode addNode​(INode elem)
      INode-related
      INode addNode​(INode elem, int where)
      Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.
      void clearCacheNode()
      Reset the cache node for this node.
      int contains​(INode n)
      Check if the given node is contained in this node's child list.
      long created()
      Get the node's creation timestamp.
      INode createNode()  
      INode createNode​(int where)  
      INode createNode​(java.lang.String nm)
      Create a new named property with a node value
      INode createNode​(java.lang.String nm, int where)
      Create a new unnamed child node at the given position.
      SubnodeList createSubnodeList()
      Create an empty subnode list.
      protected void deepRemoveNode()
      Delete the node from the db.
      void dump()  
      IProperty get​(java.lang.String propname)
      Get a property with the given name.
      boolean getBoolean​(java.lang.String propname)
      Get a boolean property with the given name.
      Node getCachedParent()
      Get parent, using cached info if it exists.
      INode getCacheNode()
      Get the cache node for this node.
      IPathElement getChildElement​(java.lang.String name)
      This implements the getChildElement() method of the IPathElement interface
      java.util.Date getDate​(java.lang.String propname)
      Get a date property with the given name.
      DbMapping getDbMapping()
      Get the node's DbMapping.
      java.lang.String getElementName()
      Get something to identify this node within a URL.
      double getFloat​(java.lang.String propname)
      Get a float property with the given name.
      protected Node getGroupbySubnode​(Node node, boolean create)
      Get or create a group name for a given content node.
      protected Node getGroupbySubnode​(java.lang.String groupname, boolean create)
      Get or create a group name for a given group name.
      NodeHandle getHandle()
      Get the node's handle.
      java.lang.String getID()
      Get the ID of this Node.
      long getInteger​(java.lang.String propname)
      Get an integer property with the given name.
      java.lang.Object getJavaObject​(java.lang.String propname)
      Get a Java object property with the given name.
      Key getKey()
      Get the node's key.
      java.lang.String getName()
      Return this node' name, which may or may not have some meaning
      INode getNode​(java.lang.String propname)
      Get a node property with the given name.
      Node getNonVirtualParent()
      This method walks down node path to the first non-virtual node and return it.
      INode getParent()
      Get parent, retrieving it if necessary.
      IPathElement getParentElement()
      This implements the getParentElement() method of the IPathElement interface
      java.lang.String getParentInfo()  
      java.lang.String getPath()
      Get the node's path
      protected Property getProperty​(java.lang.String propname)  
      java.util.Hashtable getPropMap()  
      java.lang.String getPrototype()
      Return the node's prototype name.
      int getState()
      Gets this node's stateas defined in the INode interface
      java.lang.String getString​(java.lang.String propname)
      Get a string property with the given name.
      INode getSubnode​(java.lang.String subid)
      Get a named child node with the given id.
      INode getSubnodeAt​(int index)
      Get a node at a given position.
      SubnodeList getSubnodeList()
      Return this Node's subnode list
      java.lang.String getSubnodeRelation()
      Get the node's explicit subnode select clause if one was set, or null
      java.util.Enumeration getSubnodes()
      Enumerate through the subnodes of this node.
      int hashCode()
      We overwrite hashCode to make it dependant from the prototype.
      void init​(DbMapping dbm, java.lang.String id, java.lang.String name, java.lang.String prototype, java.util.Hashtable propMap)
      Initializer used for nodes being instanced from an embedded or relational database.
      void invalidate()
      Mark node as invalid so it is re-fetched from the database
      void invalidateNode​(java.lang.String key)
      Check for a child mapping and evict the object specified by key from the cache
      boolean isAnonymous()
      Returns true if this node is accessed by id from its aprent, false if it is accessed by name
      boolean isNullNode()
      Instances of this class may be used to mark an entry in the object cache as null.
      boolean isParentOf​(Node n)
      Check if the given node is contained in this node's child list.
      boolean isRelational()
      Tell whether this node is stored inside a relational db.
      long lastModified()
      Get the node's last modification timestamp.
      void loadNodes()
      Make sure the subnode index is loaded for subnodes stored in a relational data source.
      void markSubnodesChanged()
      Called by the transactor on registered parent nodes to mark the child index as changed
      int numberOfNodes()
      Count the subnodes of this node.
      void persist()
      Public method to make a node persistent.
      void prefetchChildren​(int startIndex, int length)  
      java.util.Enumeration properties()
      Get all properties of this node.
      protected void releaseNode​(Node node)
      "Locally" remove a subnode from the subnodes table.
      boolean remove()
      Remove this node from the database.
      void removeNode​(INode node)
      Remove the given node from this node's child nodes.
      protected void set​(java.lang.String propname, java.lang.Object value, int type)
      Directly set a property on this node
      void setBoolean​(java.lang.String propname, boolean value)
      Set the property with the given name to the given boolean value.
      void setDate​(java.lang.String propname, java.util.Date value)
      Set the property with the given name to the given date value.
      void setDbMapping​(DbMapping dbmap)
      Set the node's DbMapping.
      void setFloat​(java.lang.String propname, double value)
      Set the property with the given name to the given float value.
      void setInteger​(java.lang.String propname, long value)
      Set the property with the given name to the given integer value.
      void setJavaObject​(java.lang.String propname, java.lang.Object value)
      Set the property with the given name to the given Java object value.
      void setName​(java.lang.String name)
      Set the node's name.
      void setNode​(java.lang.String propname, INode value)
      Set the property with the given name to the given node value.
      void setParent​(Node parent)
      Set this node's parent node.
      void setParentHandle​(NodeHandle parent)
      Set this node's parent node to the node referred to by the NodeHandle.
      void setPropMap​(java.util.Hashtable propMap)
      used by Xml deserialization
      void setPrototype​(java.lang.String proto)
      Set the node's prototype name.
      void setState​(int s)
      Sets this node's state as defined in the INode interface
      void setString​(java.lang.String propname, java.lang.String value)
      Set the property with the given name to the given string value.
      void setSubnodeRelation​(java.lang.String rel)
      Set an explicit select clause for the node's subnodes
      java.lang.String toString()
      Return a string representation for this node.
      void unset​(java.lang.String propname)
      Remove a property.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • created

        protected long created
      • lastmodified

        protected long lastmodified
      • anonymous

        protected boolean anonymous
      • version

        protected short version
    • Constructor Detail

      • Node

        protected Node​(long timestamp)
        Creates an empty, uninitialized Node with the given create and modify time. This is used for null-node references in the node cache.
        Parameters:
        timestamp -
      • Node

        protected Node​(WrappedNodeManager nmgr)
        Creates an empty, uninitialized Node. The init() method must be called on the Node before it can do anything useful.
      • Node

        public Node​(java.lang.String name,
                    java.lang.String id,
                    java.lang.String prototype,
                    WrappedNodeManager nmgr)
        Creates a new Node with the given name. Used by NodeManager for creating "root nodes" outside of a Transaction context, which is why we can immediately mark it as CLEAN. Also used by embedded database to re-create an existing Node.
      • Node

        public Node​(java.lang.String name,
                    java.lang.String id,
                    java.lang.String prototype,
                    WrappedNodeManager nmgr,
                    long created,
                    long lastmodified)
        Constructor used to create a Node with a given name from a embedded database.
      • Node

        public Node​(Node home,
                    java.lang.String propname,
                    WrappedNodeManager nmgr,
                    java.lang.String prototype)
        Constructor used for virtual nodes.
      • Node

        public Node​(java.lang.String name,
                    java.lang.String prototype,
                    WrappedNodeManager nmgr)
        Creates a new Node with the given name. This is used for ordinary transient nodes.
    • Method Detail

      • init

        public void init​(DbMapping dbm,
                         java.lang.String id,
                         java.lang.String name,
                         java.lang.String prototype,
                         java.util.Hashtable propMap)
        Initializer used for nodes being instanced from an embedded or relational database.
      • setPropMap

        public void setPropMap​(java.util.Hashtable propMap)
        used by Xml deserialization
      • markSubnodesChanged

        public void markSubnodesChanged()
        Called by the transactor on registered parent nodes to mark the child index as changed
      • getState

        public int getState()
        Gets this node's stateas defined in the INode interface
        Specified by:
        getState in interface INode
        Returns:
        this node's state
      • setState

        public void setState​(int s)
        Sets this node's state as defined in the INode interface
        Specified by:
        setState in interface INode
        Parameters:
        s - this node's new state
      • invalidate

        public void invalidate()
        Mark node as invalid so it is re-fetched from the database
      • invalidateNode

        public void invalidateNode​(java.lang.String key)
        Check for a child mapping and evict the object specified by key from the cache
      • getID

        public java.lang.String getID()
        Get the ID of this Node. This is the primary database key and used as part of the key for the internal node cache.
        Specified by:
        getID in interface INode
      • isAnonymous

        public boolean isAnonymous()
        Returns true if this node is accessed by id from its aprent, false if it is accessed by name
        Specified by:
        isAnonymous in interface INode
      • getName

        public java.lang.String getName()
        Return this node' name, which may or may not have some meaning
        Specified by:
        getName in interface INode
      • getElementName

        public java.lang.String getElementName()
        Get something to identify this node within a URL. This is the ID for anonymous nodes and a property value for named properties.
        Specified by:
        getElementName in interface IPathElement
      • getPath

        public java.lang.String getPath()
        Get the node's path
        Specified by:
        getPath in interface INode
      • setPrototype

        public void setPrototype​(java.lang.String proto)
        Set the node's prototype name.
        Specified by:
        setPrototype in interface INode
      • getKey

        public Key getKey()
        Get the node's key.
      • getHandle

        public NodeHandle getHandle()
        Get the node's handle.
      • setSubnodeRelation

        public void setSubnodeRelation​(java.lang.String rel)
        Set an explicit select clause for the node's subnodes
        Specified by:
        setSubnodeRelation in interface INode
      • getSubnodeRelation

        public java.lang.String getSubnodeRelation()
        Get the node's explicit subnode select clause if one was set, or null
        Specified by:
        getSubnodeRelation in interface INode
      • setName

        public void setName​(java.lang.String name)
        Set the node's name.
        Specified by:
        setName in interface INode
      • setParent

        public void setParent​(Node parent)
        Set this node's parent node.
      • setParentHandle

        public void setParentHandle​(NodeHandle parent)
        Set this node's parent node to the node referred to by the NodeHandle.
      • getParent

        public INode getParent()
        Get parent, retrieving it if necessary.
        Specified by:
        getParent in interface INode
      • getCachedParent

        public Node getCachedParent()
        Get parent, using cached info if it exists.
      • addNode

        public INode addNode​(INode elem,
                             int where)
        Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.
        Specified by:
        addNode in interface INode
        Parameters:
        elem - the node to add to this Nodes subnode-list
        where - the index-position where this node has to be added
        Returns:
        the added node itselve
      • createNode

        public INode createNode()
        Returns:
        ...
      • createNode

        public INode createNode​(int where)
        Parameters:
        where - ...
        Returns:
        ...
      • createNode

        public INode createNode​(java.lang.String nm)
        Description copied from interface: INode
        Create a new named property with a node value
        Specified by:
        createNode in interface INode
        Parameters:
        nm - ...
        Returns:
        ...
      • createNode

        public INode createNode​(java.lang.String nm,
                                int where)
        Description copied from interface: INode
        Create a new unnamed child node at the given position.
        Specified by:
        createNode in interface INode
        Parameters:
        nm - ...
        where - ...
        Returns:
        ...
      • getChildElement

        public IPathElement getChildElement​(java.lang.String name)
        This implements the getChildElement() method of the IPathElement interface
        Specified by:
        getChildElement in interface IPathElement
      • getSubnode

        public INode getSubnode​(java.lang.String subid)
        Get a named child node with the given id.
        Specified by:
        getSubnode in interface INode
      • getSubnodeAt

        public INode getSubnodeAt​(int index)
        Get a node at a given position. This causes the subnode list to be loaded in case it isn't up to date.
        Specified by:
        getSubnodeAt in interface INode
        Parameters:
        index - the subnode index
        Returns:
        the node at the given index
      • getGroupbySubnode

        protected Node getGroupbySubnode​(Node node,
                                         boolean create)
        Get or create a group name for a given content node.
        Parameters:
        node - the content node
        create - whether the node should be created if it doesn't exist
        Returns:
        the group node, or null
      • getGroupbySubnode

        protected Node getGroupbySubnode​(java.lang.String groupname,
                                         boolean create)
        Get or create a group name for a given group name.
        Parameters:
        groupname - the group name
        create - whether the node should be created if it doesn't exist
        Returns:
        the group node, or null
      • remove

        public boolean remove()
        Description copied from interface: INode
        Remove this node from the database.
        Specified by:
        remove in interface INode
        Returns:
        ...
      • removeNode

        public void removeNode​(INode node)
        Description copied from interface: INode
        Remove the given node from this node's child nodes.
        Specified by:
        removeNode in interface INode
        Parameters:
        node - ...
      • releaseNode

        protected void releaseNode​(Node node)
        "Locally" remove a subnode from the subnodes table. The logical stuff necessary for keeping data consistent is done in removeNode(INode).
      • deepRemoveNode

        protected void deepRemoveNode()
        Delete the node from the db. This mainly tries to notify all nodes referring to this that it's going away. For nodes from the embedded db it also does a cascading delete, since it can tell which nodes are actual children and which are just linked in.
      • contains

        public int contains​(INode n)
        Check if the given node is contained in this node's child list. If it is contained return its index in the list, otherwise return -1.
        Specified by:
        contains in interface INode
        Parameters:
        n - a node
        Returns:
        the node's index position in the child list, or -1
      • isParentOf

        public boolean isParentOf​(Node n)
        Check if the given node is contained in this node's child list. This is similar to contains(INode) but does not load the child index for relational nodes.
        Parameters:
        n - a node
        Returns:
        true if the given node is contained in this node's child list
      • numberOfNodes

        public int numberOfNodes()
        Count the subnodes of this node. If they're stored in a relational data source, we may actually load their IDs in order to do this.
        Specified by:
        numberOfNodes in interface INode
      • loadNodes

        public void loadNodes()
        Make sure the subnode index is loaded for subnodes stored in a relational data source. Depending on the subnode.loadmode specified in the type.properties, we'll load just the ID index or the actual nodes.
      • createSubnodeList

        public SubnodeList createSubnodeList()
        Create an empty subnode list.
        Returns:
        List an empty List of the type used by this Node
      • prefetchChildren

        public void prefetchChildren​(int startIndex,
                                     int length)
        Parameters:
        startIndex - ...
        length - ...
        Throws:
        java.lang.Exception - ...
      • getSubnodes

        public java.util.Enumeration getSubnodes()
        Enumerate through the subnodes of this node.
        Specified by:
        getSubnodes in interface INode
        Returns:
        an enumeration of this node's subnodes
      • getSubnodeList

        public SubnodeList getSubnodeList()
        Return this Node's subnode list
        Returns:
        the subnode list
      • properties

        public java.util.Enumeration properties()
        Get all properties of this node.
        Specified by:
        properties in interface INode
      • getPropMap

        public java.util.Hashtable getPropMap()
        Returns:
        ...
      • get

        public IProperty get​(java.lang.String propname)
        Description copied from interface: INode
        Get a property with the given name.
        Specified by:
        get in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getParentInfo

        public java.lang.String getParentInfo()
        Returns:
        ...
      • getProperty

        protected Property getProperty​(java.lang.String propname)
        Parameters:
        propname - ...
        Returns:
        ...
      • getString

        public java.lang.String getString​(java.lang.String propname)
        Description copied from interface: INode
        Get a string property with the given name.
        Specified by:
        getString in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getInteger

        public long getInteger​(java.lang.String propname)
        Description copied from interface: INode
        Get an integer property with the given name.
        Specified by:
        getInteger in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getFloat

        public double getFloat​(java.lang.String propname)
        Description copied from interface: INode
        Get a float property with the given name.
        Specified by:
        getFloat in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getDate

        public java.util.Date getDate​(java.lang.String propname)
        Description copied from interface: INode
        Get a date property with the given name.
        Specified by:
        getDate in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getBoolean

        public boolean getBoolean​(java.lang.String propname)
        Description copied from interface: INode
        Get a boolean property with the given name.
        Specified by:
        getBoolean in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getNode

        public INode getNode​(java.lang.String propname)
        Description copied from interface: INode
        Get a node property with the given name.
        Specified by:
        getNode in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • getJavaObject

        public java.lang.Object getJavaObject​(java.lang.String propname)
        Description copied from interface: INode
        Get a Java object property with the given name.
        Specified by:
        getJavaObject in interface INode
        Parameters:
        propname - ...
        Returns:
        ...
      • set

        protected void set​(java.lang.String propname,
                           java.lang.Object value,
                           int type)
        Directly set a property on this node
        Parameters:
        propname - ...
        value - ...
      • setString

        public void setString​(java.lang.String propname,
                              java.lang.String value)
        Description copied from interface: INode
        Set the property with the given name to the given string value.
        Specified by:
        setString in interface INode
        Parameters:
        propname - ...
        value - ...
      • setInteger

        public void setInteger​(java.lang.String propname,
                               long value)
        Description copied from interface: INode
        Set the property with the given name to the given integer value.
        Specified by:
        setInteger in interface INode
        Parameters:
        propname - ...
        value - ...
      • setFloat

        public void setFloat​(java.lang.String propname,
                             double value)
        Description copied from interface: INode
        Set the property with the given name to the given float value.
        Specified by:
        setFloat in interface INode
        Parameters:
        propname - ...
        value - ...
      • setBoolean

        public void setBoolean​(java.lang.String propname,
                               boolean value)
        Description copied from interface: INode
        Set the property with the given name to the given boolean value.
        Specified by:
        setBoolean in interface INode
        Parameters:
        propname - ...
        value - ...
      • setDate

        public void setDate​(java.lang.String propname,
                            java.util.Date value)
        Description copied from interface: INode
        Set the property with the given name to the given date value.
        Specified by:
        setDate in interface INode
        Parameters:
        propname - ...
        value - ...
      • setJavaObject

        public void setJavaObject​(java.lang.String propname,
                                  java.lang.Object value)
        Description copied from interface: INode
        Set the property with the given name to the given Java object value.
        Specified by:
        setJavaObject in interface INode
        Parameters:
        propname - ...
        value - ...
      • setNode

        public void setNode​(java.lang.String propname,
                            INode value)
        Description copied from interface: INode
        Set the property with the given name to the given node value.
        Specified by:
        setNode in interface INode
        Parameters:
        propname - ...
        value - ...
      • unset

        public void unset​(java.lang.String propname)
        Remove a property. Note that this works only for explicitly set properties, not for those specified via property relation.
        Specified by:
        unset in interface INode
      • lastModified

        public long lastModified()
        Description copied from interface: INode
        Get the node's last modification timestamp.
        Specified by:
        lastModified in interface INode
        Returns:
        ...
      • created

        public long created()
        Description copied from interface: INode
        Get the node's creation timestamp.
        Specified by:
        created in interface INode
        Returns:
        ...
      • toString

        public java.lang.String toString()
        Return a string representation for this node. This tries to call the javascript implemented toString() if it is defined.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representing this node.
      • isRelational

        public boolean isRelational()
        Tell whether this node is stored inside a relational db. This doesn't mean it actually is stored in a relational db, just that it would be, if the node was persistent
      • persist

        public void persist()
        Public method to make a node persistent.
      • getCacheNode

        public INode getCacheNode()
        Get the cache node for this node. This can be used to store transient cache data per node from Javascript.
        Specified by:
        getCacheNode in interface INode
      • clearCacheNode

        public void clearCacheNode()
        Reset the cache node for this node.
        Specified by:
        clearCacheNode in interface INode
      • getNonVirtualParent

        public Node getNonVirtualParent()
        This method walks down node path to the first non-virtual node and return it. limit max depth to 5, since there shouldn't be more then 2 layers of virtual nodes.
      • isNullNode

        public boolean isNullNode()
        Instances of this class may be used to mark an entry in the object cache as null. This method tells the caller whether this is the case.
      • hashCode

        public int hashCode()
        We overwrite hashCode to make it dependant from the prototype. That way, when the prototype changes, the node will automatically get a new ESNode wrapper, since they're cached in a hashtable. You gotta love these hash code tricks ;-)
        Overrides:
        hashCode in class java.lang.Object
      • dump

        public void dump()