001: /*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:
018: package org.sape.carbon.services.log.console;
019:
020: import java.util.Enumeration;
021: import java.util.Hashtable;
022: import java.util.Vector;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogConfigurationException;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * Implementation of the <code>LogFactory</code> to reference to the ConsoleLogger
030: *
031: * Copyright 2003 Sapient
032: * @since carbon 2.0
033: * @author Anand Raman, March 2003
034: * @version $Revision: 1.4 $($Author: dvoet $ / $Date: 2003/05/05 21:21:26 $)
035: */
036: public class ConsoleLogFactory extends LogFactory {
037:
038: /**
039: * The configuration attributes for this {@link LogFactory}.
040: */
041: private Hashtable attributes = new Hashtable();
042:
043: /**
044: * Instance of ConsoleLogger
045: */
046: private Hashtable instances = new Hashtable();
047:
048: /**
049: * Constructor for ConsoleLogFactory.
050: */
051: public ConsoleLogFactory() {
052: super ();
053: }
054:
055: /**
056: * @see org.apache.commons.logging.LogFactory#getAttribute(String)
057: */
058: public Object getAttribute(String name) {
059: return (attributes.get(name));
060: }
061:
062: /**
063: * @see org.apache.commons.logging.LogFactory#getAttributeNames()
064: */
065: public String[] getAttributeNames() {
066: Vector names = new Vector();
067: Enumeration keys = attributes.keys();
068: while (keys.hasMoreElements()) {
069: names.addElement((String) keys.nextElement());
070: }
071: String results[] = new String[names.size()];
072: for (int i = 0; i < results.length; i++) {
073: results[i] = (String) names.elementAt(i);
074: }
075: return (results);
076: }
077:
078: /**
079: * @see org.apache.commons.logging.LogFactory#getInstance(Class)
080: */
081: public Log getInstance(Class className)
082: throws LogConfigurationException {
083: return getInstance(className.getName());
084: }
085:
086: /**
087: * @see org.apache.commons.logging.LogFactory#getInstance(String)
088: */
089: public Log getInstance(String className)
090: throws LogConfigurationException {
091: Log consoleLogger = null;
092:
093: consoleLogger = (ConsoleLogger) instances.get(className);
094:
095: if (consoleLogger == null) {
096: consoleLogger = new ConsoleLogger(className);
097: }
098:
099: return consoleLogger;
100: }
101:
102: /**
103: * @see org.apache.commons.logging.LogFactory#release()
104: */
105: public void release() {
106: //forget all the created instances
107: instances.clear();
108: }
109:
110: /**
111: * @see org.apache.commons.logging.LogFactory#removeAttribute(String)
112: */
113: public void removeAttribute(String name) {
114: attributes.remove(name);
115: }
116:
117: /**
118: * @see org.apache.commons.logging.LogFactory#setAttribute(String, Object)
119: */
120: public void setAttribute(String name, Object value) {
121: attributes.put(name, value);
122: }
123:
124: }
|