com.liferay.portal.kernel.servlet.ServletContextPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-service Show documentation
Show all versions of portal-service Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.servlet;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.util.PortalUtil;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletContext;
/**
* @author Brian Wing Shun Chan
*/
public class ServletContextPool {
public static void clear() {
_instance._servletContexts.clear();
}
public static boolean containsKey(String servletContextName) {
return _instance._containsKey(servletContextName);
}
public static ServletContext get(String servletContextName) {
return _instance._get(servletContextName);
}
public static Set keySet() {
return _instance._keySet();
}
public static void put(
String servletContextName, ServletContext servletContext) {
_instance._put(servletContextName, servletContext);
}
public static ServletContext remove(String servletContextName) {
return _instance._remove(servletContextName);
}
private ServletContextPool() {
_servletContexts = new ConcurrentHashMap();
}
private boolean _containsKey(String servletContextName) {
if (servletContextName == null) {
return false;
}
boolean value = _servletContexts.containsKey(servletContextName);
if (_log.isDebugEnabled()) {
_log.debug("Contains key " + servletContextName + " " + value);
}
return value;
}
private ServletContext _get(String servletContextName) {
ServletContext servletContext = _servletContexts.get(
servletContextName);
if (_log.isDebugEnabled()) {
_log.debug("Get " + servletContextName + " " + servletContext);
}
return servletContext;
}
private Set _keySet() {
return _servletContexts.keySet();
}
private void _put(
String servletContextName, ServletContext servletContext) {
if (_log.isDebugEnabled()) {
_log.debug("Put " + servletContextName + " " + servletContext);
}
_servletContexts.put(servletContextName, servletContext);
}
private ServletContext _remove(String servletContextName) {
// We should never remove the portal context. See LPS-12683.
String contextPath = PortalUtil.getPathContext();
if (contextPath.equals(servletContextName)) {
return null;
}
ServletContext servletContext = _servletContexts.remove(
servletContextName);
if (_log.isDebugEnabled()) {
_log.debug("Remove " + servletContextName + " " + servletContext);
}
return servletContext;
}
private static Log _log = LogFactoryUtil.getLog(ServletContextPool.class);
private static ServletContextPool _instance = new ServletContextPool();
private Map _servletContexts;
}