Interface Tree
-
public interface TreeA tree instance represents a snapshot of theContentRepositorytree at the time the instance was acquired from aContentSession. Tree instances may become invalid over time due to garbage collection of old content, at which point an outdated snapshot will start throwingIllegalStateExceptions to indicate that the snapshot is no longer available.Order and orderability
The children of aTreeare generally unordered. That is, the sequence of the children returned bygetChildren()may change over time as thisTreeis modified either directly or through some other session. CallingorderBefore(String)will persist the current order and maintain the order as new children are added or removed. In this case a new child will be inserted after the last child as seen bygetChildren().State and state transitions
A tree instance belongs to the client and its state is only modified in response to method calls made by the client. The various accessors on this interface mirror these of the underlyingNodeStateinterface. However, since instances of this class are mutable return values may change between invocations.All tree instances created in the context of a content session become invalid after the content session is closed. Any method called on an invalid tree instance will throw an
InvalidStateException.Treeinstances may become non existing after a call toRoot.refresh(),Root.rebase()orRoot.commit(). Any write access to non existingTreeinstances will cause anInvalidStateException.Thread safety
Tree instances are not thread-safe for write access, so writing clients need to ensure that they are not accessed concurrently from multiple threads. Instances are however thread-safe for read access, so implementations need to ensure that all reading clients see a coherent state.Visibility and access control
The data returned by this class and intermediary objects such as are access controlled governed by theContentSessioninstance from which the containingRootwas obtained.Existence and iterability of trees
The
getChild(String)method is special in that it never returns anullvalue, even if the named tree does not exist. Instead a client should use theexists()method on the returned tree to check whether that tree exists.The iterability of a tree is a related to existence. A node state is iterable if it is included in the return values of the
getChildrenCount(long)andgetChildren()methods. An iterable node is guaranteed to exist, though not all existing nodes are necessarily iterable.Furthermore, a non-existing node is guaranteed to contain no properties or iterable child nodes. It can, however contain non-iterable children. Such scenarios are typically the result of access control restrictions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTree.StatusStatus of an item in aTree
-
Field Summary
Fields Modifier and Type Field Description static Tree[]EMPTY_ARRAYEmpty array of trees.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @NotNull TreeaddChild(@NotNull java.lang.String name)Add a child with the givenname.booleanexists()Determine whether this tree has been removed or does not exist otherwise (e.g.@NotNull TreegetChild(@NotNull java.lang.String name)Get a possibly non existing child of thisTree.@NotNull java.lang.Iterable<Tree>getChildren()All accessible children of thisTreeinstance.longgetChildrenCount(long max)Determine the number of children of thisTreeinstance taking access restrictions into account.@NotNull java.lang.StringgetName()@NotNull TreegetParent()@NotNull java.lang.StringgetPath()@NotNull java.lang.Iterable<? extends PropertyState>getProperties()All accessible property states.@Nullable PropertyStategetProperty(@NotNull java.lang.String name)Get a property statelonggetPropertyCount()Determine the number of properties accessible to the current content session.@Nullable Tree.StatusgetPropertyStatus(@NotNull java.lang.String name)Get theStatusof a property state ornull.@NotNull Tree.StatusgetStatus()Get theStatusof this tree instance.booleanhasChild(@NotNull java.lang.String name)Determine if a child of thisTreeinstance exists.booleanhasProperty(@NotNull java.lang.String name)Determine if a property state exists and is accessible.booleanisRoot()booleanorderBefore(@Nullable java.lang.String name)Orders thisTreebefore the sibling tree with the givenname.booleanremove()Remove this tree instance.voidremoveProperty(@NotNull java.lang.String name)Remove the property with the given name.voidsetOrderableChildren(boolean enable)Changes the nature of this tree such that the order of the children is kept stable.<T> voidsetProperty(@NotNull java.lang.String name, T value)Set a property state<T> voidsetProperty(@NotNull java.lang.String name, T value, @NotNull Type<T> type)Set a property statevoidsetProperty(@NotNull PropertyState property)Set a property state
-
-
-
Field Detail
-
EMPTY_ARRAY
static final Tree[] EMPTY_ARRAY
Empty array of trees.
-
-
Method Detail
-
getName
@NotNull @NotNull java.lang.String getName()
- Returns:
- the name of this
Treeinstance.
-
isRoot
boolean isRoot()
- Returns:
trueiff this is the root
-
getPath
@NotNull @NotNull java.lang.String getPath()
- Returns:
- the absolute path of this
Treeinstance from itsRoot.
-
getStatus
@NotNull @NotNull Tree.Status getStatus()
Get theStatusof this tree instance.- Returns:
- The status of this tree instance.
-
exists
boolean exists()
Determine whether this tree has been removed or does not exist otherwise (e.g. caused by a refresh, rebase or commit) or is not visible due to access control restriction or does not exist at all.- Returns:
trueif this tree exists,falseotherwise.
-
getParent
@NotNull @NotNull Tree getParent()
- Returns:
- the possibly non existent parent of this
Tree. - Throws:
java.lang.IllegalStateException- if called on the root tree.
-
getProperty
@Nullable @Nullable PropertyState getProperty(@NotNull @NotNull java.lang.String name)
Get a property state- Parameters:
name- The name of the property state.- Returns:
- the property state with the given
nameornullif no such property state exists or the property is not accessible.
-
getPropertyStatus
@Nullable @Nullable Tree.Status getPropertyStatus(@NotNull @NotNull java.lang.String name)
Get theStatusof a property state ornull.- Parameters:
name- The name of the property state.- Returns:
- The status of the property state with the given
nameornullin no such property state exists or if the name refers to a property that is not accessible.
-
hasProperty
boolean hasProperty(@NotNull @NotNull java.lang.String name)Determine if a property state exists and is accessible.- Parameters:
name- The name of the property state- Returns:
trueif and only if a property with the givennameexists and is accessible.
-
getPropertyCount
long getPropertyCount()
Determine the number of properties accessible to the current content session.- Returns:
- The number of accessible properties.
-
getProperties
@NotNull @NotNull java.lang.Iterable<? extends PropertyState> getProperties()
All accessible property states. The returnedIterablehas snapshot semantics. That is, it reflect the state of thisTreeinstance at the time of the call. Later changes to this instance are no visible to iterators obtained from the returned iterable.- Returns:
- An
Iterablefor all accessible property states.
-
getChild
@NotNull @NotNull Tree getChild(@NotNull @NotNull java.lang.String name) throws java.lang.IllegalArgumentException
Get a possibly non existing child of thisTree.- Parameters:
name- The name of the child to retrieve.- Returns:
- The child with the given
name. - Throws:
java.lang.IllegalArgumentException- if the given name is invalid
-
hasChild
boolean hasChild(@NotNull @NotNull java.lang.String name)Determine if a child of thisTreeinstance exists. If no child exists or an existing child isn't accessible this method returnsfalse.- Parameters:
name- The name of the child- Returns:
trueif and only if a child with the givennameexists and is accessible for the current content session.
-
getChildrenCount
long getChildrenCount(long max)
Determine the number of children of thisTreeinstance taking access restrictions into account.If 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:
- the number of accessible children.
-
getChildren
@NotNull @NotNull java.lang.Iterable<Tree> getChildren()
All accessible children of thisTreeinstance. The returnedIterablehas snapshot semantics. That is, it reflect the state of thisTreeinstance at the time of the call. Later changes to this instance are not visible to iterators obtained from the returned iterable.- Returns:
- An
Iterablefor all accessible children
-
remove
boolean remove()
Remove this tree instance. This operation never succeeds for the root tree.- Returns:
trueif the node was removed;falseotherwise.
-
addChild
@NotNull @NotNull Tree addChild(@NotNull @NotNull java.lang.String name) throws java.lang.IllegalArgumentException
Add a child with the givenname. Does nothing if such a child already exists.- Parameters:
name- name of the child. A valid name does not start with a colon, is not empty and does not contain a forward slash.- Returns:
- the
Treeinstance of the child with the givenname. - Throws:
java.lang.IllegalArgumentException- ifnameis not valid.
-
setOrderableChildren
void setOrderableChildren(boolean enable)
Changes the nature of this tree such that the order of the children is kept stable. The expected behavior is as follows:- Calling
setOrderableChildren(true)on a tree the first time will stabilize the order of existing children. Any subsequentaddChild(String)call is guaranteed to insert the new tree and the end of the child list. - Calling
setOrderableChildren(true)on a tree that already has its children ordered has no effect. - Calling
setOrderableChildren(false)on a tree that doesn't have ordered children has not effect - Calling
setOrderableChildren(false)on a tree with ordered children will remove the necessity to keep the child list stable. The order of children upongetChildren()is subsequently undefined.
Calling
orderBefore(String)on a tree, implicitly enables orderable children on the parent tree.- Parameters:
enable- Enable (or disable) orderable children for this tree.
- Calling
-
orderBefore
boolean orderBefore(@Nullable @Nullable java.lang.String name)Orders thisTreebefore the sibling tree with the givenname. Calling this method for the first time on thisTreeor any of its siblings will persist the current order of siblings and maintain it from this point on.- Parameters:
name- the name of the sibling node where this tree is ordered before. This tree will become the last sibling ifnameisnull.- Returns:
falseif there is no sibling with the givennameor no reordering was performed;trueotherwise.- Throws:
java.lang.IllegalArgumentException- if the given name is invalid
-
setProperty
void setProperty(@NotNull @NotNull PropertyState property)Set a property state- Parameters:
property- The property state to set- Throws:
java.lang.IllegalArgumentException- ifpropertyhas a non valid name. A valid name does not start with a colon, is not empty and does not contain a forward slash.
-
setProperty
<T> void setProperty(@NotNull @NotNull java.lang.String name, @NotNull T value) throws java.lang.IllegalArgumentExceptionSet a property state- Type Parameters:
T- The type of this property. Must be one ofString, Blob, byte[], Long, Integer, Double, Boolean, BigDecimal- Parameters:
name- The name of this property. A valid name does not start with a colon, is not empty and does not contain a forward slash.value- The value of this property- Throws:
java.lang.IllegalArgumentException- ifTis not one of the above types or ifnameis not valid.
-
setProperty
<T> void setProperty(@NotNull @NotNull java.lang.String name, @NotNull T value, @NotNull @NotNull Type<T> type) throws java.lang.IllegalArgumentExceptionSet a property state- Type Parameters:
T- The type of this property.- Parameters:
name- The name of this property. A valid name does not start with a colon, is not empty and does not contain a forward slash.value- The value of this propertytype- The type of this property.- Throws:
java.lang.IllegalArgumentException- ifnameis not valid.
-
removeProperty
void removeProperty(@NotNull @NotNull java.lang.String name)Remove the property with the given name. This method has no effect if a property of the givennamedoes not exist.- Parameters:
name- The name of the property
-
-