1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }