/**
*
* The error code is an integer number. The error codes are defined in an * separate configuration file, readed be the SettingsReader. If the * SettingsReader can not initialized, a corresponding error message can not * read! *
** The error code can be seen a a replacement of the exception message. For all * intents and purposes, the error code should be used to provide exceptional * feedback to the user. Nevertheless, if possible, a debug message String (the * message parameter) should still be provided giving in depth developer * descriptions of the problem. These message strings will then show up in the * log files accordingly. *
* * @author wlackner * @author wprinz (enforced error code) * * @deprecated * * @see at.knowcenter.wag.egov.egiz.cfg.SettingsReader */ public class ErrorCodeException extends PresentableException { /** * SVUID. */ private static final long serialVersionUID = 2071967845179686593L; /** * Template key getting error messages */ private static final String ERROR_CODE_KEY = "error.code."; /** * The default error message */ private static final String DEFAULT_ERROR_MESSAGE = "Fehler Code:"; /** * The logger definition. */ private static final Logger logger_ = ConfigLogger.getLogger(ErrorCodeException.class); /** * The SettingsReader instance */ private SettingsReader settings_ = null; /** * The default error code */ private int error_code_ = -1; /** * If an external application is called */ private String externalErrorCode_ = null; /** * If an external application is called */ private String externalErrorMessage_ = null; /** * Constructor that sets the error code. * * @param error_code * The error code. */ public ErrorCodeException(final int error_code) { super(error_code, "just an error code"); this.error_code_ = error_code; loadSettings(); } /** * Inherit Constructor from Exception, * * @param error_code * The error code. * @param message * The in depth developer provided error message. * @see Exception */ public ErrorCodeException(final int error_code, String message) { super(error_code, message); this.error_code_ = error_code; loadSettings(); } /** * Inherit Constructor from Exception, * * @param error_code * The error code. * @param message * The in depth developer provided error message. * @param cause * The cause of this exception. * @see Exception */ public ErrorCodeException(final int error_code, String message, Throwable cause) { super(error_code, message, cause); this.error_code_ = error_code; loadSettings(); } /** * Inherit Constructor from Exception, * * @param error_code * The error code. * @param cause * The cause of this exception. * @see Exception */ public ErrorCodeException(final int error_code, Throwable cause) { super(error_code, cause); this.error_code_ = error_code; loadSettings(); } /** * Load the settings file. Call the SettingsReader instance. */ private void loadSettings() { if (settings_ == null) { try { settings_ = SettingsReader.getInstance(); } catch (SettingsException e) { String log_message = "Can not load pdf signature settings. Cause:\n" + e.getMessage(); logger_.error(log_message, e); } } } /** * Return the manually stored error code. The error code is only a key for a * configurable error message. The error code and its corresponding message * have to be declared in an separate property file, loaded by the * SettingsReader * * @see at.knowcenter.wag.egov.egiz.cfg.SettingsReader * @return Returns the errorCode. */ public int getErrorCode() { return this.error_code_; } /** * Set a special error code in case of commuicating this error in an user * interface. The error code is only a key for a configurable error message. * The error code and its corresponding message have to be declared in an * separate property file, loaded by the SettingsReader * * @see at.knowcenter.wag.egov.egiz.cfg.SettingsReader * @param error_code * The error code to be set. */ public void setErrorCode(final int error_code) { this.error_code_ = error_code; } /** * Set a special error code in case of commuicating this error in an user * interface. The error code is a key for an external application error * message. The error code and its corresponding message have to be declared * by the external tool that used. * * @param errorCode * The errorCode to set. */ public void setExternalErrorCode(String errorCode) { externalErrorCode_ = errorCode; } /** * Returns an external error code that is set manually * * @return the external error code if set,null
otherwise
*/
public String getExternalErrorCode()
{
return externalErrorCode_;
}
/**
* Set a special error message in case of commuicating this error in an user
* interface. The error message and its corresponding error code have to be
* declared by the external tool that used.
*
* @param errorMessage
*/
public void setExternalErrorMessage(String errorMessage)
{
externalErrorMessage_ = errorMessage;
}
/**
* Returns an external error message that is set manually
*
* @return the external error message if set, null
otherwise
*/
public String getExternalErrorMessage()
{
return externalErrorMessage_;
}
/**
* Checks if an external error message is set.
*
* @return returns true
if a message is set, false
* otherwise
*/
public boolean hasExternalErrorMessage()
{
return (externalErrorMessage_ != null);
}
/**
* Get the configured error message that corresponds to the error code. If the
* config file can't be read, or an error code is not declared in the config
* file, the default error message would be returned.
*
* @return an error message that can be used for ui communication
*/
public String getErrorCodeMessage()
{
String err_msg = null;
if (settings_ != null)
{
err_msg = settings_.getSetting(ERROR_CODE_KEY + error_code_, DEFAULT_ERROR_MESSAGE + error_code_);
}
return err_msg;
}
/**
* Get the configured error message that corresponds to the given error code.
* If the config file can't be read, or an error code is not declared in the
* config file, the default error message would be returned.
*
* @return an error message that can be used for ui communication
*/
public static String getErrorCodeMessage(int errorCode)
{
SettingsReader settings = null;
String err_msg = DEFAULT_ERROR_MESSAGE + errorCode;
try
{
settings = SettingsReader.getInstance();
err_msg = settings.getSetting(ERROR_CODE_KEY + errorCode, DEFAULT_ERROR_MESSAGE + errorCode);
}
catch (SettingsException e)
{
logger_.error(e.getMessage(), e);
}
return err_msg;
}
/**
* Checks if the exception has an ErrorCode state.
*
* @return true if an ErrorCode does exist false otherwise
*/
public boolean hasErrorCode()
{
return error_code_ != 0;
}
}