    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.io;
    018
    019import java.net.URL;
    020
    021/**
    022 * <p>
    023 * An interface allowing applications to customize the process of locating a file.
    024 * </p>
    025 * <p>
    026 * {@link FileHandler} uses {@link FileLocator} objects for referencing files. These objects are not guaranteed to
    027 * identify a file in a unique way. For instance, if only a file name is defined, this could mean a relative file name
    028 * in the current directory, the name of a resource to be loaded from the class path, or something else. Before the file
    029 * described by a {@code FileLocator} can be actually accessed, an unambiguous URL pointing to this file has to be
    030 * obtained. This is the job of a {@code FileLocationStrategy}.
    031 * </p>
    032 * <p>
    033 * This interface defines a method for locating a file provided as a {@code FileLocator} object. If location is
    034 * successful, a URL is returned. A concrete implementation can perform arbitrary actions to search for the file in
    035 * question at various places. There will also be an implementation allowing the combination of multiple
    036 * {@code FileLocationStrategy} implementations; so a file can be searched using multiple strategies until one of them
    037 * is successful.
    038 * </p>
    039 *
    040 * @since 2.0
    041 */
    042public interface FileLocationStrategy {
    043    /**
    044     * Tries to locate the specified file. The method also expects the {@code FileSystem} to be used. Note that the
    045     * {@code FileLocator} object may also contain a {@code FileSystem}, but this is optional. The passed in
    046     * {@code FileSystem} should be used, and callers must not pass a <strong>null</strong> reference for this argument. A concrete
    047     * implementation has to evaluate the properties stored in the {@code FileLocator} object and try to match them to an
    048     * existing file. If this can be done, a corresponding URL is returned. Otherwise, result is <strong>null</strong>.
    049     * Implementations should not throw an exception (unless parameters are <strong>null</strong>) as there might be alternative
    050     * strategies which can find the file in question.
    051     *
    052     * @param fileSystem the {@code FileSystem} to be used for this operation
    053     * @param locator the object describing the file to be located
    054     * @return a URL pointing to the referenced file if location was successful; <strong>null</strong> if the file could not be
    055     *         resolved
    056     */
    057    URL locate(FileSystem fileSystem, FileLocator locator);
    058}