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.kernel.search;
016    
017    import java.util.List;
018    
019    /**
020     * @author Raymond Augé
021     */
022    public class IndexerRegistryUtil {
023    
024            public static Indexer getIndexer(Class<?> clazz) {
025                    return getIndexerRegistry().getIndexer(clazz.getName());
026            }
027    
028            public static Indexer getIndexer(String className) {
029                    return getIndexerRegistry().getIndexer(className);
030            }
031    
032            public static IndexerRegistry getIndexerRegistry() {
033                    return _indexerRegistry;
034            }
035    
036            public static List<Indexer> getIndexers() {
037                    return getIndexerRegistry().getIndexers();
038            }
039    
040            public static void register(Indexer indexer) {
041                    for (String className : indexer.getClassNames()) {
042                            register(className, indexer);
043                    }
044    
045                    register(indexer.getClass().getName(), indexer);
046            }
047    
048            public static void register(String className, Indexer indexer) {
049                    getIndexerRegistry().register(className, indexer);
050            }
051    
052            public static void unregister(Indexer indexer) {
053                    for (String className : indexer.getClassNames()) {
054                            unregister(className);
055                    }
056    
057                    unregister(indexer.getClass().getName());
058            }
059    
060            public static void unregister(String className) {
061                    getIndexerRegistry().unregister(className);
062            }
063    
064            public void setIndexerRegistry(IndexerRegistry indexerRegistry) {
065                    _indexerRegistry = indexerRegistry;
066            }
067    
068            private static IndexerRegistry _indexerRegistry;
069    
070    }