0N/A/*
2362N/A * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage java.util.logging;
0N/A
0N/A/**
0N/A * ErrorManager objects can be attached to Handlers to process
1664N/A * any error that occurs on a Handler during Logging.
0N/A * <p>
0N/A * When processing logging output, if a Handler encounters problems
0N/A * then rather than throwing an Exception back to the issuer of
0N/A * the logging call (who is unlikely to be interested) the Handler
0N/A * should call its associated ErrorManager.
0N/A */
0N/A
0N/Apublic class ErrorManager {
0N/A private boolean reported = false;
0N/A
0N/A /*
0N/A * We declare standard error codes for important categories of errors.
0N/A */
0N/A
0N/A /**
0N/A * GENERIC_FAILURE is used for failure that don't fit
0N/A * into one of the other categories.
0N/A */
0N/A public final static int GENERIC_FAILURE = 0;
0N/A /**
0N/A * WRITE_FAILURE is used when a write to an output stream fails.
0N/A */
0N/A public final static int WRITE_FAILURE = 1;
0N/A /**
0N/A * FLUSH_FAILURE is used when a flush to an output stream fails.
0N/A */
0N/A public final static int FLUSH_FAILURE = 2;
0N/A /**
0N/A * CLOSE_FAILURE is used when a close of an output stream fails.
0N/A */
0N/A public final static int CLOSE_FAILURE = 3;
0N/A /**
0N/A * OPEN_FAILURE is used when an open of an output stream fails.
0N/A */
0N/A public final static int OPEN_FAILURE = 4;
0N/A /**
0N/A * FORMAT_FAILURE is used when formatting fails for any reason.
0N/A */
0N/A public final static int FORMAT_FAILURE = 5;
0N/A
0N/A /**
0N/A * The error method is called when a Handler failure occurs.
0N/A * <p>
1664N/A * This method may be overridden in subclasses. The default
0N/A * behavior in this base class is that the first call is
0N/A * reported to System.err, and subsequent calls are ignored.
0N/A *
0N/A * @param msg a descriptive string (may be null)
0N/A * @param ex an exception (may be null)
0N/A * @param code an error code defined in ErrorManager
0N/A */
0N/A public synchronized void error(String msg, Exception ex, int code) {
0N/A if (reported) {
0N/A // We only report the first error, to avoid clogging
0N/A // the screen.
0N/A return;
0N/A }
0N/A reported = true;
0N/A String text = "java.util.logging.ErrorManager: " + code;
0N/A if (msg != null) {
0N/A text = text + ": " + msg;
0N/A }
0N/A System.err.println(text);
0N/A if (ex != null) {
0N/A ex.printStackTrace();
0N/A }
0N/A }
0N/A}