001
014
015 package com.liferay.portal.kernel.portlet;
016
017 import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018 import com.liferay.portal.kernel.servlet.PluginContextListener;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 import javax.servlet.ServletContext;
024
025
028 public class PortletClassLoaderUtil {
029
030 public static ClassLoader getClassLoader() {
031 Thread currentThread = Thread.currentThread();
032
033 return _classLoaders.get(currentThread.getId());
034 }
035
036 public static ClassLoader getClassLoader(String portletId) {
037 PortalRuntimePermission.checkGetClassLoader(portletId);
038
039 PortletBag portletBag = PortletBagPool.get(portletId);
040
041 if (portletBag == null) {
042 return null;
043 }
044
045 ServletContext servletContext = portletBag.getServletContext();
046
047 return (ClassLoader)servletContext.getAttribute(
048 PluginContextListener.PLUGIN_CLASS_LOADER);
049 }
050
051 public static String getServletContextName() {
052 return _servletContextName;
053 }
054
055 public static void setClassLoader(ClassLoader classLoader) {
056 PortalRuntimePermission.checkSetBeanProperty(
057 PortletClassLoaderUtil.class);
058
059 Thread currentThread = Thread.currentThread();
060
061 _classLoaders.put(currentThread.getId(), classLoader);
062 }
063
064 public static void setServletContextName(String servletContextName) {
065 PortalRuntimePermission.checkSetBeanProperty(
066 PortletClassLoaderUtil.class);
067
068 _servletContextName = servletContextName;
069 }
070
071 private static Map<Long, ClassLoader> _classLoaders =
072 new HashMap<Long, ClassLoader>();
073 private static String _servletContextName;
074
075 }