001: /**
002: * Copyright (C) 2001-2003 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.util.monolog.wrapper.config;
018:
019: import org.objectweb.util.monolog.api.Handler;
020: import org.objectweb.util.monolog.api.Level;
021: import org.objectweb.util.monolog.api.LevelFactory;
022: import org.objectweb.util.monolog.api.TopicalLogger;
023:
024: import java.io.Serializable;
025: import java.util.ArrayList;
026: import java.util.Enumeration;
027: import java.util.HashMap;
028:
029: /**
030: * This class is a basic implementatio of the TopicalLogger interface. It is not
031: * linked to any underlying log system. The log methods do nothing. Only the
032: * configuration aspect is treated. Therefore all the logger structure is
033: * stored into internal struture.
034: *
035: * @author Sebastien Chassande-Barrioz
036: */
037: public class BasicLogger implements TopicalLogger, Serializable {
038:
039: /**
040: * This fields references by their name the handlers associated to the
041: * logger.
042: * key = a handler name
043: * value = a Handler instance
044: */
045: protected HashMap handlers = null;
046:
047: /**
048: * The fields lists all topics the logger.
049: */
050: protected ArrayList topics = null;
051:
052: /**
053: * This field references the level factory.
054: */
055: protected LevelFactory levelFactory = null;
056:
057: boolean additivity = true;
058:
059: /**
060: * The current level of the logger.
061: */
062: protected Level level = null;
063:
064: BasicLogger(String topic, LevelFactory lf) {
065: topics = new ArrayList();
066: handlers = new HashMap();
067: topics.add(topic);
068: levelFactory = lf;
069: }
070:
071: // IMPLEMENTATION OF THE TopicalLogger INTERFACE //
072: //--------------------------------------------//
073:
074: public void addHandler(Handler h) throws Exception {
075: handlers.put(h.getName(), h);
076: }
077:
078: public void removeHandler(Handler h) throws Exception {
079: handlers.remove(h.getName());
080: }
081:
082: public Handler[] getHandler() {
083: return (Handler[]) handlers.values().toArray(new Handler[0]);
084: }
085:
086: public Handler getHandler(String hn) {
087: return (Handler) handlers.get(hn);
088: }
089:
090: public void removeAllHandlers() throws Exception {
091: handlers.clear();
092: }
093:
094: public void setAdditivity(boolean a) {
095: additivity = a;
096: }
097:
098: public boolean getAdditivity() {
099: return additivity;
100: }
101:
102: public void addTopic(String topic) throws Exception {
103: if (!topics.contains(topic)) {
104: topics.add(topic);
105: }
106: }
107:
108: /**
109: * TODO
110: */
111: public Enumeration getTopics() {
112: //TODO
113: return null;
114: }
115:
116: public String[] getTopic() {
117: return (String[]) topics.toArray(new String[0]);
118: }
119:
120: public void removeTopic(String topic) throws Exception {
121: topics.remove(topic);
122: }
123:
124: // IMPLEMENTATION OF THE Handler INTERFACE //
125: //----------------------------------------//
126: public String getName() {
127: return (String) topics.get(0);
128: }
129:
130: public void setName(String name) {
131: topics.set(0, name);
132: }
133:
134: public String getType() {
135: return "logger";
136: }
137:
138: public String[] getAttributeNames() {
139: return new String[0];
140: }
141:
142: public Object getAttribute(String name) {
143: return null;
144: }
145:
146: public Object setAttribute(String name, Object value) {
147: return null;
148: }
149:
150: // IMPLEMENTATION OF THE Logger INTERFACE //
151: //----------------------------------------//
152:
153: public void setIntLevel(int l) {
154: level = levelFactory.getLevel(l);
155: }
156:
157: public void setLevel(Level l) {
158: level = l;
159: }
160:
161: public int getCurrentIntLevel() {
162: return (level != null ? level.getIntValue() : 0);
163: }
164:
165: public Level getCurrentLevel() {
166: return level;
167: }
168:
169: public boolean isLoggable(int level) {
170: return false;
171: }
172:
173: public boolean isLoggable(Level l) {
174: return false;
175: }
176:
177: public boolean isOn() {
178: return false;
179: }
180:
181: public void log(int level, Object message) {
182: }
183:
184: public void log(Level level, Object message) {
185: }
186:
187: public void log(int level, Object message, Throwable throwable) {
188: }
189:
190: public void log(Level level, Object message, Throwable throwable) {
191: }
192:
193: public void log(int level, Object message, Object location,
194: Object method) {
195: }
196:
197: public void log(Level l, Object message, Object location,
198: Object method) {
199: }
200:
201: public void log(int level, Object message, Throwable throwable,
202: Object location, Object method) {
203: }
204:
205: public void log(Level level, Object message, Throwable throwable,
206: Object location, Object method) {
207: }
208:
209: public void turnOn() {
210: }
211:
212: public void turnOff() {
213: }
214: }
|