org.apache.commons.configuration2.io

## Class CombinedLocationStrategy

- java.lang.Object
- - org.apache.commons.configuration2.io.CombinedLocationStrategy

- All Implemented Interfaces:
    FileLocationStrategy

      public class CombinedLocationStrategy
      extends Object
      implements FileLocationStrategy

  A specialized implementation of a `FileLocationStrategy` which encapsulates an arbitrary number of `FileLocationStrategy` objects.

  A collection with the wrapped `FileLocationStrategy` objects is passed at construction time. During a [`locate()` operation the wrapped strategies are called one after the other until one returns a non null URL. This URL is returned. If none of the wrapped strategies is able to resolve the passed in `FileLocator`, result is null. This is similar to the chain of responsibility design pattern.

  This class, together with the provided concrete `FileLocationStrategy` implementations, offers a convenient way to customize the lookup for configuration files: Just add the desired concrete strategies to a `CombinedLocationStrategy` object. If necessary, custom strategies can be implemented if there are specific requirements. Note that the order in which strategies are added to a `CombinedLocationStrategy` matters: sub strategies are queried in the same order as they appear in the collection passed to the constructor.

  Since:
    2.0
  Version:
    $Id: CombinedLocationStrategy.java 1790899 2017-04-10 21:56:46Z ggregory $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CombinedLocationStrategy(Collection<? extends FileLocationStrategy> subs)` Creates a new instance of `CombinedLocationStrategy` and initializes it with the provided sub strategies.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<FileLocationStrategy>` | `getSubStrategies()` Returns a (unmodifiable) collection with the sub strategies managed by this object.
    `URL` | `locate(FileSystem fileSystem, FileLocator locator)` Tries to locate the specified file.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CombinedLocationStrategy

          public CombinedLocationStrategy(Collection<? extends FileLocationStrategy> subs)

      Creates a new instance of `CombinedLocationStrategy` and initializes it with the provided sub strategies. The passed in collection must not be null or contain null elements.
      Parameters:
        `subs` - the collection with sub strategies
      Throws:
        `IllegalArgumentException` - if the collection is null or has null elements

  - ### Method Detail

    - #### getSubStrategies

          public Collection<FileLocationStrategy> getSubStrategies()

      Returns a (unmodifiable) collection with the sub strategies managed by this object.
      Returns:
        the sub `FileLocationStrategy` objects

    - #### locate

          public URL locate(FileSystem fileSystem,
                            FileLocator locator)

      Tries to locate the specified file. The method also expects the `FileSystem` to be used. Note that the `FileLocator` object may also contain a `FileSystem`, but this is optional. The passed in `FileSystem` should be used, and callers must not pass a null reference for this argument. A concrete implementation has to evaluate the properties stored in the `FileLocator` object and try to match them to an existing file. If this can be done, a corresponding URL is returned. Otherwise, result is null. Implementations should not throw an exception (unless parameters are null) as there might be alternative strategies which can find the file in question. This implementation tries to locate the file by delegating to the managed sub strategies.
      Specified by:
        `locate` in interface `FileLocationStrategy`
      Parameters:
        `fileSystem` - the `FileSystem` to be used for this operation
        `locator` - the object describing the file to be located
      Returns:
        a URL pointing to the referenced file if location was successful; null if the file could not be resolved

Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.