001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package util;
012:
013: /**
014: Handle error reporting in a way that looks less catastrophic
015: than exceptions typically do.
016: *
017: */
018: public final class ReportError {
019: /**
020: * Culpable party is the administrator - the
021: * applet was fed the wrong parameters.
022: */
023: public final static String ADMIN = Messages.ADMIN;
024: /**
025: * Culpable party was the developer who wrote bad code.
026: */
027: public final static String INTERNAL = Messages.INTERNAL;
028: /**
029: * Culpable party was the developer who wrote bad code for
030: * other developers.
031: */
032: public final static String SYSTEM = Messages.SYSTEM;
033: /**
034: * Culpable party was the user.
035: */
036: public final static String USER = Messages.USER;
037:
038: /**
039: * Serious error.
040: */
041: public final static String ERROR = Messages.ERROR;
042: /**
043: * Warning.
044: */
045: public final static String WARNING = Messages.WARNING;
046: /**
047: * Informational only.
048: */
049: public final static String INFORMATION = Messages.INFORMATION;
050:
051: /**
052: * Unknown.
053: */
054: public final static String UNKNOWN = Messages.UNKNOWN;
055:
056: private static String checkType(String s) {
057: if ((s.compareTo(Messages.USER) == 0)
058: || (s.compareTo(Messages.SYSTEM) == 0)
059: || (s.compareTo(Messages.INTERNAL) == 0)
060: || (s.compareTo(Messages.ADMIN) == 0)) {
061: return s;
062: } else {
063: return UNKNOWN;
064: }
065: }
066:
067: private static String checkLevel(String s) {
068: if ((s.compareTo(Messages.ERROR) == 0)
069: || (s.compareTo(Messages.WARNING) == 0)
070: || (s.compareTo(Messages.INFORMATION) == 0)) {
071: return s;
072: } else {
073: return UNKNOWN;
074: }
075: }
076:
077: /**
078: * Report an internal error.
079: * @param type error type
080: * @param obj the unhappy class
081: * @param mthd the unhappy method
082: * @param s the error string
083: */
084: public static void reportError(String type, String obj,
085: String mthd, String s) {
086: reportError(Messages.ERROR, type, obj, mthd, s);
087: }
088:
089: /**
090: * Report an internal error.
091: * @param level error level
092: * @param type error type
093: * @param obj the unhappy class
094: * @param mthd the unhappy method
095: * @param s the error string
096: */
097: public static void reportError(String level, String type,
098: String obj, String mthd, String s) {
099: System.out.println("---< " + checkType(type) + " "
100: + checkLevel(level) + " >---");
101: System.out.println(obj + "." + mthd + "() " + checkLevel(level)
102: + ": " + s);
103: }
104:
105: /**
106: * Handle an exception. With stack trace.
107: * @param e exception
108: * @param obj the unhappy class
109: * @param mthd the unhappy method
110: * @param s the error string
111: */
112: public static void handleException(Exception e, String obj,
113: String mthd, String s) {
114: handleException(e, obj, mthd, s, true);
115: }
116:
117: /**
118: * Handle an exception.
119: * @param e exception
120: * @param obj the unhappy class
121: * @param mthd the unhappy method
122: * @param s the error string
123: * @param doTrace optionally dump stack trace
124: */
125: public static void handleException(Exception e, String obj,
126: String mthd, String s, boolean doTrace) {
127: System.out.println("---< " + INTERNAL + " " + Messages.ERROR
128: + " >---");
129: System.out.println(obj + "." + mthd + "() " + Messages.ERROR
130: + ": " + s);
131: if (doTrace) {
132: e.printStackTrace();
133: }
134: }
135: }
|