001    /*
002     * Copyright (c) 2003, The Regents of the University of California, through
003     * Lawrence Berkeley National Laboratory (subject to receipt of any required
004     * approvals from the U.S. Dept. of Energy). All rights reserved.
005     */
006    package gov.lbl.dsd.sea.event;
007    
008    import gov.lbl.dsd.sea.Stage;
009    
010    /**
011     * A generic runtime exception that can be thrown when a problem occurs within
012     * {@link gov.lbl.dsd.sea.EventHandler#handle(java.lang.Object)}.
013     * <p>
014     * If appropriate, you can enqueue an instance of this class onto a stage.
015     *
016     * @author whoschek@lbl.gov
017     * @author $Author: hoschek3 $
018     * @version $Revision: 1.2 $, $Date: 2004/07/22 18:04:54 $
019     */
020    public class ExceptionEvent extends RuntimeException {
021    
022        protected Object causingEvent;
023        protected Stage source;
024    
025        /**
026         * Constructs a new exception.
027         *
028         * @param causingEvent
029         *            the event that caused the exception.
030         * @param source
031         *            the stage that could not properly handle the causing event.
032         */
033        public ExceptionEvent(Object causingEvent, Stage source) {
034            this(null, null, causingEvent, source);
035        }
036    
037        /**
038         * Constructs a new exception.
039         *
040         * @param  cause the cause (which is saved for later retrieval by the
041         *         {@link #getCause()} method).  (A <tt>null</tt> value is
042         *         permitted, and indicates that the cause is nonexistent or
043         *         unknown.)
044         * @param causingEvent
045         *            the event that caused the exception.
046         * @param source
047         *            the stage that could not properly handle the causing event.
048         */
049        public ExceptionEvent(Throwable cause, Object causingEvent, Stage source) {
050            this(null, cause, causingEvent, source);
051        }
052    
053        /**
054         * Constructs a new exception.
055         *
056         * @param message
057         *            the detail message. The detail message is saved for later
058         *            retrieval by the {@link #getMessage()}method.
059         * @param  cause the cause (which is saved for later retrieval by the
060         *         {@link #getCause()} method).  (A <tt>null</tt> value is
061         *         permitted, and indicates that the cause is nonexistent or
062         *         unknown.)
063         * @param causingEvent
064         *            the event that caused the exception.
065         * @param source
066         *            the stage that could not properly handle the causing event.
067         */
068        public ExceptionEvent(String message, Throwable cause, Object causingEvent, Stage source) {
069            super(message, cause);
070            this.causingEvent = causingEvent;
071            this.source = source;
072        }
073    
074        public Object getCausingEvent() {
075            return this.causingEvent;
076        }
077    
078        public Stage getSource() {
079            return this.source;
080        }
081    
082    
083        public String toString() {
084            String str = super.toString();
085            if (getCausingEvent() != null) str = str + ", causingEventType=" + getCausingEvent().getClass().getName();
086            if (getCausingEvent() != null) str = str + ", causingEvent=" + getCausingEvent();
087            if (getSource() != null) str = str + ", source=" + getSource();
088            return str;
089        }
090    
091    }