com.sun.faban.harness
Class ParamRepository

java.lang.Object
  extended by com.sun.faban.harness.ParamRepository

public class ParamRepository
extends Object

The ParamRepository is the programmatic representation of the configuration file. It allows access to the xml file via xpath. In addition, the ParamRepository also allows updating the configuration file. Such updates should be made during the validation stage.


Nested Class Summary
static class ParamRepository.HostConfig
          HostConfig structure holding a hostConfig element from the config file.
 
Constructor Summary
ParamRepository(String file, boolean warnDeprecated)
          Constructor: Open specified repository.
 
Method Summary
 Element addParameter(Element parent, String paramName)
          Adds a new XPath to the param repository, based on a previously added parameter.
 Element addParameter(Element parent, String namespace, String prefix, String paramName)
          Adds a new XPath to the param repository, based on a previously added parameter.
 Element addParameter(String baseXPath, String paramName)
          Adds a new XPath to the param repository.
 Element addParameter(String baseXPath, String namespace, String prefix, String paramName)
          Adds a new XPath to the param repository.
 List<String> getAttributeValues(String elementPath, String attributeName)
          Gets the attribute values for the specified attribute of a certain XPath.
 boolean getBooleanValue(String xpath)
          This method reads a value using the XPath and converts it to a boolean.
 boolean getBooleanValue(String xpath, boolean defaultValue)
          Obtains the boolean value at the given xpath, providing a default value if it does not exist or is not a boolean.
 boolean getBooleanValue(String xpath, Element base)
          This method reads a value using the XPath and converts it to a boolean.
 boolean getBooleanValue(String xpath, Element base, boolean defaultValue)
          This method reads a value using the XPath and converts it to a boolean.
 List<NameValuePair<Integer>> getEnabledHostPorts(Element base)
          Obtains the list of enabled hostports.
 String[] getEnabledHosts(Element base)
          Obtains the list of enabled hosts.
 List<ParamRepository.HostConfig> getHostConfigs()
          Obtains the list of enabled host configurations.
 List<NameValuePair<Integer>> getHostPorts(Element base)
          Obtains the host:port pairs at this element.
 List<NameValuePair<Integer>> getHostPorts(String xPathExpr)
          Obtains the host:port name value pair list from the element matching this XPath.
 List<NameValuePair<String>> getHostRoles()
          Obtains the host/role mappings.
 Node getNode(String xPath)
          Generic method to get a Node for a given xpath.
 Node getNode(String xPath, Element top)
          Generic method to get a Node for a given xpath with respect to base node.
 NodeList getNodeListForTagName(String tagName)
          Generic method to get NodeList for a given tagName.
 NodeList getNodes(String xPath)
          Generic method to get NodeList for a given xpath.
 NodeList getNodes(String xPath, Element top)
          Generic method to get NodeList for a given xpath with respect to base node.
 String getParameter(String xpath)
          Generic parameter access method.
 String getParameter(String xpath, Element top)
          Generic parameter access method.
 List<String> getParameters(String xpath)
          Generic parameter access method.
 List<String[]> getTokenizedList(String xpath)
          Obtains xpath values matching an xpath, broken into tokens.
 List<String[]> getTokenizedParameters(String xpath)
          This returns tokenized values of parameters in a list.
 String[] getTokenizedValue(String xpath)
          Obtains the value at an XPath, tokenized into an array.
 String[] getTokenizedValue(String xpath, Element base)
          Obtains the value at an XPath, tokenized into an array, from a specific base node in the document.
 NodeList getTopLevelElements()
          Generic method to get a list of top level nodes.
 void save()
          Saves the parameter repository back to file if it has been modified.
 void setParameter(Element element, String value)
          Sets the parameter for a newly added DOM element.
 void setParameter(String xpath, String newValue)
          Sets or replaces the parameter referenced by the XPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParamRepository

public ParamRepository(String file,
                       boolean warnDeprecated)
Constructor: Open specified repository.

Parameters:
file - Name of repository
warnDeprecated - Log warning when config file is deprecated
Method Detail

getParameter

public String getParameter(String xpath)
Generic parameter access method.

Parameters:
xpath -
Returns:
value of the parameter of type string

getParameter

public String getParameter(String xpath,
                           Element top)
Generic parameter access method.

Parameters:
xpath - string
top - element
Returns:
value of the parameter

getNodeListForTagName

public NodeList getNodeListForTagName(String tagName)
Generic method to get NodeList for a given tagName.

Parameters:
tagName - of type string
Returns:
NodeList for the tagName

getTopLevelElements

public NodeList getTopLevelElements()
Generic method to get a list of top level nodes.

Returns:
NodeList

getNodes

public NodeList getNodes(String xPath)
Generic method to get NodeList for a given xpath.

Parameters:
xPath - string
Returns:
NodeList for the xpath

getNodes

public NodeList getNodes(String xPath,
                         Element top)
Generic method to get NodeList for a given xpath with respect to base node.

Parameters:
xPath - string
top - element
Returns:
NodeList

getNode

public Node getNode(String xPath)
Generic method to get a Node for a given xpath.

Parameters:
xPath - string
Returns:
Node for the xpath

getNode

public Node getNode(String xPath,
                    Element top)
Generic method to get a Node for a given xpath with respect to base node.

Parameters:
xPath - string
top - element
Returns:
Node for the xpath

addParameter

public Element addParameter(String baseXPath,
                            String paramName)
Adds a new XPath to the param repository.

Parameters:
baseXPath - The base XPath to add this node
paramName - The element name
Returns:
The newly added element, or null on failure

addParameter

public Element addParameter(String baseXPath,
                            String namespace,
                            String prefix,
                            String paramName)
Adds a new XPath to the param repository.

Parameters:
baseXPath - The base XPath to add this node
namespace - The namespace for this new element, if any
prefix - The namespace prefix for this new element, if any
paramName - The element name
Returns:
The newly added element, or null on failure

addParameter

public Element addParameter(Element parent,
                            String paramName)
Adds a new XPath to the param repository, based on a previously added parameter.

Parameters:
parent - The parent element to add this node to
paramName - The element name
Returns:
The newly added element, or null on failure

addParameter

public Element addParameter(Element parent,
                            String namespace,
                            String prefix,
                            String paramName)
Adds a new XPath to the param repository, based on a previously added parameter.

Parameters:
parent - The parent element to add this node to
namespace - The namespace for this new element, if any
prefix - The namespace prefix for this new element, if any
paramName - The element name
Returns:
The newly added element, or null on failure

setParameter

public void setParameter(String xpath,
                         String newValue)
Sets or replaces the parameter referenced by the XPath.

Parameters:
xpath - The xpath referencing the parameter
newValue - The new value to set

setParameter

public void setParameter(Element element,
                         String value)
Sets the parameter for a newly added DOM element.

Parameters:
element - The newly added element
value - The value to assign to the element

save

public void save()
          throws Exception
Saves the parameter repository back to file if it has been modified.

Throws:
Exception - If there is an exception saving the repository.

getParameters

public List<String> getParameters(String xpath)
Generic parameter access method.

Parameters:
xpath -
Returns:
list containing all paramters with the xpath

getAttributeValues

public List<String> getAttributeValues(String elementPath,
                                       String attributeName)
Gets the attribute values for the specified attribute of a certain XPath.

Parameters:
elementPath - The XPath of the element
attributeName - The name of the attribute
Returns:
A list of attribute values

getHostConfigs

public List<ParamRepository.HostConfig> getHostConfigs()
                                                throws ConfigurationException
Obtains the list of enabled host configurations.

Returns:
A list of enabled hosts configurations
Throws:
ConfigurationException - Error reading the configuration

getEnabledHosts

public String[] getEnabledHosts(Element base)
                         throws ConfigurationException
Obtains the list of enabled hosts.

Parameters:
base - element
Returns:
A list of enabled hosts, grouped by host type.
Throws:
ConfigurationException

getEnabledHostPorts

public List<NameValuePair<Integer>> getEnabledHostPorts(Element base)
                                                 throws ConfigurationException
Obtains the list of enabled hostports.

Parameters:
base - element
Returns:
A list of enabled hostports.
Throws:
ConfigurationException

getTokenizedParameters

public List<String[]> getTokenizedParameters(String xpath)
This returns tokenized values of parameters in a list. Mainly used to get host(s)

Parameters:
xpath - The xpath to the parameters
Returns:
List of tokenized values

getTokenizedValue

public String[] getTokenizedValue(String xpath)
Obtains the value at an XPath, tokenized into an array.

Parameters:
xpath - XPath expression to get SPACE seperated values from a single parameter. For Example sutConfig/host The values are seperated by SPACE
Returns:
An array of hostnames.

getTokenizedValue

public String[] getTokenizedValue(String xpath,
                                  Element base)
Obtains the value at an XPath, tokenized into an array, from a specific base node in the document.

Parameters:
xpath - XPath expression to get SPACE seperated values from a single parameter. For Example sutConfig/host The values are seperated by SPACE
base - The base element.
Returns:
An array of hostnames.

getTokenizedList

public List<String[]> getTokenizedList(String xpath)
Obtains xpath values matching an xpath, broken into tokens.

Parameters:
xpath - XPath expression to get ',' and SPACE seperated values from a single parameter. For Example sutConfig/instances The values are seperated by ',' and then by SPACE
Returns:
List of arrays of hostnames

getHostPorts

public List<NameValuePair<Integer>> getHostPorts(String xPathExpr)
Obtains the host:port name value pair list from the element matching this XPath.

Parameters:
xPathExpr -
Returns:
The list of host:port elements, or null if the XPath does not exist or does not point to a host:port node.

getHostPorts

public List<NameValuePair<Integer>> getHostPorts(Element base)
Obtains the host:port pairs at this element.

Parameters:
base - The base element
Returns:
The list of host:port pairs

getHostRoles

public List<NameValuePair<String>> getHostRoles()
                                         throws ConfigurationException
Obtains the host/role mappings.

Returns:
The host/role mappings
Throws:
ConfigurationException - Invalid host/role mapping

getBooleanValue

public boolean getBooleanValue(String xpath)
This method reads a value using the XPath and converts it to a boolean.

Parameters:
xpath - XPath expression to the value which is true or false
Returns:
true or false

getBooleanValue

public boolean getBooleanValue(String xpath,
                               boolean defaultValue)
Obtains the boolean value at the given xpath, providing a default value if it does not exist or is not a boolean.

Parameters:
xpath - The given xpath
defaultValue - The default value
Returns:
The boolean at the xpath, or the given default

getBooleanValue

public boolean getBooleanValue(String xpath,
                               Element base)
This method reads a value using the XPath and converts it to a boolean.

Parameters:
xpath - XPath expression to the value which is true or false
base - element
Returns:
true or false

getBooleanValue

public boolean getBooleanValue(String xpath,
                               Element base,
                               boolean defaultValue)
This method reads a value using the XPath and converts it to a boolean.

Parameters:
xpath - XPath expression to the value which is true or false
base - element
defaultValue -
Returns:
true or false