2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.kernel.bean;
\r
17 import com.liferay.portal.kernel.log.Log;
\r
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
20 import java.util.HashMap;
\r
21 import java.util.Map;
\r
24 * @author Brian Wing Shun Chan
\r
26 public class PortletBeanLocatorUtil {
\r
28 public static BeanLocator getBeanLocator(String servletContextName) {
\r
29 return _beanLocators.get(servletContextName);
\r
32 public static Object locate(String servletContextName, String name)
\r
33 throws BeanLocatorException {
\r
35 BeanLocator beanLocator = getBeanLocator(servletContextName);
\r
37 if (beanLocator == null) {
\r
39 "BeanLocator is null for servlet context " +
\r
40 servletContextName);
\r
42 System.out.println();
\r
43 System.out.println("*******************************************************");
\r
44 System.out.println("PORTLET " + servletContextName + " NEED TO BE DEPLOYED");
\r
45 System.out.println("*******************************************************");
\r
46 System.out.println();
\r
48 throw new BeanLocatorException(
\r
49 "BeanLocator has not been set for servlet context " +
\r
50 servletContextName);
\r
53 return beanLocator.locate(name);
\r
57 public static void setBeanLocator(
\r
58 String servletContextName, BeanLocator beanLocator) {
\r
60 if (_log.isDebugEnabled()) {
\r
61 if (beanLocator != null) {
\r
63 "Setting BeanLocator " + beanLocator.hashCode() +
\r
64 " for servlet context " + servletContextName);
\r
68 "Removing BeanLocator for servlet context " +
\r
69 servletContextName);
\r
73 _beanLocators.put(servletContextName, beanLocator);
\r
76 private static Log _log = LogFactoryUtil.getLog(
\r
77 PortletBeanLocatorUtil.class);
\r
79 private static Map<String, BeanLocator> _beanLocators =
\r
80 new HashMap<String, BeanLocator>();
\r