1
22
23 package com.liferay.portal.velocity;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
31 import javax.servlet.ServletContext;
32
33
38 public class VelocityContextPool {
39
40 public static boolean containsKey(String name) {
41 return _instance._containsKey(name);
42 }
43
44 public static ServletContext get(String name) {
45 return _instance._get(name);
46 }
47
48 public static void put(String name, ServletContext servletContext) {
49 _instance._put(name, servletContext);
50 }
51
52 public static ServletContext remove(String name) {
53 return _instance._remove(name);
54 }
55
56 private VelocityContextPool() {
57 _pool = new ConcurrentHashMap<String, ServletContext>();
58 }
59
60 private boolean _containsKey(String name) {
61 boolean value = _pool.containsKey(name);
62
63 if (_log.isDebugEnabled()) {
64 _log.debug("Contains key " + name + " " + value);
65 }
66
67 return value;
68 }
69
70 private ServletContext _get(String name) {
71 ServletContext servletContext = _pool.get(name);
72
73 if (_log.isDebugEnabled()) {
74 _log.debug("Get " + name + " " + servletContext);
75 }
76
77 return servletContext;
78 }
79
80 private void _put(String name, ServletContext servletContext) {
81 if (_log.isDebugEnabled()) {
82 _log.debug("Put " + name + " " + servletContext);
83 }
84
85 _pool.put(name, servletContext);
86 }
87
88 private ServletContext _remove(String name) {
89 ServletContext servletContext = _pool.remove(name);
90
91 if (_log.isDebugEnabled()) {
92 _log.debug("Remove " + name + " " + servletContext);
93 }
94
95 return servletContext;
96 }
97
98 private static Log _log = LogFactoryUtil.getLog(VelocityContextPool.class);
99
100 private static VelocityContextPool _instance = new VelocityContextPool();
101
102 private Map<String, ServletContext> _pool;
103
104 }