public class TrackedNodeModel extends Object implements NodeModel<ImmutableNode>
 A specialized NodeModel implementation that uses a tracked node
 managed by an InMemoryNodeModel object as root node.
 
 Models of this type are useful when working on specific sub trees of a nodes
 structure. This is the case for instance for a SubnodeConfiguration.
 
 An instance of this class is constructed with an
 InMemoryNodeModelSupport object providing a reference to the
 underlying InMemoryNodeModel and the NodeSelector pointing to
 the tracked node acting as this model's root node. The NodeModel
 operations are implemented by delegating to the wrapped
 InMemoryNodeModel object specifying the selector to the tracked node
 as target root node for the update transaction. Note that the tracked node
 can become detached at any time. This situation is handled transparently by
 the implementation of InMemoryNodeModel. The reason for using an
 InMemoryNodeModelSupport object rather than an
 InMemoryNodeModel directly is that this additional layer of
 indirection can be used for performing special initializations on the model
 before it is returned to the TrackedNodeModel object. This is needed
 by some dynamic configuration implementations, e.g. by
 CombinedConfiguration.
 
 If the tracked node acting as root node is exclusively used by this model, it
 should be released when this model is no longer needed. This can be done
 manually by calling the close() method. It is also possible to pass
 a value of true to the untrackOnFinalize argument of
 the constructor. This causes close() to be called automatically if
 this object gets claimed by the garbage collector.
 
 As InMemoryNodeModel, this class is thread-safe.
 
| Constructor and Description | 
|---|
TrackedNodeModel(InMemoryNodeModelSupport modelSupport,
                NodeSelector sel,
                boolean untrackOnFinalize)
Creates a new instance of  
TrackedNodeModel and initializes it
 with the given underlying model and the selector to the root node. | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
addNodes(String key,
        Collection<? extends ImmutableNode> nodes,
        NodeKeyResolver<ImmutableNode> resolver)
Adds a collection of new nodes to this model. 
 | 
void | 
addProperty(String key,
           Iterable<?> values,
           NodeKeyResolver<ImmutableNode> resolver)
Adds a new property to this node model consisting of an arbitrary number
 of values. 
 | 
void | 
clear(NodeKeyResolver<ImmutableNode> resolver)
Removes all data from this model. 
 | 
void | 
clearProperty(String key,
             NodeKeyResolver<ImmutableNode> resolver)
Clears the value of a property. 
 | 
List<QueryResult<ImmutableNode>> | 
clearTree(String key,
         NodeKeyResolver<ImmutableNode> resolver)
Removes the sub trees defined by the given key from this model. 
 | 
void | 
close()
Closes this model. 
 | 
protected void | 
finalize()
 This implementation calls  
close() if the
 untrackOnFinalize flag was set when this instance was
 constructed. | 
ImmutableNode | 
getInMemoryRepresentation()
Returns a representation of the data stored in this model in form of a
 nodes hierarchy of  
ImmutableNode objects. | 
NodeHandler<ImmutableNode> | 
getNodeHandler()
Returns a  
NodeHandler for dealing with the nodes managed by this
 model. | 
InMemoryNodeModel | 
getParentModel()
Returns the parent model. 
 | 
InMemoryNodeModelSupport | 
getParentModelSupport()
Returns the  
InMemoryNodeModelSupport object which is used to gain
 access to the underlying node model. | 
NodeSelector | 
getSelector()
Returns the  
NodeSelector pointing to the tracked node managed by
 this model. | 
boolean | 
isReleaseTrackedNodeOnFinalize()
Returns the flag whether the managed tracked node is to be released when
 this object gets finalized. 
 | 
void | 
setProperty(String key,
           Object value,
           NodeKeyResolver<ImmutableNode> resolver)
Changes the value of a property. 
 | 
void | 
setRootNode(ImmutableNode newRoot)
Sets a new root node for this model. 
 | 
public TrackedNodeModel(InMemoryNodeModelSupport modelSupport, NodeSelector sel, boolean untrackOnFinalize)
TrackedNodeModel and initializes it
 with the given underlying model and the selector to the root node. The
 boolean argument controls whether the associated tracked node should be
 released when this object gets finalized. This allows the underlying
 model to free some resources. If used as model within a
 SubnodeConfiguration, there is typically no way to discard the
 model explicitly. Therefore, it makes sense to do this automatically on
 finalization.modelSupport - the underlying InMemoryNodeModelSupport (must not be
        null)sel - the selector to the root node of this model (must not be
        null)untrackOnFinalize - a flag whether the tracked node should be
        released on finalizationIllegalArgumentException - if a required parameter is missingpublic InMemoryNodeModelSupport getParentModelSupport()
InMemoryNodeModelSupport object which is used to gain
 access to the underlying node model.InMemoryNodeModelSupport objectpublic InMemoryNodeModel getParentModel()
public NodeSelector getSelector()
NodeSelector pointing to the tracked node managed by
 this model.public boolean isReleaseTrackedNodeOnFinalize()
InMemoryNodeModel.untrackNode(NodeSelector)public void setRootNode(ImmutableNode newRoot)
NodeModelsetRootNode in interface NodeModel<ImmutableNode>newRoot - the new root node to be set (can be null, then an
        empty root node is set)public NodeHandler<ImmutableNode> getNodeHandler()
NodeModelNodeHandler for dealing with the nodes managed by this
 model.getNodeHandler in interface NodeModel<ImmutableNode>NodeHandlerpublic void addProperty(String key, Iterable<?> values, NodeKeyResolver<ImmutableNode> resolver)
NodeModelNodeAddData object defining the add operation to be performed.addProperty in interface NodeModel<ImmutableNode>key - the keyvalues - the values to be added at the position defined by the keyresolver - the NodeKeyResolverpublic void addNodes(String key, Collection<? extends ImmutableNode> nodes, NodeKeyResolver<ImmutableNode> resolver)
NodeModeladdNodes() method of the HierarchicalConfiguration
 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 in NodeKeyResolver is used to interpret the given key.addNodes in interface NodeModel<ImmutableNode>key - the keynodes - the collection of nodes to be added (may be null)resolver - the NodeKeyResolverpublic void setProperty(String key, Object value, NodeKeyResolver<ImmutableNode> resolver)
NodeModelNodeKeyResolver which will produce a corresponding
 NodeUpdateData object. Based on the content of this object,
 update operations are performed.setProperty in interface NodeModel<ImmutableNode>key - the keyvalue - the new value for this property (to be evaluated by the
        NodeKeyResolver)resolver - the NodeKeyResolverpublic List<QueryResult<ImmutableNode>> clearTree(String key, NodeKeyResolver<ImmutableNode> resolver)
NodeModelNodeKeyResolver and removed from the model.clearTree in interface NodeModel<ImmutableNode>key - the key selecting the properties to be removedresolver - the NodeKeyResolverpublic void clearProperty(String key, NodeKeyResolver<ImmutableNode> resolver)
NodeModelNodeModel.clearTree(String, NodeKeyResolver): However, the nodes
 referenced by the passed in key are not removed completely, but only
 their value is set to null.clearProperty in interface NodeModel<ImmutableNode>key - the key selecting the properties to be clearedresolver - the NodeKeyResolverpublic void clear(NodeKeyResolver<ImmutableNode> resolver)
clear in interface NodeModel<ImmutableNode>resolver - the NodeKeyResolver.public ImmutableNode getInMemoryRepresentation()
ImmutableNode 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. This implementation returns the tracked node instance
 acting as root node of this model.getInMemoryRepresentation in interface NodeModel<ImmutableNode>public void close()
InMemoryNodeModel.untrackNode(NodeSelector)
 is called). This method should be called when this model is no longer
 needed. This implementation is idempotent; it is safe to call
 close() multiple times - only the first invocation has an effect.
 After this method has been called this model can no longer be used
 because there is no guarantee that the node can still be accessed from
 the parent model.protected void finalize()
                 throws Throwable
close() if the
 untrackOnFinalize flag was set when this instance was
 constructed. While this is not 100 percent reliable, it is better than
 keeping the tracked node hanging around. Note that it is not a problem if
 close() already had been invoked manually because this method is
 idempotent.Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.