Class NavuLeaf
- Direct Known Subclasses:
NavuLeafList
NavuLeaf
class corresponds to the
YANG leaf and leaf-list node types.
A NavuLeaf
is a node in the NAVU-Tree that
that does not have any children and holds a value.
To retrieve a value the method value()
should be called
which on first invocation retrieves the value through the current context.
Subsequent calls to the value
method will return the "cached"
value.
It is important to understand that the first call to value
method will cache the value in the instance which means that
subsequent calls to the value
will return the
cached value.
To clear the cache held by an instance of NavuLeaf
, the method
reset()
should be called.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Create an empty leaf node.delete()
Deletes a leaf.deref()
Derefs a leafref and returns the referenced objectsEncodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.boolean
Compares the specified object with thisNavuLeaf
for equality.boolean
exists()
Tests for the existence of the leaf node.getCdbSession
(CdbDBType dbType) Deprecated.Returns the latest change that thisNavuNode
has been a subject to by a transaction.Returns the parent of the node.Returns the root namespace of the topmost ancestor.Read an arbitrary set of sub-elements of a container or list entry.boolean
boolean
isKey()
Returns true if thisNavuLeaf
is a key node.void
reset()
When navigating through NAVU to a certain leaf and retrieving its value, this value will be cached.void
Create an empty leaf node, silently succeeding if the leaf already existsselect
(ConfObject[] query) void
Sets the value of the leaf node.void
Sets the value and tries to perform an update.setChange
(List<ConfObject> kp, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) void
This method is almost identical toset(String)
with the exception that the value should be wrapped inside XML tag.void
Create an empty leaf node, silently succeeding if the leaf already exists and also maintain the FASTMAP reference counter on the leaf.void
Sets the value of a leaf node with FastMap support, creating backpointers and reference counter similar to sharedCreate() All FastMap code shall (in principle) allways use this method instead of set()void
SharedSet using string representation of value.toKey()
Convert the leaf value to a ConfKey.toString()
value()
Returns the effective value on the first call, or cached value in the subsequent calls of this leaf.Returns the Schema aware string representation of a leaf.void
valueUpdateInd
(NavuNode child) Methods inherited from class com.tailf.navu.NavuNode
children, container, container, container, container, context, getChange, getChanges, getChanges, getChanges, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getValues, getXml, hashCode, leaf, leaf, leaf, leaf, leafList, leafList, leafList, leafList, list, list, list, list, namespace, prepareXMLCall, setValues, sharedSetValues, sharedSetValues, startCdbSession, stopCdbSession, xPathSelect, xPathSelectIterate
-
Method Details
-
isKey
public boolean isKey()Returns true if thisNavuLeaf
is a key node.- Returns:
- true whether this
NavuLeaf
is a key node false otherwise
-
delete
Deletes a leaf.- Returns:
- a pointer to self.
- Throws:
NavuException
-
encodeXML
Description copied from class:NavuNode
Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.The returned
ConfXMLParam
array contains no values except for list keys. The leaf elements are encoded asConfXMLParamLeaf
. Therefore, the returning array can be used as a the input parameter toNavuNode.getValues(ConfXMLParam[])
on the current node's parent.NavuNode node = ...; ConfXMLParam[] cxa = node.encodeXML().toArray(new ConfXMLParam[0]); // cxa contains a structure that does not contain values except for // keys in list elements NavuNode parent = node.getParent(); ConfXMLParam[] cxb = parent.getValues(cxa); // cxb contains the same sub-tree with all the values
- Specified by:
encodeXML
in classNavuNode
- Returns:
- A list of
ConfXMLParam
objects corresponding to the sub-tree of this node, with no values except list keys. - Throws:
NavuException
- See Also:
-
encodeValues
Description copied from class:NavuNode
Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.As opposed to
NavuNode.encodeXML()
, the returnedConfXMLParam
array does contain values in the form ofConfXMLParamValue
- Specified by:
encodeValues
in classNavuNode
- Returns:
- A list of
ConfXMLParam
objects corresponding to the sub-tree of this node, including all values. - Throws:
NavuException
- See Also:
-
reset
public void reset()When navigating through NAVU to a certain leaf and retrieving its value, this value will be cached. This method will reset the cache and indicate that the value should be re-read next time the value is retrieved. -
select
- Specified by:
select
in classNavuNode
- Parameters:
path
- a list of regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
select
- Specified by:
select
in classNavuNode
- Parameters:
path
- a "/" separated regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
getValues
Description copied from class:NavuNode
Read an arbitrary set of sub-elements of a container or list entry.The xml string must be pre-populated with tags and parameterized values ("?") which indicate that the operation should read the values of the corresponding tags.
NOTE: The specified xml string should not contain the version tag (<?xml version="1.0" encoding="UTF-8"?>) and do not wrap xml string with current node tag.
Example - Get tree in a service model:list buzz-service { key name; leaf name { type string; } uses ncs:service-data; ncs:servicepoint buzz-service-servicepoint; container buzz { container servers { list server { key "srv-name"; max-elements "64"; leaf srv-name { type string; } leaf ip { type inet:host; mandatory true; } leaf port { type inet:port-number; default "80"; } container foo { leaf bar { type int64; default "42"; } leaf baz { type int64; default "7"; } } list interface { key "if-name"; max-elements "8"; leaf if-name { type string; } leaf mtu { type int64; default "1500"; } } } } } } NavuContainer buzz = ncsRoot.container(buzzService.hash) .list(buzzService._buzz_service) .elem("service1") .container(buzzService._buzz);
ConfXMLParam[] param = buzz.getValues("<buzz xmlns=\"http://com/example/buzzservice\">" + "<servers><server><srv-name>www1</srv-name>" + "<ip>?</ip></server><server>" + "<srv-name>www2</srv-name><ip>?</ip>" + "</server></servers></buzz>");
- Overrides:
getValues
in classNavuNode
- Parameters:
xml
- XML structure corresponding to the part of the configuration tree that is to be fetched.- Throws:
NavuException
-
set
Sets the value of the leaf node.When setting a leaf node the cached value inside the instance is reflected. Subsequent calls to
value
retrieves the cached value.Setting a leaf value is only valid when writing to a transaction or when writing to operational data store.
When writing to the operational data store the write is done with the
CdbLockType.LOCK_REQUEST
lock type set.- Parameters:
val
- - the value to set- Throws:
NavuException
- If an error occurred when setting the leaf value the underlying/caused exception is wrapped inside the NavuException and should be retrieved throughgetCause
method of Throwable.An
IllegalArgumentException
is wrapped inside aNavuException
if writes is done to running withNavuContext
created withCdbSession
orCdb
.
-
setValues
This method is almost identical toset(String)
with the exception that the value should be wrapped inside XML tag.For example to set the value "123" it needs to be wrapped with "<leaf-name>123 </leaf-name>.
- Overrides:
setValues
in classNavuNode
- Parameters:
xml
- A string value wrapped inside XML tag.- Throws:
NavuException
- See Also:
-
set
Sets the value and tries to perform an update. For this to succeed, it must be possible to convert this string value into a value consistent with the type of the NavuLeaf. For example "123" if the YANG model has a leaf of, for example "int32".- Parameters:
val
- The string representation of a new value. For this to succeed, it must be possible to convert this string value into a value consistent with the type of the NavuLeaf. For example "123" if the YANG model has a leaf of, for example "int32".- Throws:
NavuException
-
exists
Tests for the existence of the leaf node.- Specified by:
exists
in classNavuNode
- Returns:
- boolean
- Throws:
NavuException
- on failure
-
create
Create an empty leaf node.- Throws:
NavuException
- on failure to create
-
safeCreate
Create an empty leaf node, silently succeeding if the leaf already exists- Throws:
NavuException
- on failure to create
-
toKey
Convert the leaf value to a ConfKey. This is convenient, but only works for lists that have singleton keys.- Returns:
- the leaf value represented as a key.
- Throws:
NavuException
-
toString
-
value
Returns the effective value on the first call, or cached value in the subsequent calls of this leaf.After this method has been called the first time it stores the value in this object which means that subsequent calls to this method will return the cached value.
- Returns:
- the effective value (first call) or cached value in subsequent calls of this leaf.
- Throws:
NavuException
-
valueAsString
Returns the Schema aware string representation of a leaf.An example of the difference between this method and
toString()
is forConfEnumerations
where the schema aware representation is the label whiletoString()
returns a representation of the ordinal value.- Returns:
- String representation of the leaf
- Throws:
NavuException
-
getChangeFlag
Returns the latest change that thisNavuNode
has been a subject to by a transaction.- Overrides:
getChangeFlag
in classNavuNode
- Returns:
- Flag for the latest change
- See Also:
-
getOldValue
- Returns:
- the old value. null if no old value exists.
-
getParent
Description copied from class:NavuNode
Returns the parent of the node. -
select
-
getCdbSession
Deprecated.This method is deprecated. Use one ofNavuContextBase.getReadConfSession()
,NavuContextBase.getReadConfSession()
orNavuContextBase.getWriteOperSession()
instead.- Overrides:
getCdbSession
in classNavuNode
- Returns:
- The current
CdbSession
or null if this node is attached to aMaapi
context
-
getRootNS
Description copied from class:NavuNode
Returns the root namespace of the topmost ancestor. -
deref
Derefs a leafref and returns the referenced objects- Returns:
- array of keypaths where each keypath is an array of ConfObject
- Throws:
NavuException
-
idrefDerivedOrSelf
- Throws:
NavuException
-
equals
Compares the specified object with thisNavuLeaf
for equality. Returnstrue
if the given object is also aNavuLeaf
and it has the sameConfPath
as thisNavuLeaf
. Note that the actual values held by the leaves (if any) are ignored as they are not relevant to this comparison.
-