View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.configuration2.io;
18  
19  import java.net.URL;
20  
21  /**
22   * <p>
23   * An interface allowing applications to customize the process of locating a file.
24   * </p>
25   * <p>
26   * {@link FileHandler} uses {@link FileLocator} objects for referencing files. These objects are not guaranteed to
27   * identify a file in a unique way. For instance, if only a file name is defined, this could mean a relative file name
28   * in the current directory, the name of a resource to be loaded from the class path, or something else. Before the file
29   * described by a {@code FileLocator} can be actually accessed, an unambiguous URL pointing to this file has to be
30   * obtained. This is the job of a {@code FileLocationStrategy}.
31   * </p>
32   * <p>
33   * This interface defines a method for locating a file provided as a {@code FileLocator} object. If location is
34   * successful, a URL is returned. A concrete implementation can perform arbitrary actions to search for the file in
35   * question at various places. There will also be an implementation allowing the combination of multiple
36   * {@code FileLocationStrategy} implementations; so a file can be searched using multiple strategies until one of them
37   * is successful.
38   * </p>
39   *
40   * @since 2.0
41   */
42  public interface FileLocationStrategy {
43      /**
44       * Tries to locate the specified file. The method also expects the {@code FileSystem} to be used. Note that the
45       * {@code FileLocator} object may also contain a {@code FileSystem}, but this is optional. The passed in
46       * {@code FileSystem} should be used, and callers must not pass a <b>null</b> reference for this argument. A concrete
47       * implementation has to evaluate the properties stored in the {@code FileLocator} object and try to match them to an
48       * existing file. If this can be done, a corresponding URL is returned. Otherwise, result is <b>null</b>.
49       * Implementations should not throw an exception (unless parameters are <b>null</b>) as there might be alternative
50       * strategies which can find the file in question.
51       *
52       * @param fileSystem the {@code FileSystem} to be used for this operation
53       * @param locator the object describing the file to be located
54       * @return a URL pointing to the referenced file if location was successful; <b>null</b> if the file could not be
55       *         resolved
56       */
57      URL locate(FileSystem fileSystem, FileLocator locator);
58  }