001: /*
002: * ====================================================================
003: * The JRefactory License, Version 1.0
004: *
005: * Copyright (c) 2001 JRefactory. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "JRefactory" must not be used to endorse or promote
027: * products derived from this software without prior written
028: * permission. For written permission, please contact seguin@acm.org.
029: *
030: * 5. Products derived from this software may not be called "JRefactory",
031: * nor may "JRefactory" appear in their name, without prior written
032: * permission of Chris Seguin.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of JRefactory. For more information on
050: * JRefactory, please see
051: * <http://www.sourceforge.org/projects/jrefactory>.
052: */
053: package org.acm.seguin.awt;
054:
055: import java.io.PrintWriter;
056: import java.io.StringWriter;
057: import javax.swing.JOptionPane;
058:
059: /**
060: * Prints exceptions
061: *
062: *@author Chris Seguin
063: *@created October 18, 2001
064: *@since 2.6.33
065: */
066: public abstract class ExceptionPrinter implements
067: net.sourceforge.jrefactory.factory.ExceptionPrinter {
068: private int count;
069: private static ExceptionPrinter singleton = null;
070:
071: /**
072: * Constructor for the ExceptionPrinter object
073: *
074: *@since 2.6.33
075: */
076: public ExceptionPrinter() {
077: count = 0;
078: }
079:
080: public static ExceptionPrinter getInstance() {
081: return singleton;
082: }
083:
084: /**
085: * Prints exceptions
086: *
087: *@param exc the exception to be printed
088: *@param interactive Description of the Parameter
089: *@since 2.6.33
090: */
091: public abstract void printException(Throwable exc,
092: boolean interactive);
093:
094: /**
095: * Gets the exceptionsPrinted attribute of the ExceptionPrinter class
096: *
097: *@return The exceptionsPrinted value
098: *@since 2.6.33
099: */
100: public static int getExceptionsPrinted() {
101: if (singleton == null) {
102: singleton = new GUIExceptionPrinter();
103: }
104:
105: return singleton.count;
106: }
107:
108: /**
109: * Prints exceptions
110: *
111: *@param exc the exception to be printed
112: *@param interactive Is this interactive
113: *@since 2.6.33
114: */
115: public static void print(Throwable exc, boolean interactive) {
116: if (singleton == null) {
117: singleton = new GUIExceptionPrinter();
118: }
119:
120: singleton.printException(exc, interactive);
121: singleton.count++;
122: }
123:
124: /**
125: * Description of the Method
126: *
127: *@param printer Description of the Parameter
128: *@since 2.6.33
129: */
130: public static void register(ExceptionPrinter printer) {
131: singleton = printer;
132: }
133: }
134: // EOF
|