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.servlet;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  
20  import java.util.Map;
21  import java.util.concurrent.ConcurrentHashMap;
22  
23  import javax.servlet.ServletContext;
24  
25  /**
26   * <a href="ServletContextPool.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class ServletContextPool {
31  
32      public static boolean containsKey(String servletContextName) {
33          return _instance._containsKey(servletContextName);
34      }
35  
36      public static ServletContext get(String servletContextName) {
37          return _instance._get(servletContextName);
38      }
39  
40      public static void put(
41          String servletContextName, ServletContext servletContext) {
42  
43          _instance._put(servletContextName, servletContext);
44      }
45  
46      public static ServletContext remove(String servletContextName) {
47          return _instance._remove(servletContextName);
48      }
49  
50      private ServletContextPool() {
51          _servletContextPool = new ConcurrentHashMap<String, ServletContext>();
52      }
53  
54      private boolean _containsKey(String servletContextName) {
55          boolean value = _servletContextPool.containsKey(servletContextName);
56  
57          if (_log.isDebugEnabled()) {
58              _log.debug("Contains key " + servletContextName + " " + value);
59          }
60  
61          return value;
62      }
63  
64      private ServletContext _get(String servletContextName) {
65          ServletContext servletContext = _servletContextPool.get(
66              servletContextName);
67  
68          if (_log.isDebugEnabled()) {
69              _log.debug("Get " + servletContextName + " " + servletContext);
70          }
71  
72          return servletContext;
73      }
74  
75      private void _put(
76          String servletContextName, ServletContext servletContext) {
77  
78          if (_log.isDebugEnabled()) {
79              _log.debug("Put " + servletContextName + " " + servletContext);
80          }
81  
82          _servletContextPool.put(servletContextName, servletContext);
83      }
84  
85      private ServletContext _remove(String servletContextName) {
86          ServletContext servletContext = _servletContextPool.remove(
87              servletContextName);
88  
89          if (_log.isDebugEnabled()) {
90              _log.debug("Remove " + servletContextName + " " + servletContext);
91          }
92  
93          return servletContext;
94      }
95  
96      private static Log _log = LogFactoryUtil.getLog(ServletContextPool.class);
97  
98      private static ServletContextPool _instance = new ServletContextPool();
99  
100     private Map<String, ServletContext> _servletContextPool;
101 
102 }