1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.kernel.log;
16  
17  import java.util.Hashtable;
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Vector;
22  
23  /**
24   * <a href="LogFactoryWrapper.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class LogFactoryWrapper implements LogFactory {
29  
30      public LogFactoryWrapper(LogFactory logFactory) {
31          _logFactory = logFactory;
32      }
33  
34      public void setLogFactory(LogFactory logFactory) {
35          _logFactory = logFactory;
36  
37          Iterator<Map.Entry<String, List<Log>>> itr1 =
38              _logs.entrySet().iterator();
39  
40          while (itr1.hasNext()) {
41              Map.Entry<String, List<Log>> entry = itr1.next();
42  
43              String name = entry.getKey();
44              List<Log> list = entry.getValue();
45  
46              Iterator<Log> itr2 = list.iterator();
47  
48              while (itr2.hasNext()) {
49                  LogWrapper logWrapper = (LogWrapper)itr2.next();
50  
51                  logWrapper.setLog(_logFactory.getLog(name));
52              }
53          }
54      }
55  
56      public Log getLog(Class<?> c) {
57          return getLog(c.getName());
58      }
59  
60      public Log getLog(String name) {
61          List<Log> list = _logs.get(name);
62  
63          if (list == null) {
64              list = new Vector<Log>();
65  
66              _logs.put(name, list);
67          }
68  
69          Log log = new LogWrapper(_logFactory.getLog(name));
70  
71          list.add(log);
72  
73          return log;
74      }
75  
76      private LogFactory _logFactory;
77      private Map<String, List<Log>> _logs = new Hashtable<String, List<Log>>();
78  
79  }