issrg.pba.rbac.xmlpolicy
Class PolicyXMLNode

java.lang.Object
  extended by issrg.pba.rbac.xmlpolicy.PolicyXMLNode
Direct Known Subclasses:
TermNode, XMLPolicyParser.ActionPolicyNode, XMLPolicyParser.DomainPolicyNode, XMLPolicyParser.DomainSpecNode, XMLPolicyParser.MSoDPolicySetNode, XMLPolicyParser.PMIXMLPolicyNode, XMLPolicyParser.RepositoryPolicyNode, XMLPolicyParser.RoleAssignmentPolicyNode, XMLPolicyParser.RoleHierarchyNode, XMLPolicyParser.RoleHierarchyPolicyNode, XMLPolicyParser.RoleListNode, XMLPolicyParser.RoleSpecNode, XMLPolicyParser.SOAPolicyNode, XMLPolicyParser.TargetAccessPolicyNode

public class PolicyXMLNode
extends java.lang.Object

This is the class that represents the node of the XML Policy. Its subclasses are used when parsing the Policy.

As the XMLPolicyParser has been written in 2000, the DOM3 classes were not readily available with Java, so we went for a lightweight parser, SAX parser. XMLPolicyParser is an extension of SAXParser, which builds a tree of PolicyXMLNodes, similar to the trees of Nodes, built by modern DOM3 parsers. XMLPolicyParser keeps a register of classes corresponding to each XML tag, so when such tag is encountered in XML, a respective class is instantiated. It is assumed that each class extends PolicyXMLNode.

Version:
1.0
Author:
A Otenko

Field Summary
protected  java.util.Map attributes
          This is the Map of element attributes by their names; each element is a String.
protected  java.util.Vector children
          This is a collection of the element children nodes; each element is of the PolicyXMLNode class.
protected  java.lang.String name
          The name of the node.
protected  java.lang.String nodeStr
          This is the string associated with the node.
 
Constructor Summary
protected PolicyXMLNode()
          This constructor builds a PolicyXMLNode with no name and no attributes.
protected PolicyXMLNode(java.lang.String nodeName)
          This constructor builds a node with a given name, but no attributes.
  PolicyXMLNode(java.lang.String nodeName, org.xml.sax.Attributes attr)
          This constructor builds a node with the given name and a set of attributes.
  PolicyXMLNode(java.lang.String nodeName, java.util.Map attrs)
          This constructor builds a node with the given name and a set of attributes, though, the attributes are in a different form.
 
Method Summary
 void addChild(PolicyXMLNode child)
          This method adds another child to the collection of children.
 void addString(java.lang.String str)
          This method adds more text that is read in blocks by the XML Parser.
 void construct()
          This method is called when the node is closed.
 java.util.Map getAttributes()
          This method returns the collection of attributes for this node; for walking the tree.
 java.util.Vector getChildren()
          This method returns the collection of children.
 java.lang.String getName()
          This method returns the name of the node, so you could walk down the tree, if you wanted.
 java.lang.String getString()
          This method returns the text contained between the opening and closing tags of the element.
 java.lang.String toString()
           
 java.lang.String toXML()
          This function returnes the XML representation of the XML element.
 void toXML(java.lang.StringBuffer xmlStr, java.lang.String currentIndent, java.lang.String indentIncrement)
          This method converts the node to XML text with the specified indent for the current node and the indent increment for children nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of the node. It can differ from what is actually stated in the XML, if the implementation desires.


attributes

protected java.util.Map attributes
This is the Map of element attributes by their names; each element is a String.


children

protected java.util.Vector children
This is a collection of the element children nodes; each element is of the PolicyXMLNode class.


nodeStr

protected java.lang.String nodeStr
This is the string associated with the node. it is normally the string that appears beteeen the opening tag and the closing tag. For example, if <Obligation> This is the obligation node. </Obligation> string will be holding the String "This is the obligation node."

Constructor Detail

PolicyXMLNode

protected PolicyXMLNode()
This constructor builds a PolicyXMLNode with no name and no attributes. This is equivalent to using PolicyXMLNode("", null) constructor.


PolicyXMLNode

protected PolicyXMLNode(java.lang.String nodeName)
This constructor builds a node with a given name, but no attributes.

Parameters:
nodeName - - the name of the XML element

PolicyXMLNode

public PolicyXMLNode(java.lang.String nodeName,
                     org.xml.sax.Attributes attr)
This constructor builds a node with the given name and a set of attributes.

Parameters:
nodeName - - the name of the XML element
attr - - the attributes of the XML element represented by this object

PolicyXMLNode

public PolicyXMLNode(java.lang.String nodeName,
                     java.util.Map attrs)
This constructor builds a node with the given name and a set of attributes, though, the attributes are in a different form.

Parameters:
nodeName - - the name of the XML element
attrs - - the Map of attributes of the XML element represented by this object
Method Detail

addString

public void addString(java.lang.String str)
This method adds more text that is read in blocks by the XML Parser. This text is the text that appears between the opening and closing tags of a XML element.

Parameters:
str - is the string associated with the node

getString

public java.lang.String getString()
This method returns the text contained between the opening and closing tags of the element. <Obligation> This is the text returned by this method </Obligation>

Returns:
the String associated with the node

addChild

public void addChild(PolicyXMLNode child)
This method adds another child to the collection of children. It should be called before the call to the construct method to have any effect.

Parameters:
child - is the node to append as a child node at the end of the list of children
See Also:
construct()

getName

public java.lang.String getName()
This method returns the name of the node, so you could walk down the tree, if you wanted.

Returns:
String name of the XML element represented by this object

getAttributes

public java.util.Map getAttributes()
This method returns the collection of attributes for this node; for walking the tree.

Returns:
Map of the attributes of this XML element

getChildren

public java.util.Vector getChildren()
This method returns the collection of children. Each of the objects of the Vector is of type PolicyXMLNode.

Returns:
Vector of children of this XML element; never null, but may be empty, if there are no children of this element

construct

public void construct()
               throws PolicyParsingException
This method is called when the node is closed. It performs the actual semantic loading of the node. Without it, the implementations may assume they are not ready to be used.

This method does nothing by default, and should be overridden.

Throws:
PolicyParsingException - if any syntax or semantics error occurred

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this XML element; by default returns the XML representation of it

toXML

public java.lang.String toXML()
This function returnes the XML representation of the XML element. It outputs the internal structure to XML text. The text is not a complete XML file as it does not include the XML headers, etc. It only generates the text as a component of an XML file, thus it's the text of the subtree begining with the current node. Example Output:
<Obligations>
  <Obligation ObligationID="111" Chronicle="BeforeEnforcement"/>
  <Obligation ObligationID="123" Chronicle="BeforeEnforcement">
  Any Text here representing the chilldren of the obligation 123.
  </Obligation>
 </Obligations>


toXML

public void toXML(java.lang.StringBuffer xmlStr,
                  java.lang.String currentIndent,
                  java.lang.String indentIncrement)
This method converts the node to XML text with the specified indent for the current node and the indent increment for children nodes.

Parameters:
xmlStr - - the StringBuffer to output the XML text to
currentIndent - - the indent for the current node; if null, no indentation is performed for this node, or any children, and the whole piece of XML will be output as a single line
indentIncrement - - the increment of indentation between the current node and its childrent; has no effect, if the currentIndent is null; if this value is null, two white spaces are used as the indentation