public class CombinedLocationStrategy extends Object implements FileLocationStrategy
A specialized implementation of a
encapsulates an arbitrary number of
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
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.
|Constructor and Description|
Creates a new instance of
|Modifier and Type||Method and Description|
Returns a (unmodifiable) collection with the sub strategies managed by this object.
Tries to locate the specified file.
public CombinedLocationStrategy(Collection<? extends FileLocationStrategy> subs)
CombinedLocationStrategyand initializes it with the provided sub strategies. The passed in collection must not be null or contain null elements.
subs- the collection with sub strategies
IllegalArgumentException- if the collection is null or has null elements
public Collection<FileLocationStrategy> getSubStrategies()
public URL locate(FileSystem fileSystem, FileLocator locator)
FileSystemto be used. Note that the
FileLocatorobject may also contain a
FileSystem, but this is optional. The passed in
FileSystemshould be used, and callers must not pass a null reference for this argument. A concrete implementation has to evaluate the properties stored in the
FileLocatorobject 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.
Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.