001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.bean;
016    
017    import com.liferay.portal.kernel.bean.BeanLocator;
018    import com.liferay.portal.kernel.bean.BeanLocatorException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class PortletBeanLocatorUtil {
026    
027            public static BeanLocator getBeanLocator() {
028                    return _beanLocator;
029            }
030    
031            public static Object locate(String name) throws BeanLocatorException {
032                    if (_beanLocator == null) {
033                            _log.error("BeanLocator is null");
034    
035                            throw new BeanLocatorException("BeanLocator has not been set");
036                    }
037                    else {
038                            return _beanLocator.locate(name);
039                    }
040            }
041    
042            public static void setBeanLocator(BeanLocator beanLocator) {
043                    if (_log.isDebugEnabled()) {
044                            if (beanLocator != null) {
045                                    _log.debug("Setting BeanLocator " + beanLocator.hashCode());
046                            }
047                            else {
048                                    _log.debug("Setting BeanLocator null");
049                            }
050                    }
051    
052                    _beanLocator = beanLocator;
053            }
054    
055            private static Log _log = LogFactoryUtil.getLog(
056                    PortletBeanLocatorUtil.class);
057    
058            private static BeanLocator _beanLocator;
059    
060    }