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