001
014
015 package com.liferay.portal.kernel.spring.context;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.servlet.PortalClassLoaderServletContextListener;
020 import com.liferay.portal.kernel.util.ContextPathUtil;
021 import com.liferay.portal.kernel.util.PortalClassInvoker;
022 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
023
024 import javax.servlet.ServletContext;
025 import javax.servlet.ServletContextListener;
026
027
030 public class PortletContextLoaderListener
031 extends PortalClassLoaderServletContextListener {
032
033 public static String getLockKey(ServletContext servletContext) {
034 String contextPath = ContextPathUtil.getContextPath(servletContext);
035
036 return getLockKey(contextPath);
037 }
038
039 public static String getLockKey(String contextPath) {
040 try {
041 Object returnValue = PortalClassInvoker.invoke(
042 false, _CLASS_NAME, "getLockKey",
043 new String[] {String.class.getName()}, contextPath);
044
045 return String.valueOf(returnValue);
046 }
047 catch (Exception e) {
048 _log.error(e, e);
049
050 throw new IllegalStateException("Unable to get lock key", e);
051 }
052 }
053
054 @Override
055 protected ServletContextListener getInstance() throws Exception {
056 Class<?> clazz = Class.forName(
057 _CLASS_NAME, true, PortalClassLoaderUtil.getClassLoader());
058
059 return (ServletContextListener)clazz.newInstance();
060 }
061
062 private static final String _CLASS_NAME =
063 "com.liferay.portal.spring.context.PortletContextLoaderListener";
064
065 private static Log _log = LogFactoryUtil.getLog(
066 PortletContextLoaderListener.class.getName());
067
068 }