QedeqLog.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2011,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.kernel.bo.log;
017 
018 import java.util.ArrayList;
019 import java.util.List;
020 
021 import org.qedeq.base.trace.Trace;
022 
023 
024 /**
025  * This class organizes the logging.
026  *
027  @author  Michael Meyling
028  */
029 public final class QedeqLog implements LogListener {
030 
031     /** This class. */
032     private static final Class CLASS = QedeqLog.class;
033 
034     /** The one and only instance. */
035     private static QedeqLog instance = new QedeqLog();
036 
037     /** The loggers. */
038     private List loggers = new ArrayList();
039 
040 
041     /**
042      * Get instance of Logger.
043      *
044      @return  singleton
045      */
046     public static final QedeqLog getInstance() {
047         return instance;
048     }
049 
050 
051     /**
052      * Don't use me outside of this class.
053      */
054     private QedeqLog() {
055     }
056 
057     /**
058      * Add listener.
059      *
060      @param   log Add this listener.
061      */
062     public final void addLog(final LogListener log) {
063         loggers.add(log);
064         Trace.paramInfo(CLASS, this, "addLog(LogListener)""log", log.getClass());
065     }
066 
067     /**
068      * Remove listener.
069      *
070      @param   log Remove this listener.
071      */
072     public final void removeLog(final LogListener log) {
073         loggers.remove(log);
074         Trace.paramInfo(CLASS, this, "removeLog(LogListener)""log", log.getClass());
075     }
076 
077     public void logMessageState(final String text, final String url) {
078         for (int i = 0; i < loggers.size(); i++) {
079             try {   // we don't know if the LogListener is free of programming errors...
080                 ((LogListenerloggers.get(i)).logMessageState(text, url);
081             catch (RuntimeException e) {
082                 Trace.fatal(CLASS, this, "logMessageState""LogListener throwed RuntimeException",
083                     e);
084             }
085         }
086     }
087 
088     public void logFailureState(final String text, final String url, final String description) {
089         for (int i = 0; i < loggers.size(); i++) {
090             try {   // we don't know if the LogListener is free of programming errors...
091                 ((LogListenerloggers.get(i)).logFailureState(text, url, description);
092             catch (RuntimeException e) {
093                 Trace.fatal(CLASS, this, "logFailureState""LogListener throwed RuntimeException",
094                     e);
095             }
096         }
097     }
098 
099     public void logSuccessfulState(final String text, final String url) {
100         for (int i = 0; i < loggers.size(); i++) {
101             try {   // we don't know if the LogListener is free of programming errors...
102                 ((LogListenerloggers.get(i)).logSuccessfulState(text, url);
103             catch (RuntimeException e) {
104                 Trace.fatal(CLASS, this, "logSuccessfulState",
105                     "LogListener throwed RuntimeException", e);
106             }
107         }
108     }
109 
110     public void logRequest(final String text) {
111         for (int i = 0; i < loggers.size(); i++) {
112             try {   // we don't know if the LogListener is free of programming errors...
113                 ((LogListenerloggers.get(i)).logRequest(text);
114             catch (RuntimeException e) {
115                 Trace.fatal(CLASS, this, "logRequest""LogListener throwed RuntimeException", e);
116             }
117         }
118     }
119 
120     public void logSuccessfulReply(final String text) {
121         try {   // we don't know if the LogListener is free of programming errors...
122             for (int i = 0; i < loggers.size(); i++) {
123                 ((LogListenerloggers.get(i)).logSuccessfulReply(text);
124             }
125         catch (RuntimeException e) {
126             Trace.fatal(CLASS, this, "logSuccessfulReply""LogListener throwed RuntimeException",
127                 e);
128         }
129     }
130 
131     public void logFailureReply(final String text, final String description) {
132         for (int i = 0; i < loggers.size(); i++) {
133             try {   // we don't know if the LogListener is free of programming errors...
134                 ((LogListenerloggers.get(i)).logFailureReply(text, description);
135             catch (RuntimeException e) {
136                 Trace.fatal(CLASS, this, "logFailureReply""LogListener throwed RuntimeException",
137                     e);
138             }
139         }
140     }
141 
142     public void logMessage(final String text) {
143         for (int i = 0; i < loggers.size(); i++) {
144             try {   // we don't know if the LogListener is free of programming errors...
145                 ((LogListenerloggers.get(i)).logMessage(text);
146             catch (RuntimeException e) {
147                 Trace.fatal(CLASS, this, "logMessage""LogListener throwed RuntimeException", e);
148             }
149         }
150     }
151 
152 
153 }