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