001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy;
048:
049: import java.io.PrintStream;
050: import java.io.PrintWriter;
051:
052: /**
053: *
054: * Parent of all Jemmy exceptions.
055: * Exception can be throught from inside jemmy methods,
056: * if some exception occurs from code invoked from jemmy.
057: *
058: * @author Alexandre Iline (alexandre.iline@sun.com)
059: */
060:
061: public class JemmyException extends RuntimeException {
062:
063: private Throwable innerException = null;
064: private Object object = null;
065:
066: /**
067: * Constructor.
068: * @param description An exception description.
069: */
070: public JemmyException(String description) {
071: super (description);
072: }
073:
074: /**
075: * Constructor.
076: * @param description An exception description.
077: * @param innerException Exception from code invoked from jemmy.
078: */
079: public JemmyException(String description, Throwable innerException) {
080: this (description);
081: this .innerException = innerException;
082: }
083:
084: /**
085: * Constructor.
086: * @param description An exception description.
087: * @param object Object regarding which exception is thrown.
088: */
089: public JemmyException(String description, Object object) {
090: this (description);
091: this .object = object;
092: }
093:
094: /**
095: * Constructor.
096: * @param description An exception description.
097: * @param innerException Exception from code invoked from jemmy.
098: * @param object Object regarding which exception is thrown.
099: */
100: public JemmyException(String description, Throwable innerException,
101: Object object) {
102: this (description, innerException);
103: this .object = object;
104: }
105:
106: /**
107: * Returns "object" constructor parameter.
108: * @return the Object value associated with the exception.
109: */
110: public Object getObject() {
111: return (object);
112: }
113:
114: /**
115: * Returns inner exception.
116: * @return An inner exception.
117: * @deprecated Use getInnerThrowable()
118: */
119: public Exception getInnerException() {
120: if (innerException instanceof Exception) {
121: return ((Exception) innerException);
122: } else {
123: return (null);
124: }
125: }
126:
127: /**
128: * Returns inner throwable.
129: * @return An inner throwable.
130: */
131: public Throwable getInnerThrowable() {
132: return (innerException);
133: }
134:
135: /**
136: * Prints stack trace into System.out.
137: */
138: public void printStackTrace() {
139: printStackTrace(System.out);
140: }
141:
142: /**
143: * Prints stack trace.
144: * @param ps PrintStream to print stack trace into.
145: */
146: public void printStackTrace(PrintStream ps) {
147: super .printStackTrace(ps);
148: if (innerException != null) {
149: ps.println("Inner exception:");
150: innerException.printStackTrace(ps);
151: }
152: if (object != null) {
153: ps.println("Object:");
154: ps.println(object.toString());
155: ;
156: }
157: }
158:
159: /**
160: * Prints stack trace.
161: *
162: * @param pw PrintWriter to print stack trace into.
163: *
164: */
165: public void printStackTrace(PrintWriter pw) {
166: super .printStackTrace(pw);
167: if (innerException != null) {
168: pw.println("Inner exception:");
169: innerException.printStackTrace(pw);
170: }
171: if (object != null) {
172: pw.println("Object:");
173: pw.println(object.toString());
174: ;
175: }
176: }
177: }
|