1
14
15 package com.liferay.portal.kernel.bean;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23
28 public class PortletBeanLocatorUtil {
29
30 public static BeanLocator getBeanLocator(String servletContextName) {
31 return _beanLocators.get(servletContextName);
32 }
33
34 public static Object locate(String servletContextName, String name)
35 throws BeanLocatorException {
36
37 BeanLocator beanLocator = getBeanLocator(servletContextName);
38
39 if (beanLocator == null) {
40 _log.error("BeanLocator is null");
41
42 throw new BeanLocatorException("BeanLocator has not been set");
43 }
44 else {
45 return beanLocator.locate(name);
46 }
47 }
48
49 public static void setBeanLocator(
50 String servletContextName, BeanLocator beanLocator) {
51
52 if (_log.isDebugEnabled()) {
53 if (beanLocator != null) {
54 _log.debug("Setting BeanLocator " + beanLocator.hashCode());
55 }
56 else {
57 _log.debug("Setting BeanLocator null");
58 }
59 }
60
61 _beanLocators.put(servletContextName, beanLocator);
62 }
63
64 private static Log _log = LogFactoryUtil.getLog(
65 PortletBeanLocatorUtil.class);
66
67 private static Map<String, BeanLocator> _beanLocators =
68 new HashMap<String, BeanLocator>();
69
70 }