public abstract class YangElement extends Element
Element. It is an extension of the Element
class to make the configuration sub-tree data model aware. Classes generated
from the JNC pyang plugin are either YangElements or derived data types.
Thus the YangElement which is an abstract class is never used directly.
Fundamental methods for comparing, syncing, and inspecting sets of configuration data, is provided by this class. The following two methods highlights the fundamental purpose of this library:
checkSync - checks if two configurations are equal,
or if a sync is needed. This is a typical operation a manager would like to
do when one configuration is stored on the device and the other is stored in
a database.
sync - will calculate the difference between two
configuration sub trees and build up a resulting subtree which is basically
a tree with NETCONF operations needed to turn the source tree into the
target tree. The purpose of this is to find a minimal set of operations to
sync two configurations so that they become equal.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COLON_UNEXPECTED_ELEMENT |
static java.lang.String |
DUMMY |
static java.lang.String |
DUMMY_LC |
children, CREATE_MERGE, CREATE_MERGE_MULTI, CREATE_NEW, defaultPrefixes, name, namespace, NETCONF_NAMESPACE, OP_CREATE, OP_DELETE, OP_MERGE, OP_REPLACE, OPERATION, parent, prefixes, value| Constructor and Description |
|---|
YangElement(java.lang.String ns,
java.lang.String name)
Constructor with namespace and name
|
| Modifier and Type | Method and Description |
|---|---|
protected static java.lang.String |
camelize(java.lang.String s) |
static boolean |
checkSync(NodeSet a,
NodeSet b)
Checks if two configurations are equal, or if a sync is needed.
|
boolean |
checkSync(YangElement b)
Checks if two configurations are equal, or if a sync is needed.
|
static boolean |
checkSync(YangElement a,
YangElement b)
Checks if two configurations are equal, or if a sync is needed.
|
protected abstract java.lang.String[] |
childrenNames()
Structure information.
|
protected YangElement |
cloneContent(YangElement copy)
Clones the content of this YangElement into a target copy.
|
protected abstract Element |
cloneShallow()
Clones a YangElement.
|
protected YangElement |
cloneShallowContent(YangElement copy)
Clones the contents of this YangElement into a target copy.
|
int |
compare(Element b)
Compares children values of this YangElement with those of another
Element.
|
int |
compare(YangElement b)
Compares children values of this YangElement with those of another
YangElement.
|
protected static Element |
createInstance(com.tailf.jnc.ElementHandler parser,
Element parent,
java.lang.String ns,
java.lang.String name)
Creates an instance of a child using class generated by the JNC pyang
plugin.
|
protected void |
encode(Transport out,
boolean newline_at_end,
Capabilities capas)
Encode to XML and send it to the provided stream.
|
static void |
getDiff(YangElement a,
YangElement b,
NodeSet uniqueA,
NodeSet uniqueB,
NodeSet changedA,
NodeSet changedB)
Produces the 'diff' between two trees.
|
static java.lang.String |
getPackage(java.lang.String ns)
Locate package from Namespace.
|
boolean |
isChild(java.lang.String childName)
Checks if this YangElement has a child with specified name.
|
protected boolean |
isLeafDefault(java.lang.String path) |
boolean |
keyCompare(YangElement b)
Given two (YANG) list entries - compare the keys and return true if both
YANG objects are the same
|
protected abstract java.lang.String[] |
keyNames()
Structure information.
|
protected void |
markLeafCreate(java.lang.String path) |
protected void |
markLeafDelete(java.lang.String path) |
protected void |
markLeafMerge(java.lang.String path) |
protected void |
markLeafReplace(java.lang.String path) |
protected static java.lang.String |
normalize(java.lang.String s) |
static YangElement |
readFile(java.lang.String filename)
Read file with XML text and parse it into a data model aware
configuration tree.
|
static void |
removePackage(java.lang.String ns)
Remove a package from the list of Packages
|
protected YangElement |
searchOne(java.lang.String path) |
protected void |
setLeafListValue(java.lang.String ns,
java.lang.String path,
java.lang.Object value,
java.lang.String[] childrenNames) |
protected void |
setLeafValue(java.lang.String ns,
java.lang.String path,
java.lang.Object value,
java.lang.String[] childrenNames) |
void |
setLeafValue(java.lang.String ns,
java.lang.String name,
java.lang.String value)
Sets the leaf value of the specified leaf of this YangElement.
|
static void |
setPackage(java.lang.String ns,
java.lang.String pkg)
Assiciate a JAVA package with a namespace.
|
static NodeSet |
sync(NodeSet a,
NodeSet b)
Will return a list of subtrees for syncing a subtree A with all the
necessary operations to make it look like the target tree B.
|
YangElement |
sync(YangElement b)
Will return a subtree for syncing a subtree A with all the necessary
operations to make it look like the target tree B.
|
static YangElement |
sync(YangElement a,
YangElement b)
Will return a subtree for syncing a subtree A with all the necessary
operations to make it look like the target tree B.
|
static NodeSet |
syncMerge(NodeSet a,
NodeSet b)
Returns a list of subtrees for syncing a subtree A with all the
necessary operations to make it look like the target tree B.
|
static YangElement |
syncMerge(YangElement a,
YangElement b)
Will return a subtree for syncing a subtree A with all the necessary
operations to make it look like the target tree B.
|
addAttr, addChild, clone, cloneAttrs, cloneValue, create, create, create, createChild, createChild, createChild, createPath, createPath, createPath, createPath, createPath, createPath, delete, delete, deleteChild, deleteValue, deleteValue, encode, encode, encode, equals, exists, get, getAttr, getAttrs, getAttrValue, getChild, getChild, getChildren, getChildren, getContextPrefixMap, getElementPath, getElementPath, getFirst, getLast, getParent, getRootElement, getValue, getValue, getValueOfChild, getValues, getValuesAsSet, hasChildren, hashCode, insertChild, insertChild, insertChild, insertFirst, insertLast, iterator, iterator, lookupContextPrefix, markCreate, markCreate, markDelete, markDelete, markMerge, markMerge, markReplace, markReplace, merge, nsToPrefix, position, prefix, qualifiedName, removeAttr, removeAttr, removeDefaultPrefix, removeMark, removeMarks, removePrefix, setAttr, setAttr, setDebugLevel, setDefaultPrefix, setPrefix, setPrefix, setPrefix, setValue, setValue, tagpath, toString, toXMLString, writeFilepublic static final java.lang.String COLON_UNEXPECTED_ELEMENT
public static final java.lang.String DUMMY
public static final java.lang.String DUMMY_LC
public YangElement(java.lang.String ns,
java.lang.String name)
protected abstract java.lang.String[] childrenNames()
protected abstract java.lang.String[] keyNames()
protected static Element createInstance(com.tailf.jnc.ElementHandler parser, Element parent, java.lang.String ns, java.lang.String name) throws YangException
parser - ElementHandler to set unknownLevel in, in case incoming
data uses a newer revisionparent - The parent element of the child to be instantiated,
null if root.ns - Namespace of the child to be instantiatedname - Name of the child to be instantiatedYangException - if unable to instantiate the childpublic void setLeafValue(java.lang.String ns,
java.lang.String name,
java.lang.String value)
throws YangException,
JNCException
ns - name - value - YangExceptionJNCExceptionpublic static java.lang.String getPackage(java.lang.String ns)
public static void setPackage(java.lang.String ns,
java.lang.String pkg)
public static void removePackage(java.lang.String ns)
protected static java.lang.String camelize(java.lang.String s)
protected static java.lang.String normalize(java.lang.String s)
protected void setLeafValue(java.lang.String ns,
java.lang.String path,
java.lang.Object value,
java.lang.String[] childrenNames)
throws JNCException
JNCExceptionprotected void setLeafListValue(java.lang.String ns,
java.lang.String path,
java.lang.Object value,
java.lang.String[] childrenNames)
throws JNCException
JNCExceptionprotected boolean isLeafDefault(java.lang.String path)
throws JNCException
JNCExceptionprotected void markLeafReplace(java.lang.String path)
throws JNCException
JNCExceptionprotected void markLeafMerge(java.lang.String path)
throws JNCException
JNCExceptionprotected void markLeafCreate(java.lang.String path)
throws JNCException
JNCExceptionprotected void markLeafDelete(java.lang.String path)
throws JNCException
JNCExceptionprotected YangElement searchOne(java.lang.String path) throws JNCException
JNCExceptionpublic boolean keyCompare(YangElement b)
public int compare(YangElement b)
b - YangElement to compare against.public int compare(Element b)
public static void getDiff(YangElement a, YangElement b, NodeSet uniqueA, NodeSet uniqueB, NodeSet changedA, NodeSet changedB)
Attributes are not included in the inspection. Only YangElement structures and leaf-values are checked.
Note that both subtrees must have a common starting point YangElement in order to compare them.
a - Subtree A (YangElement)b - Subtree B (YangElement)uniqueA - Place for elements that are unique to A.uniqueB - Place for elements that are unique to B.changedA - Place for elements changed in A.changedB - Place for elements changed in B.public boolean checkSync(YangElement b)
b - public static boolean checkSync(NodeSet a, NodeSet b)
public static boolean checkSync(YangElement a, YangElement b)
public YangElement sync(YangElement b) throws JNCException
JNCExceptionpublic static YangElement sync(YangElement a, YangElement b) throws JNCException
syncMerge(com.tailf.jnc.NodeSet, com.tailf.jnc.NodeSet) produces a NETCONF tree with the merge
operation instead.JNCExceptionpublic static NodeSet syncMerge(NodeSet a, NodeSet b) throws JNCException
JNCExceptionpublic static YangElement syncMerge(YangElement a, YangElement b)
public static NodeSet sync(NodeSet a, NodeSet b) throws JNCException
JNCExceptionprotected abstract Element cloneShallow()
cloneShallow in class Elementprotected YangElement cloneShallowContent(YangElement copy)
Note: Used by the generated JNC classes The key children are already cloned.
copy - The target copy to clone the contents toprotected YangElement cloneContent(YangElement copy)
Note: Used by the generated JNC classes. The key children should already be cloned into copy.
copy - The target copy to clone the contents intopublic static YangElement readFile(java.lang.String filename) throws JNCException
filename - File name.JNCExceptionElement.writeFile(String)protected void encode(Transport out, boolean newline_at_end, Capabilities capas) throws JNCException
ElementThe newline_at_end argument controls whether a newline char is permitted at the end or not.
encode in class Elementout - Stream to send the encoded version of this element to.newline_at_end - If 'true' a newline is printed at the end.JNCException - If a YangElement encode implementation fails.public boolean isChild(java.lang.String childName)
childName - The name to check fortrue if the child exists, false
otherwise.