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
020 import java.util.HashMap;
021 import java.util.Map;
022
023
026 public class PortletBeanLocatorUtil {
027
028 public static BeanLocator getBeanLocator(String servletContextName) {
029 return _beanLocators.get(servletContextName);
030 }
031
032 public static Object locate(String servletContextName, String name)
033 throws BeanLocatorException {
034
035 BeanLocator beanLocator = getBeanLocator(servletContextName);
036
037 if (beanLocator == null) {
038 _log.error(
039 "BeanLocator is null for servlet context " +
040 servletContextName);
041
042 throw new BeanLocatorException(
043 "BeanLocator has not been set for servlet context " +
044 servletContextName);
045 }
046 else {
047 return beanLocator.locate(name);
048 }
049 }
050
051 public static void setBeanLocator(
052 String servletContextName, BeanLocator beanLocator) {
053
054 if (_log.isDebugEnabled()) {
055 if (beanLocator != null) {
056 _log.debug(
057 "Setting BeanLocator " + beanLocator.hashCode() +
058 " for servlet context " + servletContextName);
059 }
060 else {
061 _log.debug(
062 "Removing BeanLocator for servlet context " +
063 servletContextName);
064 }
065 }
066
067 _beanLocators.put(servletContextName, beanLocator);
068 }
069
070 private static Log _log = LogFactoryUtil.getLog(
071 PortletBeanLocatorUtil.class);
072
073 private static Map<String, BeanLocator> _beanLocators =
074 new HashMap<String, BeanLocator>();
075
076 }