net.sf.itcb.common.business.exceptions.CommonItcbException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of itcb-common-business Show documentation
Show all versions of itcb-common-business Show documentation
This module is the common module that must depend all the business modules.
package net.sf.itcb.common.business.exceptions;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NestedRuntimeException;
/**
* Generic exception managing localized message
* All exceptions has to extend directly or indirectly this class
*
* @author Pierre Le Roux
*
*/
public class CommonItcbException extends NestedRuntimeException
{
private static final long serialVersionUID = 1L;
protected String messageKey;
protected String message;
protected String localizedMessage;
public static final QName EXCEPTION_CLASS = new QName("exception-class");
public static final QName COMMON_MESSAGE = new QName("common-message");
public static final String ITCB_NAMESPACE_URI = "http://itcb.sf.net";
protected final Logger log = LoggerFactory.getLogger(getClass());
public CommonItcbException(ExceptionMappingErrors exceptionMappingErrors, String localizedMessage) {
this(exceptionMappingErrors, localizedMessage, null);
}
public CommonItcbException(ExceptionMappingErrors exceptionMappingErrors, String localizedMessage, Throwable cause) {
super(exceptionMappingErrors.getMessage(), cause);
setMessage(exceptionMappingErrors.getMessage());
setLocalizedMessage(localizedMessage);
setMessageKey(exceptionMappingErrors.getMessageKey());
log.error(this.toString());
}
@Override
public String toString() {
StackTraceElement methodCaller = this.getStackTrace()[0];
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(this.getMessageKey());
stringBuilder.append(" : ");
stringBuilder.append(this.getMessage());
stringBuilder.append("\nCause : ");
stringBuilder.append(methodCaller.toString());
stringBuilder.append("\nUser message : ");
stringBuilder.append(this.getLocalizedMessage());
return stringBuilder.toString();
}
public String getMessageKey()
{
return messageKey;
}
public void setMessageKey(String messageKey)
{
this.messageKey = messageKey;
}
public String getMessage()
{
return message;
}
public void setMessage(String message)
{
this.message = message;
}
public String getLocalizedMessage() {
return localizedMessage;
}
public void setLocalizedMessage(String localizedMessage) {
this.localizedMessage = localizedMessage;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy