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("BeanLocator is null");
039
040 throw new BeanLocatorException("BeanLocator has not been set");
041 }
042 else {
043 return beanLocator.locate(name);
044 }
045 }
046
047 public static void setBeanLocator(
048 String servletContextName, BeanLocator beanLocator) {
049
050 if (_log.isDebugEnabled()) {
051 if (beanLocator != null) {
052 _log.debug("Setting BeanLocator " + beanLocator.hashCode());
053 }
054 else {
055 _log.debug("Setting BeanLocator null");
056 }
057 }
058
059 _beanLocators.put(servletContextName, beanLocator);
060 }
061
062 private static Log _log = LogFactoryUtil.getLog(
063 PortletBeanLocatorUtil.class);
064
065 private static Map<String, BeanLocator> _beanLocators =
066 new HashMap<String, BeanLocator>();
067
068 }