org.apache.empire.commons
Class ErrorObject

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
All Implemented Interfaces:
ErrorInfo
Direct Known Subclasses:
ActionError, BeanRecordProxy, DBDatabaseDriver, DBObject, DBSQLScript, FormActionSupport, ListActionSupport, 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 ErrorObject.ObjectErrorInfo 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.


Nested Class Summary
protected static class ErrorObject.ObjectErrorInfo
          This class is internally used by the ErrorObject to provide thread-safe access to the error information.
 
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.
protected  void clearErrorInfo()
          Clears the ErrorInfo.
protected  boolean error(ErrorInfo other)
          Copies the error set on another object to this object.
protected  boolean error(ErrorType errType)
          Sets the error.
protected  boolean error(ErrorType errType, java.lang.Object param)
          Sets the specified error and and the message.
protected  boolean error(ErrorType errType, java.lang.Object[] params)
          Sets an error from an error code an an array of parameters
protected  boolean error(ErrorType errType, java.lang.Object param1, java.lang.Object param2)
          Sets the specified error and two messages.
protected  boolean error(ErrorType errType, java.lang.Throwable exptn)
          Sets the specified error and the corresponding error message on this object.
protected  boolean error(java.lang.Throwable exptn)
          Sets the last error and the error message: ERR_EXCEPTION.
protected  ErrorObject.ObjectErrorInfo getErrorInfo(boolean create)
          getErrorInfo
 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.
protected  boolean internalSetError(ErrorType errType, java.lang.Object[] params, ErrorInfo source)
          Sets the last error and the corresponding error message on this object.
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
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
protected  boolean success()
          returns true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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.

getErrorInfo

protected ErrorObject.ObjectErrorInfo getErrorInfo(boolean create)
getErrorInfo


clearErrorInfo

protected void clearErrorInfo()
Clears the ErrorInfo.


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.

internalSetError

protected boolean internalSetError(ErrorType errType,
                                   java.lang.Object[] params,
                                   ErrorInfo source)
Sets the last error and the corresponding error message on this object.

Parameters:
errType - the type of error to set.
params - array of parameters for the error message if any.
source - object from which this error originated from.
Returns:
always false except if the errType is of Type Errors.None

success

protected final boolean success()
returns true


error

protected final boolean error(ErrorType errType,
                              java.lang.Object[] params)
Sets an error from an error code an an array of parameters

Parameters:
errType - the type of error to set.
params - array of parameters for the error message if any.
Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(ErrorType errType)
Sets the error.

Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(ErrorType errType,
                              java.lang.Object param)
Sets the specified error and and the message.

Parameters:
errType - the type of error to set.
param - parameter for the error message.
Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(ErrorType errType,
                              java.lang.Object param1,
                              java.lang.Object param2)
Sets the specified error and two messages.

Parameters:
errType - the type of error to set.
param1 - parameter for the error message.
param2 - parameter for the error message.
Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(ErrorType errType,
                              java.lang.Throwable exptn)
Sets the specified error and the corresponding error message on this object.

Parameters:
errType - the type of error to set.
exptn - Exception from witch the error message is copied.
Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(java.lang.Throwable exptn)
Sets the last error and the error message: ERR_EXCEPTION.

Parameters:
exptn - Exception from witch the error message is copied.
Returns:
always false except if the errType is of Type Errors.None

error

protected final boolean error(ErrorInfo other)
Copies the error set on another object to this object.

Parameters:
other - the object from which to copy the error.
Returns:
always false except if the errType is of Type Errors.None


Copyright © 2008-2009 Apache Software Foundation. All Rights Reserved.