net.sf.rej.files
Class ClassIndex

java.lang.Object
  extended by net.sf.rej.files.ClassIndex

public class ClassIndex
extends java.lang.Object

Manages relationships between fully qualified class names and the physical locations of the classfiles they are defined in. Each set of files can be cached to the disk, so that it is not necessary to recreate it at start-up.

Author:
Sami Koivu

Constructor Summary
ClassIndex()
           
 
Method Summary
 void addElement(FileSet fs)
          Add a FileSet to the index and mark the index as being not up to date.
 void addLocator(FileSet fs, java.lang.String file)
          Add a single locator to the index
 void conditionalUpdate()
          Updates the index if it has been marked as not up to date.
 java.util.List<ClassLocator> getAll()
          Returns a List containing the ClassLocator of all the classes in call the FileSets of this index.
 ClassFile getByFullName(java.lang.String name)
          Returns the ClassFile object for the class whose fully qualified name is given as a parameter.
 java.util.List<java.lang.String> getClassNames(FileSet fs)
          Return a List of all the names classes in the given FileSet.
 ClassLocator getLocator(java.lang.String className)
          Return ClassLocator for the given full class name
 void removeElement(FileSet current)
          Remove one fileset from the index
 void removeLocator(FileSet fs, java.lang.String file)
          Remove a single locator from the index.
 void update()
          Update the index, reading (from cache or disk) all the locators for FileSets for which there are no index entries yet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassIndex

public ClassIndex()
Method Detail

addElement

public void addElement(FileSet fs)
Add a FileSet to the index and mark the index as being not up to date. Nothing is loaded at this point. The FileSet is simply queued for addition.

Parameters:
fs - fileset to add to the index.

getByFullName

public ClassFile getByFullName(java.lang.String name)
                        throws java.io.IOException
Returns the ClassFile object for the class whose fully qualified name is given as a parameter. Or null if no class is found.

Parameters:
name - fully qualified name of the class to return.
Returns:
ClassFile of the class name given as a parameter.
Throws:
java.io.IOException - I/O Exception while reading/parsing the class.

getAll

public java.util.List<ClassLocator> getAll()
Returns a List containing the ClassLocator of all the classes in call the FileSets of this index.

Returns:
java.util.List containing ClassLocator objects.

conditionalUpdate

public void conditionalUpdate()
Updates the index if it has been marked as not up to date.


update

public void update()
Update the index, reading (from cache or disk) all the locators for FileSets for which there are no index entries yet.


removeElement

public void removeElement(FileSet current)
Remove one fileset from the index

Parameters:
current -

getLocator

public ClassLocator getLocator(java.lang.String className)
Return ClassLocator for the given full class name

Parameters:
className -
Returns:
ClassLocator An object for locating the class file and ClassFile object

getClassNames

public java.util.List<java.lang.String> getClassNames(FileSet fs)
Return a List of all the names classes in the given FileSet.

Parameters:
fs - a FileSet object for which the class names are requested.
Returns:
a List of String objects.

addLocator

public void addLocator(FileSet fs,
                       java.lang.String file)
                throws java.io.IOException
Add a single locator to the index

Parameters:
fs - FileSet where the file belongs to.
file - name of file to add.
Throws:
java.io.IOException - I/O problem while adding.

removeLocator

public void removeLocator(FileSet fs,
                          java.lang.String file)
Remove a single locator from the index.

Parameters:
fs - FileSet where the file belongs to.
file - name of file to remove.