001: /**
002: * InstantJ
003: *
004: * Copyright (C) 2002 Nils Meier
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */package instantj.reflect;
017:
018: /**
019: * Abstract superclass for all exceptions thrown from this package's
020: * classes. It can contain a nested exception (the reason for the
021: * exception) and contains the name of the property describing the
022: * context.
023: *
024: * @author <A href="mailto:nils@meiers.net">Nils Meier</A>
025: */
026: public abstract class PropertyException extends Exception {
027:
028: /** the target of which the property was accessed */
029: private Object target;
030:
031: /** the name of the property that led to this exception */
032: private String property;
033:
034: /** the nested reason for the exception */
035: private Throwable reason;
036:
037: /**
038: * Constructor
039: */
040: public PropertyException(String msg, Object target, String property) {
041: super (msg);
042: this .target = target;
043: this .property = property;
044: }
045:
046: /**
047: * The message (mangled) of this exception
048: */
049: public String getMessage() {
050: return super .getMessage() + " (target=" + target + ","
051: + "property=" + property + ")";
052: }
053:
054: /**
055: * Getter for the name of the property that lead to this exception
056: */
057: public String getProperty() {
058: return property;
059: }
060:
061: /**
062: * Getter for the (nested) reason that led to this exception
063: * while dealing with the property getName()
064: */
065: public Throwable getReason() {
066: return reason;
067: }
068:
069: /**
070: * Getter for the name of the property that lead to this exception
071: */
072: public Object getTarget() {
073: return target;
074: }
075:
076: /**
077: * Convenient logger
078: */
079: public void printStackTrace(java.io.PrintStream s) {
080: if (reason != null) {
081: s.println(this );
082: reason.printStackTrace(s);
083: }
084: super .printStackTrace(s);
085: }
086:
087: /**
088: * Convenient logger
089: */
090: public void printStackTrace(java.io.PrintWriter s) {
091: if (reason != null) {
092: s.println(this );
093: reason.printStackTrace(s);
094: }
095: super .printStackTrace(s);
096: }
097:
098: /**
099: * Provide a (nested) reason for this exception
100: */
101: protected void setReason(Throwable reason) {
102: this.reason = reason;
103: }
104:
105: }
|