public class NavuLeaf extends NavuNode
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 NavuLeaf.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
NavuLeaf.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()
Encodes the sub-tree including the current
NavuNode
as the topmost NavuNode as a ConfXMLParam array. |
List<ConfXMLParam> |
encodeXML()
Encodes the sub-tree including the current
NavuNode
as the topmost NavuNode as a ConfXMLParam array. |
boolean |
equals(Object o)
Compares the specified object with this
NavuLeaf
for equality. |
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 or list entry.
|
boolean |
idrefDerivedOrSelf(ConfIdentityRef base) |
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
NavuLeaf.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, 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
public boolean isKey()
public NavuLeaf delete() throws NavuException
NavuException
public List<ConfXMLParam> encodeXML() throws NavuException
NavuNode
NavuNode
as the topmost NavuNode
as a ConfXMLParam
array.
The returned ConfXMLParam
array contains no values except
for list keys. The leaf elements are encoded as ConfXMLParamLeaf
.
Therefore, the returning array can be used as a the input parameter
to NavuNode.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
encodeXML
in class NavuNode
ConfXMLParam
objects corresponding to the
sub-tree of this node, with no values except list keys.NavuException
ConfXMLParam
,
ConfXMLParamValue
public List<ConfXMLParam> encodeValues() throws NavuException
NavuNode
NavuNode
as the topmost NavuNode
as a ConfXMLParam
array.
As opposed to NavuNode.encodeXML()
, the returned ConfXMLParam
array does contain values in the form of ConfXMLParamValue
encodeValues
in class NavuNode
ConfXMLParam
objects corresponding to the
sub-tree of this node, including all values.NavuException
ConfXMLParam
,
ConfXMLParamValue
public void reset()
public Collection<NavuNode> select(List<String> path) throws NavuException
select
in class NavuNode
path
- a list of regular expression.NavuException
public Collection<NavuNode> select(String path) throws NavuException
select
in class NavuNode
path
- a "/" separated regular expression.NavuException
public ConfXMLParam[] getValues(String xml) throws NavuException
NavuNode
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>");
getValues
in class NavuNode
xml
- XML structure corresponding to the part of the configuration
tree that is to be fetched.NavuException
public void sharedSet(ConfValue val) throws NavuException
NavuException
public void sharedSet(String val) throws NavuException
NavuException
public 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 setValues(String xml) throws NavuException
NavuLeaf.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 NavuNode
xml
- A string value wrapped inside XML tag.NavuException
NavuNode.setValues(ConfXMLParam[])
,
ConfXMLParam
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".NavuException
public boolean exists() throws NavuException
exists
in class NavuNode
NavuException
- on failurepublic void create() throws NavuException
NavuException
- on failure to createpublic void safeCreate() throws NavuException
NavuException
- on failure to createpublic void sharedCreate() throws NavuException
NavuException
- on failure to createpublic ConfKey toKey() throws NavuException
NavuException
public 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.
NavuException
public 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.
NavuException
public void valueUpdateInd(NavuNode child)
valueUpdateInd
in class NavuNode
public DiffIterateOperFlag getChangeFlag()
NavuNode
NavuNode
has
been a subject to by a transaction.getChangeFlag
in class NavuNode
DiffIterateOperFlag
public ConfValue getOldValue()
public NavuNode setChange(List<ConfObject> kp, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) throws NavuException
setChange
in class NavuNode
NavuException
public NavuNode getParent()
NavuNode
public Collection<NavuNode> select(ConfObject[] query)
@Deprecated public CdbSession getCdbSession(CdbDBType dbType)
NavuContextBase.getReadConfSession()
,
NavuContextBase.getReadConfSession()
or
NavuContextBase.getWriteOperSession()
instead.getCdbSession
in class NavuNode
CdbSession
or null if
this node is attached to a Maapi
contextpublic ConfNamespace getRootNS()
NavuNode
public List<NavuNode> deref() throws NavuException
NavuException
public boolean idrefDerivedOrSelf(ConfIdentityRef base) throws NavuException
NavuException
public boolean equals(Object o)
NavuLeaf
for equality.
Returns true
if the given object is also a
NavuLeaf
and it has the same ConfPath
as this
NavuLeaf
. Note that the actual values held by the leaves
(if any) are ignored as they are not relevant to this comparison.