1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }