Package org.apache.jackrabbit.core.state
Class NodeState
- java.lang.Object
-
- org.apache.jackrabbit.core.state.ItemState
-
- org.apache.jackrabbit.core.state.NodeState
-
- Direct Known Subclasses:
VirtualNodeState
public class NodeState extends ItemState
NodeState
represents the state of aNode
.
-
-
Field Summary
-
Fields inherited from class org.apache.jackrabbit.core.state.ItemState
overlayedState, status, STATUS_EXISTING, STATUS_EXISTING_MODIFIED, STATUS_EXISTING_REMOVED, STATUS_NEW, STATUS_STALE_DESTROYED, STATUS_UNDEFINED
-
-
Constructor Summary
Constructors Constructor Description NodeState(NodeId id, Name nodeTypeName, NodeId parentId, int initialStatus, boolean isTransient)
Constructs a new node state that is not connected.NodeState(NodeState overlayedState, int initialStatus, boolean isTransient)
Constructs a new node state that is initially connected to an overlayed state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChildNodeEntry
addChildNodeEntry(Name nodeName, NodeId id)
Adds a newChildNodeEntry
.void
addPropertyName(Name propName)
Adds a property name entry.boolean
addShare(NodeId parentId)
Add a parent to the shared set.long
calculateMemoryFootprint()
Returns an estimate of the memory size of this node state.boolean
containsShare(NodeId parentId)
Return a flag whether the given parent id appears in the shared set.void
copy(ItemState state, boolean syncModCount)
Copy state information from another state into this stateList<ChildNodeEntry>
getAddedChildNodeEntries()
Returns a list of child node entries that do not exist in the overlayed node state but have been added to this node state.Set<Name>
getAddedPropertyNames()
Returns a set ofName
s denoting those properties that do not exist in the overlayed node state but have been added to this node state.Set<NodeId>
getAddedShares()
Returns a set of shares that were added.List<ChildNodeEntry>
getChildNodeEntries()
Returns a list ofChildNodeEntry
objects denoting the child nodes of this node.List<ChildNodeEntry>
getChildNodeEntries(Name nodeName)
Returns a list ofChildNodeEntry
s with the specified name.ChildNodeEntry
getChildNodeEntry(NodeId id)
Returns theChildNodeEntry
with the specifiedNodeId
ornull
if there's no matching entry.ChildNodeEntry
getChildNodeEntry(Name nodeName, int index)
Returns theChildNodeEntry
with the specified name and index ornull
if there's no matching entry.ItemId
getId()
Returns the identifier of this item.Set<Name>
getMixinTypeNames()
Returns the names of this node's mixin types.NodeId
getNodeId()
Returns the identifier of this node.Name
getNodeTypeName()
Returns the name of this node's node type.NodeId
getParentId()
Returns the NodeId of the parentNodeState
ornull
if either this item state represents the root node or this item state is 'free floating', i.e.Set<Name>
getPropertyNames()
Returns the names of this node's properties as a set ofQNames
objects.List<ChildNodeEntry>
getRemovedChildNodeEntries()
Returns a list of child node entries, that exist in the overlayed node state but have been removed from this node state.Set<Name>
getRemovedPropertyNames()
Returns a set ofName
s denoting those properties that exist in the overlayed node state but have been removed from this node state.Set<NodeId>
getRemovedShares()
Returns a set of shares that were removed.List<ChildNodeEntry>
getRenamedChildNodeEntries()
Returns a list of child node entries that exist both in this node state and in the overlayed node state but have been renamed.List<ChildNodeEntry>
getReorderedChildNodeEntries()
Returns a list of child node entries that exist both in this node state and in the overlayed node state but have been reordered.Set<NodeId>
getSharedSet()
Return the shared set as an unmodifiable collection.boolean
hasChildNodeEntries()
Determines if there are any child node entries.boolean
hasChildNodeEntry(NodeId id)
Determines if there is aChildNodeEntry
with the specifiedNodeId
.boolean
hasChildNodeEntry(Name name)
Determines if there is aChildNodeEntry
with the specifiedname
.boolean
hasChildNodeEntry(Name name, int index)
Determines if there is aChildNodeEntry
with the specifiedname
andindex
.boolean
hasPropertyName(Name propName)
Determines if there is a property entry with the specifiedName
.boolean
isNode()
Determines if this item state represents a node.boolean
isShareable()
Return a flag indicating whether this state is shareable, i.e.protected void
notifyNodeAdded(ChildNodeEntry added)
Notify the listeners that a child node entry has been addedprotected void
notifyNodeRemoved(ChildNodeEntry removed)
Notify the listeners that a child node entry has been removedprotected void
notifyNodesReplaced()
Notify the listeners that the child node entries have been replacedvoid
removeAllChildNodeEntries()
Removes allChildNodeEntry
s.void
removeAllPropertyNames()
Removes all property name entries.boolean
removeChildNodeEntry(NodeId id)
Removes aChildNodeEntry
.boolean
removeChildNodeEntry(Name nodeName, int index)
Removes aChildNodeEntry
.boolean
removePropertyName(Name propName)
Removes a property name entry.int
removeShare(NodeId parentId)
Remove a parent from the shared set.boolean
renameChildNodeEntry(NodeId id, Name newName)
Renames aChildNodeEntry
by removing the old entry and appending the new entry to the end of the list.boolean
renameChildNodeEntry(Name oldName, int index, Name newName)
Renames aChildNodeEntry
by removing the old entry and appending the new entry to the end of the list.boolean
replaceChildNodeEntry(NodeId oldId, Name newName, NodeId newId)
Replaces theChildNodeEntry
identified byoldId
with a new entry.void
setChildNodeEntries(List<ChildNodeEntry> nodeEntries)
Sets the list ofChildNodeEntry
objects denoting the child nodes of this node.void
setContainer(ItemStateListener listener)
Set the parent container that will receive notifications about changes to this state.void
setMixinTypeNames(Set<Name> names)
Sets the names of this node's mixin types.void
setNodeTypeName(Name nodeTypeName)
Set the node type name.void
setParentId(NodeId parentId)
Sets the id of this node's parent.void
setPropertyNames(Set<Name> propNames)
Sets the set ofName
objects denoting the properties of this node.void
setSharedSet(Set<NodeId> set)
Set the shared set of this state to the shared set of another state.-
Methods inherited from class org.apache.jackrabbit.core.state.ItemState
connect, discard, disconnect, getContainer, getModCount, getOverlayedState, getStatus, hasOverlayedState, isConnected, isStale, isTransient, notifyStateCreated, notifyStateDestroyed, notifyStateDiscarded, notifyStateUpdated, reconnect, setModCount, setStatus
-
-
-
-
Constructor Detail
-
NodeState
public NodeState(NodeState overlayedState, int initialStatus, boolean isTransient)
Constructs a new node state that is initially connected to an overlayed state.- Parameters:
overlayedState
- the backing node state being overlayedinitialStatus
- the initial status of the node state objectisTransient
- flag indicating whether this state is transient or not
-
NodeState
public NodeState(NodeId id, Name nodeTypeName, NodeId parentId, int initialStatus, boolean isTransient)
Constructs a new node state that is not connected.- Parameters:
id
- id of this nodenodeTypeName
- node type of this nodeparentId
- id of the parent nodeinitialStatus
- the initial status of the node state objectisTransient
- flag indicating whether this state is transient or not
-
-
Method Detail
-
copy
public void copy(ItemState state, boolean syncModCount)
Copy state information from another state into this state
-
isNode
public final boolean isNode()
Determines if this item state represents a node.
-
getParentId
public NodeId getParentId()
Returns the NodeId of the parentNodeState
ornull
if either this item state represents the root node or this item state is 'free floating', i.e. not attached to the repository's hierarchy.- Specified by:
getParentId
in classItemState
- Returns:
- the parent
NodeState
's Id
-
getId
public ItemId getId()
Returns the identifier of this item.
-
getNodeId
public NodeId getNodeId()
Returns the identifier of this node.- Returns:
- the id of this node.
-
setParentId
public void setParentId(NodeId parentId)
Sets the id of this node's parent.- Parameters:
parentId
- the parent node's id ornull
if either this node state should represent the root node or this node state should be 'free floating', i.e. detached from the workspace's hierarchy.
-
getNodeTypeName
public Name getNodeTypeName()
Returns the name of this node's node type.- Returns:
- the name of this node's node type.
-
getMixinTypeNames
public Set<Name> getMixinTypeNames()
Returns the names of this node's mixin types.- Returns:
- a set of the names of this node's mixin types.
-
setMixinTypeNames
public void setMixinTypeNames(Set<Name> names)
Sets the names of this node's mixin types.- Parameters:
names
- set of names of mixin types
-
hasChildNodeEntries
public boolean hasChildNodeEntries()
Determines if there are any child node entries.- Returns:
true
if there are child node entries,false
otherwise.
-
hasChildNodeEntry
public boolean hasChildNodeEntry(Name name)
Determines if there is aChildNodeEntry
with the specifiedname
.- Parameters:
name
-Name
object specifying a node name- Returns:
true
if there is aChildNodeEntry
with the specifiedname
.
-
hasChildNodeEntry
public boolean hasChildNodeEntry(NodeId id)
Determines if there is aChildNodeEntry
with the specifiedNodeId
.- Parameters:
id
- the id of the child node- Returns:
true
if there is aChildNodeEntry
with the specifiedname
.
-
hasChildNodeEntry
public boolean hasChildNodeEntry(Name name, int index)
Determines if there is aChildNodeEntry
with the specifiedname
andindex
.- Parameters:
name
-Name
object specifying a node nameindex
- 1-based index if there are same-name child node entries- Returns:
true
if there is aChildNodeEntry
with the specifiedname
andindex
.
-
hasPropertyName
public boolean hasPropertyName(Name propName)
Determines if there is a property entry with the specifiedName
.- Parameters:
propName
-Name
object specifying a property name- Returns:
true
if there is a property entry with the specifiedName
.
-
getChildNodeEntry
public ChildNodeEntry getChildNodeEntry(Name nodeName, int index)
Returns theChildNodeEntry
with the specified name and index ornull
if there's no matching entry.- Parameters:
nodeName
-Name
object specifying a node nameindex
- 1-based index if there are same-name child node entries- Returns:
- the
ChildNodeEntry
with the specified name and index ornull
if there's no matching entry.
-
getChildNodeEntry
public ChildNodeEntry getChildNodeEntry(NodeId id)
Returns theChildNodeEntry
with the specifiedNodeId
ornull
if there's no matching entry.- Parameters:
id
- the id of the child node- Returns:
- the
ChildNodeEntry
with the specifiedNodeId
ornull
if there's no matching entry. - See Also:
addChildNodeEntry(org.apache.jackrabbit.spi.Name, org.apache.jackrabbit.core.id.NodeId)
,removeChildNodeEntry(org.apache.jackrabbit.spi.Name, int)
-
getChildNodeEntries
public List<ChildNodeEntry> getChildNodeEntries()
Returns a list ofChildNodeEntry
objects denoting the child nodes of this node.- Returns:
- list of
ChildNodeEntry
objects - See Also:
addChildNodeEntry(org.apache.jackrabbit.spi.Name, org.apache.jackrabbit.core.id.NodeId)
,removeChildNodeEntry(org.apache.jackrabbit.spi.Name, int)
-
getChildNodeEntries
public List<ChildNodeEntry> getChildNodeEntries(Name nodeName)
Returns a list ofChildNodeEntry
s with the specified name.- Parameters:
nodeName
- name of the child node entries that should be returned- Returns:
- list of
ChildNodeEntry
objects - See Also:
addChildNodeEntry(org.apache.jackrabbit.spi.Name, org.apache.jackrabbit.core.id.NodeId)
,removeChildNodeEntry(org.apache.jackrabbit.spi.Name, int)
-
addChildNodeEntry
public ChildNodeEntry addChildNodeEntry(Name nodeName, NodeId id)
Adds a newChildNodeEntry
.- Parameters:
nodeName
-Name
object specifying the name of the new entry.id
- the id the new entry is refering to.- Returns:
- the newly added
ChildNodeEntry
-
renameChildNodeEntry
public boolean renameChildNodeEntry(Name oldName, int index, Name newName)
Renames aChildNodeEntry
by removing the old entry and appending the new entry to the end of the list.- Parameters:
oldName
-Name
object specifying the entry's old nameindex
- 1-based index if there are same-name child node entriesnewName
-Name
object specifying the entry's new name- Returns:
true
if the entry was successfully renamed; otherwisefalse
-
renameChildNodeEntry
public boolean renameChildNodeEntry(NodeId id, Name newName)
Renames aChildNodeEntry
by removing the old entry and appending the new entry to the end of the list.- Parameters:
id
- id the entry to be renamed is refering to.newName
-Name
object specifying the entry's new name- Returns:
true
if the entry was successfully renamed; otherwisefalse
-
replaceChildNodeEntry
public boolean replaceChildNodeEntry(NodeId oldId, Name newName, NodeId newId)
Replaces theChildNodeEntry
identified byoldId
with a new entry. Note that the entry will overwrite the old entry at the same relative position within the child node entries list.- Parameters:
oldId
- id the entry to be replaced is referring to.newName
-Name
object specifying the entry's new namenewId
- the id the new entry is referring to.- Returns:
true
if the entry was successfully replaced; otherwisefalse
-
removeChildNodeEntry
public boolean removeChildNodeEntry(Name nodeName, int index)
Removes aChildNodeEntry
.- Parameters:
nodeName
-ChildNodeEntry
object specifying a node nameindex
- 1-based index if there are same-name child node entries- Returns:
true
if the specified child node entry was found in the list of child node entries and could be removed.
-
removeChildNodeEntry
public boolean removeChildNodeEntry(NodeId id)
Removes aChildNodeEntry
.- Parameters:
id
- the id of the entry to be removed- Returns:
true
if the specified child node entry was found in the list of child node entries and could be removed.
-
removeAllChildNodeEntries
public void removeAllChildNodeEntries()
Removes allChildNodeEntry
s.
-
setChildNodeEntries
public void setChildNodeEntries(List<ChildNodeEntry> nodeEntries)
Sets the list ofChildNodeEntry
objects denoting the child nodes of this node.- Parameters:
nodeEntries
- list ofChildNodeEntry
s
-
getPropertyNames
public Set<Name> getPropertyNames()
Returns the names of this node's properties as a set ofQNames
objects.- Returns:
- set of
QNames
objects - See Also:
addPropertyName(org.apache.jackrabbit.spi.Name)
,removePropertyName(org.apache.jackrabbit.spi.Name)
-
addPropertyName
public void addPropertyName(Name propName)
Adds a property name entry.- Parameters:
propName
-Name
object specifying the property name
-
removePropertyName
public boolean removePropertyName(Name propName)
Removes a property name entry.- Parameters:
propName
-Name
object specifying the property name- Returns:
true
if the specified property name was found in the list of property name entries and could be removed.
-
removeAllPropertyNames
public void removeAllPropertyNames()
Removes all property name entries.
-
setPropertyNames
public void setPropertyNames(Set<Name> propNames)
Sets the set ofName
objects denoting the properties of this node.- Parameters:
propNames
- set ofName
s.
-
setNodeTypeName
public void setNodeTypeName(Name nodeTypeName)
Set the node type name. Needed for deserialization and should therefore not change the internal status.- Parameters:
nodeTypeName
- node type name
-
isShareable
public boolean isShareable()
Return a flag indicating whether this state is shareable, i.e. whether there is at least one member inside its shared set.- Returns:
true
if this state is shareable.
-
addShare
public boolean addShare(NodeId parentId)
Add a parent to the shared set.- Parameters:
parentId
- parent id to add to the shared set- Returns:
true
if the parent was successfully added;false
otherwise
-
containsShare
public boolean containsShare(NodeId parentId)
Return a flag whether the given parent id appears in the shared set.- Parameters:
parentId
- parent id- Returns:
true
if the parent id appears in the shared set;false
otherwise.
-
getSharedSet
public Set<NodeId> getSharedSet()
Return the shared set as an unmodifiable collection.- Returns:
- unmodifiable collection
-
setSharedSet
public void setSharedSet(Set<NodeId> set)
Set the shared set of this state to the shared set of another state. This state will get a deep copy of the shared set given.- Parameters:
set
- shared set
-
removeShare
public int removeShare(NodeId parentId)
Remove a parent from the shared set. Returns the number of elements in the shared set. If this number is0
, the shared set is empty, i.e. there are no more parent items referencing this item and the state is free floating.- Parameters:
parentId
- parent id to remove from the shared set- Returns:
- the number of elements left in the shared set
-
getAddedPropertyNames
public Set<Name> getAddedPropertyNames()
Returns a set ofName
s denoting those properties that do not exist in the overlayed node state but have been added to this node state.- Returns:
- set of
Name
s denoting the properties that have been added.
-
getAddedChildNodeEntries
public List<ChildNodeEntry> getAddedChildNodeEntries()
Returns a list of child node entries that do not exist in the overlayed node state but have been added to this node state.- Returns:
- list of added child node entries
-
getRemovedPropertyNames
public Set<Name> getRemovedPropertyNames()
Returns a set ofName
s denoting those properties that exist in the overlayed node state but have been removed from this node state.- Returns:
- set of
Name
s denoting the properties that have been removed.
-
getRemovedChildNodeEntries
public List<ChildNodeEntry> getRemovedChildNodeEntries()
Returns a list of child node entries, that exist in the overlayed node state but have been removed from this node state.- Returns:
- list of removed child node entries
-
getRenamedChildNodeEntries
public List<ChildNodeEntry> getRenamedChildNodeEntries()
Returns a list of child node entries that exist both in this node state and in the overlayed node state but have been renamed.- Returns:
- list of renamed child node entries
-
getReorderedChildNodeEntries
public List<ChildNodeEntry> getReorderedChildNodeEntries()
Returns a list of child node entries that exist both in this node state and in the overlayed node state but have been reordered.The list may include only the minimal set of nodes that have been reordered. That is, even though a certain number of nodes have changed their absolute position the list may include less that this number of nodes.
Example:
Initial state:+ node1 + node2 + node3
After reorder:+ node2 + node3 + node1
All nodes have changed their absolute position. The returned list however may only return thatnode1
has been reordered (from the first position to the end).- Returns:
- list of reordered child node enties.
-
getAddedShares
public Set<NodeId> getAddedShares()
Returns a set of shares that were added.- Returns:
- the set of shares that were added. Set of
NodeId
s.
-
getRemovedShares
public Set<NodeId> getRemovedShares()
Returns a set of shares that were removed.- Returns:
- the set of shares that were removed. Set of
NodeId
s.
-
setContainer
public void setContainer(ItemStateListener listener)
Set the parent container that will receive notifications about changes to this state.If the listener passed is at the same time a
NodeStateListener
we remember it as well.- Overrides:
setContainer
in classItemState
- Parameters:
listener
- container to be informed on modifications
-
calculateMemoryFootprint
public long calculateMemoryFootprint()
Returns an estimate of the memory size of this node state. The return value actually highly overestimates the amount of required memory, but changing the estimates would likely cause OOMs in many downstream deployments that have set their cache sizes based on experience with these erroneous size estimates. So we don't change the formula used by this method.- Specified by:
calculateMemoryFootprint
in classItemState
- Returns:
- the approximate memory consumption of this state.
-
notifyNodeAdded
protected void notifyNodeAdded(ChildNodeEntry added)
Notify the listeners that a child node entry has been added- Parameters:
added
- the entry that was added
-
notifyNodesReplaced
protected void notifyNodesReplaced()
Notify the listeners that the child node entries have been replaced
-
notifyNodeRemoved
protected void notifyNodeRemoved(ChildNodeEntry removed)
Notify the listeners that a child node entry has been removed- Parameters:
removed
- the entry that was removed
-
-