KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > NioDebug


1 package org.sapia.ubik.net.nio;
2
3 import java.io.PrintStream JavaDoc;
4
5 import org.sapia.ubik.util.Debug;
6 import org.sapia.ubik.util.StdoutDebug;
7
8 /**
9  * Singleton instance of the <code>Debug</code> interface that writes to
10  * stdout by default.
11  *
12  * @author Yanick Duchesne
13  *
14  * <dl>
15  * <dt><b>Copyright: </b>
16  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
17  * Source Software </a>. All Rights Reserved.</dd>
18  * </dt>
19  * <dt><b>License: </b>
20  * <dd>Read the license.txt file of the jar or visit the <a
21  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
22  * OSS web site</dd>
23  * </dt>
24  * </dl>
25  */

26 public final class NioDebug implements Debug {
27
28   private static Debug _instance = new StdoutDebug();
29
30   private NioDebug() {
31   }
32
33   /**
34    * @see org.sapia.ubik.net.nio.util.Debug#on()
35    */

36   public boolean on() {
37     return _instance.on();
38   }
39
40   /**
41    * @see org.sapia.ubik.net.nio.util.Debug#on(boolean)
42    */

43   public void on(boolean on) {
44     _instance.on(on);
45   }
46
47   public PrintStream JavaDoc out() {
48     return _instance.out();
49   }
50
51   public void out(Class JavaDoc caller, String JavaDoc msg, Throwable JavaDoc err) {
52     _instance.out(caller, msg, err);
53   }
54
55   public void out(Class JavaDoc caller, String JavaDoc msg) {
56     _instance.out(caller, msg);
57   }
58
59   /**
60    * @param debug
61    * the static <code>Debug</code> instance that all instances of
62    * this class delegate their output calls to.
63    */

64   public static void setDebugInstance(Debug debug) {
65     if(debug instanceof NioDebug) {
66       return;
67     }
68     debug.on(_instance.on());
69     _instance = debug;
70   }
71
72   /**
73    * @return an <code>NioDebug</code> instance.
74    */

75   public static NioDebug getInstance() {
76     return new NioDebug();
77   }
78
79 }
80
Popular Tags