Interface NodeModel<T>
- Type Parameters:
T
- the type of the nodes managed by this model
- All Known Implementing Classes:
InMemoryNodeModel
,TrackedNodeModel
Definition of an interface describing a model based on a nodes structure.
This interface can be used for dealing with hierarchical, tree-like data. It defines basic operations for manipulating the tree structure which use keys to select the nodes affected.
The idea behind this interface is that concrete implementations can be used by hierarchical configurations. This
makes it possible to integrate various hierarchical structures with the API of a hierarchical configuration, e.g.
configuration nodes stored in memory, JNDI contexts, or other structures. The configuration object interacts with the
underlying data structure via this interface. For more complex operations access to an ExpressionEngine
may
be required in order to interpret the passed in keys. For these purposes a NodeKeyResolver
has to be provided
which knows how to deal with keys.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNodes
(String key, Collection<? extends T> nodes, NodeKeyResolver<T> resolver) Adds a collection of new nodes to this model.void
addProperty
(String key, Iterable<?> values, NodeKeyResolver<T> resolver) Adds a new property to this node model consisting of an arbitrary number of values.void
clear
(NodeKeyResolver<T> resolver) Removes all data from this model.void
clearProperty
(String key, NodeKeyResolver<T> resolver) Clears the value of a property.clearTree
(String key, NodeKeyResolver<T> resolver) Removes the sub trees defined by the given key from this model.Gets a representation of the data stored in this model in form of a nodes hierarchy ofImmutableNode
objects.Gets aNodeHandler
for dealing with the nodes managed by this model.void
setProperty
(String key, Object value, NodeKeyResolver<T> resolver) Changes the value of a property.void
setRootNode
(T newRoot) Sets a new root node for this model.
-
Method Details
-
addNodes
Adds a collection of new nodes to this model. This operation corresponds to theaddNodes()
method of theHierarchicalConfiguration
interface. The new nodes are either added to an existing node (if the passed in key selects exactly one node) or to a newly created node. The passed inNodeKeyResolver
is used to interpret the given key.- Parameters:
key
- the keynodes
- the collection of nodes to be added (may be null)resolver
- theNodeKeyResolver
- Throws:
IllegalArgumentException
- if the key references an attribute (of course, it is not possible to add something to an attribute)
-
addProperty
Adds a new property to this node model consisting of an arbitrary number of values. The key for the add operation is provided. For each value a new node has to be added. The passed in resolver is queried for aNodeAddData
object defining the add operation to be performed.- Parameters:
key
- the keyvalues
- the values to be added at the position defined by the keyresolver
- theNodeKeyResolver
-
clear
Removes all data from this model.- Parameters:
resolver
- theNodeKeyResolver
-
clearProperty
Clears the value of a property. This method is similar toclearTree(String, NodeKeyResolver)
: However, the nodes referenced by the passed in key are not removed completely, but only their value is set to null.- Parameters:
key
- the key selecting the properties to be clearedresolver
- theNodeKeyResolver
-
clearTree
Removes the sub trees defined by the given key from this model. All nodes selected by this key are retrieved from the specifiedNodeKeyResolver
and removed from the model.- Parameters:
key
- the key selecting the properties to be removedresolver
- theNodeKeyResolver
- Returns:
- an object with information about the data removed
-
getInMemoryRepresentation
Gets a representation of the data stored in this model in form of a nodes hierarchy ofImmutableNode
objects. A concrete model implementation can use an arbitrary means to store its data. When a model's data is to be used together with other functionality of the Configuration library (e.g. when combining multiple configuration sources) it has to be transformed into a common format. This is done by this method.ImmutableNode
is a generic representation of a hierarchical structure. Thus, it should be possible to generate a corresponding structure from arbitrary model data.- Returns:
- the root node of an in-memory hierarchy representing the data stored in this model
-
getNodeHandler
Gets aNodeHandler
for dealing with the nodes managed by this model.- Returns:
- the
NodeHandler
-
setProperty
Changes the value of a property. This is a more complex operation as it might involve adding, updating, or deleting nodes and attributes from the model. The object representing the new value is passed to theNodeKeyResolver
which will produce a correspondingNodeUpdateData
object. Based on the content of this object, update operations are performed.- Parameters:
key
- the keyvalue
- the new value for this property (to be evaluated by theNodeKeyResolver
)resolver
- theNodeKeyResolver
-
setRootNode
Sets a new root node for this model. The whole structure is replaced by the new node and its children.- Parameters:
newRoot
- the new root node to be set (can be null, then an empty root node is set)
-