public interface Locator
Definition of the base Locator
interface.
A Locator is an object that points to a resource to be loaded by an application. There are many ways how such a resource can be specified, including
File
objectsURL
objects
Typically to be fully compatible with all kinds of clients and to be
convenient to use a service class that needs to load resources has to deal
with all these various ways. As an implementor of such services classes you
find yourself often writing similar code for converting File
s
to URL
s, strings to both or vice versa.
To make the handling of resources easier the Locator
interface
was introduced. A Locator provides an abstract view on a resource
specification. Concrete implementations will deal with specific ways of
describing resources, e.g. as URLs or files or loaded from the class path. So
a service class need not deal with conversion between the different formats
any longer, but just queries the provided locator.
The Locator
interface defines some methods for returning a
pointer to the represented resource, but the only method that must be
implemented is the getURL()
method. So URLs are the native
format. If a stream to the represented resource is to be opened, this task
should be delegated to the
class, which
contains static utility methods for exactly this purpose. These methods will
test, which of the locator's methods return defined values and then use those
to open the stream.
LocatorUtils
Modifier and Type | Method and Description |
---|---|
File |
getFile()
Returns a file for the resource represented by this locator.
|
InputStream |
getInputStream()
Returns an input stream for the represented resource.
|
URL |
getURL()
Returns a URL to the resource represented by this locator.
|
URL getURL()
LocatorException
- if an internal error occurs while determining
the URLFile getFile()
File
object for the represented resourceLocatorException
- if an internal error occursInputStream getInputStream() throws IOException
getFile()
and, last but not least, the
getURL()
methods will be tried.LocatorException
- if an internal error occursIOException
- if an IO error occurs when opening the streamCopyright © 2016 The JGUIraffe Team. All rights reserved.