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.velocity;
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="VelocityContextPool.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class VelocityContextPool {
31  
32      public static boolean containsKey(String name) {
33          return _instance._containsKey(name);
34      }
35  
36      public static ServletContext get(String name) {
37          return _instance._get(name);
38      }
39  
40      public static void put(String name, ServletContext servletContext) {
41          _instance._put(name, servletContext);
42      }
43  
44      public static ServletContext remove(String name) {
45          return _instance._remove(name);
46      }
47  
48      private Map<String, ServletContext> _pool;
49  
50      private VelocityContextPool() {
51          _pool = new ConcurrentHashMap<String, ServletContext>();
52      }
53  
54      private boolean _containsKey(String name) {
55          boolean value = _pool.containsKey(name);
56  
57          if (_log.isDebugEnabled()) {
58              _log.debug("Contains key " + name + " " + value);
59          }
60  
61          return value;
62      }
63  
64      private ServletContext _get(String name) {
65          ServletContext servletContext = _pool.get(name);
66  
67          if (_log.isDebugEnabled()) {
68              _log.debug("Get " + name + " " + servletContext);
69          }
70  
71          return servletContext;
72      }
73  
74      private void _put(String name, ServletContext servletContext) {
75          if (_log.isDebugEnabled()) {
76              _log.debug("Put " + name + " " + servletContext);
77          }
78  
79          _pool.put(name, servletContext);
80      }
81  
82      private ServletContext _remove(String name) {
83          ServletContext servletContext = _pool.remove(name);
84  
85          if (_log.isDebugEnabled()) {
86              _log.debug("Remove " + name + " " + servletContext);
87          }
88  
89          return servletContext;
90      }
91  
92      private static Log _log = LogFactoryUtil.getLog(VelocityContextPool.class);
93  
94      private static VelocityContextPool _instance = new VelocityContextPool();
95  
96  }