KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > trace > Trace


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl.trace;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.*;
28
29 public abstract class Trace implements Serializable JavaDoc {
30     protected static final Map MODULE_REPOSITORY = new HashMap();
31     public static final Module TRACE_ON = new Module(MODULE_REPOSITORY, "TRACE", 1);
32     public static final Module SESSION = new Module(MODULE_REPOSITORY, "SESSION", 2);
33     public static final Module CACHE = new Module(MODULE_REPOSITORY, "CACHE", 3);
34     public static final Module OIDTABLE = new Module(MODULE_REPOSITORY, "OIDTABLE", 4);
35     public static final Module LOGICAL = new Module(MODULE_REPOSITORY, "LOGICAL", 5);
36     public static final Module PHYSICAL = new Module(MODULE_REPOSITORY, "PHYSICAL", 6);
37     public static final Module JCA = new Module(MODULE_REPOSITORY, "JCA", 8);
38     public static final Module JCAPOOL = new Module(MODULE_REPOSITORY, "JCAPOOL", 9);
39     public static final Module REMOTE = new Module(MODULE_REPOSITORY, "REMOTE", 10);
40     public static final Module DEBUG = new Module(MODULE_REPOSITORY, "DEBUG", 50);
41
42     static final long serialVersionUID = -7589377012769961459L;
43
44     private static Trace current;
45     protected boolean enabled;
46
47     public static Trace current() {
48         if (current == null) {
49             current = new TraceNull();
50         }
51
52         return current;
53     }
54
55     public abstract boolean isEnabled(Module component);
56
57     public abstract boolean isShowThread();
58
59     public abstract void enableShowThread();
60
61     public abstract void enableTrace(boolean enable);
62
63     public abstract Set enabledModules();
64
65     protected abstract void setEnabledModules(Set modules);
66
67     public abstract void init(Iterator traceModuleNames);
68
69     public abstract void printException(Object JavaDoc message, Throwable JavaDoc t);
70
71     public abstract void println(Module component, String JavaDoc message);
72
73     public abstract void println(Module component, String JavaDoc message,
74                                  Object JavaDoc parameter1);
75
76     public abstract void println(Module component, String JavaDoc message,
77                                  Object JavaDoc parameter1, Object JavaDoc parameter2);
78
79     public abstract void println(Module component, String JavaDoc message,
80                                  Object JavaDoc parameter1, Object JavaDoc parameter2,
81                                  Object JavaDoc parameter3);
82
83     public abstract void println(Module component, String JavaDoc message,
84                                  Object JavaDoc[] parameters);
85
86     public boolean isEnabled() {
87         return enabled;
88     }
89
90     public static class Module {
91         private String JavaDoc name;
92         private int flag;
93
94         public Module(Map registry, String JavaDoc name, int flag) {
95             this.name = name;
96             this.flag = flag;
97             registry.put(name, this);
98         }
99
100         public boolean isInMask(BitSet s) {
101             return s.get(flag);
102         }
103
104         public String JavaDoc getName() {
105             return name;
106         }
107
108         public boolean equals(Object JavaDoc obj) {
109             try {
110                 return flag == (((Module) obj).flag);
111             } catch (Exception JavaDoc e) {
112                 return false;
113             }
114         }
115
116         public int hashCode() {
117             return flag;
118         }
119
120         public void putInMask(BitSet s) {
121             s.set(flag);
122         }
123
124         public String JavaDoc toString() {
125             return "[" + name + "]";
126         }
127     }
128 }
129
Popular Tags