org.apache.jackrabbit.core.state
Class LocalItemStateManager

java.lang.Object
  extended byorg.apache.jackrabbit.core.state.LocalItemStateManager
All Implemented Interfaces:
ItemStateListener, ItemStateManager, UpdatableItemStateManager
Direct Known Subclasses:
TransactionalItemStateManager

public class LocalItemStateManager
extends Object
implements UpdatableItemStateManager, ItemStateListener

Local ItemStateManager that isolates changes to persistent states from other clients.


Field Summary
protected  SharedItemStateManager sharedStateMgr
          Shared item state manager
protected  WorkspaceImpl wspImpl
          Local WorkspaceImpl instance.
 
Constructor Summary
LocalItemStateManager(SharedItemStateManager sharedStateMgr, WorkspaceImpl wspImpl)
          Creates a new LocalItemStateManager instance.
 
Method Summary
 void cancel()
          Cancel an update operation. This will undo all changes made to objects inside this item state manager.
 PropertyState createNew(QName propName, String parentUUID)
          Creates a PropertyState instance representing new, i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState) on the returned object to make it persistent.
 NodeState createNew(String uuid, QName nodeTypeName, String parentUUID)
          Creates a NodeState instance representing new, i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState) on the returned object to make it persistent.
 void destroy(ItemState state)
          Destroy an item state.
 void dispose()
          Disposes this UpdatableItemStateManager and frees resources.
 void edit()
          Start an edit operation on items inside this manager. This allows calling the operations defined below. At the end of this operation, either UpdatableItemStateManager.update() or UpdatableItemStateManager.cancel() must be invoked.
 ItemState getItemState(ItemId id)
          Return an item state, given its item id.
 NodeReferences getNodeReferences(NodeReferencesId id)
          Return a node references object, given its target id
protected  NodeState getNodeState(NodeId id)
          Retrieve a node state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.
protected  PropertyState getPropertyState(PropertyId id)
          Retrieve a property state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.
 boolean hasItemState(ItemId id)
          Return a flag indicating whether an item state for a given item id exists.
 boolean hasNodeReferences(NodeReferencesId id)
          Return a flag indicating whether a node references object for a given target id exists.
 boolean inEditMode()
          Returns true if this manager is in edit mode i.e. if an edit operation has been started by invoking UpdatableItemStateManager.edit(), otherwise returns false.
 void stateCreated(ItemState created)
          Called when an ItemState has successfully been created (i.e. its underlying persistent state was created).
 void stateDestroyed(ItemState destroyed)
          Called when an ItemState has successfully been removed (i.e. its underlying persistent state has been destroyed).
 void stateDiscarded(ItemState discarded)
          Called when an ItemState has been discarded (i.e. it has been rendered 'invalid').
 void stateModified(ItemState modified)
          Called when an ItemState has successfully been modified (i.e. its underlying persistent state has changed).
 void store(ItemState state)
          Store an item state.
 void store(NodeReferences refs)
          Store a node references object
 void update()
          End an update operation. This will save all items added to this update operation in a single step. If this operation fails, no item will have been saved.
protected  void update(ChangeLog changeLog)
          End an update operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedStateMgr

protected final SharedItemStateManager sharedStateMgr
Shared item state manager


wspImpl

protected final WorkspaceImpl wspImpl
Local WorkspaceImpl instance.

Constructor Detail

LocalItemStateManager

public LocalItemStateManager(SharedItemStateManager sharedStateMgr,
                             WorkspaceImpl wspImpl)
Creates a new LocalItemStateManager instance. todo LocalItemStateManager without a wspImpl will not generate observation events!

Parameters:
sharedStateMgr - shared state manager
wspImpl - the workspace instance where this item state manager belongs to, or null if this item state manager is not associated with a workspace. This is the case for the version item state manager. Version item states are not associated with a specific workspace instance.
Method Detail

getNodeState

protected NodeState getNodeState(NodeId id)
                          throws NoSuchItemStateException,
                                 ItemStateException
Retrieve a node state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.

Parameters:
id - node id
Returns:
node state
Throws:
NoSuchItemStateException
ItemStateException

getPropertyState

protected PropertyState getPropertyState(PropertyId id)
                                  throws NoSuchItemStateException,
                                         ItemStateException
Retrieve a property state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.

Parameters:
id - property id
Returns:
property state
Throws:
NoSuchItemStateException
ItemStateException

getItemState

public ItemState getItemState(ItemId id)
                       throws NoSuchItemStateException,
                              ItemStateException
Return an item state, given its item id.

Specified by:
getItemState in interface ItemStateManager
Parameters:
id - item id
Returns:
item state
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - if an error occurs

hasItemState

public boolean hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.

Specified by:
hasItemState in interface ItemStateManager
Parameters:
id - item id
Returns:
true if an item state exists, otherwise false

getNodeReferences

public NodeReferences getNodeReferences(NodeReferencesId id)
                                 throws NoSuchItemStateException,
                                        ItemStateException
Return a node references object, given its target id

Specified by:
getNodeReferences in interface ItemStateManager
Parameters:
id - target id
Returns:
node references object
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - if an error occurs

hasNodeReferences

public boolean hasNodeReferences(NodeReferencesId id)
Return a flag indicating whether a node references object for a given target id exists.

Specified by:
hasNodeReferences in interface ItemStateManager
Parameters:
id - target id
Returns:
true if an item state exists, otherwise false

edit

public void edit()
          throws IllegalStateException
Start an edit operation on items inside this manager. This allows calling the operations defined below. At the end of this operation, either UpdatableItemStateManager.update() or UpdatableItemStateManager.cancel() must be invoked.

Specified by:
edit in interface UpdatableItemStateManager
Throws:
IllegalStateException - if the manager is already in edit mode.

inEditMode

public boolean inEditMode()
Returns true if this manager is in edit mode i.e. if an edit operation has been started by invoking UpdatableItemStateManager.edit(), otherwise returns false.

Specified by:
inEditMode in interface UpdatableItemStateManager
Returns:
true if this manager is in edit mode, otherwise false

createNew

public NodeState createNew(String uuid,
                           QName nodeTypeName,
                           String parentUUID)
                    throws IllegalStateException
Creates a NodeState instance representing new, i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState) on the returned object to make it persistent.

Specified by:
createNew in interface UpdatableItemStateManager
Parameters:
uuid - node UUID
nodeTypeName - qualified node type name
parentUUID - parent node's UUID
Returns:
a node state
Throws:
IllegalStateException - if the manager is not in edit mode.

createNew

public PropertyState createNew(QName propName,
                               String parentUUID)
                        throws IllegalStateException
Creates a PropertyState instance representing new, i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState) on the returned object to make it persistent.

Specified by:
createNew in interface UpdatableItemStateManager
Parameters:
propName - qualified property name
parentUUID - parent node UUID
Returns:
a property state
Throws:
IllegalStateException - if the manager is not in edit mode.

store

public void store(ItemState state)
           throws IllegalStateException
Store an item state.

Specified by:
store in interface UpdatableItemStateManager
Parameters:
state - item state that should be stored
Throws:
IllegalStateException - if the manager is not in edit mode.

store

public void store(NodeReferences refs)
           throws IllegalStateException
Store a node references object

Specified by:
store in interface UpdatableItemStateManager
Parameters:
refs - node references object that should be stored
Throws:
IllegalStateException - if the manager is not in edit mode.

destroy

public void destroy(ItemState state)
             throws IllegalStateException
Destroy an item state.

Specified by:
destroy in interface UpdatableItemStateManager
Parameters:
state - item state that should be destroyed
Throws:
IllegalStateException - if the manager is not in edit mode.

cancel

public void cancel()
            throws IllegalStateException
Cancel an update operation. This will undo all changes made to objects inside this item state manager.

Specified by:
cancel in interface UpdatableItemStateManager
Throws:
IllegalStateException - if the manager is not in edit mode.

update

public void update()
            throws StaleItemStateException,
                   ItemStateException,
                   IllegalStateException
End an update operation. This will save all items added to this update operation in a single step. If this operation fails, no item will have been saved.

Specified by:
update in interface UpdatableItemStateManager
Throws:
IllegalStateException - if the manager is not in edit mode.
ItemStateException - if the operation failed for another reason
StaleItemStateException - if at least one of the affected items has become stale in the meantime

update

protected void update(ChangeLog changeLog)
               throws StaleItemStateException,
                      ItemStateException
End an update operation. Fetch the states and references from the parent (shared) item manager, reconnect them to the items collected in our (local) change log and overwrite the shared items with our copies.

Parameters:
changeLog - change log containing local states and references
Throws:
StaleItemStateException - if at least one of the affected item states has become stale in the meantime
ItemStateException - if an error occurs

dispose

public void dispose()
Disposes this UpdatableItemStateManager and frees resources.

Specified by:
dispose in interface UpdatableItemStateManager

stateCreated

public void stateCreated(ItemState created)
Called when an ItemState has successfully been created (i.e. its underlying persistent state was created).

Specified by:
stateCreated in interface ItemStateListener
Parameters:
created - the ItemState that has been 'created'

stateModified

public void stateModified(ItemState modified)
Called when an ItemState has successfully been modified (i.e. its underlying persistent state has changed).

Specified by:
stateModified in interface ItemStateListener
Parameters:
modified - the ItemState that has been 'modified'

stateDestroyed

public void stateDestroyed(ItemState destroyed)
Called when an ItemState has successfully been removed (i.e. its underlying persistent state has been destroyed).

Specified by:
stateDestroyed in interface ItemStateListener
Parameters:
destroyed - the ItemState that has been 'destroyed'

stateDiscarded

public void stateDiscarded(ItemState discarded)
Called when an ItemState has been discarded (i.e. it has been rendered 'invalid').

Specified by:
stateDiscarded in interface ItemStateListener
Parameters:
discarded - the ItemState that has been discarded
See Also:
ItemState.discard()


Copyright © 2004-2005 The Apache Software Foundation. All Rights Reserved.