org.apache.empire.commons
Class ErrorObject

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
All Implemented Interfaces:
ErrorInfo
Direct Known Subclasses:
DBDatabaseDriver, DBObject, DBSQLScript, XMLConfiguration, XMLWriter

public abstract class ErrorObject
extends java.lang.Object
implements ErrorInfo

This class holds and provides information about the last error that occured on an object.

In order to use this class you must derive your class from Error Object.
If a method fails then you must set the error by calling one of the error(...) functions.
The method usually indicates failure by returning false.
You may then retrieve error information by calling one of the function defined by the ErrorInfo interface.
All classes of the empire framework are derived from this class.

This class is thread save so each thread may have it's own error information for a particular object.


Constructor Summary
ErrorObject()
          Constructs an ErrorObject object.
ErrorObject(ErrorInfo other)
          Constructs a ErrorObject object copying the Error information of another object.
 
Method Summary
 void clearError()
          Clears the error for this object.
 java.lang.String getErrorMessage()
          Returns the message associated with the last error.
 java.lang.Object[] getErrorParams()
          Returns the parameters used to build the error text.
 java.lang.String getErrorSource()
          Returns the parameters used to build the error text.
 ErrorType getErrorType()
          Returns the last error code.
static java.lang.String getMessage(ErrorInfo error)
          Returns the message associated with an error.
 boolean hasError()
          Returns wether or not an error is set.
static boolean isExceptionsEnabled()
          Returns wether or not Exceptions will be thrown on failure.
static void setExceptionsEnabled(boolean enableExceptions)
          Use this to enable or disable Exceptions.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ErrorObject

public ErrorObject()
Constructs an ErrorObject object.


ErrorObject

public ErrorObject(ErrorInfo other)
Constructs a ErrorObject object copying the Error information of another object.

Parameters:
other - the source error information
Method Detail

isExceptionsEnabled

public static boolean isExceptionsEnabled()
Returns wether or not Exceptions will be thrown on failure.
If disabled (default) the functions' return values will indicate success or failure

Returns:
true if Exceptions are enable or false otherwise

setExceptionsEnabled

public static void setExceptionsEnabled(boolean enableExceptions)
Use this to enable or disable Exceptions.
If exceptionsEnabled is false no exceptions will be thrown.
Instead the functions' return values will indicate success or failure

Parameters:
enableExceptions - true to enable exceptions or false to disable

getMessage

public static java.lang.String getMessage(ErrorInfo error)
Returns the message associated with an error.

Parameters:
error - the error information for which to obtain an error message
Returns:
the error message or an empty string if no error has been set.

hasError

public final boolean hasError()
Returns wether or not an error is set.

Specified by:
hasError in interface ErrorInfo
Returns:
true if an error has been set, or otherwise false

getErrorType

public final ErrorType getErrorType()
Returns the last error code.

Specified by:
getErrorType in interface ErrorInfo
Returns:
the error code of ERR_NONE if no error has been set.

getErrorSource

public final java.lang.String getErrorSource()
Returns the parameters used to build the error text.

Specified by:
getErrorSource in interface ErrorInfo
Returns:
the error message or null if no error has been set.

getErrorParams

public final java.lang.Object[] getErrorParams()
Returns the parameters used to build the error text.

Specified by:
getErrorParams in interface ErrorInfo
Returns:
the error message or null if no error has been set.

clearError

public final void clearError()
Clears the error for this object.


getErrorMessage

public final java.lang.String getErrorMessage()
Returns the message associated with the last error.

Returns:
the error message or an empty string if no error has been set.