KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > DefaultLF5Configurator


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.lf5;
18
19 import org.apache.log4j.PropertyConfigurator;
20 import org.apache.log4j.spi.Configurator;
21 import org.apache.log4j.spi.LoggerRepository;
22
23 import java.io.IOException JavaDoc;
24 import java.net.URL JavaDoc;
25
26 /**
27  * The <code>DefaultLF5Configurator</code> provides a default
28  * configuration for the <code>LF5Appender</code>.
29  *
30  * Note: The preferred method for configuring a <code>LF5Appender</code>
31  * is to use the <code>LF5Manager</code> class. This class ensures
32  * that configuration does not occur multiple times, and improves system
33  * performance. Reconfiguring the monitor multiple times can result in
34  * unexpected behavior.
35  *
36  * @author Brent Sprecher
37  */

38
39 // Contributed by ThoughtWorks Inc.
40

41 public class DefaultLF5Configurator implements Configurator {
42   //--------------------------------------------------------------------------
43
// Constants:
44
//--------------------------------------------------------------------------
45

46   //--------------------------------------------------------------------------
47
// Protected Variables:
48
//--------------------------------------------------------------------------
49

50   //--------------------------------------------------------------------------
51
// Private Variables:
52
//--------------------------------------------------------------------------
53

54   //--------------------------------------------------------------------------
55
// Constructors:
56
//--------------------------------------------------------------------------
57
/**
58    * This class should never be instantiated! It implements the <code>
59    * Configurator</code>
60    * interface, but does not provide the same functionality as full
61    * configurator class.
62    */

63   private DefaultLF5Configurator() {
64
65   }
66
67   //--------------------------------------------------------------------------
68
// Public Methods:
69
//--------------------------------------------------------------------------
70
/**
71    * This method configures the <code>LF5Appender</code> using a
72    * default configuration file. The default configuration file is
73    * <bold>defaultconfig.properties</bold>.
74    * @throws java.io.IOException
75    */

76   public static void configure() throws IOException JavaDoc {
77     String JavaDoc resource =
78         "/org/apache/log4j/lf5/config/defaultconfig.properties";
79     URL JavaDoc configFileResource =
80         DefaultLF5Configurator.class.getResource(resource);
81
82     if (configFileResource != null) {
83       PropertyConfigurator.configure(configFileResource);
84     } else {
85       throw new IOException JavaDoc("Error: Unable to open the resource" +
86           resource);
87     }
88
89   }
90
91   /**
92    * This is a dummy method that will throw an
93    * <code>IllegalStateException</code> if used.
94    */

95   public void doConfigure(URL JavaDoc configURL, LoggerRepository repository) {
96     throw new IllegalStateException JavaDoc("This class should NOT be" +
97         " instantiated!");
98   }
99
100   //--------------------------------------------------------------------------
101
// Protected Methods:
102
//--------------------------------------------------------------------------
103

104   //--------------------------------------------------------------------------
105
// Private Methods:
106
//--------------------------------------------------------------------------
107

108   //--------------------------------------------------------------------------
109
// Nested Top-Level Classes or Interfaces:
110
//--------------------------------------------------------------------------
111

112 }
Popular Tags