001/*
002 *  Copyright 2014 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.plugins.contentio.in;
017
018import java.util.Collections;
019import java.util.List;
020import java.util.stream.Collectors;
021
022import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentPrioritizableExtensionPoint;
023
024/**
025 * Extension point for {@link ContentImporter}s.
026 */
027public class ContentImporterExtensionPoint extends AbstractThreadSafeComponentPrioritizableExtensionPoint<ContentImporter>
028{
029    /** Avalon Role */
030    public static final String ROLE = ContentImporterExtensionPoint.class.getName();
031    
032    /** The importers, sorted by priority. */
033    protected List<ContentImporter> _importersByPriority;
034    
035    /**
036     * Get the importer IDs, sorted by ascending priority.
037     * @return the importer IDs, sorted by ascending priority.
038     */
039    public List<ContentImporter> getImportersByPriority()
040    {
041        // On the first call, resolve the extensions in a list, they are already sorted.
042        if (_importersByPriority == null)
043        {
044            _importersByPriority = getExtensionsIds()
045                    .stream()
046                    .map(this::getExtension)
047                    .collect(Collectors.toList());
048        }
049        
050        // Return the 
051        return Collections.unmodifiableList(_importersByPriority);
052    }
053}