001    /**
002     * Copyright (c) 2000-2012 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.ServiceBeanAopCacheManagerUtil;
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            public Indexer getIndexer(String className) {
035                    return _indexers.get(className);
036            }
037    
038            public List<Indexer> getIndexers() {
039                    return ListUtil.fromMapValues(_indexers);
040            }
041    
042            public Indexer nullSafeGetIndexer(String className) {
043                    Indexer indexer = _indexers.get(className);
044    
045                    if (indexer != null) {
046                            return indexer;
047                    }
048    
049                    if (_log.isWarnEnabled()) {
050                            _log.warn("No indexer found for " + className);
051                    }
052    
053                    return _dummyIndexer;
054            }
055    
056            public void register(String className, Indexer indexerInstance) {
057                    _indexers.put(className, indexerInstance);
058    
059                    ServiceBeanAopCacheManagerUtil.reset();
060            }
061    
062            public void unregister(String className) {
063                    _indexers.remove(className);
064            }
065    
066            private static Log _log = LogFactoryUtil.getLog(IndexerRegistryImpl.class);
067    
068            private Indexer _dummyIndexer = new DummyIndexer();
069            private Map<String, Indexer> _indexers =
070                    new ConcurrentHashMap<String, Indexer>();
071    
072    }