Class CombinedLocationStrategy
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionCombinedLocationStrategy
(Collection<? extends FileLocationStrategy> subs) Creates a new instance ofCombinedLocationStrategy
and initializes it with the provided sub strategies. -
Method Summary
Modifier and TypeMethodDescriptionGets a (unmodifiable) collection with the sub strategies managed by this object.locate
(FileSystem fileSystem, FileLocator locator) Tries to locate the specified file.
-
Constructor Details
-
CombinedLocationStrategy
Creates a new instance ofCombinedLocationStrategy
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 Details
-
getSubStrategies
Gets a (unmodifiable) collection with the sub strategies managed by this object.- Returns:
- the sub
FileLocationStrategy
objects
-
locate
Tries to locate the specified file. The method also expects theFileSystem
to be used. Note that theFileLocator
object may also contain aFileSystem
, but this is optional. The passed inFileSystem
should be used, and callers must not pass a null reference for this argument. A concrete implementation has to evaluate the properties stored in theFileLocator
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 interfaceFileLocationStrategy
- Parameters:
fileSystem
- theFileSystem
to be used for this operationlocator
- 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
-