KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > log > console > ConsoleLogFactory


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.log.console;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogConfigurationException;
26 import org.apache.commons.logging.LogFactory;
27
28 /**
29  * Implementation of the <code>LogFactory</code> to reference to the ConsoleLogger
30  *
31  * Copyright 2003 Sapient
32  * @since carbon 2.0
33  * @author Anand Raman, March 2003
34  * @version $Revision: 1.4 $($Author: dvoet $ / $Date: 2003/05/05 21:21:26 $)
35  */

36 public class ConsoleLogFactory extends LogFactory {
37
38     /**
39      * The configuration attributes for this {@link LogFactory}.
40      */

41     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
42
43     /**
44      * Instance of ConsoleLogger
45      */

46     private Hashtable JavaDoc instances = new Hashtable JavaDoc();
47
48     /**
49      * Constructor for ConsoleLogFactory.
50      */

51     public ConsoleLogFactory() {
52         super();
53     }
54
55     /**
56      * @see org.apache.commons.logging.LogFactory#getAttribute(String)
57      */

58     public Object JavaDoc getAttribute(String JavaDoc name) {
59         return (attributes.get(name));
60     }
61
62     /**
63      * @see org.apache.commons.logging.LogFactory#getAttributeNames()
64      */

65     public String JavaDoc[] getAttributeNames() {
66         Vector JavaDoc names = new Vector JavaDoc();
67         Enumeration JavaDoc keys = attributes.keys();
68         while (keys.hasMoreElements()) {
69             names.addElement((String JavaDoc) keys.nextElement());
70         }
71         String JavaDoc results[] = new String JavaDoc[names.size()];
72         for (int i = 0; i < results.length; i++) {
73             results[i] = (String JavaDoc) names.elementAt(i);
74         }
75         return (results);
76     }
77
78     /**
79      * @see org.apache.commons.logging.LogFactory#getInstance(Class)
80      */

81     public Log getInstance(Class JavaDoc className) throws LogConfigurationException {
82         return getInstance(className.getName());
83     }
84
85     /**
86      * @see org.apache.commons.logging.LogFactory#getInstance(String)
87      */

88     public Log getInstance(String JavaDoc className) throws LogConfigurationException {
89         Log consoleLogger = null;
90
91         consoleLogger = (ConsoleLogger) instances.get(className);
92
93         if ( consoleLogger == null ) {
94             consoleLogger = new ConsoleLogger(className);
95         }
96
97         return consoleLogger;
98     }
99
100     /**
101      * @see org.apache.commons.logging.LogFactory#release()
102      */

103     public void release() {
104         //forget all the created instances
105
instances.clear();
106     }
107
108     /**
109      * @see org.apache.commons.logging.LogFactory#removeAttribute(String)
110      */

111     public void removeAttribute(String JavaDoc name) {
112         attributes.remove(name);
113     }
114
115     /**
116      * @see org.apache.commons.logging.LogFactory#setAttribute(String, Object)
117      */

118     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
119         attributes.put(name, value);
120     }
121
122 }
123
Popular Tags