1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.log;
21  
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Vector;
27  
28  /**
29   * <a href="LogFactoryWrapper.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   *
33   */
34  public class LogFactoryWrapper implements LogFactory {
35  
36      public LogFactoryWrapper(LogFactory logFactory) {
37          _logFactory = logFactory;
38      }
39  
40      public void setLogFactory(LogFactory logFactory) {
41          _logFactory = logFactory;
42  
43          Iterator<Map.Entry<String, List<Log>>> itr1 =
44              _logs.entrySet().iterator();
45  
46          while (itr1.hasNext()) {
47              Map.Entry<String, List<Log>> entry = itr1.next();
48  
49              String name = entry.getKey();
50              List<Log> list = entry.getValue();
51  
52              Iterator<Log> itr2 = list.iterator();
53  
54              while (itr2.hasNext()) {
55                  LogWrapper logWrapper = (LogWrapper)itr2.next();
56  
57                  logWrapper.setLog(_logFactory.getLog(name));
58              }
59          }
60      }
61  
62      public Log getLog(Class<?> c) {
63          return getLog(c.getName());
64      }
65  
66      public Log getLog(String name) {
67          List<Log> list = _logs.get(name);
68  
69          if (list == null) {
70              list = new Vector<Log>();
71  
72              _logs.put(name, list);
73          }
74  
75          Log log = new LogWrapper(_logFactory.getLog(name));
76  
77          list.add(log);
78  
79          return log;
80      }
81  
82      private LogFactory _logFactory;
83      private Map<String, List<Log>> _logs = new Hashtable<String, List<Log>>();
84  
85  }