View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.monitor;
24  
25  /***
26   * Abstract base class for implementations of the Monitor interface.
27   *
28   * <p>This class unifies logging to a single method for easy sub classing.
29   * Subclasses only have to implement the two methods
30   * <code>monitor(java.lang.String)</code> and
31   * <code>monitor(java.lang.Throwable)</code>.</p>
32   *
33   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
34   */
35  public abstract class AbstractDefaultMonitor extends AbstractMonitor {
36  
37      /***
38       * Default constructor.
39       */
40      public AbstractDefaultMonitor() {
41          super();
42      }
43  
44      /***
45       * Constructor.
46       *
47       * @param theLevel the level of the new monitor, can be one of
48       * {@link de.bea.domingo.monitor.AbstractMonitor#DEBUG DEBUG},
49       * {@link de.bea.domingo.monitor.AbstractMonitor#INFO INFO},
50       * {@link de.bea.domingo.monitor.AbstractMonitor#WARN WARN},
51       * {@link de.bea.domingo.monitor.AbstractMonitor#ERROR ERROR} or
52       * {@link de.bea.domingo.monitor.AbstractMonitor#FATAL FATAL}
53       */
54      public AbstractDefaultMonitor(final int theLevel) {
55          super(theLevel);
56      }
57  
58      /***
59       * {@inheritDoc}
60       * @see de.bea.domingo.DNotesMonitor#debug(java.lang.String)
61       */
62      public final void debug(final String s) {
63          if (isDebugEnabled()) {
64              monitor("DEBUG: " + s);
65          }
66      }
67  
68      /***
69       * {@inheritDoc}
70       * @see de.bea.domingo.DNotesMonitor#debug(java.lang.String, java.lang.Throwable)
71       */
72      public final void debug(final String s, final Throwable throwable) {
73          if (isDebugEnabled()) {
74              monitor("DEBUG: " + s);
75              monitor(throwable);
76          }
77      }
78  
79      /***
80       * {@inheritDoc}
81       * @see de.bea.domingo.DNotesMonitor#info(java.lang.String)
82       */
83      public final void info(final String s) {
84          if (isInfoEnabled()) {
85              monitor("INFO:  " + s);
86          }
87      }
88  
89      /***
90       * {@inheritDoc}
91       * @see de.bea.domingo.DNotesMonitor#info(java.lang.String, java.lang.Throwable)
92       */
93      public final void info(final String s, final Throwable throwable) {
94          if (isInfoEnabled()) {
95              monitor("INFO:  " + s);
96              monitor(throwable);
97          }
98      }
99  
100     /***
101      * {@inheritDoc}
102      * @see de.bea.domingo.DNotesMonitor#warn(java.lang.String)
103      */
104     public final void warn(final String s) {
105         if (isWarnEnabled()) {
106             monitor("WARN:  " + s);
107         }
108     }
109 
110     /***
111      * {@inheritDoc}
112      * @see de.bea.domingo.DNotesMonitor#warn(java.lang.String, java.lang.Throwable)
113      */
114     public final void warn(final String s, final Throwable throwable) {
115         if (isWarnEnabled()) {
116             monitor("WARN:  " + s);
117             monitor(throwable);
118         }
119     }
120 
121     /***
122      * {@inheritDoc}
123      * @see de.bea.domingo.DNotesMonitor#error(java.lang.String)
124      */
125     public final void error(final String s) {
126         if (isErrorEnabled()) {
127             monitor("ERROR: " + s);
128         }
129     }
130 
131     /***
132      * {@inheritDoc}
133      * @see de.bea.domingo.DNotesMonitor#error(java.lang.String, java.lang.Throwable)
134      */
135     public final void error(final String s, final Throwable throwable) {
136         if (isErrorEnabled()) {
137             monitor("ERROR: " + s);
138             monitor(throwable);
139         }
140     }
141 
142     /***
143      * {@inheritDoc}
144      * @see de.bea.domingo.DNotesMonitor#fatalError(java.lang.String)
145      */
146     public final void fatalError(final String s) {
147         if (isFatalErrorEnabled()) {
148             monitor("FATAL: " + s);
149         }
150     }
151 
152     /***
153      * {@inheritDoc}
154      * @see de.bea.domingo.DNotesMonitor#fatalError(java.lang.String, java.lang.Throwable)
155      */
156     public final void fatalError(final String s, final Throwable throwable) {
157         if (isFatalErrorEnabled()) {
158             monitor("FATAL: " + s);
159             monitor(throwable);
160         }
161     }
162 
163     /***
164      * Abstract monitoring method, must be implemented by concrete monitors.
165      *
166      * @param message a message to monitor
167      */
168     protected abstract void monitor(final String message);
169 
170     /***
171      * Abstract monitoring method, must be implemented by concrete monitors.
172      *
173      * @param throwable a throwable to monitor
174      */
175     protected abstract void monitor(final Throwable throwable);
176 }