public abstract class NavuNode extends Object
NavuContainer
, NavuList
, NavuLeaf
etc.
A NavuNode
could explicitly be retrieved
through getNavuNode(ConfPath)
.
//attach to MAAPI context NavuContainer root = new NavuContainer(new Navu2Context(maapi,th)); NavuNode node = root.getNavuNode( new ConfPath("/ncs:devices/device{device0}/config"));
Implementations of this interface represents YANG constructs that
is either a containment element container,list,
leaf that holds values or as tailf:action
which
represents an action in the data model.
The interface specifies minimum requirement that a NavuNode
should implement. To extend the functionality of the NavuNode
a explicit cast must be performed.
NavuNode node = ...; if(node.getInfo().isAction()) NavuAction theAction = (NavuAction)node; theAction.call(); //or if(node instanceof NavuAction) NavuAction theAction = (NavuAction)node; theAction.call();The methods in this interface is divided up in three types of categories.
- Navigational methods. Basic navigational methods
container(String)
,leaf(String)
,list(String)
each retrieves the adjacentNavuNode
in the next level.
getParent()
retrieve theNavuNode
for the previous level (parent node). To retrieve all the children elements in the next level for a givenNavuNode
children()
returns aCollection
ofNavuNode
's.For retrieving descendants for a (based on some regular expression) for a
NavuNode
select
could be used.- Informational methods. Provide information for a
NavuNode
.getInfo()
,getKeyPath()
,getName()
,getRootNS()
.Context specific methods. This means that certain types of methods is used based on the current attached context. The current context is retrieved through
context()
method.if(node.context().isMaapi()) //node is in MAAPI context else if(node.context().isCdbSession()) //CDB contextgetChangeFlag()/getCdbSession()/getChanges()
for MAAPI context. andgetCdbSession()
for CDB context.- Data retrieving methods. Which extract/reads values with
getValues()
.There are also methods that does not fall into the above categories:
encodeXML()
that is helpful method in conjunction withgetValues()
to extract a sub-tree.Context specific methods like
startCdbSession()/startCdbSession()
to start new CDBSession from a currentNavuNode
.set()
which sets a value to a leaf element.
Constructor and Description |
---|
NavuNode() |
Modifier and Type | Method and Description |
---|---|
Collection<NavuNode> |
children()
Return the children of this NavuNode.
|
NavuContainer |
container(Integer key)
Returns a subordinate reference to a container according to
the given hash value.
|
NavuContainer |
container(String key)
Returns a subordinate reference to NavuNode according to
the given string
key . |
NavuContainer |
container(String prefix,
String key)
Returns a subordinate reference to container according to
the given
key and prefix . |
NavuContext |
context()
Returns the current
NavuContext that this node is
attached to. |
abstract List<ConfXMLParam> |
encodeValues()
Encoding the sub-tree including the current
NavuNode
as the topmost NavuNode to a ConfXMLParam array. |
abstract List<ConfXMLParam> |
encodeXML()
Encoding the sub-tree including the current
NavuNode
as the topmost NavuNode to a ConfXMLParam array. |
abstract boolean |
equals(Object o)
Check the equality of this NavuNode against the targeted
NavuNode.
|
abstract boolean |
exists()
Generic exists test for Navu navigational elements
|
CdbSession |
getCdbSession(CdbDBType dbType)
Deprecated.
|
DiffIterateOperFlag |
getChange()
Deprecated.
|
DiffIterateOperFlag |
getChangeFlag()
Returns the latest change that this
NavuNode has
been a subject to by a transaction. |
List<NavuNode> |
getChanges()
Return the descendant
NavuNode 's
(including this element) that has been affected by
changes to the MAAPI transaction. |
List<NavuNode> |
getChanges(boolean emitSubTree)
Return the descendant
NavuNode including this
NavuNode that has been affected by the
current MAAPI transaction. |
List<NavuNode> |
getChanges(boolean emitSubTree,
DiffIterateOperFlag... forOps)
Return the descendant
NavuNode including this
NavuNode that has been affected by the
current MAAPI transaction. |
ConfPath |
getConfPath()
Returns the corresponding ConfPath for the corresponding NavuNode.
|
NavuNodeInfo |
getInfo()
Returns the
NaveNodeInfo regarding this node. |
String |
getKeyPath()
Returns the absolute keypath of this node.
|
String |
getName()
Returns the name of this NavuNode.
|
NavuNode |
getNavuNode(ConfPath path)
Retrieve a NavuNode based on the given absolute or relative
path.
|
NavuNode |
getParent()
Returns the parent of the node.
|
ConfNamespace |
getRootNS()
Returns the root namespace of the topmost ancestor.
|
ConfXMLParam[] |
getValues(ConfXMLParam[] params)
Read an arbitrary set of sub-elements from this
NavuNode . |
ConfXMLParam[] |
getValues(String xml)
Read an arbitrary set of sub-elements of a container element.
|
ConfXMLParam[] |
getXml(String xml)
Deprecated.
|
abstract int |
hashCode()
Return the hashCode of this NavuNode.
|
NavuLeaf |
leaf(Integer key)
Returns a subordinate reference to a leaf node according to
the given hash value
key . |
NavuLeaf |
leaf(String key)
Returns a subordinate reference to a NavuNode according to
the given string
key . |
NavuLeaf |
leaf(String prefix,
String key)
Returns a subordinate reference to leaf according to
the given
key and prefix . |
NavuList |
list(Integer key)
Returns a subordinate reference to list according to
the given hash value
key . |
NavuList |
list(String key)
Returns a subordinate reference to NavuNode according to
the given string
key . |
NavuList |
list(String prefix,
String key)
Returns a subordinate reference to list according to
the given
key and prefix . |
PreparedXMLStatement |
prepareXMLCall(String xml)
A Prepared xml setValues() that accepts parameterized values "?"
instead of a string representation of the value
when on invocation the value is not known.
|
abstract void |
reset()
When navigating through NAVU to a certain location.
|
abstract Collection<NavuNode> |
select(ConfObject[] query) |
abstract Collection<NavuNode> |
select(List<String> query) |
abstract Collection<NavuNode> |
select(String query) |
void |
setValues(ConfXMLParam[] params)
Set arbitrary sub-elements of a container or list entry.
|
void |
setValues(String xml)
Set arbitrary sub-elements of a container element.
|
void |
sharedSetValues(ConfXMLParam[] params)
Set arbitrary sub-elements of a container or list entry
with FastMap support, creating backpointers and reference counter.
|
void |
sharedSetValues(String xml)
Set arbitrary sub-elements of a container or list entry
with FastMap support, creating backpointers and reference counter.
|
void |
startCdbSession(CdbDBType dbtype,
EnumSet<CdbLockType> lockflags)
Deprecated.
|
void |
stopCdbSession()
Closes all CdbSessions for the NavuContainer.
|
List<NavuNode> |
xPathSelect(String query)
Evaluates the XPath Path expression query returns
resulting node set as list of NavuNode's.
|
void |
xPathSelectIterate(String query,
NavuNodeSetIterate iterate)
Iterate through a NodeSet based on a supplied XPath query.
|
public Collection<NavuNode> children() throws NavuException
NavuException
public NavuContainer container(Integer key) throws NavuException
container
hashvalue could be obtained through
ConfNamespace.stringToHash(String)
,
MaapiSchemas.stringToHash(String)
or use the
overloaded method container(String)
key
- hashed value of the container to returnNavuException
- if the corresponding subordinate node is not
a container or if subordinate node has no matching container
with the hash value key
public NavuContainer container(String key) throws NavuException
key
.key
- the name of the subordinate containerNavuException
- if the corresponding subordinate node is not
a container node or if subordinate node has no matching container
with the name key
public NavuContainer container(String prefix, String key) throws NavuException
key
and prefix
.prefix
- the prefix for the namespacekey
- the name of the subordinate containerNavuException
- if the corresponding subordinate node is not
a container node or if subordinate node has no matching container
with the name key
and prefix
public NavuContext context()
NavuContext
that this node is
attached to.NavuContext
.public abstract List<ConfXMLParam> encodeValues() throws NavuException
NavuNode
as the topmost NavuNode
to a ConfXMLParam
array.
As opposed to encodeXML, the returning ConfXMLParam
array
does contain values in form of ConfXMLParamValue
ConfXMLParam
of the sub-tree
including valuesNavuException
- If the operation could not be performed for some reasonsConfXMLParam
,
ConfXMLParamValue
public abstract List<ConfXMLParam> encodeXML() throws NavuException
NavuNode
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 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);
ConfXMLParam
of the sub-tree
(including key values) with key values.NavuException
- If the operation could not be performed for some reasonsConfXMLParam
,
ConfXMLParamValue
public abstract boolean equals(Object o)
public abstract boolean exists() throws NavuException
NavuException
@Deprecated public CdbSession getCdbSession(CdbDBType dbType)
NavuContextBase.getReadConfSession()
,
NavuContextBase.getReadConfSession()
or
NavuContextBase.getWriteOperSession()
instead.
Returns the current CdbSession.CdbSession
or null if
this node is attached to a Maapi
context@Deprecated public DiffIterateOperFlag getChange()
getChangeFlag()
instead.public DiffIterateOperFlag getChangeFlag()
NavuNode
has
been a subject to by a transaction.DiffIterateOperFlag
public List<NavuNode> getChanges() throws NavuException
NavuNode
's
(including this element) that has been affected by
changes to the MAAPI
transaction.
The default behavior is to emit the affected descendant and
include all the affected NavuNode
's regardless of
type of change.
To filter out specific type of change use the methods
getChanges(boolean, DiffIterateOperFlag...)
NavuNode
's that has been affected by
the changes to the current MAAPI
transaction.NavuException
- Is returned if we try to iterate on a
transaction which is in the wrong state and not attached.public List<NavuNode> getChanges(boolean emitSubTree) throws NavuException
NavuNode
including this
NavuNode
that has been affected by the
current MAAPI transaction.
The emitSubtree
flag specified if the desired sub-tree
should be included in the return set. If set to true
then the behavior is to include the whole sub-tree of affected
NavuNode
's.
If set to false the sibling changes to the current transaction is to only included.
NavuNode
that has been affected by
changes to the current MAAPI
transaction.NavuException
- Is returned if we try to iterate on changes on a
transaction which is in the wrong state and not attached.public List<NavuNode> getChanges(boolean emitSubTree, DiffIterateOperFlag... forOps) throws NavuException
NavuNode
including this
NavuNode
that has been affected by the
current MAAPI transaction.
The emitSubtree
flag specified if the desired sub-tree
should be included in the return set. If set to true
then the behavior is to include the whole sub-tree of affected
NavuNode
's.
If set to false the sibling NavuNode
that has been affected by changes to the current
transaction is to be included.
The forOps argument specifies those specific changes
that the NavuNode previously NavuNode
's to be
included filter out the set
that does not match the specified arguments.
NavuNode
that has been affected by
changes to the current MAAPI
transaction.NavuException
- Is returned if we try to iterate on a
transaction which is in the wrong state and not attached.public ConfPath getConfPath()
public NavuNodeInfo getInfo()
NaveNodeInfo
regarding this node.
A NavuNodeInfo
is an object which further information
could be retrieved from the current node.
NavuNode
public String getKeyPath()
NavuNode
NavuException
- If the keypath could not be determinepublic String getName()
public NavuNode getNavuNode(ConfPath path) throws NavuException
If the path is relative it is relative this NavuNode .
NavuException
- if the path is invalid according the
schema or does not lead to a instance node.public NavuNode getParent()
public ConfNamespace getRootNS()
public ConfXMLParam[] getValues(ConfXMLParam[] params) throws NavuException
NavuNode
.
Input array of ConfXMLParam
where desired values to be extracted should be replaced with
ConfXMLParamLeaf
in the ConfXMLParam array.
The return value is a array of the type ConfXMLParam
with ConfXMLParamLeaf
is replaced with
ConfXMLParamValue
.
params
- pre-populated array of ConfXMLParam
ConfXMLParam
where
ConfXMLParamLeaf
is replaced with
ConfXMLParamValue
NavuException
- If the input parameters does
not confirm to the current data model or external
error have occurredpublic ConfXMLParam[] getValues(String xml) throws NavuException
The 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>");
xml
- -
XML structure corresponding values that will be fetched.NavuException
@Deprecated public ConfXMLParam[] getXml(String xml) throws NavuException
getValues(String)
which should be used instead.xml
- Array which specifies what data
should be retrievedConfXMLParam
NavuException
- If the input parameters does not confirm to the current data
model or external error have occurredpublic abstract int hashCode()
public NavuLeaf leaf(Integer key) throws NavuException
key
.key
- hashed value of the subordinate leafNavuException
- if the corresponding subordinate node is not
a leaf node or if subordinate node has no matching leaf
with the hash value key
public NavuLeaf leaf(String key) throws NavuException
key
.key
- the name of the subordinate leafNavuException
- if the corresponding subordinate node is not
a leaf node or if subordinate node has no matching leaf
with the name key
public NavuLeaf leaf(String prefix, String key) throws NavuException
key
and prefix
.prefix
- the prefix for the namespacekey
- the name of the subordinate leafNavuException
- if the corresponding subordinate node is not
a leaf node or if subordinate node has no matching leaf
with the name key
and prefix
public NavuList list(Integer key) throws NavuException
key
.key
- the name of the subordinate listNavuException
- if the corresponding subordinate node is not
a list node or if subordinate node has no matching list
with the hash value key
public NavuList list(String key) throws NavuException
key
.key
- the name of the subordinate listNavuException
- if the corresponding subordinate node is not
a list node or if subordinate node has no matching list
with the name key
public NavuList list(String prefix, String key) throws NavuException
key
and prefix
.prefix
- the prefix for the namespacekey
- the name of the subordinate listNavuException
- if the corresponding subordinate node is not
a list node or if subordinate node has no matching list
with the name key
and prefix
public PreparedXMLStatement prepareXMLCall(String xml) throws NavuException
PreparedXMLStatement xmlst = node.prepareXMLCall("<server><srv-name>?</srv-name>" + "<ip>?</ip>" + " <port>?</port>" + "</server>"); xmlst.put(0,new ConfKey(new ConfBuf("www1")); xmlst.put(1,new ConfIPv4(new ConfIPv4(new int[]{ 192,168,10,12}); xmlst.put(2,new ConfUInt16(80)); xmlst.setValues();If no put() method is called before setValues() then the ? is treated as ConfDefault.
xml
- -
Parameterized xml string.NavuException
public abstract void reset()
public abstract Collection<NavuNode> select(ConfObject[] query) throws NavuException
query
- NavuException
public abstract Collection<NavuNode> select(List<String> query) throws NavuException
query
- a list of regular expression.NavuException
public abstract Collection<NavuNode> select(String query) throws NavuException
query
- a "/" separated regular expression.NavuException
public void setValues(ConfXMLParam[] params) throws NavuException
The ConfXMLParam
array must be populated with values
according to the specification of the ConfXMLParam
array structure.
If the container or list entry itself, or any sub-elements that are specified as existing, do not exist before this call, they will be created, otherwise the existing values will be updated.
Both mandatory and optional elements may be omitted from the array, and all omitted elements are left unchanged.
To actually delete a non-mandatory leaf or presence container
ConfNoExists
should be used in
ConfXMLParamValue
instead of being omitted.
For a list entry, the key values can be specified either in the
path or via key elements in ConfXMLParamValue
-
if the values are in the path, the key elements can be omitted
from the array. For sub-lists present in the array, the key elements
must of course always also be present though,
immediately following the ConfXMLParamStart
element and in
the order defined by the data model.
For a list without keys the "pseudo" key may (or in some cases must) be present in the array, but of course there is no tag value for it, since it isn't present in the data model. In this case we must use a tag value of 0, i.e. it can be set with code like:
ConfXMLParam[] p = new ConfXMLParam[7]; p[1] = new ConfXMLParam(hash, 0, new ConfInt64(42));
params
- ConfXMLParam
structure corresponding values that will
be set.IOException
ConfException
NavuException
public void setValues(String xml) throws NavuException
This method share the same behavior as
setValues(ConfXMLParam[])
but the input parameter is
an XML string.
The XML string passed as the input parameter
should reflect the equivalent ConfXMLParam
array structure.
ConfXMLParam p = new ConfXMLParam[]; final int hash = new Ncs().hash(); p[0] = new ConfXMLParamStart(hash,Ncs._config); final int hash2 = new Foo().hash(); p[1] = new ConfXMLParamStart(hash2,Foo._interfaces); p[2] = new ConfXMLParamStart(hash2,Foo._buzz); p[3] = new ConfXMLParamStart(hash2,Foo._servers); p[4] = new ConfXMLParamStart(hash2,Foo._server); p[5] = new ConfXMLParamValue(hash2,Foo._srv_name,new ConfBuf("www")); p[6] = new ConfXMLParamValue(hash2,Foo._port,new ConfUInt16(80)); p[7] = new ConfXMLParamStop(hash2,Foo._server); p[8] = new ConfXMLParamStop(hash2,Foo._servers); p[9] = new ConfXMLParamStop(hash2,Foo.buzz); p[10] = new ConfXMLParamStop(hash2,Foo._interfaces); p[11] = new ConfXMLParamStop(hash,Ncs._config); Represents the XML String Below: <config> <foo:foo xmlns="http://acme.com/foo"> <foo:interfaces> <foo:buzz> <foo:servers> <foo:server> <foo:srv-name>www</foo:srv-name> <foo:port>80</foo:port> </foo:server> </foo:servers> </foo:buzz> </foo:interfaces> </foo:zconfigzub> </config>
The specified XML string should not contain the "version" tag (<?xml version="1.0" encoding="UTF-8"?>) the method will be appended it.
The values that is intended to be set must represent a legal string representation of a the value. The corresponding string representation of values will be validated against the current the schema and the operation will fail if the string representation could not be determine.
Example - Populate tree in a service model:For operational data with lists without keys, list instances cannot be created without passing a pseudo-key. This pseudo-key is used to identify which item in the list to set or update. The pseudo-key has to be specified in the supplied xml-string an is identified by the "<tailf-navu-pseudo-key>1</tailf-navu-pseudo-key>" tag. Internally the pseudo-key value is represented as a ConfInt64 type.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 buzz = ncsRoot.container(Ncs._ncs) .container(Ncs._sm_).list(Ncs._service_) .elem(new ConfKey(new ConfBuf("service1"))) .container(Ncs._type_).container(Buzz._buzz_); //Does wrap string withservers.set("<servers><server> <srv-name>www1</srv-name<ip>192.178.0.1</ip>" "<port>80</port><foo><bar>55</bar> <baz>44</baz></foo>" + "<interface><if-name>eth0</if-name>" + "<mtu>1500</mtu> <if-name>eth1</if-name> <mtu>1600</mtu>" + "</interface></server><server> ;<srv-name>www2</srv-name>" + "<ip>192.178.0.2</ip>" + "<port>8080</port>" + "<foo> <bar>66</bar> <baz>55</baz></foo>" + "<interface><if-name>eth0</if-name>" + "<mtu>1500</mtu> ;<if-name>eth1</if-name>" + "<mtu>1600</mtu> </interface></server>">/servers≷);
xml
- -
XML structure corresponding values that will be set.NavuException
setValues(ConfXMLParam[])
,
ConfXMLParam
public void sharedSetValues(ConfXMLParam[] params) throws NavuException
NavuException
public void sharedSetValues(String xml) throws NavuException
This method share the same behavior as
sharedSetValues(ConfXMLParam[])
but the input parameter is
an XML string.
NavuException
@Deprecated public void startCdbSession(CdbDBType dbtype, EnumSet<CdbLockType> lockflags)
dbtype
- lockflags
- public void stopCdbSession()
public List<NavuNode> xPathSelect(String query) throws NavuException
The expression query will be evaluated using this node as the context node. examples:
NavuContainer = root.container(myns._somecontainer1). container(myns._somecontainer2).container(myns._servers); //retrieve all the instance entries of the server list "server" servers.xPathSelect("server"); //retrieve all child nodes of instance with srv-name: www1 //entries of the server list "server" servers.xPathSelect("server[srv-name='www1']/*"); //retrieve all leaf ip node of instance with srv-name: www1 //entries of the server list "server" servers.xPathSelect("server[srv-name='www1']/ip");
query
- - XPath 1.0 queryNavuException
public void xPathSelectIterate(String query, NavuNodeSetIterate iterate) throws NavuException
xPathSelect(String)
in this method a supplied
callback is called for each node iteration.
See @link NavuNodeSetIterate}query
- - XPath 1.0 queryiterate
- - supplied user codeNavuException