001: /*
002: * Jalisto - JAva LIght STOrage
003: * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library 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 GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
018: *
019: * Xcalia
020: * 71, rue Desnouettes
021: * 75014 Paris - France
022: * http://www.xcalia.com
023: */
024: package org.objectweb.jalisto.se.impl.trace;
025:
026: import java.io.Serializable;
027: import java.util.*;
028:
029: public abstract class Trace implements Serializable {
030: protected static final Map MODULE_REPOSITORY = new HashMap();
031: public static final Module TRACE_ON = new Module(MODULE_REPOSITORY,
032: "TRACE", 1);
033: public static final Module SESSION = new Module(MODULE_REPOSITORY,
034: "SESSION", 2);
035: public static final Module CACHE = new Module(MODULE_REPOSITORY,
036: "CACHE", 3);
037: public static final Module OIDTABLE = new Module(MODULE_REPOSITORY,
038: "OIDTABLE", 4);
039: public static final Module LOGICAL = new Module(MODULE_REPOSITORY,
040: "LOGICAL", 5);
041: public static final Module PHYSICAL = new Module(MODULE_REPOSITORY,
042: "PHYSICAL", 6);
043: public static final Module JCA = new Module(MODULE_REPOSITORY,
044: "JCA", 8);
045: public static final Module JCAPOOL = new Module(MODULE_REPOSITORY,
046: "JCAPOOL", 9);
047: public static final Module REMOTE = new Module(MODULE_REPOSITORY,
048: "REMOTE", 10);
049: public static final Module DEBUG = new Module(MODULE_REPOSITORY,
050: "DEBUG", 50);
051:
052: static final long serialVersionUID = -7589377012769961459L;
053:
054: private static Trace current;
055: protected boolean enabled;
056:
057: public static Trace current() {
058: if (current == null) {
059: current = new TraceNull();
060: }
061:
062: return current;
063: }
064:
065: public abstract boolean isEnabled(Module component);
066:
067: public abstract boolean isShowThread();
068:
069: public abstract void enableShowThread();
070:
071: public abstract void enableTrace(boolean enable);
072:
073: public abstract Set enabledModules();
074:
075: protected abstract void setEnabledModules(Set modules);
076:
077: public abstract void init(Iterator traceModuleNames);
078:
079: public abstract void printException(Object message, Throwable t);
080:
081: public abstract void println(Module component, String message);
082:
083: public abstract void println(Module component, String message,
084: Object parameter1);
085:
086: public abstract void println(Module component, String message,
087: Object parameter1, Object parameter2);
088:
089: public abstract void println(Module component, String message,
090: Object parameter1, Object parameter2, Object parameter3);
091:
092: public abstract void println(Module component, String message,
093: Object[] parameters);
094:
095: public boolean isEnabled() {
096: return enabled;
097: }
098:
099: public static class Module {
100: private String name;
101: private int flag;
102:
103: public Module(Map registry, String name, int flag) {
104: this .name = name;
105: this .flag = flag;
106: registry.put(name, this );
107: }
108:
109: public boolean isInMask(BitSet s) {
110: return s.get(flag);
111: }
112:
113: public String getName() {
114: return name;
115: }
116:
117: public boolean equals(Object obj) {
118: try {
119: return flag == (((Module) obj).flag);
120: } catch (Exception e) {
121: return false;
122: }
123: }
124:
125: public int hashCode() {
126: return flag;
127: }
128:
129: public void putInMask(BitSet s) {
130: s.set(flag);
131: }
132:
133: public String toString() {
134: return "[" + name + "]";
135: }
136: }
137: }
|