001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.velocity;
022:
023: import com.liferay.util.CollectionFactory;
024:
025: import java.util.Map;
026:
027: import javax.servlet.ServletContext;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031:
032: /**
033: * <a href="VelocityContextPool.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Brian Wing Shun Chan
036: *
037: */
038: public class VelocityContextPool {
039:
040: public static boolean containsKey(String name) {
041: return _instance._containsKey(name);
042: }
043:
044: public static ServletContext get(String name) {
045: return _instance._get(name);
046: }
047:
048: public static void put(String name, ServletContext ctx) {
049: _instance._put(name, ctx);
050: }
051:
052: public static ServletContext remove(String name) {
053: return _instance._remove(name);
054: }
055:
056: private VelocityContextPool() {
057: _pool = CollectionFactory.getSyncHashMap();
058: }
059:
060: private boolean _containsKey(String name) {
061: boolean value = _pool.containsKey(name);
062:
063: if (_log.isDebugEnabled()) {
064: _log.debug("Contains key " + name + " " + value);
065: }
066:
067: return value;
068: }
069:
070: private ServletContext _get(String name) {
071: ServletContext ctx = (ServletContext) _pool.get(name);
072:
073: if (_log.isDebugEnabled()) {
074: _log.debug("Get " + name + " " + ctx);
075: }
076:
077: return ctx;
078: }
079:
080: private void _put(String name, ServletContext ctx) {
081: if (_log.isDebugEnabled()) {
082: _log.debug("Put " + name + " " + ctx);
083: }
084:
085: _pool.put(name, ctx);
086: }
087:
088: private ServletContext _remove(String name) {
089: ServletContext ctx = (ServletContext) _pool.remove(name);
090:
091: if (_log.isDebugEnabled()) {
092: _log.debug("Remove " + name + " " + ctx);
093: }
094:
095: return ctx;
096: }
097:
098: private static Log _log = LogFactory
099: .getLog(VelocityContextPool.class);
100:
101: private static VelocityContextPool _instance = new VelocityContextPool();
102:
103: private Map _pool;
104:
105: }
|