org.objectweb.proactive.core.xml
Class XMLPropertiesStore

java.lang.Object
  |
  +--org.objectweb.proactive.core.xml.XMLPropertiesStore

public class XMLPropertiesStore
extends java.lang.Object

This class implements a XML based preferences store. Constructor expect a URI pointing to an XML file containing the values. The URI can point to a file using the file protocol : file:///D:/doc/xml/properties.xml The data are loaded and parsed in memory. In order to query the values, the class uses a stripped down version of XPath expressions. The only supported expressions are combination of /, . and @ for the attributes. Here some examples of supported expressions : /a/b/c : returns the value of the node or the node c /a/b/c/ : returns the value of the node or the node c /a/b/c/. : returns the value of the node or the node c e/. : returns the value of the node e which should be a child of the given current node /a/b/c/@t : returns the value of the attribute node or the attribute node t &t : returns the value of the attribute node or the attribute node t which should be a child of the given current node

Version:
1.0
Author:
Lionel Mestre

Constructor Summary
XMLPropertiesStore(java.lang.String uri)
          Contructs a new intance of XMLPropertiesStore based on th given URI pointing to XML data.
 
Method Summary
 org.w3c.dom.Node[] getAllNodes(java.lang.String path)
          Returns all child nodes defined by the given path.
 org.w3c.dom.Node[] getAllNodes(java.lang.String path, org.w3c.dom.Node context)
          Returns all child nodes defined by the given path.
 int getValueAsInt(java.lang.String path, int defaultValue)
          Returns the value defined by the given path as an int.
 int getValueAsInt(java.lang.String path, org.w3c.dom.Node context, int defaultValue)
          Returns the value defined by the given path as a string.
 org.w3c.dom.Node getValueAsNode(java.lang.String path)
          Returns the value defined by the given path as an int.
 org.w3c.dom.Node getValueAsNode(java.lang.String path, org.w3c.dom.Node context)
          Returns the node defined by the given path.
 java.lang.String getValueAsString(java.lang.String path)
          Returns the value defined by the given path as a string.
 java.lang.String getValueAsString(java.lang.String path, org.w3c.dom.Node context)
          Returns the value defined by the given path as a string.
static org.w3c.dom.Document parseFromURI(java.lang.String uri)
          Parses the XML data the given URI points to and returns the DOM Document representing that XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLPropertiesStore

public XMLPropertiesStore(java.lang.String uri)
                   throws java.io.IOException
Contructs a new intance of XMLPropertiesStore based on th given URI pointing to XML data. The data are loaded and parsed into a DOM.

Parameters:
uri - the URI of the XML data containing the properties to read
Throws:
java.io.IOException - if the XML data cannot be loaded
Method Detail

parseFromURI

public static org.w3c.dom.Document parseFromURI(java.lang.String uri)
                                         throws java.io.IOException
Parses the XML data the given URI points to and returns the DOM Document representing that XML.

Parameters:
uri - the URI of the XML data containing the data to read
Throws:
java.io.IOException - if the XML data cannot be read or parsed

getValueAsString

public java.lang.String getValueAsString(java.lang.String path)
Returns the value defined by the given path as a string. If the XPath is not found null is returned

Parameters:
path - represents the XPath expression leading to the value. (see restrictions in the class description)
Returns:
the value identified by path or null

getValueAsInt

public int getValueAsInt(java.lang.String path,
                         int defaultValue)
Returns the value defined by the given path as an int. If the XPath is not found null is returned

Parameters:
path - represents the XPath expression leading to the value. (see restrictions in the class description)
defaultValue - the defaultValue to return if the value cannot be found
Returns:
the value identified by path or the defaultValue

getValueAsNode

public org.w3c.dom.Node getValueAsNode(java.lang.String path)
Returns the value defined by the given path as an int. If the XPath is not found null is returned

Parameters:
path - represents the XPath expression leading to the value. (see restrictions in the class description)
Returns:
the node identified by path or null

getAllNodes

public org.w3c.dom.Node[] getAllNodes(java.lang.String path)
Returns all child nodes defined by the given path. If the XPath is not found null is returned.

Parameters:
path - represents the XPath expression leading to the nodes. (see restrictions in the class description)
Returns:
all nodes identified by path or null

getValueAsString

public java.lang.String getValueAsString(java.lang.String path,
                                         org.w3c.dom.Node context)
Returns the value defined by the given path as a string. If the XPath is not found null is returned

Parameters:
path - represents the XPath expression leading to the value. It is relative to the given context.
context - the node from which to interprete the XPath expression.
Returns:
the value identified by path or null

getValueAsInt

public int getValueAsInt(java.lang.String path,
                         org.w3c.dom.Node context,
                         int defaultValue)
Returns the value defined by the given path as a string. If the XPath is not found null is returned

Parameters:
path - represents the XPath expression leading to the value. It is relative to the given context.
context - the node from which to interprete the XPath expression.
defaultValue - the defaultValue to return if the value cannot be found
Returns:
the value identified by path or the defaultValue

getValueAsNode

public org.w3c.dom.Node getValueAsNode(java.lang.String path,
                                       org.w3c.dom.Node context)
Returns the node defined by the given path. If the XPath is not found null is returned. The XPath is interpreted from the given node.

Parameters:
path - represents the XPath expression leading to the property. (see restrictions in the class description)
context - the node from which to interprete the XPath expression.
Returns:
the node of the property identified by path or null

getAllNodes

public org.w3c.dom.Node[] getAllNodes(java.lang.String path,
                                      org.w3c.dom.Node context)
Returns all child nodes defined by the given path. If the XPath is not found null is returned. The XPath is interpreted from the given node.

Parameters:
path - represents the XPath expression leading to the nodes. (see restrictions in the class description)
context - the node from which to interprete the XPath expression.
Returns:
all nodes identified by path or null


Copyright © April 2004 INRIA All Rights Reserved.