001/*
002 *  Copyright 2020 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.core.resources;
017
018import org.apache.excalibur.source.Source;
019
020/**
021 * Provides a {@link ResourceHandler} able to process a {@link Source}.
022 */
023public interface ResourceHandlerProvider
024{
025    /** Minimum priority. */
026    public static final int MIN_PRIORITY = 0;
027    /** Maximum priority. */
028    public static final int MAX_PRIORITY = Integer.MAX_VALUE;
029
030    /**
031     * Get the priority of this provider.
032     * @return the priority. The bigger the highest priority
033     */
034    default int getPriority()
035    {
036        return MIN_PRIORITY;
037    }
038    
039    /**
040     * Returns the corresponding {@link ResourceHandler} or null if none.<br>
041     * Returned {@link ResourceHandler} should be thread safe.
042     * @param source the requested resource.
043     * @return a ResourceHandler able to process the resource.
044     * @throws Exception if an error occurs during ResourceHandler creation.
045     */
046    public ResourceHandler getResourceHandler(String source) throws Exception;
047}