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.portal.kernel.search;
016    
017    import com.liferay.portal.kernel.bean.BeanLocator;
018    import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
019    import com.liferay.portal.kernel.messaging.MessageBus;
020    import com.liferay.portal.kernel.messaging.MessageBusUtil;
021    import com.liferay.portal.kernel.portlet.PortletClassLoaderUtil;
022    
023    /**
024     * @author Michael C. Han
025     */
026    public class PluginSearchEngineConfigurator
027            extends AbstractSearchEngineConfigurator {
028    
029            public void setDefaultSearchEngineId(String defaultSearchEngineId) {
030                    _defaultSearchEngineId = defaultSearchEngineId;
031            }
032    
033            @Override
034            protected String getDefaultSearchEngineId() {
035                    return _defaultSearchEngineId;
036            }
037    
038            @Override
039            protected IndexSearcher getIndexSearcher() {
040                    BeanLocator beanLocator = PortalBeanLocatorUtil.getBeanLocator();
041    
042                    return (IndexSearcher)beanLocator.locate(
043                            IndexSearcherProxyBean.class.getName());
044            }
045    
046            @Override
047            protected IndexWriter getIndexWriter() {
048                    BeanLocator beanLocator = PortalBeanLocatorUtil.getBeanLocator();
049    
050                    return (IndexWriter)beanLocator.locate(
051                            IndexWriterProxyBean.class.getName());
052            }
053    
054            @Override
055            protected MessageBus getMessageBus() {
056                    return MessageBusUtil.getMessageBus();
057            }
058    
059            @Override
060            protected ClassLoader getOperatingClassloader() {
061                    ClassLoader classLoader = PortletClassLoaderUtil.getClassLoader();
062    
063                    if (classLoader == null) {
064                            Thread currentThread = Thread.currentThread();
065    
066                            classLoader = currentThread.getContextClassLoader();
067                    }
068    
069                    return classLoader;
070            }
071    
072            private String _defaultSearchEngineId;
073    
074    }