net.larsan.urd.util.fileset
Class JarFileSet

java.lang.Object
  |
  +--net.larsan.urd.util.fileset.FileSet
        |
        +--net.larsan.urd.util.fileset.JarFileSet
All Implemented Interfaces:
ResourceLocator, WatchableFileSet

public class JarFileSet
extends FileSet
implements WatchableFileSet

A jar file set is a watchable file set that works on JAR archives. This file set is not recursive by default. The file set checks for modified dates on the jar archives.

This file set needs to be started for the automatic rescans to take effect. This means that the file set also needs to be stopped to cancel all pending threads.

This file set supports signed jar files.

This class can be extended to validate the JAR files before their inclusion using the validate method.

This class pre-caches all files in the JAR file not to hold the file open.

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

Nested Class Summary
static class JarFileSet.JarResource
          Inner class for a resource within a jar archive.
 
Field Summary
 
Fields inherited from class net.larsan.urd.util.fileset.FileSet
root
 
Constructor Summary
JarFileSet(java.io.File root, java.util.Timer timer)
          Contruct the file set with a root folder and a timer to use for the watch.
 
Method Summary
 void addFileSetListener(FileSetListener listener)
          Register file set listener.
 java.io.File[] getActiveFiles()
          Get the active archves files in this file set.
 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 scan of available files for the set.
 void start(long interval)
          Start watching this file set.
 void stop()
          Stop watcing this file set.
protected  boolean validateJar(java.io.File file)
          Check if a JAR file should be included in the 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
 

Constructor Detail

JarFileSet

public JarFileSet(java.io.File root,
                  java.util.Timer timer)
           throws java.io.IOException
Contruct the file set with a root folder and a timer to use for the watch. This will throw an IOException if the root does not exist or denotes a file.

If the timer is set to null, the filet will not be watchable.

Parameters:
root - File set root folder, must exist
timer - Timer to use for resource change checks, may be null
Throws:
java.io.IOException - If the root folder does not exist
Method Detail

getActiveFiles

public java.io.File[] getActiveFiles()
Get the active archves files in this file set.

Returns:
The current file set.

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.


scan

public void scan()
          throws java.io.IOException
Perform a scan of available files for the set. This method can be called at any time and it is up to subclasses to take steps to synchronize resources.

Specified by:
scan in class FileSet
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 reported 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 FileSet.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 returns null if the resource is not signed.

Specified by:
getCertificates in class FileSet
Parameters:
resource - The resource to check for signing certificates
Returns:
An arraya of signing certificates or null if not signed

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

validateJar

protected boolean validateJar(java.io.File file)
                       throws java.io.IOException
Check if a JAR file should be included in the file set.

Parameters:
file - Jar file to check
Returns:
true Only if the jar file should be included
java.io.IOException