uk.ac.ic.doc.automed
Class Util

java.lang.Object
  extended by uk.ac.ic.doc.automed.Util

public class Util
extends java.lang.Object


Constructor Summary
Util()
           
 
Method Summary
static java.util.List addArrayToList(java.lang.Object[] src, java.util.List dst)
          Adds in order all elements in the source array to the destination List and returns the destination list so that the method can be used as an argument to a method call.
static java.lang.String addPrefix(java.lang.String prefix, java.lang.String msg)
          Adds the prefix to the beginning of each line in message
static java.lang.String caseCommand(java.lang.String command)
          converts the argument into lower case with the first letter in uppercase
static java.lang.Object executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.OutputStream feedback)
           
static java.lang.Object executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.OutputStream feedback, java.util.Set nullifyZeros)
           
static java.lang.Object executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.Writer feedback)
          Executes the sql statement on the JDBC Concection and returns either a ResultSet, an Integer representing the update count or an SQLException if thrown when executing the command.
static java.lang.Object executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.Writer feedback, java.util.Set nullifyZeros)
           
static java.lang.Object[] executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.OutputStream feedback)
           
static java.lang.Object[] executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.OutputStream feedback, java.util.Set nullifyZeros)
           
static java.lang.Object[] executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.Writer feedback)
          Calls {link #executeStatement(String, Connection, Writer)} with each each statement in sql seperated by del.
static java.lang.Object[] executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.Writer feedback, java.util.Set nullifyZeros)
           
static java.net.URL findAutoMedFile(java.lang.String filename, java.lang.String className)
           
static java.net.URL findFile(java.lang.String name, java.lang.String relClassName)
          Returns a URL for the given name using several methods to make it useful for locating configuration files, resources etc.
static java.io.InputStream getAutoMedFile(java.lang.String filename, java.lang.String className)
           
static java.lang.String[] getColumnNames(java.sql.ResultSet rst)
           
static int[] getColumnTypes(java.sql.ResultSet rst)
           
static java.lang.String getDefaultPath(java.lang.String path)
          Return the default path to a file/directory given its relative name
E.g.: given automed --> $USERHOME/.automed/automed
static java.io.InputStream getFile(java.lang.String name, java.lang.String className)
           
static java.lang.String getInsertableSQLValue(java.lang.Object value, int sqlType)
           
static java.lang.String[] getOpts(java.lang.String format, java.lang.String[] args)
           
static int getSQLType(java.lang.String name)
           
static java.lang.String getSQLTypeName(int t)
           
static long getStackSize(java.lang.Throwable t)
          Determine the size (in bytes) of an exception stack
static void printObject(java.lang.Object val, java.io.OutputStream out)
           
static void printObject(java.lang.Object val, java.io.Writer out)
           
static void printResultSet(java.sql.ResultSet rst, java.io.OutputStream out)
           
static void printResultSet(java.sql.ResultSet rst, java.io.Writer out)
           
static void printSQLFeedback(java.lang.Object obj, java.io.OutputStream out, java.lang.String sql)
           
static void printSQLFeedback(java.lang.Object obj, java.io.Writer out, java.lang.String sql)
           
static java.lang.String replace(java.lang.String s, java.lang.String substring)
          Returns a new string resulting from replacing all occurences of substring in string s with \ followed by substring.
static java.lang.String replaceAll(java.lang.String original, java.lang.String pattern, java.lang.String replacement)
          Replace all occurences of a substring with a new string
static java.lang.Object[][] resultSetToArray(java.sql.ResultSet rst)
           
static java.lang.String safeSQLString(java.lang.String unsafeSQLString)
          Provide a version of a string that is safe to use in JDBC update statements.
static java.lang.String[] split(java.lang.String splitStr, java.lang.String delimiter)
          Split a delimited string dmle 27/2/2006
static java.lang.String[] split(java.lang.String splitStr, java.lang.String delimiter, int limit)
          A classic-version of split-string method which does NOT support RegExp
static java.lang.Object stringToObject(java.lang.String value, java.lang.Class type)
           
static java.lang.String[] tokenize(java.lang.String s)
          Returns the tokens in s (as defined by default StringTokenizer) as an array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

safeSQLString

public static java.lang.String safeSQLString(java.lang.String unsafeSQLString)
Provide a version of a string that is safe to use in JDBC update statements. In particular, all single quotes are changed to be escaped with an extra single quote, abd the text string has single quotes added around it

Parameters:
unsafeSQLString - String to make safe
Returns:
Version of string safe to insert into JDBC statements

addPrefix

public static java.lang.String addPrefix(java.lang.String prefix,
                                         java.lang.String msg)
Adds the prefix to the beginning of each line in message


caseCommand

public static java.lang.String caseCommand(java.lang.String command)
converts the argument into lower case with the first letter in uppercase


findFile

public static java.net.URL findFile(java.lang.String name,
                                    java.lang.String relClassName)
                             throws java.io.IOException
Returns a URL for the given name using several methods to make it useful for locating configuration files, resources etc. If the name is a normal path then the URL is a file URL constructed in the normal way, either relative to the current working directory or from the root of the filesystem if absolute. If the name contains a double colon then the name is assumed to be relative to the fully qualified class name before the double colon (or the caller's class if no class name given). If the file name is absolute then the root is taken as the classpath element from which the given class was loaded otherwise the path is relative to the directory in which the given class was loaded from. This works for classes loaded normally and from jar files but hasn't yet been tested with http.

Parameters:
name - Either a local file path or a fully qualified class name (if none, calling classs used) followed by a double colon followed by a file path.
Throws:
java.io.IOException

getFile

public static java.io.InputStream getFile(java.lang.String name,
                                          java.lang.String className)
                                   throws java.io.IOException
Throws:
java.io.IOException

findAutoMedFile

public static java.net.URL findAutoMedFile(java.lang.String filename,
                                           java.lang.String className)
                                    throws java.io.IOException
Throws:
java.io.IOException

getAutoMedFile

public static java.io.InputStream getAutoMedFile(java.lang.String filename,
                                                 java.lang.String className)
                                          throws java.io.IOException,
                                                 DSRException
Throws:
java.io.IOException
DSRException

getDefaultPath

public static java.lang.String getDefaultPath(java.lang.String path)
Return the default path to a file/directory given its relative name
E.g.: given automed --> $USERHOME/.automed/automed


tokenize

public static java.lang.String[] tokenize(java.lang.String s)
Returns the tokens in s (as defined by default StringTokenizer) as an array


split

public static java.lang.String[] split(java.lang.String splitStr,
                                       java.lang.String delimiter,
                                       int limit)
A classic-version of split-string method which does NOT support RegExp


split

public static java.lang.String[] split(java.lang.String splitStr,
                                       java.lang.String delimiter)
Split a delimited string dmle 27/2/2006


replaceAll

public static java.lang.String replaceAll(java.lang.String original,
                                          java.lang.String pattern,
                                          java.lang.String replacement)
Replace all occurences of a substring with a new string


executeStatements

public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                   java.lang.String del,
                                                   java.sql.Connection dbs,
                                                   java.io.OutputStream feedback)

executeStatements

public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                   java.lang.String del,
                                                   java.sql.Connection dbs,
                                                   java.io.OutputStream feedback,
                                                   java.util.Set nullifyZeros)

executeStatements

public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                   java.lang.String del,
                                                   java.sql.Connection dbs,
                                                   java.io.Writer feedback)
Calls {link #executeStatement(String, Connection, Writer)} with each each statement in sql seperated by del.

Returns:
An Object array with one element for each statement containing the return value from {link #executeStatement(String, Connection, Writer)}.

executeStatements

public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                   java.lang.String del,
                                                   java.sql.Connection dbs,
                                                   java.io.Writer feedback,
                                                   java.util.Set nullifyZeros)

executeStatement

public static java.lang.Object executeStatement(java.lang.String sql,
                                                java.sql.Connection dbs,
                                                java.io.OutputStream feedback)

executeStatement

public static java.lang.Object executeStatement(java.lang.String sql,
                                                java.sql.Connection dbs,
                                                java.io.OutputStream feedback,
                                                java.util.Set nullifyZeros)

executeStatement

public static java.lang.Object executeStatement(java.lang.String sql,
                                                java.sql.Connection dbs,
                                                java.io.Writer feedback)
Executes the sql statement on the JDBC Concection and returns either a ResultSet, an Integer representing the update count or an SQLException if thrown when executing the command.

Parameters:
sql - The sql statement to execute.
dbs - The connection on which to create and execute the statement.
feedback - A Writer on which to output the ResultSet, update count or SQLException. If null, no feedback is generated. If not null and not a PrintWriter the Writer is wrapped in a printwriter.
Returns:
A ResultSet, Ineteger update count or SQLException

executeStatement

public static java.lang.Object executeStatement(java.lang.String sql,
                                                java.sql.Connection dbs,
                                                java.io.Writer feedback,
                                                java.util.Set nullifyZeros)

printSQLFeedback

public static void printSQLFeedback(java.lang.Object obj,
                                    java.io.OutputStream out,
                                    java.lang.String sql)

printSQLFeedback

public static void printSQLFeedback(java.lang.Object obj,
                                    java.io.Writer out,
                                    java.lang.String sql)

printResultSet

public static void printResultSet(java.sql.ResultSet rst,
                                  java.io.OutputStream out)

printResultSet

public static void printResultSet(java.sql.ResultSet rst,
                                  java.io.Writer out)

getColumnNames

public static java.lang.String[] getColumnNames(java.sql.ResultSet rst)
                                         throws java.sql.SQLException
Throws:
java.sql.SQLException

getColumnTypes

public static int[] getColumnTypes(java.sql.ResultSet rst)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

resultSetToArray

public static java.lang.Object[][] resultSetToArray(java.sql.ResultSet rst)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

getSQLTypeName

public static java.lang.String getSQLTypeName(int t)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getSQLType

public static int getSQLType(java.lang.String name)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

getInsertableSQLValue

public static java.lang.String getInsertableSQLValue(java.lang.Object value,
                                                     int sqlType)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

stringToObject

public static java.lang.Object stringToObject(java.lang.String value,
                                              java.lang.Class type)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

printObject

public static void printObject(java.lang.Object val,
                               java.io.OutputStream out)

printObject

public static void printObject(java.lang.Object val,
                               java.io.Writer out)

getOpts

public static java.lang.String[] getOpts(java.lang.String format,
                                         java.lang.String[] args)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

addArrayToList

public static java.util.List addArrayToList(java.lang.Object[] src,
                                            java.util.List dst)
Adds in order all elements in the source array to the destination List and returns the destination list so that the method can be used as an argument to a method call. This is paricularly useful for the this() or super() call in a constructor where you need to convert an array to a list as the method call has to be the first line of code.

Parameters:
src - An array of Objects to add to the list.
dst - The List to which the source array's elememts are to be added.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String substring)
Returns a new string resulting from replacing all occurences of substring in string s with \ followed by substring.


getStackSize

public static long getStackSize(java.lang.Throwable t)
Determine the size (in bytes) of an exception stack