001
014
015 package com.liferay.portal.kernel.bean;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020
021 import java.util.HashMap;
022 import java.util.Map;
023
024
027 public class PortletBeanLocatorUtil {
028
029 public static BeanLocator getBeanLocator(String servletContextName) {
030 PortalRuntimePermission.checkGetBeanProperty(
031 servletContextName, PortletBeanLocatorUtil.class);
032
033 return _beanLocators.get(servletContextName);
034 }
035
036 public static Object locate(String servletContextName, String name)
037 throws BeanLocatorException {
038
039 BeanLocator beanLocator = getBeanLocator(servletContextName);
040
041 if (beanLocator == null) {
042 _log.error(
043 "BeanLocator is null for servlet context " +
044 servletContextName);
045
046 throw new BeanLocatorException(
047 "BeanLocator has not been set for servlet context " +
048 servletContextName);
049 }
050 else {
051 return beanLocator.locate(name);
052 }
053 }
054
055 public static void setBeanLocator(
056 String servletContextName, BeanLocator beanLocator) {
057
058 PortalRuntimePermission.checkSetBeanProperty(
059 servletContextName, PortletBeanLocatorUtil.class);
060
061 if (_log.isDebugEnabled()) {
062 if (beanLocator != null) {
063 _log.debug(
064 "Setting BeanLocator " + beanLocator.hashCode() +
065 " for servlet context " + servletContextName);
066 }
067 else {
068 _log.debug(
069 "Removing BeanLocator for servlet context " +
070 servletContextName);
071 }
072 }
073
074 _beanLocators.put(servletContextName, beanLocator);
075 }
076
077 private static Log _log = LogFactoryUtil.getLog(
078 PortletBeanLocatorUtil.class);
079
080 private static Map<String, BeanLocator> _beanLocators =
081 new HashMap<String, BeanLocator>();
082
083 }