com.philemonworks.selfdiagnose
Class DiagnoseUtil

java.lang.Object
  extended by com.philemonworks.selfdiagnose.DiagnoseUtil

public class DiagnoseUtil
extends Object

Provides a set of static utility methods that are used in the setting up and running diagnostic tasks.

Author:
Ernest Micklei

Constructor Summary
DiagnoseUtil()
           
 
Method Summary
static Class[] argumentTypesFrom(Object[] arguments)
           
static Class classForName(String className)
          Resolve the name to a Class using the ContextClassLoader of the current thread.
protected static Class detectRequestorClass()
          Try to determine the class of the object that registered a DiagnosticTask by inspecting the stack frame of a locally thrown Exception.
static URL findResource(String resource, boolean useContextClassLoaderOnly)
          Try finding a resource using a class loader.
static String format(Date dateTime)
          Use XSD datetime format without zone indication
static String format(String template, String param0)
           
static String format(String template, String param0, String param1)
           
static String format(String template, String param0, String param1, String param2)
           
static String format(String template, String param0, String param1, String param2, String param3)
           
static String format(String template, String param0, String param1, String param2, String param3, String param4)
           
static Connection getDataSourceConnection(String datasourceName)
          Get a DataSource connection using JNDI.
static String getErrorMessage(Exception ex)
          Compose an error message from the exception and/or its causes.
static String getPropertyAccessMethodName(String property)
          Return the standard non-boolean getter for a property unless the property refers to the object "this".
static Object newInstance(Class instanceClass, Object[] constructorArguments)
          Performs the constructing of a new instance from a Class.
static Object perform(Object receiver, String methodName)
           
static Object perform(Object receiver, String methodName, Object[] arguments)
          Can invoke both instance and static methods on the receiver
static Object perform(Object receiver, String methodName, Object[] arguments, Class[] types)
          Can invoke both instance and static methods on the receiver
static URL retrieveURL(ExecutionContext ctx, String resourceName, String urlSpec)
           
static String shortName(Class someClass)
          Return the unqualified name of a Java Class.
static void verifyNonEmptyString(String variableName, Object value, Class owner)
          Test that the value is a non empty String.
static void verifyNotNull(String variableName, Object value, Class owner)
          Test that the value is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiagnoseUtil

public DiagnoseUtil()
Method Detail

verifyNonEmptyString

public static void verifyNonEmptyString(String variableName,
                                        Object value,
                                        Class owner)
                                 throws DiagnoseException
Test that the value is a non empty String. Throws an exception otherwise.

Parameters:
variableName - field name for the Task
value - of the variable
owner - Task class
Throws:
DiagnoseException

verifyNotNull

public static void verifyNotNull(String variableName,
                                 Object value,
                                 Class owner)
                          throws DiagnoseException
Test that the value is not null. Throws an exception otherwise.

Parameters:
variableName - field name for the Task
value - of the variable
owner - Task class
Throws:
DiagnoseException

shortName

public static String shortName(Class someClass)
Return the unqualified name of a Java Class.

Parameters:
someClass - Class
Returns:
String name of the Class

perform

public static Object perform(Object receiver,
                             String methodName)
                      throws DiagnoseException
Throws:
DiagnoseException

perform

public static Object perform(Object receiver,
                             String methodName,
                             Object[] arguments)
                      throws DiagnoseException
Can invoke both instance and static methods on the receiver

Parameters:
receiver -
methodName -
arguments -
Returns:
Throws:
DiagnoseException

perform

public static Object perform(Object receiver,
                             String methodName,
                             Object[] arguments,
                             Class[] types)
                      throws DiagnoseException
Can invoke both instance and static methods on the receiver

Parameters:
receiver -
methodName -
arguments -
Returns:
Throws:
DiagnoseException

newInstance

public static Object newInstance(Class instanceClass,
                                 Object[] constructorArguments)
                          throws DiagnoseException
Performs the constructing of a new instance from a Class.

Parameters:
instanceClass -
constructorArguments -
Returns:
Throws:
DiagnoseException

argumentTypesFrom

public static Class[] argumentTypesFrom(Object[] arguments)

classForName

public static Class classForName(String className)
                          throws ClassNotFoundException
Resolve the name to a Class using the ContextClassLoader of the current thread.

Parameters:
className -
Returns:
Class
Throws:
DiagnoseException
ClassNotFoundException

detectRequestorClass

protected static Class detectRequestorClass()
Try to determine the class of the object that registered a DiagnosticTask by inspecting the stack frame of a locally thrown Exception. Kind of a trick to do it this way.

Returns:
Class

getDataSourceConnection

public static Connection getDataSourceConnection(String datasourceName)
                                          throws DiagnoseException
Get a DataSource connection using JNDI.

Parameters:
datasourceName - String
Returns:
Connection
Throws:
DiagnoseException

findResource

public static URL findResource(String resource,
                               boolean useContextClassLoaderOnly)
Try finding a resource using a class loader. First use the context classloader of the current thread then try to use the classloader of this utility unless useContextClassLoaderOnly is true

Parameters:
resource - String
useContextClassLoaderOnly - boolean
Returns:
URL || null

format

public static String format(String template,
                            String param0)

format

public static String format(String template,
                            String param0,
                            String param1)

format

public static String format(String template,
                            String param0,
                            String param1,
                            String param2)

format

public static String format(String template,
                            String param0,
                            String param1,
                            String param2,
                            String param3)

format

public static String format(String template,
                            String param0,
                            String param1,
                            String param2,
                            String param3,
                            String param4)

format

public static String format(Date dateTime)
Use XSD datetime format without zone indication


retrieveURL

public static URL retrieveURL(ExecutionContext ctx,
                              String resourceName,
                              String urlSpec)
                       throws Exception
Throws:
Exception

getPropertyAccessMethodName

public static String getPropertyAccessMethodName(String property)
Return the standard non-boolean getter for a property unless the property refers to the object "this".

Parameters:
property -
Returns:
getter or this

getErrorMessage

public static String getErrorMessage(Exception ex)
Compose an error message from the exception and/or its causes.

Parameters:
ex -
Returns:


Copyright © 2012. All Rights Reserved.