public interface NodeBuilder
node states.
A node builder can be thought of as a mutable version of a node state.
In addition to property and child node access methods like the ones that
are already present in the NodeState interface, the NodeBuilder
interface contains the following key methods:
setProperty and removeProperty methods for
modifying propertiesgetChildNode method for accessing or modifying an existing
subtreesetChildNode and removeChildNode methods for adding,
replacing or removing a subtreeexists method for checking whether the node represented by
a builder exists or is accessiblegetNodeState method for getting a frozen snapshot of the
modified content tree
NodeBuilder rootBuilder = root.builder();
NodeBuilder fooBuilder = rootBuilder.getChildNode("foo");
NodeBuilder barBuilder = fooBuilder.getChildNode("bar");
assert !barBuilder.getBoolean("x");
fooBuilder.getChildNode("bar").setProperty("x", Boolean.TRUE);
assert barBuilder.getBoolean("x");
assert barBuilder.exists();
fooBuilder.removeChildNode("bar");
assert !barBuilder.exists();
The getNodeState method returns a frozen, immutable snapshot of the current
state of the builder. Providing such a snapshot can be somewhat expensive especially
if there are many changes in the builder, so the method should generally only be used
as the last step after all intended changes have been made. Meanwhile the accessors
in the NodeBuilder interface can be used to provide efficient read access to
the current state of the tree being modified.
The node states constructed by a builder often retain an internal reference to the base state used by the builder. This allows common node state comparisons to perform really.
| Modifier and Type | Method and Description |
|---|---|
NodeBuilder |
child(String name)
Returns a builder for constructing changes to the named child node.
|
org.apache.jackrabbit.oak.api.Blob |
createBlob(InputStream stream) |
boolean |
exists()
Checks whether this builder represents a node that exists.
|
NodeState |
getBaseState()
Returns the original base state that this builder is modifying.
|
boolean |
getBoolean(String name)
Returns the boolean value of the named property.
|
NodeBuilder |
getChildNode(String name)
Returns a builder for constructing changes to the named child node.
|
long |
getChildNodeCount(long max)
Returns the current number of child nodes.
|
Iterable<String> |
getChildNodeNames()
Returns the names of current child nodes.
|
String |
getName(String name)
Returns the name value of the named property.
|
Iterable<String> |
getNames(String name)
Returns the name values of the named property.
|
NodeState |
getNodeState()
Returns an immutable node state that matches the current state of
the builder.
|
Iterable<? extends org.apache.jackrabbit.oak.api.PropertyState> |
getProperties()
Returns the current properties.
|
org.apache.jackrabbit.oak.api.PropertyState |
getProperty(String name)
Returns the current state of the named property, or
null
if the property is not set. |
long |
getPropertyCount()
Returns the current number of properties.
|
String |
getString(String name)
Returns the name value of the named property.
|
boolean |
hasChildNode(String name)
Checks whether the named child node currently exists.
|
boolean |
hasProperty(String name)
Checks whether the named property exists.
|
boolean |
isModified()
Check whether this builder represents a modified node, which has either modified properties
or removed or added child nodes.
|
boolean |
isNew()
Check whether this builder represents a new node, which is not present in the base state.
|
boolean |
isNew(String name)
Check whether the named property is new, i.e.
|
boolean |
isReplaced()
Check whether this builder represents a node that used to exist but
was then replaced with other content, for example as a result of
a
setChildNode(String) call. |
boolean |
isReplaced(String name)
Check whether the named property exists in the base state but is
replaced with other content, for example as a result of
a
setProperty(PropertyState) call. |
boolean |
moveTo(NodeBuilder newParent,
String newName)
Move this child to a new parent with a new name.
|
boolean |
remove()
Remove this child node from its parent.
|
NodeBuilder |
removeProperty(String name)
Remove the named property.
|
NodeBuilder |
setChildNode(String name)
Adds the named child node and returns a builder for modifying it.
|
NodeBuilder |
setChildNode(String name,
NodeState nodeState)
Adds or replaces a subtree.
|
NodeBuilder |
setProperty(org.apache.jackrabbit.oak.api.PropertyState property)
Set a property state
|
<T> NodeBuilder |
setProperty(String name,
T value)
Set a property state
|
<T> NodeBuilder |
setProperty(String name,
T value,
org.apache.jackrabbit.oak.api.Type<T> type)
Set a property state
|
@Nonnull NodeState getNodeState()
@Nonnull NodeState getBaseState()
exists method
returns false) if this builder represents a new node that
didn't exist in the base content tree.boolean exists()
true if the node exists, false otherwiseboolean isNew()
true for a new nodeboolean isNew(String name)
name - property nametrue for a new propertyboolean isModified()
true for a modified nodeboolean isReplaced()
setChildNode(String) call.true for a replaced nodeboolean isReplaced(String name)
setProperty(PropertyState) call.name - property nametrue for a replaced propertylong getChildNodeCount(long max)
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).
max - the maximum value@Nonnull Iterable<String> getChildNodeNames()
boolean hasChildNode(@Nonnull String name)
name - child node nametrue if the named child node exists,
false otherwise@Nonnull NodeBuilder child(@Nonnull String name) throws IllegalArgumentException
All updates to the returned child builder will implicitly affect
also this builder, as if a
setNode(name, childBuilder.getNodeState()) method call
had been made after each update. Repeated calls to this method with
the same name will return the same child builder instance until an
explicit setChildNode(String, NodeState) or
remove() call is made, at which point the link
between this builder and a previously returned child builder for
that child node name will get broken.
name - name of the child nodeIllegalArgumentException - if the given name string is empty
or contains the forward slash character@Nonnull NodeBuilder getChildNode(@Nonnull String name) throws IllegalArgumentException
IllegalStateExceptions to be thrown.name - name of the child nodeIllegalArgumentException - if the given name string is empty
or contains the forward slash character@Nonnull NodeBuilder setChildNode(@Nonnull String name) throws IllegalArgumentException
name - name of the child nodeIllegalArgumentException - if the given name string is empty
or contains the forward slash character@Nonnull NodeBuilder setChildNode(@Nonnull String name, @Nonnull NodeState nodeState) throws IllegalArgumentException
name - name of the child node containing the new subtreenodeState - subtreeIllegalArgumentException - if the given name string is empty
or contains the forward slash characterboolean remove()
true for existing nodes, false otherwiseboolean moveTo(@Nonnull NodeBuilder newParent, @Nonnull String newName) throws IllegalArgumentException
newParent as child newName. Otherwise neither
this builder nor newParent are modified.
The move succeeds if both, this builder and newParent exist, there is no child with
newName at newParent and newParent is not in the subtree of this
builder.
The move fails if the this builder or newParent does not exist or if there is
already a child newName at newParent.
For all remaining cases (e.g. moving a builder into its own subtree) it is left to the implementation whether the move succeeds or fails as long as the state of the involved builder stays consistent.
newParent - builder for the new parent.newName - name of this child at the new parenttrue on success, false otherwiseIllegalArgumentException - if the given name string is empty
or contains the forward slash characterlong getPropertyCount()
@Nonnull Iterable<? extends org.apache.jackrabbit.oak.api.PropertyState> getProperties()
boolean hasProperty(String name)
getProperty(name) != null, but may be optimized
to avoid having to load the property value.name - property nametrue if the named property exists,
false otherwise@CheckForNull org.apache.jackrabbit.oak.api.PropertyState getProperty(String name)
null
if the property is not set.name - property nameboolean getBoolean(@Nonnull String name)
PropertyState property = builder.getProperty(name);
return property != null
&& property.getType() == Type.BOOLEAN
&& property.getValue(Type.BOOLEAN);
name - property namefalse@CheckForNull String getString(String name)
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.STRING) {
return property.getValue(Type.STRING);
} else {
return null;
}
name - property namenull@CheckForNull String getName(@Nonnull String name)
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAME) {
return property.getValue(Type.NAME);
} else {
return null;
}
name - property namenull@Nonnull Iterable<String> getNames(@Nonnull String name)
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAMES) {
return property.getValue(Type.NAMES);
} else {
return Collections.emptyList();
}
name - property name@Nonnull NodeBuilder setProperty(@Nonnull org.apache.jackrabbit.oak.api.PropertyState property) throws IllegalArgumentException
property - The property state to setIllegalArgumentException - if the property name is empty
or contains the forward slash character@Nonnull <T> NodeBuilder setProperty(String name, @Nonnull T value) throws IllegalArgumentException
T - The type of this property. Must be one of String, Blob, byte[], Long, Integer, Double, Boolean, BigDecimalname - The name of this propertyvalue - The value of this propertyIllegalArgumentException - if T is not one of the above types, or if the property name is empty or contains the forward slash character@Nonnull <T> NodeBuilder setProperty(String name, @Nonnull T value, org.apache.jackrabbit.oak.api.Type<T> type) throws IllegalArgumentException
T - The type of this property.name - The name of this propertyvalue - The value of this propertyIllegalArgumentException - if the property name is empty
or contains the forward slash character@Nonnull NodeBuilder removeProperty(String name)
name does not exist.name - name of the propertyorg.apache.jackrabbit.oak.api.Blob createBlob(InputStream stream) throws IOException
IOExceptionCopyright © 2012–2017 The Apache Software Foundation. All rights reserved.