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(int) 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
ConstructorsConstructorDescriptionThis constructor creates a root container.NavuContainer(Maapi m, int handle, int rootHash) Constructor for a single namespace.NavuContainer(NavuContext context) Creates an rootNavuContainera starting point of which further navigation is performed. -
Method Summary
Modifier and TypeMethodDescriptionReturns a reference to a subordinateactionwith the hash valuekey.Returns a reference to a subordinateactionwith the namekey.children()Returns a collection containing the children of this container.Returns a reference to a subordinatechoicewith the namename.container(ConfNamespace ns, String containerName) Returns a reference to a subordinatecontainerwith the namecontainerName, belonging to the namespacens.Returns a reference to a subordinatecontainerwith the hash valuekey.Returns a reference to a subordinatecontainerwith the namekey.booleancontainsNode(NavuNode node) Checks if the given node is a direct child of this container according to the schema.booleancontainsNode(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 currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.Encodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.entrySet()Returns a set of value-pairs.booleanCompares the specified object with thisNavuContainerfor equality.booleanexists()Verifies the existence of container.findChanges(NavuContext delContext, Integer[] criteria) Analyzes what changes has been done within this transaction.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.intGet the current Maapi user session if this container context uses Maapi.inthashCode()Return the hashCode of this NavuNode.booleanisEmpty()Checks if the container has any members.booleanReturnstrueif thisNavuContainerrepresents 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 subordinateleafwith the nameleafName, belonging to the namespacens.Returns a reference to a subordinateleafwith the hash valuekey.Returns a reference to a subordinateleafwith the namekey.leafList(ConfNamespace ns, String leafListName) Returns a reference to a subordinateleaf-listwith the nameleafListName, belonging to the namespacens.Returns a reference to a subordinateleaf-listwith the hash valuekey.Returns a reference to a subordinateleaf-listwith the namekey.list(ConfNamespace ns, String listName) Returns a reference to a subordinatelistwith the namelistName, belonging to the namespacens.Returns a reference to a subordinatelistwith the hash valuekey.Returns a reference to a subordinatelistwith the namekey.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.voidreset()Resets the contained nodesCreates an optional container.select(ConfObject[] kp) setChange(List<ConfObject> path, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) Creates an optional container.intsize()Returns the number of nodes contained by the container.toString()voidvalueUpdateInd(NavuNode child) An indication received from a child node.Methods inherited from class com.tailf.navu.NavuNode
context, getChangeFlag, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getParent, getValues, getValues, prepareXMLCall, setValues, setValues, sharedSetValues, sharedSetValues, 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_WRITEMAAPIsockethandle- a valid transaction handlerootHash- the root hash 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:
namespacein classNavuNode- Parameters:
ns- the namespace id- Returns:
- reference to this NavuContainer object
- Throws:
NavuException
-
container
Returns a reference to a subordinatecontainerwith the hash valuekey. Thecontainerhash value can be obtained as a constant from a namespace file generated byconfdcorncsc, 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:
containerin 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 subordinatecontainerwith the namekey.- Overrides:
containerin 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
containerwith the namecontainerName, belonging to the namespacens.Note that if
containerNameby itself uniquely identifies a subordinate container, that container will still have to belong to the namespacenscontrary to the functionality of the previous method using prefix and containerName.To get the namespace, you can use
ConfNamespace.findNamespace(String)with the namespace identifier or URI.- Overrides:
containerin 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 namecontainerNamein the namespacens
-
leaf
Returns a reference to a subordinateleafwith the hash valuekey.- Overrides:
leafin 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 subordinateleafwith the namekey.- Overrides:
leafin 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
leafwith the nameleafName, belonging to the namespacens.Note that if
leafNameby itself uniquely identifies a subordinate leaf, that leaf will still have to belong to the namespacenscontrary to the functionality of the previous method using prefix and leafName.To get the namespace, you can use
ConfNamespace.findNamespace(String)with the namespace identifier or URI.- Overrides:
leafin 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 namekeyin the namespacens
-
leafList
Returns a reference to a subordinateleaf-listwith the hash valuekey.- Overrides:
leafListin 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-listwith the namekey.- Overrides:
leafListin 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-listwith the nameleafListName, belonging to the namespacens.Note that if
leafListNameby itself uniquely identifies a subordinate leaf-list, that leaf-list will still have to belong to the namespacenscontrary to the functionality of the previous method using prefix and leafListName.To get the namespace, you can use
ConfNamespace.findNamespace(String)with the namespace identifier or URI.- Overrides:
leafListin 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 nameleafListNamein the namespacens
-
list
Returns a reference to a subordinatelistwith the hash valuekey.- Overrides:
listin 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 subordinatelistwith the namekey.- Overrides:
listin 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
listwith the namelistName, belonging to the namespacens.Note that if
listNameby itself uniquely identifies a subordinate list, that list will still have to belong to the namespacenscontrary to the functionality of the previous method using prefix and listName.- Overrides:
listin 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 namelistNamein the namespacens
-
action
Returns a reference to a subordinateactionwith 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 subordinateactionwith 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()Returnstrueif thisNavuContainerrepresents a list-entry- Returns:
trueif thisNavuContaineris 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:
childrenin classNavuNode- Returns:
- the children of this container
- Throws:
NavuException
-
choice
Returns a reference to a subordinatechoicewith 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:
existsin classNavuNode- Returns:
- boolean
- Throws:
NavuException
-
delete
Deletes an optional container.- 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:
-
entrySet
Returns a set of value-pairs.- Returns:
- a set of nodeName-node pairs according to the schema
- 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:
iteratein 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:
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
-
size
Returns the number of nodes contained by the container.- Returns:
- the number contained nodes.
- Throws:
NavuException
-
toString
-
select
- Specified by:
selectin classNavuNode- Returns:
- a collection a nodes matching a Regular Expression query
- Throws:
NavuException
-
getRootNS
Description copied from class:NavuNodeReturns the root namespace of the topmost ancestor. -
equals
Compares the specified object with thisNavuContainerfor equality. Returnstrueif the specified object is also aNavuContainerand 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
ConfPathinstances.
- Both nodes are modules according to
-
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.
-