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 TypeMethodDescriptionvoidcreate()Create an empty leaf node.delete()Deletes a leaf.deref()Derefs a leafref and returns the referenced objectsEncodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.Encodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.booleanCompares the specified object with thisNavuLeaffor equality.booleanexists()Tests for the existence of the leaf node.Returns the latest change that thisNavuNodehas 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.inthashCode()Return the hashCode of this NavuNode.booleanbooleanisKey()Returns true if thisNavuLeafis a key node.voidreset()When navigating through NAVU to a certain leaf and retrieving its value, this value will be cached.voidCreate an empty leaf node, silently succeeding if the leaf already existsselect(ConfObject[] query) voidSets the value of the leaf node.voidSets the value and tries to perform an update.setChange(List<ConfObject> kp, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) voidThis method is almost identical toset(String)with the exception that the value should be wrapped inside XML tag.voidCreate an empty leaf node, silently succeeding if the leaf already exists and also maintain the FASTMAP reference counter on the leaf.voidSets 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()voidSharedSet 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.voidvalueUpdateInd(NavuNode child) Methods inherited from class com.tailf.navu.NavuNode
children, container, container, container, context, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getValues, leaf, leaf, leaf, leafList, leafList, leafList, list, list, list, namespace, prepareXMLCall, setValues, sharedSetValues, sharedSetValues, stopCdbSession, xPathSelect, xPathSelectIterate
-
Method Details
-
isKey
public boolean isKey()Returns true if thisNavuLeafis a key node.- Returns:
- true whether this
NavuLeafis a key node false otherwise
-
delete
Deletes a leaf.- Returns:
- a pointer to self.
- Throws:
NavuException
-
encodeXML
Description copied from class:NavuNodeEncodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.The returned
ConfXMLParamarray 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:
encodeXMLin classNavuNode- Returns:
- A list of
ConfXMLParamobjects corresponding to the sub-tree of this node, with no values except list keys. - Throws:
NavuException- See Also:
-
encodeValues
Description copied from class:NavuNodeEncodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.As opposed to
NavuNode.encodeXML(), the returnedConfXMLParamarray does contain values in the form ofConfXMLParamValue- Specified by:
encodeValuesin classNavuNode- Returns:
- A list of
ConfXMLParamobjects 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:
selectin classNavuNode- Parameters:
path- a list of regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
select
- Specified by:
selectin classNavuNode- Parameters:
path- a "/" separated regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
getValues
Description copied from class:NavuNodeRead 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:
getValuesin 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
valueretrieves 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_REQUESTlock 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 throughgetCausemethod of Throwable.An
IllegalArgumentExceptionis wrapped inside aNavuExceptionif writes is done to running withNavuContextcreated withCdbSessionorCdb.
-
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:
setValuesin 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:
existsin 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 forConfEnumerationswhere 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 thisNavuNodehas been a subject to by a transaction.- Overrides:
getChangeFlagin 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:NavuNodeReturns the parent of the node. -
select
-
getRootNS
Description copied from class:NavuNodeReturns 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 thisNavuLeaffor equality. Returnstrueif the given object is also aNavuLeafand it has the sameConfPathas thisNavuLeaf. Note that the actual values held by the leaves (if any) are ignored as they are not relevant to this comparison. -
hashCode
public int hashCode()Description copied from class:NavuNodeReturn the hashCode of this NavuNode. For most nodes, the hash code is based on theConfPathof the node. For module root containers there is noConfPathand instead the hash code is based on the hash code of the module schema.
-