001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }