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
NodeDelegateserve as internal representations ofNodes. Most methods of this class throw anInvalidItemStateExceptionexception 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 NodeDelegateaddChild(String name, String typeName)Add a child nodevoidaddMixin(Function<Tree,Iterable<String>> existingMixins, String typeName)booleancanAddMixin(String typeName)booleanexists()Determine whether the underlying item exists@Nullable NodeDelegategetChild(String relPath)Get child nodelonggetChildCount(long max)Get the number of child nodes@NotNull Iterator<NodeDelegate>getChildren()Returns an iterator for traversing all the children of this node.@NotNull StringgetIdentifier()@Nullable NodeDelegategetLock()StringgetLockOwner()@NotNull StringgetName()Get the name of this item@Nullable NodeDelegategetParent()Get the parent of this item ornull.@NotNull StringgetPath()Get the path of this item@NotNull Iterator<PropertyDelegate>getProperties()Get the properties of the node@NotNull PropertyDelegategetProperty(String relPath)Get a property.longgetPropertyCount()Get the number of properties of the node@Nullable PropertyDelegategetPropertyOrNull(String relPath)Get a property@Nullable Tree.StatusgetStatus()Get the status of this item.@NotNull TreegetTree()booleanholdsLock(boolean deep)Checks whether this node holds a lock.booleanisLocked()Checks whether this node is locked, either directly or through a deep lock on an ancestor.booleanisLockOwner(String user)booleanisProtected()booleanisRoot()Determine whether this is the root nodevoidlock(boolean isDeep)voidorderBefore(String source, String target)booleanremove()Remove this node.voidremoveMixin(String typeName)voidsetMixins(Set<String> mixinNames)voidsetOrderableChildren(boolean enable)Enables or disabled orderable children on the underlying tree.@NotNull PropertyDelegatesetProperty(PropertyState propertyState, boolean exactTypeMatch, boolean setProtected)Set a propertyStringtoString()voidunlock()voidupdateMixins(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:ItemDelegateGet the name of this item- Specified by:
getNamein classItemDelegate- Returns:
- oak name of this item
-
getPath
@NotNull public @NotNull String getPath()
Description copied from class:ItemDelegateGet the path of this item- Specified by:
getPathin classItemDelegate- Returns:
- oak path of this item
-
getParent
@Nullable public @Nullable NodeDelegate getParent()
Description copied from class:ItemDelegateGet the parent of this item ornull.- Specified by:
getParentin classItemDelegate- Returns:
- parent of this item or
nullfor root or if the parent is not accessible.
-
exists
public boolean exists()
Description copied from class:ItemDelegateDetermine whether the underlying item exists- Specified by:
existsin classItemDelegate- Returns:
truethe underlying tree exists,falseotherwise.
-
getStatus
@Nullable public @Nullable Tree.Status getStatus()
Description copied from class:ItemDelegateGet the status of this item.- Specified by:
getStatusin classItemDelegate- Returns:
Tree.Statusof this item ornullif not available.
-
getIdentifier
@NotNull public @NotNull String getIdentifier() throws InvalidItemStateException
- Throws:
InvalidItemStateException
-
isProtected
public boolean isProtected() throws InvalidItemStateException- Specified by:
isProtectedin classItemDelegate- Throws:
InvalidItemStateException
-
isRoot
public boolean isRoot() throws InvalidItemStateExceptionDetermine whether this is the root node- Returns:
trueiff this is the root node- Throws:
InvalidItemStateException
-
getPropertyCount
public long getPropertyCount() throws InvalidItemStateExceptionGet 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
relPathornullif 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 anInvalidItemStateExceptionon 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 InvalidItemStateExceptionGet 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
relPathornullif 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, ornullif a default type should be used- Returns:
- the added node or
nullif such a node already exists - Throws:
RepositoryException
-
remove
public boolean remove() throws InvalidItemStateExceptionRemove this node. This operation never succeeds for the root node.- Specified by:
removein classItemDelegate- Returns:
trueif the node was removed;falseotherwise.- Throws:
InvalidItemStateException
-
setOrderableChildren
public void setOrderableChildren(boolean enable) throws InvalidItemStateExceptionEnables 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
-
-