org.xins.common
Class Utils

java.lang.Object
  extended byorg.xins.common.Utils

public final class Utils
extends Object

General utility functions.

Since:
XINS 1.1.0
Version:
$Revision: 1.33 $ $Date: 2006/08/28 09:12:35 $
Author:
Ernst de Haan

Method Summary
static String getCallingClass()
          Retrieves the name of the calling class.
static String getCallingClass(int level)
          Retrieves the name of the calling class at the specified level.
static String getCallingMethod()
          Retrieves the name of the calling method.
static String getCallingMethod(int level)
          Retrieves the name of the calling method at the specified level.
static String getClassName(Object object)
          Determines the name of the class of the specified object.
static double getJavaVersion()
          Retrieves the actual (major) Java version.
static String getNameOfClass(Class c)
          Determines the name of the specified class.
static void logIgnoredException(String detectingClass, String detectingMethod, String subjectClass, String subjectMethod, String detail, Throwable exception)
          Logs an exception that will be ignored, with the specified detail message.
static void logIgnoredException(String detectingClass, String detectingMethod, String subjectClass, String subjectMethod, Throwable exception)
          Logs an exception that will be ignored.
static void logIgnoredException(Throwable exception)
          Logs an exception that will be ignored.
static ProgrammingException logProgrammingError(String detail)
          Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.
static ProgrammingException logProgrammingError(String detectingClass, String detectingMethod, String subjectClass, String subjectMethod, String detail)
          Logs a programming error with no cause exception, and returns a ProgrammingException object for it.
static ProgrammingException logProgrammingError(String detectingClass, String detectingMethod, String subjectClass, String subjectMethod, String detail, Throwable cause)
          Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.
static ProgrammingException logProgrammingError(Throwable cause)
          Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getJavaVersion

public static double getJavaVersion()
Retrieves the actual (major) Java version.

Returns:
the actual Java version.
Since:
XINS 1.2.0

getCallingClass

public static String getCallingClass(int level)
                              throws IllegalArgumentException
Retrieves the name of the calling class at the specified level. The level 0 indicates the direct caller, while 1 indicates the caller of the caller.

If it cannot be determined, then "<unknown>" is returned.

Parameters:
level - the level of the caller, must be >= 0.
Returns:
the class name of the caller of the caller of this method, at the specified level, never an empty string and never null.
Throws:
IllegalArgumentException - if level < 0.
Since:
XINS 1.3.0

getCallingClass

public static String getCallingClass()
Retrieves the name of the calling class. If it cannot be determined, then a special string (e.g. "<unknown>") is returned.

Returns:
the class name of the caller of the caller of this method, never an empty string and never null.

getCallingMethod

public static String getCallingMethod(int level)
                               throws IllegalArgumentException
Retrieves the name of the calling method at the specified level. The level 0 indicates the direct caller, while 1 indicates the caller of the caller.

If it cannot be determined, then "<unknown>" is returned.

Parameters:
level - the level of the caller, must be >= 0.
Returns:
the method name of the caller of the caller of this method, at the specified level, never an empty string and never null.
Throws:
IllegalArgumentException - if level < 0.
Since:
XINS 1.3.0

getCallingMethod

public static String getCallingMethod()
Retrieves the name of the calling method. If it cannot be determined, then a special string (e.g. "<unknown>") is returned.

Returns:
the method name of the caller of the caller of this method, never an empty string and never null.

logIgnoredException

public static void logIgnoredException(String detectingClass,
                                       String detectingMethod,
                                       String subjectClass,
                                       String subjectMethod,
                                       String detail,
                                       Throwable exception)
                                throws IllegalArgumentException
Logs an exception that will be ignored, with the specified detail message.

Parameters:
detectingClass - the name of the class that caught the exception, cannot be null.
detectingMethod - the name of the method within the detectingClass that caught the exception, cannot be null.
subjectClass - the name of the class which threw the exception, cannot be null.
subjectMethod - the name of the method (within the subjectClass) which threw the exception, cannot be null.
detail - detail message, can be null.
exception - the exception to log, cannot be null.
Throws:
IllegalArgumentException - if detectingClass == null || detectingMethod == null || subjectClass == null || subjectMethod == null || exception == null.
Since:
XINS 1.3.0

logIgnoredException

public static void logIgnoredException(Throwable exception)
                                throws IllegalArgumentException
Logs an exception that will be ignored.

Parameters:
exception - the exception to log, cannot be null.
Throws:
IllegalArgumentException - if exception == null.
Since:
XINS 1.5.0

logIgnoredException

public static void logIgnoredException(String detectingClass,
                                       String detectingMethod,
                                       String subjectClass,
                                       String subjectMethod,
                                       Throwable exception)
                                throws IllegalArgumentException
Logs an exception that will be ignored.

Parameters:
detectingClass - the name of the class that caught the exception, cannot be null.
detectingMethod - the name of the method within the detectingClass that caught the exception, cannot be null.
subjectClass - the name of the class which threw the exception, cannot be null.
subjectMethod - the name of the method (within the subjectClass) which threw the exception, cannot be null.
exception - the exception to log, cannot be null.
Throws:
IllegalArgumentException - if detectingClass == null || detectingMethod == null || subjectClass == null || subjectMethod == null || exception == null.
Since:
XINS 1.3.0

logProgrammingError

public static ProgrammingException logProgrammingError(String detail)
Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.

The calling class/method are considered the detecting class and the caller of those (one level up) is considered the subject class/method for the programming error.

Parameters:
detail - the detail message, can be null.
Returns:
an appropriate ProgrammingException that can be thrown by the calling method, never null.

logProgrammingError

public static ProgrammingException logProgrammingError(Throwable cause)
Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.

Parameters:
cause - the cause exception, cannot be null.
Returns:
an appropriate ProgrammingException that can be thrown by the calling method, never null.

logProgrammingError

public static ProgrammingException logProgrammingError(String detectingClass,
                                                       String detectingMethod,
                                                       String subjectClass,
                                                       String subjectMethod,
                                                       String detail,
                                                       Throwable cause)
Logs a programming error with an optional cause exception, and returns a ProgrammingException object for it.

Parameters:
detectingClass - the name of the class that detected the problem, or null if unknown.
detectingMethod - the name of the method within the detectingClass that detected the problem, or null if unknown.
subjectClass - the name of the class which exposes the programming error, or null if unknown.
subjectMethod - the name of the method (within the subjectClass) which exposes the programming error, or null if unknown.
detail - the detail message, can be null.
cause - the cause exception, can be null.
Returns:
an appropriate ProgrammingException that can be thrown by the calling method, never null.

logProgrammingError

public static ProgrammingException logProgrammingError(String detectingClass,
                                                       String detectingMethod,
                                                       String subjectClass,
                                                       String subjectMethod,
                                                       String detail)
Logs a programming error with no cause exception, and returns a ProgrammingException object for it.

Parameters:
detectingClass - the name of the class that detected the problem, or null if unknown.
detectingMethod - the name of the method within the detectingClass that detected the problem, or null if unknown.
subjectClass - the name of the class which exposes the programming error, or null if unknown.
subjectMethod - the name of the method (within the subjectClass) which exposes the programming error, or null if unknown.
detail - the detail message, can be null.
Returns:
an appropriate ProgrammingException that can be thrown by the calling method, never null.

getNameOfClass

public static String getNameOfClass(Class c)
                             throws IllegalArgumentException
Determines the name of the specified class.

Parameters:
c - the class to determine the name for, not null.
Returns:
the name of the class, never null.
Throws:
IllegalArgumentException - if c == null.
Since:
XINS 1.2.0

getClassName

public static String getClassName(Object object)
                           throws IllegalArgumentException
Determines the name of the class of the specified object.

Parameters:
object - the object to determine the name of the class for, not null.
Returns:
the name of the class, never null.
Throws:
IllegalArgumentException - if object == null.
Since:
XINS 1.2.0


See http://www.xins.org/.