1 16 17 package org.apache.commons.logging.impl; 18 19 20 import java.util.Enumeration ; 21 import java.util.Hashtable ; 22 import java.util.Vector ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogConfigurationException; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.log4j.Logger; 28 29 39 public final class Log4jFactory extends LogFactory { 40 41 public Log4jFactory() { 42 super(); 43 } 44 45 48 private Hashtable attributes = new Hashtable (); 49 50 private Hashtable instances = new Hashtable (); 52 53 55 61 public Object getAttribute(String name) { 62 return (attributes.get(name)); 63 } 64 65 66 71 public String [] getAttributeNames() { 72 Vector names = new Vector (); 73 Enumeration keys = attributes.keys(); 74 while (keys.hasMoreElements()) { 75 names.addElement((String ) keys.nextElement()); 76 } 77 String results[] = new String [names.size()]; 78 for (int i = 0; i < results.length; i++) { 79 results[i] = (String ) names.elementAt(i); 80 } 81 return (results); 82 } 83 84 85 94 public Log getInstance(Class clazz) 95 throws LogConfigurationException 96 { 97 Log instance = (Log) instances.get(clazz); 98 if( instance != null ) 99 return instance; 100 101 instance=new Log4JLogger( Logger.getLogger( clazz )); 102 instances.put( clazz, instance ); 103 return instance; 104 } 105 106 107 public Log getInstance(String name) 108 throws LogConfigurationException 109 { 110 Log instance = (Log) instances.get(name); 111 if( instance != null ) 112 return instance; 113 114 instance=new Log4JLogger( Logger.getLogger( name )); 115 instances.put( name, instance ); 116 return instance; 117 } 118 119 120 127 public void release() { 128 129 instances.clear(); 130 131 } 133 134 135 141 public void removeAttribute(String name) { 142 attributes.remove(name); 143 } 144 145 146 155 public void setAttribute(String name, Object value) { 156 if (value == null) { 157 attributes.remove(name); 158 } else { 159 attributes.put(name, value); 160 } 161 } 162 163 } 164 | Popular Tags |