net.larsan.urd.util.fileset
Class TrivialFileSet

java.lang.Object
  |
  +--net.larsan.urd.util.fileset.FileSet
        |
        +--net.larsan.urd.util.fileset.TrivialFileSet
All Implemented Interfaces:
ResourceLocator, WatchableFileSet
Direct Known Subclasses:
JarFile

public class TrivialFileSet
extends FileSet
implements WatchableFileSet

A trivial file set is a watched file set that only works in a single file.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
protected  java.io.File file
          File to watch
protected  java.util.HashMap resources
          Hash set of resources, paths -> resources
 
Fields inherited from class net.larsan.urd.util.fileset.FileSet
root
 
Constructor Summary
TrivialFileSet(java.io.File file, java.util.Timer timer)
          Create file set.
 
Method Summary
 void addFileSetListener(FileSetListener listener)
          Register file set listener.
protected  void checkScan()
          Check if the file still exists or have been modified
protected  void doScan()
          Perfom scan.
 java.security.cert.Certificate[] getCertificates(Resource resource)
          Get the certificates for a resource.
 Resource getResource(java.lang.String path)
          Get a resource from the set.
 java.lang.String[] getResourcePaths()
          Get all available resources ids.
 void removeFileSetListener(FileSetListener listener)
          De-register file set listener
 void scan()
          Perform a new scan of available files for the set.
 void start(long interval)
          Start watching this file set.
 void stop()
          Stop watcing this file set.
 
Methods inherited from class net.larsan.urd.util.fileset.FileSet
getErrorHandler, isRecursive, matches, resolvePath, setErrorHandler, setIsRecursive, setRegexpPattern
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resources

protected java.util.HashMap resources
Hash set of resources, paths -> resources


file

protected java.io.File file
File to watch

Constructor Detail

TrivialFileSet

public TrivialFileSet(java.io.File file,
                      java.util.Timer timer)
               throws java.io.IOException
Create file set. The file must not be null and must exist. If the timer is null the file will not be watched.

Parameters:
file - File to watch, must not be null
timer - Timer to use for watching the file, may be null
Throws:
java.io.IOException - If the file does not exist
Method Detail

scan

public void scan()
          throws java.io.IOException
Perform a new scan of available files for the set.

The string array returned contains all available resources as identified by their relative path to the file set root.

Specified by:
scan in class FileSet
Returns:
A string array of relative paths, an empty array will be returned if the set is empty
Throws:
An - IOException should the scan fail
java.io.IOException - If the scan fails

getResourcePaths

public java.lang.String[] getResourcePaths()
Get all available resources ids. This arrays should be empty if the file set is empty.

Specified by:
getResourcePaths in class FileSet
Returns:
A string array of relative paths, an empty array will be returned if the set is empty

getResource

public Resource getResource(java.lang.String path)
Get a resource from the set. This should return a Resource if the resource is found or null if not. The parameter should be a relative path as returned by getResourcePaths.

Specified by:
getResource in interface ResourceLocator
Specified by:
getResource in class FileSet
Parameters:
path - A relative path to the resource to get
Returns:
A resource object representing the resource. or null if not found

getCertificates

public java.security.cert.Certificate[] getCertificates(Resource resource)
Get the certificates for a resource. This method always returns null since this file set does not support signed resource

Specified by:
getCertificates in class FileSet
Parameters:
resource - The resource to check for signing certificates
Returns:
Null

start

public void start(long interval)
Start watching this file set. The watch interval will be determined by the parameter which must be a long which is bigger than 0 for the watch to start.

Parameters:
interval - Interval in milliseconds between file set checks, must be bigger than 0

stop

public void stop()
Stop watcing this file set.


addFileSetListener

public void addFileSetListener(FileSetListener listener)
Register file set listener.

Specified by:
addFileSetListener in interface WatchableFileSet
Parameters:
listener - File set listener to add

removeFileSetListener

public void removeFileSetListener(FileSetListener listener)
De-register file set listener

Specified by:
removeFileSetListener in interface WatchableFileSet
Parameters:
listener - File set listener to remove

doScan

protected void doScan()
               throws java.io.IOException
Perfom scan. This method should populate the resource map with new resources.

java.io.IOException

checkScan

protected void checkScan()
Check if the file still exists or have been modified