com.jeceira.item.state
Class NodeState

java.lang.Object
  extended bycom.jeceira.item.state.NodeState

public abstract class NodeState
extends java.lang.Object

Implements the GoF state pattern to manage node states.

Author:
Valeri Felberg

Field Summary
static NodeState CREATED
          Represents a node existing only in the transient storage of a session.
static NodeState MODIFIED
          Represents a node saved in a persistent storage and subsequently modified.
static NodeState REMOVED
          Represents a node whose removal through the current session has been saved.
static NodeState REMOVED_PERSISTENT
          Represents a node saved in a persistent storage and subsequently removed through the current session.
static NodeState REMOVED_PERSISTENT_MODIFIED
          Represents a node saved in a persistent storage, modified through the current session, and subsequently removed.
static NodeState REMOVED_TRANSIENT
          Represents a node removed before it has been stored persistently.
static NodeState SAVED
          Represents a node saved in a persistent storage.
 
Constructor Summary
protected NodeState(java.lang.String stateName)
          Creates a node state with the specified name.
 
Method Summary
protected static void changeState(SessionNode node, NodeState nextState)
          Changes state of a node.
protected abstract  void changeStateOnRemoval(SessionNode node)
          Performs state transition in case of removal of the corresponding node.
protected  void changeStateOnSave(SessionNode node, java.util.List events, boolean processOrderEvents)
          Recursively sets the state of the specified node and its subtree after it has been successfully saved.
protected abstract  void doChangeStateOnSave(SessionNode node, java.util.List events, boolean processOrderEvents)
          Sets the state of the specified node after it has been successfully saved.
protected abstract  void doSave(Transaction transaction, SessionNode node, boolean reordered)
          Validates and applies changes made on the specified node through the current session.
protected abstract  void entry(SessionNode node)
          Performs entry action of this state as a result of the state transition on the specified node.
abstract  boolean isModified()
          Indicates if this state denotes a modified node.
abstract  boolean isNew()
          Indicates if this state denotes a new node.
abstract  boolean isRemoved()
          Indicates if this state denotes a removed node.
abstract  void modify(SessionNode node)
          Marks the specified node as modified; called if the node has changed its position under the parent node.
 void remove(SessionNode node)
          Marks the specified node and its descendants as removed through the current session.
 void save(SessionNode node)
          Saves pending changes on the specified node and its subtree.
protected  void save(Transaction transaction, SessionNode node, boolean reordered)
          Saves pending changes on the specified node and its subtree in context of a running transaction.
static void setInitialState(SessionNode node)
          Initializes the state of a newly created node.
static void setSavedState(SessionNode node)
          Initializes the state of a node retrieved from a persistent storage.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CREATED

public static final NodeState CREATED
Represents a node existing only in the transient storage of a session.


MODIFIED

public static final NodeState MODIFIED
Represents a node saved in a persistent storage and subsequently modified.


REMOVED

public static final NodeState REMOVED
Represents a node whose removal through the current session has been saved. Nodes in this state must not be used and should be released for garbage collection.


REMOVED_PERSISTENT

public static final NodeState REMOVED_PERSISTENT
Represents a node saved in a persistent storage and subsequently removed through the current session.


REMOVED_PERSISTENT_MODIFIED

public static final NodeState REMOVED_PERSISTENT_MODIFIED
Represents a node saved in a persistent storage, modified through the current session, and subsequently removed.


REMOVED_TRANSIENT

public static final NodeState REMOVED_TRANSIENT
Represents a node removed before it has been stored persistently.


SAVED

public static final NodeState SAVED
Represents a node saved in a persistent storage.

Constructor Detail

NodeState

protected NodeState(java.lang.String stateName)
Creates a node state with the specified name.

Method Detail

changeState

protected static void changeState(SessionNode node,
                                  NodeState nextState)
Changes state of a node. Before the node state is set to the next state, entry(SessionNode) method is called on the next state with the node as an argument.


setInitialState

public static void setInitialState(SessionNode node)
Initializes the state of a newly created node.


setSavedState

public static void setSavedState(SessionNode node)
Initializes the state of a node retrieved from a persistent storage.


changeStateOnRemoval

protected abstract void changeStateOnRemoval(SessionNode node)
                                      throws RepositoryException
Performs state transition in case of removal of the corresponding node.

Throws:
RepositoryException

changeStateOnSave

protected void changeStateOnSave(SessionNode node,
                                 java.util.List events,
                                 boolean processOrderEvents)
                          throws RepositoryException
Recursively sets the state of the specified node and its subtree after it has been successfully saved.

Throws:
RepositoryException

doChangeStateOnSave

protected abstract void doChangeStateOnSave(SessionNode node,
                                            java.util.List events,
                                            boolean processOrderEvents)
                                     throws RepositoryException
Sets the state of the specified node after it has been successfully saved.

Throws:
RepositoryException

doSave

protected abstract void doSave(Transaction transaction,
                               SessionNode node,
                               boolean reordered)
                        throws RepositoryException
Validates and applies changes made on the specified node through the current session. This methods is executed in context of the specified running transaction.

Throws:
RepositoryException

entry

protected abstract void entry(SessionNode node)
Performs entry action of this state as a result of the state transition on the specified node.


isModified

public abstract boolean isModified()
Indicates if this state denotes a modified node. A node is considered as modified if it has been saved in a persistent storage and subsequently got or lost a child node or a property.


isNew

public abstract boolean isNew()
Indicates if this state denotes a new node. A node is considered as new if it has not been saved in a persistent storage yet.


isRemoved

public abstract boolean isRemoved()
Indicates if this state denotes a removed node. A node is considered as removed if the SessionNode#remove() method was called on it and its parent has not been saved yet.


modify

public abstract void modify(SessionNode node)
Marks the specified node as modified; called if the node has changed its position under the parent node.


remove

public void remove(SessionNode node)
            throws RepositoryException
Marks the specified node and its descendants as removed through the current session.

Throws:
RepositoryException

save

public void save(SessionNode node)
          throws RepositoryException
Saves pending changes on the specified node and its subtree. The changes are saved transactionally, i.e. all or nothing is saved. After the transaction has been successfully committed, state transition is performed on the whole subtree by means of the changeStateOnSave(SessionNode, List, boolean) method.

Throws:
RepositoryException

save

protected void save(Transaction transaction,
                    SessionNode node,
                    boolean reordered)
             throws RepositoryException
Saves pending changes on the specified node and its subtree in context of a running transaction.

Throws:
RepositoryException

toString

public java.lang.String toString()


Copyright © 2005 Aparzev Software Ltd. All Rights Reserved.