1
22
23 package com.liferay.portal.velocity;
24
25 import com.liferay.util.CollectionFactory;
26
27 import java.util.Map;
28
29 import javax.servlet.ServletContext;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34
40 public class VelocityContextPool {
41
42 public static boolean containsKey(String name) {
43 return _instance._containsKey(name);
44 }
45
46 public static ServletContext get(String name) {
47 return _instance._get(name);
48 }
49
50 public static void put(String name, ServletContext ctx) {
51 _instance._put(name, ctx);
52 }
53
54 public static ServletContext remove(String name) {
55 return _instance._remove(name);
56 }
57
58 private VelocityContextPool() {
59 _pool = CollectionFactory.getSyncHashMap();
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 ctx = (ServletContext)_pool.get(name);
74
75 if (_log.isDebugEnabled()) {
76 _log.debug("Get " + name + " " + ctx);
77 }
78
79 return ctx;
80 }
81
82 private void _put(String name, ServletContext ctx) {
83 if (_log.isDebugEnabled()) {
84 _log.debug("Put " + name + " " + ctx);
85 }
86
87 _pool.put(name, ctx);
88 }
89
90 private ServletContext _remove(String name) {
91 ServletContext ctx = (ServletContext)_pool.remove(name);
92
93 if (_log.isDebugEnabled()) {
94 _log.debug("Remove " + name + " " + ctx);
95 }
96
97 return ctx;
98 }
99
100 private static Log _log = LogFactory.getLog(VelocityContextPool.class);
101
102 private static VelocityContextPool _instance = new VelocityContextPool();
103
104 private Map _pool;
105
106 }