/**
* InstantJ
*
* Copyright (C) 2002 Nils Meier
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package instantj.reflect;
/**
* Abstract superclass for all exceptions thrown from this package's
* classes. It can contain a nested exception (the reason for the
* exception) and contains the name of the property describing the
* context.
*
* @author <A href="mailto:nils@meiers.net">Nils Meier</A>
*/
public abstract class PropertyException extends Exception {
/** the target of which the property was accessed */
private Object target;
/** the name of the property that led to this exception */
private String property;
/** the nested reason for the exception */
private Throwable reason;
/**
* Constructor
*/
public PropertyException(String msg, Object target, String property) {
super(msg);
this.target = target;
this.property = property;
}
/**
* The message (mangled) of this exception
*/
public String getMessage() {
return super.getMessage() + " (target=" + target + "," + "property=" + property + ")";
}
/**
* Getter for the name of the property that lead to this exception
*/
public String getProperty() {
return property;
}
/**
* Getter for the (nested) reason that led to this exception
* while dealing with the property getName()
*/
public Throwable getReason() {
return reason;
}
/**
* Getter for the name of the property that lead to this exception
*/
public Object getTarget() {
return target;
}
/**
* Convenient logger
*/
public void printStackTrace(java.io.PrintStream s) {
if (reason != null) {
s.println(this);
reason.printStackTrace(s);
}
super.printStackTrace(s);
}
/**
* Convenient logger
*/
public void printStackTrace(java.io.PrintWriter s) {
if (reason != null) {
s.println(this);
reason.printStackTrace(s);
}
super.printStackTrace(s);
}
/**
* Provide a (nested) reason for this exception
*/
protected void setReason(Throwable reason) {
this.reason = reason;
}
}
|