public class NavuLeaf extends NavuNode
NavuLeaf class corresponding to the
Yang leaf and leaf-list node types.
A NavuLeaf is a node in the Navutree 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 retrieve the value through the current context.
Subsequent calls to value method returns 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
cache.
To clear the cached hold by the instance of NavuLeaf
value the method reset() should be called.
| Modifier and Type | Method and Description |
|---|---|
void |
create()
Create an empty leaf node.
|
NavuLeaf |
delete()
Deletes a leaf.
|
List<NavuNode> |
deref()
Derefs a leafref and returns the referenced objects
|
List<ConfXMLParam> |
encodeValues()
Encoding the sub-tree including the current
NavuNode
as the topmost NavuNode to a ConfXMLParam array. |
List<ConfXMLParam> |
encodeXML()
Encoding the sub-tree including the current
NavuNode
as the topmost NavuNode to a ConfXMLParam array. |
boolean |
equals(Object o)
Check the equality of this NavuNode against the targeted
NavuNode.
|
boolean |
exists()
Tests for the existence of the leaf node.
|
CdbSession |
getCdbSession(CdbDBType dbType)
Deprecated.
|
DiffIterateOperFlag |
getChangeFlag()
Returns the latest change that this
NavuNode has
been a subject to by a transaction. |
ConfValue |
getOldValue() |
NavuNode |
getParent()
Returns the parent of the node.
|
ConfNamespace |
getRootNS()
Returns the root namespace of the topmost ancestor.
|
ConfXMLParam[] |
getValues(String xml)
Read an arbitrary set of sub-elements of a container element.
|
int |
hashCode()
Return the hashCode of this NavuNode.
|
boolean |
isKey()
Returns true if this NavuLeaf is a key node.
|
void |
reset()
When navigating through NAVU to a certain leaf and retrieving its value,
this value will be cached.
|
void |
safeCreate()
Create an empty leaf node, silently succeeding
if the leaf already exists
|
Collection<NavuNode> |
select(ConfObject[] query) |
Collection<NavuNode> |
select(List<String> path) |
Collection<NavuNode> |
select(String path) |
void |
set(ConfValue val)
Sets the value of the leaf node.
|
void |
set(String val)
Sets the value and tries to perform an update.
|
NavuNode |
setChange(List<ConfObject> kp,
DiffIterateOperFlag op,
ConfValue oldValue,
NavuContext delContext) |
void |
setValues(String xml)
This method is almost identical to
set(String) with the
exception that the value should be wrapped inside XML tag. |
void |
sharedCreate()
Create an empty leaf node, silently succeeding
if the leaf already exists and also maintain the
FASTMAP reference counter on the leaf.
|
void |
sharedSet(ConfValue val)
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(String val)
SharedSet using string representation of value.
|
ConfKey |
toKey()
Convert the leaf value to a ConfKey.
|
String |
toString() |
ConfValue |
value()
Returns the effective value on the first call,
or cached value in the subsequent calls
of this leaf.
|
String |
valueAsString()
Returns the Schema aware string representation of a leaf.
|
void |
valueUpdateInd(NavuNode child) |
children, container, container, container, context, getChange, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getValues, getXml, leaf, leaf, leaf, list, list, list, prepareXMLCall, setValues, sharedSetValues, sharedSetValues, startCdbSession, stopCdbSession, xPathSelect, xPathSelectIteratepublic void create()
throws NavuException
NavuException - on failure to createpublic NavuLeaf delete() throws NavuException
NavuExceptionpublic List<NavuNode> deref() throws NavuException
NavuExceptionpublic List<ConfXMLParam> encodeValues() throws NavuException
NavuNodeNavuNode
as the topmost NavuNode to a ConfXMLParam array.
As opposed to encodeXML, the returning ConfXMLParam array
does contain values in form of ConfXMLParamValue
encodeValues in class NavuNodeConfXMLParam of the sub-tree
including valuesNavuException - If the operation could not be performed for some reasonsConfXMLParam,
ConfXMLParamValuepublic List<ConfXMLParam> encodeXML() throws NavuException
NavuNodeNavuNode
as the topmost NavuNode to a ConfXMLParam array.
The returning ConfXMLParam array contains no values except
for list keys. The leaf elements are encoded as ConfXMLParamLeaf
therefore the returning array could be used as a input parameter
to NavuNode.getValues(ConfXMLParam[]) on the current elements parent.
NavuNode node = ...; //cxa contains structure that does not contains values except for //keys in list elements ConfXMLParam[] cxa = node.encodeXML().toArray(new ConfXMLParam[0]); NavuNode parent = node.getParent(); //contains sub-tree with all the values ConfXMLParam[] cxb = parent.getValues(cxa);
encodeXML in class NavuNodeConfXMLParam of the sub-tree
(including key values) with key values.NavuException - If the operation could not be performed for some reasonsConfXMLParam,
ConfXMLParamValuepublic boolean equals(Object o)
NavuNodepublic boolean exists()
throws NavuException
exists in class NavuNodeNavuException - on failure@Deprecated public CdbSession getCdbSession(CdbDBType dbType)
NavuContextBase.getReadConfSession(),
NavuContextBase.getReadConfSession() or
NavuContextBase.getWriteOperSession() instead.getCdbSession in class NavuNodeCdbSession or null if
this node is attached to a Maapi contextpublic DiffIterateOperFlag getChangeFlag()
NavuNodeNavuNode has
been a subject to by a transaction.getChangeFlag in class NavuNodeDiffIterateOperFlagpublic ConfValue getOldValue()
public NavuNode getParent()
NavuNodepublic ConfNamespace getRootNS()
NavuNodepublic ConfXMLParam[] getValues(String xml) throws NavuException
NavuNodeThe xml string must be pre-populated with tags and parameterized with values ("?") which indicates that the operation will read value of the corresponding tag.
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:
augment /ncs:services/ncs:service/ncs:type/ncs:service-type-choice {
case buzz-case {
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 type =
ncsRoot.container(Ncs._ncs)
.container(Ncs._sm_).list(Ncs._service_)
.elem(new ConfKey(new ConfBuf("service1")))
.container(Ncs._type_);
ConfXMLParam[] param =
type.getValues(
"<buzz xmlns=\"http://org.baz.servicemapper/buzz\>"
+ "<servers><server><srv-name>www1</srv-name>"
+ "<ip>?</ip></server><server>"
+ "<srv-name>www2</srv-name><ip>?</ip>"
+ " </server></servers> </buzz>");getValues in class NavuNodexml - -
XML structure corresponding values that will be fetched.NavuExceptionpublic int hashCode()
NavuNodepublic boolean isKey()
public void reset()
public void safeCreate()
throws NavuException
NavuException - on failure to createpublic Collection<NavuNode> select(ConfObject[] query)
public Collection<NavuNode> select(List<String> path) throws NavuException
select in class NavuNodepath - a list of regular expression.NavuExceptionpublic Collection<NavuNode> select(String path) throws NavuException
select in class NavuNodepath - a "/" separated regular expression.NavuExceptionpublic void set(ConfValue val) throws NavuException
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.
val - - the value to setNavuException - If an error occurred when setting the leaf
value the underlying/caused exception is wrapped inside
the NavuException and should be retrieved through
getCause method of Throwable.
An IllegalArgumentException is wrapped inside
a NavuException if writes is done to
running with NavuContext created with
CdbSession or Cdb.
public void set(String val) throws NavuException
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".NavuExceptionpublic NavuNode setChange(List<ConfObject> kp, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) throws NavuException
setChange in class NavuNodeNavuExceptionpublic void setValues(String xml) throws NavuException
set(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>.
setValues in class NavuNodexml - A string value wrapped inside XML tag.NavuExceptionNavuNode.setValues(ConfXMLParam[]),
ConfXMLParampublic void sharedCreate()
throws NavuException
NavuException - on failure to createpublic void sharedSet(ConfValue val) throws NavuException
NavuExceptionpublic void sharedSet(String val) throws NavuException
NavuExceptionpublic ConfKey toKey() throws NavuException
NavuExceptionpublic ConfValue value() throws NavuException
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.
NavuExceptionpublic String valueAsString() throws NavuException
An example of the difference between this method and
toString() is
for ConfEnumerations where the schema aware
representation is the label
while toString() returns a representation of
the ordinal value.
NavuExceptionpublic void valueUpdateInd(NavuNode child)
valueUpdateInd in class NavuNode