org.optimizationservices.oscommon.util
Class XPathUtil

java.lang.Object
  extended by org.optimizationservices.oscommon.util.XPathUtil

public class XPathUtil
extends java.lang.Object

The XPathUtil class contains methods for performing common basic XPath-related operations used by various classes in the Optimization Services (OS) framework.

Since:
OS1.0
Version:
1.0, 03/14/2004
Author:
Robert Fourer, Jun Ma, Kipp Martin

Constructor Summary
XPathUtil(java.lang.String xmlData, boolean isFile)
          constructor.
 
Method Summary
static void main(java.lang.String[] args)
          main for test purposes.
static java.lang.String printQueryResult(java.util.List queryResult)
          Print out the query result to a string for easy reading.
 java.util.List query(java.lang.String xPathString, java.util.HashMap variables)
          Use an XPath string to query xml data.
 java.lang.String queryFirst(java.lang.String xPathString, java.util.HashMap variables)
          Use an XPath string to query xml data and return the first found object in a string.
static java.lang.String queryResultToString(java.util.List queryResult)
          Convert a query result to a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathUtil

public XPathUtil(java.lang.String xmlData,
                 boolean isFile)
constructor.

Parameters:
xmlData - holds the name of the xml data to be queried. If null, the xml data will be located from within the xPath, i.e. the doc(...) section of xpath. The xmlData can either be a file name or an actual string that holds the xml data.
isFile - holds whether the xmlData is a a file name or, otherwise (if false) an actual string that holds the xml data.
Method Detail

query

public java.util.List query(java.lang.String xPathString,
                            java.util.HashMap variables)
Use an XPath string to query xml data.

Parameters:
xPathString - holds the XPath string that can be used to query xml data.
variables - holds a hashmap of external variable name-value paris to be fed into the the XPath.
Returns:
a list of query result in type java.util.List. If there is an error querying, returns null.

queryFirst

public java.lang.String queryFirst(java.lang.String xPathString,
                                   java.util.HashMap variables)
Use an XPath string to query xml data and return the first found object in a string.

Parameters:
xPathString - holds the XPath string that can be used to query xml data.
variables - holds a hashmap of external variable name-value paris to be fed into the the XPath.
Returns:
the first found object in string.

printQueryResult

public static java.lang.String printQueryResult(java.util.List queryResult)
Print out the query result to a string for easy reading.

Parameters:
queryResult - holds a list of query result in type java.util.List.
Returns:
the query result in a string for easy reading.

queryResultToString

public static java.lang.String queryResultToString(java.util.List queryResult)
Convert a query result to a string.

Parameters:
queryResult - holds a list of query result in type java.util.List.
Returns:
a string representation of the query result.

main

public static void main(java.lang.String[] args)
main for test purposes.

Parameters:
argv - command line arguments.