net.juniper.netconf
Class XML

java.lang.Object
  extended bynet.juniper.netconf.XML

public class XML
extends java.lang.Object

An XML object represents XML content and provides methods to manipulate it. The XML object has an 'active' element, which represents the hierarchy at which the XML can be manipulated.

As an example, one

  1. creates a XMLBuilder object.
  2. create a configuration as an XML object.
  3. Call the loadXMLConfiguration(XML) method on Device


Constructor Summary
protected XML(org.w3c.dom.Element active)
           
 
Method Summary
 XML addPath(java.lang.String path)
          Append multiple elements under the active element of XML object, by specifying the path.The bottommost hierarchy element now becomes the active element.
 void addSibling(java.lang.String element)
          Add a sibling element with the active element of XML object.
 void addSibling(java.lang.String element, java.lang.String text)
          Append a sibling element, with text, with the active element of XML object.
 void addSiblings(java.util.HashMap map)
          Add multiple siblings with different names and different text, with the active element of XML object.
 void addSiblings(java.lang.String element, java.lang.String[] text)
          Add multiple sibling elements,with same names but different text, with the active element of XML object.
 void append(java.util.HashMap map)
          Append multiple elements with different names and different text, under the active element of XML object.
 XML append(java.lang.String element)
          Append an element under the active element of XML object.
 XML append(java.lang.String element, java.util.HashMap map)
          Append an element under the active element of XML object.
 XML append(java.lang.String element, java.lang.String text)
          Append an element, with text, under the active element of XML object.
 void append(java.lang.String element, java.lang.String[] text)
          Append multiple elements, with same name but different text under the active element of XML object.
 java.util.List findNodes(java.util.List list)
          Get all the nodes at a given hiearchy, as list of org.w3c.dom.Node objects.
 java.lang.String findValue(java.util.List list)
          Find the text value of an element.
 org.w3c.dom.Document getOwnerDocument()
          Get the owner Document for the XML object.
 void junosActivate()
          Sets the attribute ("active","active") for the active element of XML object.
 void junosDeactivate()
          Sets the attribute ("inactive","inactive") for the active element of XML object.
 void junosDelete()
          Sets the attribute ("delete","delete") for the active element of XML object.
 void junosInsert(java.lang.String before, java.lang.String name)
          Sets the attribute ("insert") and ("name") for the active element of XML object.
 void junosRename(java.lang.String toBeRenamed, java.lang.String newName)
          Sets the attribute ("rename") and ("name") for the active element of XML object.
 void setAttribute(java.lang.String name, java.lang.String value)
          Set attribute for the active element of XML object.
 void setText(java.lang.String text)
          Set text for the active element of XML object.
 java.lang.String toString()
          Get the xml string of the XML object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XML

protected XML(org.w3c.dom.Element active)
Method Detail

getOwnerDocument

public org.w3c.dom.Document getOwnerDocument()
Get the owner Document for the XML object.

Returns:
The org.w3c.dom.Document object for the XML

append

public XML append(java.lang.String element)
Append an element under the active element of XML object. The new element now becomes the active element.

Parameters:
element - The name of element to append.
Returns:
The modified XML after appending the element.

append

public XML append(java.lang.String element,
                  java.lang.String text)
Append an element, with text, under the active element of XML object. The new element now becomes the active element.

Parameters:
element - The name of element to append.
text - The text value of the element to be appended
Returns:
The modified XML after appending the element.

append

public void append(java.lang.String element,
                   java.lang.String[] text)
Append multiple elements, with same name but different text under the active element of XML object.

Parameters:
element - The name of elements to append.
text - The array containing text value for each element.

append

public void append(java.util.HashMap map)
Append multiple elements with different names and different text, under the active element of XML object.

Parameters:
map - The hashmap, each entry containing element name as the key and text value as the key value.

append

public XML append(java.lang.String element,
                  java.util.HashMap map)
Append an element under the active element of XML object. The new element now becomes the active element. Then, append multiple elements with different names and different text, under the new active element.

Parameters:
element - The name of the element to be appended.
map - The hashmap, each entry containing element name as the key and text value as the key value.
Returns:
The modified XML after appending the element.

addSibling

public void addSibling(java.lang.String element)
Add a sibling element with the active element of XML object.

Parameters:
element - The name of the new element to be added.

addSibling

public void addSibling(java.lang.String element,
                       java.lang.String text)
Append a sibling element, with text, with the active element of XML object.

Parameters:
element - The name of element to add.
text - The text value of the element to be appended.

addSiblings

public void addSiblings(java.lang.String element,
                        java.lang.String[] text)
Add multiple sibling elements,with same names but different text, with the active element of XML object.

Parameters:
element - The name of elements to add.
text - The array containing text value for each element.

addSiblings

public void addSiblings(java.util.HashMap map)
Add multiple siblings with different names and different text, with the active element of XML object.

Parameters:
map - The hashmap, each entry containing element name as the key and text value as the key value.

addPath

public XML addPath(java.lang.String path)
Append multiple elements under the active element of XML object, by specifying the path.The bottommost hierarchy element now becomes the active element.

Parameters:
path - The path to be added. For example, to add the hierarchy: <a> <b> <c/> </b> </a> The path should be "a/b/c"
Returns:
The modified XML

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Set attribute for the active element of XML object.

Parameters:
name - The name of the attribute.
value - The value of the attribute.

setText

public void setText(java.lang.String text)
             throws javax.xml.parsers.ParserConfigurationException
Set text for the active element of XML object.

Parameters:
text - The text value to be set
Throws:
javax.xml.parsers.ParserConfigurationException

junosDelete

public void junosDelete()
Sets the attribute ("delete","delete") for the active element of XML object.


junosActivate

public void junosActivate()
Sets the attribute ("active","active") for the active element of XML object.


junosDeactivate

public void junosDeactivate()
Sets the attribute ("inactive","inactive") for the active element of XML object.


junosRename

public void junosRename(java.lang.String toBeRenamed,
                        java.lang.String newName)
Sets the attribute ("rename") and ("name") for the active element of XML object.


junosInsert

public void junosInsert(java.lang.String before,
                        java.lang.String name)
Sets the attribute ("insert") and ("name") for the active element of XML object.


findValue

public java.lang.String findValue(java.util.List list)
Find the text value of an element.

Parameters:
list - The String based list of elements which determine the hierarchy. For example, for the below XML: <rpc-reply> <environment-information> <environment-item> <name>FPC 0 CPU</name> <temperature> To find out the text value of temperature node, the list should be- {"environment-information","environment-item", "name~FPC 0 CPU","temperature"}
Returns:
The text value of the element.

findNodes

public java.util.List findNodes(java.util.List list)
Get all the nodes at a given hiearchy, as list of org.w3c.dom.Node objects.

Parameters:
list - The String based list of elements which determine the hierarchy. For example, for the below XML: <rpc-reply> <environment-information> <environment-item> <name>FPC 0 CPU</name> To get the 'environment-item' Node with name 'FPC 0 CPU', , the list should be- {"environment-information", "environment-item", "name~FPC 0 CPU"}
Returns:
The list containing Nodes as org.w3c.dom.Node objects.

toString

public java.lang.String toString()
Get the xml string of the XML object.

Returns:
The XML data as a string