KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > component > MonologComponent


1 /**
2  * Copyright (C) 2003 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.util.monolog.component;
19
20 import org.objectweb.util.monolog.api.LoggerFactory;
21 import org.objectweb.util.monolog.api.Logger;
22 import org.objectweb.util.monolog.api.LevelFactory;
23 import org.objectweb.util.monolog.api.Level;
24 import org.objectweb.util.monolog.api.HandlerFactory;
25 import org.objectweb.util.monolog.api.Handler;
26 import org.objectweb.util.monolog.api.MonologFactory;
27 import org.objectweb.util.monolog.Monolog;
28
29 import java.util.Properties JavaDoc;
30
31 /**
32  * Is a simple fractal component encapsualiting a MonologFactory.
33  *
34  * @author S.Chassande-Barrioz
35  */

36 public class MonologComponent
37         implements MonologFactory, MonologAttributes {
38
39     private static MonologFactory singleton = Monolog.getDefaultMonologFactory();
40
41     public static LoggerFactory getLoggerFactory() {
42         return singleton;
43     }
44
45     public static LevelFactory getLevelFactory() {
46         return singleton;
47     }
48
49     public static HandlerFactory getHandlerFactory() {
50         return singleton;
51     }
52
53
54     private MonologFactory factory;
55     private String JavaDoc fileName;
56
57     public MonologComponent() {
58         factory = Monolog.getDefaultMonologFactory();
59     }
60
61     // IMPLEMENTATION OF THE LoggerFactory INTERFACE //
62
//-----------------------------------------------//
63

64     public String JavaDoc getPropertiesFileName() {
65         return fileName;
66     }
67
68     public void setPropertiesFileName(String JavaDoc propfn) {
69         if (fileName != null && fileName.equals(propfn))
70             return;
71         fileName = propfn;
72         if (propfn != null) {
73             factory = Monolog.getMonologFactory(propfn);
74             if (singleton != Monolog.getDefaultMonologFactory()) {
75                 singleton = factory;
76             }
77         }
78     }
79
80     // IMPLEMENTATION OF THE LoggerFactory INTERFACE //
81
//-----------------------------------------------//
82

83     public Logger getLogger(String JavaDoc key) {
84         return factory.getLogger(key);
85     }
86
87     public Logger getLogger(String JavaDoc key, String JavaDoc resourceBundleName) {
88         return factory.getLogger(key, resourceBundleName);
89     }
90
91     public String JavaDoc getResourceBundleName() {
92         return factory.getResourceBundleName();
93     }
94
95     public void setResourceBundleName(String JavaDoc resourceBundleName) {
96         factory.setResourceBundleName(resourceBundleName);
97     }
98
99     public Logger[] getLoggers() {
100         return factory.getLoggers();
101     }
102
103
104     // IMPLEMENTATION OF THE LoggerFactory INTERFACE //
105
//-----------------------------------------------//
106

107     public Level defineLevel(String JavaDoc name, int value) {
108         return factory.defineLevel(name, value);
109     }
110
111     public Level defineLevel(String JavaDoc name, String JavaDoc value) {
112         return factory.defineLevel(name, value);
113     }
114
115     public Level getLevel(String JavaDoc name) {
116         return factory.getLevel(name);
117     }
118
119     public Level getLevel(int value) {
120         return factory.getLevel(value);
121     }
122
123     public Level[] getLevels() {
124         return factory.getLevels();
125     }
126
127     public void removeLevel(String JavaDoc name) {
128         factory.removeLevel(name);
129     }
130
131
132     // IMPLEMENTATION OF THE HandlerFactory INTERFACE //
133
//------------------------------------------------//
134

135     public Handler createHandler(String JavaDoc hn, String JavaDoc handlertype) {
136         return factory.createHandler(hn, handlertype);
137     }
138
139     public Handler[] getHandlers() {
140         return factory.getHandlers();
141     }
142
143     public Handler getHandler(String JavaDoc handlername) {
144         return factory.getHandler(handlername);
145     }
146
147     public Handler removeHandler(String JavaDoc handlername) {
148         return factory.removeHandler(handlername);
149     }
150
151     // IMPLEMENTATION OF THE MonologFactory INTERFACE //
152
//------------------------------------------------//
153

154     public void configure(Properties JavaDoc prop) throws Exception JavaDoc {
155         factory.configure(prop);
156     }
157 }
158
Popular Tags