Class NodeDelegate
- java.lang.Object
-
- org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate
-
- org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate
-
- Direct Known Subclasses:
VersionDelegate
,VersionHistoryDelegate
public class NodeDelegate extends ItemDelegate
NodeDelegate
serve as internal representations ofNode
s. Most methods of this class throw anInvalidItemStateException
exception if the instance is stale. An instance is stale if the underlying items does not exist anymore.
-
-
Field Summary
-
Fields inherited from class org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate
sessionDelegate
-
-
Constructor Summary
Constructors Constructor Description NodeDelegate(SessionDelegate sessionDelegate, Tree tree)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable NodeDelegate
addChild(String name, String typeName)
Add a child nodevoid
addMixin(Function<Tree,Iterable<String>> existingMixins, String typeName)
boolean
canAddMixin(String typeName)
boolean
exists()
Determine whether the underlying item exists@Nullable NodeDelegate
getChild(String relPath)
Get child nodelong
getChildCount(long max)
Get the number of child nodes@NotNull Iterator<NodeDelegate>
getChildren()
Returns an iterator for traversing all the children of this node.@NotNull String
getIdentifier()
@Nullable NodeDelegate
getLock()
String
getLockOwner()
@NotNull String
getName()
Get the name of this item@Nullable NodeDelegate
getParent()
Get the parent of this item ornull
.@NotNull String
getPath()
Get the path of this item@NotNull Iterator<PropertyDelegate>
getProperties()
Get the properties of the node@NotNull PropertyDelegate
getProperty(String relPath)
Get a property.long
getPropertyCount()
Get the number of properties of the node@Nullable PropertyDelegate
getPropertyOrNull(String relPath)
Get a property@Nullable Tree.Status
getStatus()
Get the status of this item.@NotNull Tree
getTree()
boolean
holdsLock(boolean deep)
Checks whether this node holds a lock.boolean
isLocked()
Checks whether this node is locked, either directly or through a deep lock on an ancestor.boolean
isLockOwner(String user)
boolean
isProtected()
boolean
isRoot()
Determine whether this is the root nodevoid
lock(boolean isDeep)
void
orderBefore(String source, String target)
boolean
remove()
Remove this node.void
removeMixin(String typeName)
void
setMixins(Set<String> mixinNames)
void
setOrderableChildren(boolean enable)
Enables or disabled orderable children on the underlying tree.@NotNull PropertyDelegate
setProperty(PropertyState propertyState, boolean exactTypeMatch, boolean setProtected)
Set a propertyString
toString()
void
unlock()
void
updateMixins(Set<String> addMixinNames, Set<String> removedOakMixinNames)
-
Methods inherited from class org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate
checkAlive, checkUpdate, save, update
-
-
-
-
Constructor Detail
-
NodeDelegate
public NodeDelegate(SessionDelegate sessionDelegate, Tree tree)
-
-
Method Detail
-
getName
@NotNull public @NotNull String getName()
Description copied from class:ItemDelegate
Get the name of this item- Specified by:
getName
in classItemDelegate
- Returns:
- oak name of this item
-
getPath
@NotNull public @NotNull String getPath()
Description copied from class:ItemDelegate
Get the path of this item- Specified by:
getPath
in classItemDelegate
- Returns:
- oak path of this item
-
getParent
@Nullable public @Nullable NodeDelegate getParent()
Description copied from class:ItemDelegate
Get the parent of this item ornull
.- Specified by:
getParent
in classItemDelegate
- Returns:
- parent of this item or
null
for root or if the parent is not accessible.
-
exists
public boolean exists()
Description copied from class:ItemDelegate
Determine whether the underlying item exists- Specified by:
exists
in classItemDelegate
- Returns:
true
the underlying tree exists,false
otherwise.
-
getStatus
@Nullable public @Nullable Tree.Status getStatus()
Description copied from class:ItemDelegate
Get the status of this item.- Specified by:
getStatus
in classItemDelegate
- Returns:
Tree.Status
of this item ornull
if not available.
-
getIdentifier
@NotNull public @NotNull String getIdentifier() throws InvalidItemStateException
- Throws:
InvalidItemStateException
-
isProtected
public boolean isProtected() throws InvalidItemStateException
- Specified by:
isProtected
in classItemDelegate
- Throws:
InvalidItemStateException
-
isRoot
public boolean isRoot() throws InvalidItemStateException
Determine whether this is the root node- Returns:
true
iff this is the root node- Throws:
InvalidItemStateException
-
getPropertyCount
public long getPropertyCount() throws InvalidItemStateException
Get the number of properties of the node- Returns:
- number of properties of the node
- Throws:
InvalidItemStateException
-
getPropertyOrNull
@Nullable public @Nullable PropertyDelegate getPropertyOrNull(String relPath) throws RepositoryException
Get a property- Parameters:
relPath
- oak path- Returns:
- property at the path given by
relPath
ornull
if no such property exists - Throws:
RepositoryException
-
getProperty
@NotNull public @NotNull PropertyDelegate getProperty(String relPath) throws RepositoryException
Get a property. In contrast togetPropertyOrNull(String)
this method never returnsnull
. In the case where no property exists at the given path, the returned property delegate throws anInvalidItemStateException
on access. See See OAK-395.- Parameters:
relPath
- oak path- Returns:
- property at the path given by
relPath
. - Throws:
RepositoryException
-
getProperties
@NotNull public @NotNull Iterator<PropertyDelegate> getProperties() throws InvalidItemStateException
Get the properties of the node- Returns:
- properties of the node
- Throws:
InvalidItemStateException
-
getChildCount
public long getChildCount(long max) throws InvalidItemStateException
Get the number of child nodesIf an implementation does know the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
- Parameters:
max
- the maximum value- Returns:
- number of child nodes of the node
- Throws:
InvalidItemStateException
-
getChild
@Nullable public @Nullable NodeDelegate getChild(String relPath) throws RepositoryException
Get child node- Parameters:
relPath
- oak path- Returns:
- node at the path given by
relPath
ornull
if no such node exists - Throws:
RepositoryException
-
getChildren
@NotNull public @NotNull Iterator<NodeDelegate> getChildren() throws InvalidItemStateException
Returns an iterator for traversing all the children of this node. If the node is orderable then the iterator will return child nodes in the specified order. Otherwise the ordering of the iterator is undefined.- Returns:
- child nodes of the node
- Throws:
InvalidItemStateException
-
orderBefore
public void orderBefore(String source, String target) throws ItemNotFoundException, InvalidItemStateException
-
canAddMixin
public boolean canAddMixin(String typeName) throws RepositoryException
- Throws:
RepositoryException
-
addMixin
public void addMixin(Function<Tree,Iterable<String>> existingMixins, String typeName) throws RepositoryException
- Throws:
RepositoryException
-
removeMixin
public void removeMixin(String typeName) throws RepositoryException
- Throws:
RepositoryException
-
setMixins
public void setMixins(Set<String> mixinNames) throws RepositoryException
- Throws:
RepositoryException
-
updateMixins
public void updateMixins(Set<String> addMixinNames, Set<String> removedOakMixinNames) throws RepositoryException
- Throws:
RepositoryException
-
setProperty
@NotNull public @NotNull PropertyDelegate setProperty(PropertyState propertyState, boolean exactTypeMatch, boolean setProtected) throws RepositoryException
Set a property- Returns:
- the set property
- Throws:
RepositoryException
-
addChild
@Nullable public @Nullable NodeDelegate addChild(String name, String typeName) throws RepositoryException
Add a child node- Parameters:
name
- Oak name of the new child nodetypeName
- Oak name of the type of the new child node, ornull
if a default type should be used- Returns:
- the added node or
null
if such a node already exists - Throws:
RepositoryException
-
remove
public boolean remove() throws InvalidItemStateException
Remove this node. This operation never succeeds for the root node.- Specified by:
remove
in classItemDelegate
- Returns:
true
if the node was removed;false
otherwise.- Throws:
InvalidItemStateException
-
setOrderableChildren
public void setOrderableChildren(boolean enable) throws InvalidItemStateException
Enables or disabled orderable children on the underlying tree.- Parameters:
enable
- whether to enable or disable orderable children.- Throws:
InvalidItemStateException
-
isLocked
public boolean isLocked()
Checks whether this node is locked, either directly or through a deep lock on an ancestor.- Returns:
- whether this node is locked
-
getLock
@Nullable public @Nullable NodeDelegate getLock()
-
holdsLock
public boolean holdsLock(boolean deep)
Checks whether this node holds a lock.- Parameters:
deep
- iftrue
, only check for deep locks- Returns:
- whether this node holds a lock
-
getLockOwner
public String getLockOwner()
-
isLockOwner
public boolean isLockOwner(String user)
-
lock
public void lock(boolean isDeep) throws RepositoryException
- Throws:
RepositoryException
-
unlock
public void unlock() throws RepositoryException
- Throws:
RepositoryException
-
getTree
@NotNull public @NotNull Tree getTree() throws InvalidItemStateException
- Throws:
InvalidItemStateException
-
-