Class NavuContainer
- All Implemented Interfaces:
ConfIterate
,MaapiDiffIterate
- Direct Known Subclasses:
NavuListEntry
NavuContainer
is a representation of the yang
construct container,module and list-entry.
A NavuContainer
is usually supplied or returned from
a method call. It can also be created using one of its constructors,
typically NavuContainer(NavuContext)
.
A NavuContainer
is created with a NavuContext
initialized with a Maapi
socket:
NavuContext context = new NavuContext(maapi); context.startRunningTrans(Conf.MODE_READ_WRITE); NavuContainer root = new NavuContainer(context);
As shown above, a transaction must be started before the context can be used for navigating.
A transaction can alternatively be started for operational data instead:
NavuContext context = new NavuContext(maapi); context.startOperationalTrans(Conf.MODE_READ_WRITE); NavuContainer root = new NavuContainer(context);
Either way, when a NavuContainer
is created using the above
mentioned context, the object pointed to by root
is the "root"
of the NAVU-Tree.
The root's children represent all of the loaded modules. To
choose a particular module, the method container(Integer)
must be called with the hash value of the corresponding module
(ConfNamespace.hash()
).
This will return a new NavuContainer
pointing to the root of
the chosen module.
NavuContainer module = root.container(new Ncs().hash());
To continue further down to the next child, use
container(Integer)
, container(String)
,
list(Integer)
, list(String)
or leaf(Integer)
,
leaf(String)
as dictated by the YANG model.
The string version is the corresponding
MaapiSchemas.hashToString(long)
of the Integer parameter
which is the hash value of the tag name.
Usually the generated namespace classes static method are used for convenience. The absence of underscore (_) at the end of the static field name indicates the integer version.
Then continuing with the devices node:
NavuContainer devicesNode = module.container(Ncs._devices);
-
Constructor Summary
ConstructorDescriptionThis constructor creates a root container.NavuContainer
(Cdb cdb, int hash) Deprecated.NavuContainer
(Maapi m, int handle, int rootHash) Constructor for a single namespace.NavuContainer
(Maapi readWrite, int readWriteTid, Maapi readOnly, int readOnlyTid, int rootHash) Deprecated.NavuContainer
(NavuContext context) Creates an rootNavuContainer
a starting point of which further navigation is performed. -
Method Summary
Modifier and TypeMethodDescriptionReturns a reference to a subordinateaction
with the hash valuekey
.Returns a reference to a subordinateaction
with the namekey
.children()
Returns a collection containing the children of this container.Returns a reference to a subordinatechoice
with the namename
.container
(ConfNamespace ns, String containerName) Returns a reference to a subordinatecontainer
with the namecontainerName
, belonging to the namespacens
.Returns a reference to a subordinatecontainer
with the hash valuekey
.Returns a reference to a subordinatecontainer
with the namekey
.Deprecated.boolean
containsNode
(NavuNode node) Checks if the given node is a direct child of this container according to the schema.boolean
containsNode
(String nodeName) Checks if there is a child node in the schema with given name.create()
Creates an optional container.delete()
Deletes an optional container.Encodes 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.entrySet()
Returns a set of value-pairs.boolean
Compares the specified object with thisNavuContainer
for equality.boolean
exists()
Verifies the existence of container.findChanges
(NavuContext delContext, Integer[] criteria) Analyzes what changes has been done within this transaction.findChanges
(Integer[] criteria) Deprecated.Returns a subordinate node with the namenodeName
.getKey()
If this container is a list instance this method can be used to get the list entry key.Returns the root namespace of the topmost ancestor.getSelectCaseAsNavuChoice
(String choice) Returns a collection of the "toplevel" choice elements of the a current selected case.getSelectCaseAsNavuNode
(String choice) Returns a collection of the top-level node elements of the currently selected case of the specifiedchoice
.getSelectedCase
(String choice) Returns the selected cases of a given choice.int
Get the current Maapi user session if this container context uses Maapi.boolean
isEmpty()
Checks if the container has any members.boolean
Returnstrue
if thisNavuContainer
represents a list-entryiterate
(ConfObject[] kp, DiffIterateOperFlag op, ConfObject oldValue, ConfObject newValue, Object state) keySet()
Returns a set of nodeNames.leaf
(ConfNamespace ns, String leafName) Returns a reference to a subordinateleaf
with the nameleafName
, belonging to the namespacens
.Returns a reference to a subordinateleaf
with the hash valuekey
.Returns a reference to a subordinateleaf
with the namekey
.Deprecated.leafList
(ConfNamespace ns, String leafListName) Returns a reference to a subordinateleaf-list
with the nameleafListName
, belonging to the namespacens
.Returns a reference to a subordinateleaf-list
with the hash valuekey
.Returns a reference to a subordinateleaf-list
with the namekey
.Deprecated.list
(ConfNamespace ns, String listName) Returns a reference to a subordinatelist
with the namelistName
, belonging to the namespacens
.Returns a reference to a subordinatelist
with the hash valuekey
.Returns a reference to a subordinatelist
with the namekey
.Deprecated.The namespace specified here will be used when selecting a child to this NavuContainer and returns a reference to this NavuContainer object according to the given namespace idns
.void
reset()
Resets the contained nodesCreates an optional container.select
(ConfObject[] kp) void
Deprecated.setChange
(List<ConfObject> path, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) setOperationalDataCase
(String choiceStr, String caseStr) Deprecated.void
setOperDataCase
(String choiceStr, String caseStr) Set a case with the namecaseStr
for a choicechoiceStr
for Cdb when writing operational data.Creates an optional container.int
size()
Returns the number of nodes contained by the container.toString()
void
valueUpdateInd
(NavuNode child) An indication received from a child node.Methods inherited from class com.tailf.navu.NavuNode
context, getCdbSession, getChange, getChangeFlag, getChanges, getChanges, getChanges, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getParent, getValues, getValues, getXml, hashCode, prepareXMLCall, setValues, setValues, sharedSetValues, sharedSetValues, startCdbSession, stopCdbSession, xPathSelect, xPathSelectIterate
-
Constructor Details
-
NavuContainer
public NavuContainer()This constructor creates a root container. This container holds all loaded schemas as its children. -
NavuContainer
Constructor for a single namespace. Bypasses the root node.- Parameters:
m
- READ or READ_WRITEMAAPI
sockethandle
- a valid transaction handlerootHash
- the root hash of the module
-
NavuContainer
@Deprecated public NavuContainer(Maapi readWrite, int readWriteTid, Maapi readOnly, int readOnlyTid, int rootHash) Deprecated.This constructor is deprecated. The readOnly Maapi and readOnly transaction is not used and therefore obsolete. This constructor shall be used if you want the container to be aware of the changes that have been applied within this transaction.- Parameters:
readWrite
- MAAPI socket to perform changes onreadWriteTid
- READ/WRITE transaction handle to use for READ/WRITE operationsreadOnly
- MAAPI socket to the RUNNING datastorereadOnlyTid
- READ transaction handle to use when readingrootHash
- root hash of the module
-
NavuContainer
Deprecated.Constructor for aNavuContainer
that will be able to connect to the Cdb database to retrieve config and operational data.- Parameters:
cdb
- The CDB instance to use for read/write operationshash
- Namespace hash integer value representation of the module
-
-
Method Details
-
namespace
The namespace specified here will be used when selecting a child to this NavuContainer and returns a reference to this NavuContainer object according to the given namespace idns
.- Overrides:
namespace
in classNavuNode
- Parameters:
ns
- the namespace id- Returns:
- reference to this NavuContainer object
- Throws:
ConfException
IOException
-
container
Returns a reference to a subordinatecontainer
with the hash valuekey
. Thecontainer
hash value can be obtained as a constant from a namespace file generated byconfdc
orncsc
, or retrieved with one of the methodsConfNamespace.stringToHash(String)
orMaapiSchemas.stringToHash(String)
. It is also possible to access a container based on its name only, using the overloaded methodcontainer(String)
.- Overrides:
container
in classNavuNode
- Parameters:
key
- hashed name of the container to return- Returns:
- reference to a subordinate container node
- Throws:
NavuException
- if the corresponding subordinate node is not a container or if there is no subordinate node with the hash valuekey
-
container
Returns a reference to a subordinatecontainer
with the namekey
.- Overrides:
container
in classNavuNode
- Parameters:
key
- the name of the subordinate container- Returns:
- reference to a subordinate container node
- Throws:
NavuException
- if the corresponding subordinate node is not a container node or if there is no subordinate node with the namekey
-
container
Returns a reference to a subordinate
container
with the namecontainerName
, belonging to the namespacens
.Note that if
containerName
by itself uniquely identifies a subordinate container, that container will still have to belong to the namespacens
contrary to the functionality of the previous method using prefix and containerName.- Overrides:
container
in classNavuNode
- Parameters:
ns
- the namespace objectcontainerName
- the name of the subordinate container- Returns:
- reference to a subordinate container node
- Throws:
NavuException
- if the corresponding subordinate node is not a container node or if there is no subordinate node with the namecontainerName
in the namespacens
-
container
Deprecated.- Overrides:
container
in classNavuNode
- Throws:
NavuException
-
leaf
Returns a reference to a subordinateleaf
with the hash valuekey
.- Overrides:
leaf
in classNavuNode
- Parameters:
key
- hashed name of the subordinate leaf- Returns:
- reference to a subordinate container node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf node or if there is no subordinate node with the hash valuekey
-
leaf
Returns a reference to a subordinateleaf
with the namekey
.- Overrides:
leaf
in classNavuNode
- Parameters:
key
- the name of the subordinate leaf- Returns:
- reference to a subordinate leaf node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf node or if there is no subordinate node with the namekey
-
leaf
Returns a reference to a subordinate
leaf
with the nameleafName
, belonging to the namespacens
.Note that if
leafName
by itself uniquely identifies a subordinate leaf, that leaf will still have to belong to the namespacens
contrary to the functionality of the previous method using prefix and leafName.- Overrides:
leaf
in classNavuNode
- Parameters:
ns
- the namespace objectleafName
- the name of the subordinate leaf- Returns:
- reference to a subordinate leaf node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf node or if there is no subordinate node with the namekey
in the namespacens
-
leaf
Deprecated.- Overrides:
leaf
in classNavuNode
- Throws:
NavuException
-
leafList
Returns a reference to a subordinateleaf-list
with the hash valuekey
.- Overrides:
leafList
in classNavuNode
- Parameters:
key
- hashed name of the subordinate leaf-list- Returns:
- reference to a subordinate leaf-list node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf-list node or if there is no subordinate node with the hash valuekey
-
leafList
Returns a reference to a subordinateleaf-list
with the namekey
.- Overrides:
leafList
in classNavuNode
- Parameters:
key
- the name of the subordinate leaf-list- Returns:
- reference to a subordinate leaf-list node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf-list node or if there is no subordinate node with the namekey
-
leafList
Returns a reference to a subordinate
leaf-list
with the nameleafListName
, belonging to the namespacens
.Note that if
leafListName
by itself uniquely identifies a subordinate leaf-list, that leaf-list will still have to belong to the namespacens
contrary to the functionality of the previous method using prefix and leafListName.- Overrides:
leafList
in classNavuNode
- Parameters:
ns
- the namespace objectleafListName
- the name of the subordinate leaf-list- Returns:
- reference to a subordinate leaf-list node
- Throws:
NavuException
- if the corresponding subordinate node is not a leaf-list node or if there is no subordinate node with the nameleafListName
in the namespacens
-
leafList
Deprecated.- Overrides:
leafList
in classNavuNode
- Throws:
NavuException
-
list
Returns a reference to a subordinatelist
with the hash valuekey
.- Overrides:
list
in classNavuNode
- Parameters:
key
- the hashed name of the subordinate list- Returns:
- reference to a subordinate list node
- Throws:
NavuException
- if the corresponding subordinate node is not a list node or if there is no subordinate node with the hash valuekey
-
list
Returns a reference to a subordinatelist
with the namekey
.- Overrides:
list
in classNavuNode
- Parameters:
key
- the name of the subordinate list- Returns:
- reference to a subordinate list node
- Throws:
NavuException
- if the corresponding subordinate node is not a list node or if there is no subordinate node with the namekey
-
list
Returns a reference to a subordinate
list
with the namelistName
, belonging to the namespacens
.Note that if
listName
by itself uniquely identifies a subordinate list, that list will still have to belong to the namespacens
contrary to the functionality of the previous method using prefix and listName.- Overrides:
list
in classNavuNode
- Parameters:
ns
- the namespace objectlistName
- the name of the subordinate list- Returns:
- reference to a subordinate list node
- Throws:
NavuException
- if the corresponding subordinate node is not a list node or if there is no subordinate node with the namelistName
in the namespacens
-
list
Deprecated.- Overrides:
list
in classNavuNode
- Throws:
NavuException
-
action
Returns a reference to a subordinateaction
with the hash valuekey
.- Parameters:
key
- the name of the subordinate action- Returns:
- reference to a subordinate action node
- Throws:
NavuException
- if the corresponding subordinate node is not an action node or if there is no subordinate node with the hash valuekey
-
action
Returns a reference to a subordinateaction
with the namekey
.- Parameters:
key
- the name of the subordinate action- Returns:
- reference to a subordinate action node
- Throws:
NavuException
- if the corresponding subordinate node is not a action node or if there is no subordinate node with the namekey
-
isListInstance
public boolean isListInstance()Returnstrue
if thisNavuContainer
represents a list-entry- Returns:
true
if thisNavuContainer
is a list-entry false otherwise
-
getKey
If this container is a list instance this method can be used to get the list entry key. Otherwise this method returns null.- Returns:
- the key as a ConfKey object
-
children
Returns a collection containing the children of this container.- Overrides:
children
in classNavuNode
- Returns:
- the children of this container
- Throws:
NavuException
-
choice
Returns a reference to a subordinatechoice
with the namename
.- Parameters:
name
- the name of the choice to return- Returns:
- a matching choice
- Throws:
NavuException
-
containsNode
Checks if there is a child node in the schema with given name.- Parameters:
nodeName
- the name of a node to look for- Returns:
- true if there is a match
- Throws:
NavuException
-
create
Creates an optional container.- Returns:
- a pointer to self.
- Throws:
NavuException
-
safeCreate
Creates an optional container. Will silently ignore the error when the container already exists- Returns:
- a pointer to self.
- Throws:
NavuException
-
exists
Verifies the existence of container.- Specified by:
exists
in classNavuNode
- Returns:
- boolean
- Throws:
NavuException
-
delete
Deletes an optional container.- 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:
-
entrySet
Returns a set of value-pairs.- Returns:
- a set of nodeName-node pairs according to the schema
- Throws:
NavuException
-
findChanges
Deprecated.Since this method cannot return delete changes in a reliable way this method is deprecated. Use insteadfindChanges(NavuContext, Integer[])
- Throws:
NavuException
-
get
Returns a subordinate node with the namenodeName
.- Parameters:
nodeName
- a name of a node contained within this container.- Returns:
- a matching node
- Throws:
NavuException
- if subordinate node has no matching container with the namenodeName
-
getSelectedCase
Returns the selected cases of a given choice.- Parameters:
choice
- of the choice to get selected case for.- Returns:
- - the selected case
- Throws:
NavuException
-
isEmpty
Checks if the container has any members.- Returns:
- true if it has 1 or more members.
- Throws:
NavuException
-
iterate
public DiffIterateResultFlag iterate(ConfObject[] kp, DiffIterateOperFlag op, ConfObject oldValue, ConfObject newValue, Object state) - Specified by:
iterate
in interfaceMaapiDiffIterate
-
keySet
Returns a set of nodeNames.- Returns:
- a set of nodeNames
- Throws:
NavuException
-
getUserSession
Get the current Maapi user session if this container context uses Maapi. Throws exception if the context is not Maapi.- Returns:
- user session id
- Throws:
NavuException
-
reset
public void reset()Resets the contained nodes -
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
-
size
Returns the number of nodes contained by the container.- Returns:
- the number contained nodes.
- Throws:
NavuException
-
toString
-
select
- Specified by:
select
in classNavuNode
- Returns:
- a collection a nodes matching a Regular Expression query
- Throws:
NavuException
-
getRootNS
Description copied from class:NavuNode
Returns the root namespace of the topmost ancestor. -
set
Deprecated.This method is deprecated. UseNavuNode.setValues(String)
instead.- Parameters:
xml
- - XML structure corresponding values that will be set.- Throws:
NavuException
-
setOperationalDataCase
@Deprecated public NavuContainer setOperationalDataCase(String choiceStr, String caseStr) throws NavuException Deprecated.Use the methodsetOperDataCase(String, String)
There is a difference in how cases for a choice is set in a Maapi context and a Cdb context. In Maapi, when writing configuration data, the cases are set implicitly as any leaf are set below a choice in the model tree. For Cdb, when writing operational data, this case has to be set explicitly. This is done using this method. The method returns a NavuContainer representing the selected case which can be used to navigate down the model tree.- Parameters:
choiceStr
- name of the choicecaseStr
- name of the case to set as selected case- Returns:
- NavuContainer representing the selected case
- Throws:
NavuException
-
setOperDataCase
Set a case with the namecaseStr
for a choicechoiceStr
for Cdb when writing operational data. There is a difference in how cases for a choice is set in a Maapi context and a Cdb context. In Maapi, when writing configuration data, the cases are set implicitly as any leaf are set below a choice in the model tree. For Cdb, when writing operational data, this case has to be set explicitly. This is done using this method. The method returns a NavuContainer representing the selected case which can be used to navigate down the model tree.- Parameters:
choiceStr
- name of the choicecaseStr
- name of the case to set as selected case- Throws:
NavuException
- If the caseStr could not be set
-
equals
Compares the specified object with thisNavuContainer
for equality. Returnstrue
if the specified object is also aNavuContainer
and either of the following is true:- Both nodes are modules according to
NavuNodeInfo.isModule()
) and they have the same namespace URI. - The nodes are not modules, and have identical
ConfPath
instances.
- Both nodes are modules according to
-
setOperDataCase(String, String)