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(
41 "BeanLocator is null for servlet context " +
42 servletContextName);
43
44 throw new BeanLocatorException(
45 "BeanLocator has not been set for servlet context " +
46 servletContextName);
47 }
48 else {
49 return beanLocator.locate(name);
50 }
51 }
52
53 public static void setBeanLocator(
54 String servletContextName, BeanLocator beanLocator) {
55
56 if (_log.isDebugEnabled()) {
57 if (beanLocator != null) {
58 _log.debug(
59 "Setting BeanLocator " + beanLocator.hashCode() +
60 " for servlet context " + servletContextName);
61 }
62 else {
63 _log.debug(
64 "Removing BeanLocator for servlet context " +
65 servletContextName);
66 }
67 }
68
69 _beanLocators.put(servletContextName, beanLocator);
70 }
71
72 private static Log _log = LogFactoryUtil.getLog(
73 PortletBeanLocatorUtil.class);
74
75 private static Map<String, BeanLocator> _beanLocators =
76 new HashMap<String, BeanLocator>();
77
78 }