Package net.sf.jguiraffe.locators
Class FileLocator
- java.lang.Object
-
- net.sf.jguiraffe.locators.AbstractLocator
-
- net.sf.jguiraffe.locators.FileLocator
-
- All Implemented Interfaces:
Locator
public final class FileLocator extends AbstractLocator
A concrete
Locator
class that represents files.Instances of this class can be initialized with either a
File
object or with the name of a file. Based on this data the locator methods are implemented in an appropriate way.Note that this class does not check whether the passed in file exists. So if an input stream is to be obtained for this file, it is possible that a file not found exception gets thrown.
Instances of this class are created using the
getInstance()
factory methods. They are immutable and thus can be shared between multiple threads.- Version:
- $Id: FileLocator.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Compares this object with another one.File
getFile()
Returns the represented file resource.String
getFileName()
Returns the name of the represented file.static FileLocator
getInstance(File file)
Returns aFileLocator
instance for the specified file.static FileLocator
getInstance(String fileName)
Returns aFileLocator
instance for the specified file name.URL
getURL()
Returns the URL for the represented file.int
hashCode()
Returns a hash code for this object.String
toString()
Returns a string representation for this object.-
Methods inherited from class net.sf.jguiraffe.locators.AbstractLocator
getInputStream
-
-
-
-
Method Detail
-
getInstance
public static FileLocator getInstance(File file)
Returns aFileLocator
instance for the specified file.- Parameters:
file
- the file (must not be null)- Returns:
- the
FileLocator
instance for this file - Throws:
IllegalArgumentException
- if the file is null
-
getInstance
public static FileLocator getInstance(String fileName)
Returns aFileLocator
instance for the specified file name.- Parameters:
fileName
- the file name (must not be null)- Returns:
- the
FileLocator
instance for this file - Throws:
IllegalArgumentException
- if the file name is null
-
getURL
public URL getURL()
Returns the URL for the represented file.- Returns:
- the URL
- Throws:
LocatorException
- if an error occurs
-
getFile
public File getFile()
Returns the represented file resource.- Specified by:
getFile
in interfaceLocator
- Overrides:
getFile
in classAbstractLocator
- Returns:
- the file
-
getFileName
public String getFileName()
Returns the name of the represented file. This is an absolute file path.- Returns:
- the file name
-
equals
public boolean equals(Object obj)
Compares this object with another one. Two instances of this class are considered equal if and only if they point to the same file.
-
hashCode
public int hashCode()
Returns a hash code for this object.
-
-