001/*
002 *  Copyright 2016 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.indexing.solr;
017
018import java.util.Collection;
019import java.util.Collections;
020
021import org.ametys.runtime.plugin.ExtensionPoint;
022import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
023
024import com.google.common.collect.HashMultimap;
025import com.google.common.collect.Multimap;
026
027/**
028 * {@link ExtensionPoint} for registering {@link AdditionalPropertyIndexer}s.
029 */
030public class AdditionalPropertyIndexerExtensionPoint extends AbstractThreadSafeComponentExtensionPoint<AdditionalPropertyIndexer>
031{
032    
033    /** The extension point role. */
034    public static final String ROLE = AdditionalPropertyIndexerExtensionPoint.class.getName();
035    
036    private Multimap<String, AdditionalPropertyIndexer> _extensionsByType;
037    
038    @Override
039    public void initializeExtensions() throws Exception
040    {
041        super.initializeExtensions();
042        
043        _extensionsByType = HashMultimap.create();
044        for (String id : getExtensionsIds())
045        {
046            AdditionalPropertyIndexer indexer = getExtension(id);
047            
048            for (String type : indexer.getSupportedTypes())
049            {
050                _extensionsByType.put(type, indexer);
051            }
052        }
053    }
054    
055    /**
056     * Get the additional property indexers for the given type.
057     * @param type The type.
058     * @return The additional property indexers for the given type.
059     */
060    public Collection<AdditionalPropertyIndexer> getIndexers(String type)
061    {
062        return Collections.unmodifiableCollection(_extensionsByType.get(type));
063    }
064    
065}