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.util;
16  
17  import java.util.Map;
18  import java.util.concurrent.ConcurrentHashMap;
19  
20  /**
21   * <a href="WebAppPool.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class WebAppPool {
26  
27      public static Object get(String webAppId, String key) {
28          return _instance._get(webAppId, key);
29      }
30  
31      public static void put(String webAppId, String key, Object obj) {
32          _instance._put(webAppId, key, obj);
33      }
34  
35      public static Object remove(String webAppId, String key) {
36          return _instance._remove(webAppId, key);
37      }
38  
39      private WebAppPool() {
40          _webAppPool = new ConcurrentHashMap<String, Map<String, Object>>();
41      }
42  
43      private Object _get(String webAppId, String key) {
44          Map<String, Object> map = _webAppPool.get(webAppId);
45  
46          if (map == null) {
47              return null;
48          }
49          else {
50              return map.get(key);
51          }
52      }
53  
54      private void _put(String webAppId, String key, Object obj) {
55          Map<String, Object> map = _webAppPool.get(webAppId);
56  
57          if (map == null) {
58              map = new ConcurrentHashMap<String, Object>();
59  
60              _webAppPool.put(webAppId, map);
61          }
62  
63          map.put(key, obj);
64      }
65  
66      private Object _remove(String webAppId, String key) {
67          Map<String, Object> map = _webAppPool.get(webAppId);
68  
69          if (map == null) {
70              return null;
71          }
72          else {
73              return map.remove(key);
74          }
75      }
76  
77      private static WebAppPool _instance = new WebAppPool();
78  
79      private Map<String, Map<String, Object>> _webAppPool;
80  
81  }