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.search;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.search.DummyIndexer;
020    import com.liferay.portal.kernel.search.Indexer;
021    import com.liferay.portal.kernel.search.IndexerRegistry;
022    import com.liferay.portal.kernel.util.ListUtil;
023    import com.liferay.portal.spring.aop.ServiceBeanAopProxy;
024    
025    import java.util.List;
026    import java.util.Map;
027    import java.util.concurrent.ConcurrentHashMap;
028    
029    /**
030     * @author Raymond Aug??
031     */
032    public class IndexerRegistryImpl implements IndexerRegistry {
033    
034            @Override
035            public Indexer getIndexer(String className) {
036                    return _indexers.get(className);
037            }
038    
039            @Override
040            public List<Indexer> getIndexers() {
041                    return ListUtil.fromMapValues(_indexers);
042            }
043    
044            @Override
045            public Indexer nullSafeGetIndexer(String className) {
046                    Indexer indexer = _indexers.get(className);
047    
048                    if (indexer != null) {
049                            return indexer;
050                    }
051    
052                    if (_log.isWarnEnabled()) {
053                            _log.warn("No indexer found for " + className);
054                    }
055    
056                    return _dummyIndexer;
057            }
058    
059            @Override
060            public void register(String className, Indexer indexerInstance) {
061                    _indexers.put(className, indexerInstance);
062    
063                    ServiceBeanAopProxy.clearMethodInterceptorCache();
064            }
065    
066            @Override
067            public void unregister(String className) {
068                    _indexers.remove(className);
069            }
070    
071            private static Log _log = LogFactoryUtil.getLog(IndexerRegistryImpl.class);
072    
073            private Indexer _dummyIndexer = new DummyIndexer();
074            private Map<String, Indexer> _indexers =
075                    new ConcurrentHashMap<String, Indexer>();
076    
077    }