/******************************************************************************* * Copyright (c) 2001, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.wst.validation.internal.core; import java.util.Locale; import org.eclipse.wst.validation.internal.provisional.core.IMessage; /** *
* This exception is the only exception which should be thrown by IValidators. The message in this * exception must be suitable for showing to the user. All ValidationExceptions will have their * message extracted when they're caught, and the message will be shown to the user. * * @plannedfor 1.0 *
*/ public class ValidationException extends Exception { private Throwable _lowLevelException = null; private IMessage _message = null; private ClassLoader _loader = null; private final static long serialVersionUID = -3387516993124229949L; /** * Constructs a new exception with a given message string.null
if none. java.io.IOException
  describing the exact nature
* of the problem.
*/
public ValidationException(IMessage message, Throwable exception) {
super();
_message = message;
_lowLevelException = exception;
}
/**
* @return the low-level exception associated with this ValidationException.
*/
public Throwable getAssociatedException() {
return _lowLevelException;
}
/**
* @return the IMessage to be shown to the user, or null if this exception should be handled
* internally.
*/
public IMessage getAssociatedMessage() {
return _message;
}
/**
* @return if the IValidator which threw this exception was loaded by a different ClassLoader than the
* framework, this method returns the ClassLoader of the IValidator.
*/
public ClassLoader getClassLoader() {
return _loader;
}
/**
* @return the error message string of this Throwable
object if it was
* {@link java.lang.Throwable#Throwable(String) created}with an error message string;
* or null
if it was {@link java.lang.Throwable#Throwable() created}with
* no error message.
*
*/
public String getMessage() {
return _message.getText(getClassLoader());
}
/**
* @param locale
* The locale of which to get the message.
* @return the error message string of this Throwable
object if it was
* {@link java.lang.Throwable#Throwable(String) created}with an error message string;
* or null
if it was {@link java.lang.Throwable#Throwable() created}with
* no error message.
*/
public String getMessage(Locale locale) {
return _message.getText(locale, getClassLoader());
}
/**
* * If the IValidator which threw this exception was loaded by a different ClassLoader than the * framework, this method should set the ClassLoader to be the ClassLoader of the IValidator. *
* @param loader * ClassLoader of the validator */ public void setClassLoader(ClassLoader loader) { _loader = loader; } /** *
* Returns a short description of this throwable object. If this Throwable
object
* was {@link java.lang.Throwable#Throwable(String) created}with an error message string, then
* the result is the concatenation of three strings:
*
Throwable
object was {@link java.lang.Throwable#Throwable() created}
* with no error message string, then the name of the actual class of this object is returned.
*
*
* @return a string representation of this Throwable
.
*/
public String toString() {
return toString(Locale.getDefault());
}
/**
*
* Returns a short description of this throwable object. If this Throwable
object
* was {@link java.lang.Throwable#Throwable(String) created}with an error message string, then
* the result is the concatenation of three strings:
*
Throwable
object was {@link java.lang.Throwable#Throwable() created}
* with no error message string, then the name of the actual class of this object is returned.
*
*
* @return a string representation of this Throwable
.
*/
public String toString(Locale locale) {
String s = getClass().getName();
String message = getMessage(locale);
return (message != null) ? (s + ": " + message) : s; //$NON-NLS-1$
}
}