1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
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  /**
24   * <a href="PortletBeanLocatorUtil.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
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  }