1 16 package org.mortbay.log; 17 18 import java.util.ArrayList ; 19 import java.util.HashMap ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogConfigurationException; 23 24 25 37 public class Factory extends org.apache.commons.logging.LogFactory 38 { 39 static LogImpl log = new LogImpl(); 40 static HashMap attributes = new HashMap (); 41 static ArrayList prefixes = new ArrayList (); 42 43 46 public Factory() 47 { 48 super(); 49 } 50 51 54 public Object getAttribute(String n) 55 { 56 return attributes.get(n); 57 } 58 59 62 public String [] getAttributeNames() 63 { 64 return (String []) attributes.keySet().toArray(new String [attributes.size()]); 65 } 66 67 70 public Log getInstance(Class c) throws LogConfigurationException 71 { 72 if (c!=null) 73 return getInstance(c.getName()); 74 return getInstance((String )null); 75 } 76 77 80 public Log getInstance(String name) throws LogConfigurationException 81 { 82 String match=""; 83 for (int i=prefixes.size();name!=null && i-->0;) 84 { 85 String prefix=(String )prefixes.get(i); 86 if (name.startsWith(prefix) && prefix.length()>match.length()) 87 match=prefix; 88 } 89 if (match.length()>0) 90 name=match+".*"; 91 92 Object o = attributes.get(name); 94 95 while(o!=null && o instanceof String ) 97 o=attributes.get(o); 98 99 if (o instanceof Log) 101 return (Log)o; 102 return log; 103 } 104 105 108 public void release() 109 { 110 } 111 112 115 public void removeAttribute(String n) 116 { 117 attributes.remove(n); 118 if (n.endsWith(".*")) 119 prefixes.remove(n.substring(0,n.length()-2)); 120 } 121 122 125 public void setAttribute(String n, Object v) 126 { 127 attributes.put(n,v); 128 if (n.endsWith(".*") && v instanceof Log) 129 prefixes.add(n.substring(0,n.length()-2)); 130 } 131 132 } | Popular Tags |