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 Map<String, ServletContext> _pool;
57
58 private VelocityContextPool() {
59 _pool = new ConcurrentHashMap<String, ServletContext>();
60 }
61
62 private boolean _containsKey(String name) {
63 boolean value = _pool.containsKey(name);
64
65 if (_log.isDebugEnabled()) {
66 _log.debug("Contains key " + name + " " + value);
67 }
68
69 return value;
70 }
71
72 private ServletContext _get(String name) {
73 ServletContext servletContext = _pool.get(name);
74
75 if (_log.isDebugEnabled()) {
76 _log.debug("Get " + name + " " + servletContext);
77 }
78
79 return servletContext;
80 }
81
82 private void _put(String name, ServletContext servletContext) {
83 if (_log.isDebugEnabled()) {
84 _log.debug("Put " + name + " " + servletContext);
85 }
86
87 _pool.put(name, servletContext);
88 }
89
90 private ServletContext _remove(String name) {
91 ServletContext servletContext = _pool.remove(name);
92
93 if (_log.isDebugEnabled()) {
94 _log.debug("Remove " + name + " " + servletContext);
95 }
96
97 return servletContext;
98 }
99
100 private static Log _log = LogFactoryUtil.getLog(VelocityContextPool.class);
101
102 private static VelocityContextPool _instance = new VelocityContextPool();
103
104 }