org.omegahat.Environment.Tools.ClassList
Class ObjectList

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.omegahat.Environment.Utils.OrderedTable
                    |
                    +--org.omegahat.Environment.Tools.ClassList.ObjectList
All Implemented Interfaces:
Activable, AssignableSubset, java.lang.Cloneable, Database, java.util.Map, java.io.Serializable, ShallowCopyable, Subsettable
Direct Known Subclasses:
ClassList

public class ObjectList
extends OrderedTable

Table containing information read from a file or directory which

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  boolean archive
          Flag indicating whether this file which contains the list's contents is an archive (zip or jar) file rather than a regular directory.
protected  java.io.FilenameFilter class_filter
           
protected  long compute_time
          The time the list was dynamically constructed so that we can determine whether the source has been modified since that time and hence may have changes.
protected  DirectoryFilter dir_filter
           
protected  boolean doneSearch
          A flag indicating that the lookup has been done.
protected  java.io.File file
          The name of the file (directory, etc.) which contains the contents of the list.
static java.lang.String fileSeparator
           
protected static boolean issuedWarning
           
protected  boolean recursive
          Controls whether sub-directory entries are added (false) to this list or grouped in their own sub-list and this added as a single entry.
static boolean verbose
           
 
Fields inherited from class org.omegahat.Environment.Utils.OrderedTable
listeners, name, orderedElements, orderedKeys, state
 
Fields inherited from interface org.omegahat.Environment.Databases.Database
ALL, ASSIGN, ATTACH, DETACH, NULL_ENTRY, READ, READ_WRITE, REMOVE
 
Fields inherited from interface org.omegahat.Environment.Databases.Activable
ACTIVE, INACTIVE
 
Constructor Summary
ObjectList()
          Default constructor allowing derived classes to avoid calling super(..).
ObjectList(java.io.File f)
          Constructor which reads the contents of the list from the specified "file", be it a directory or archive file.
 
Method Summary
 java.lang.Object add(java.util.zip.ZipEntry entry)
           
 java.lang.Object add(java.util.zip.ZipEntry entry, boolean check)
           
 void addElement(java.lang.Object el)
           
 boolean archive(boolean val)
          Specify whether the source of the list's contents is a zip or jar file or not.
 boolean checkIsArchive(java.lang.String f)
          Determines whether the file identified by the supplied name is an archive (zip or jar) file or not.
 long computeTime()
          Return the time when the contents of the list were computed, causing it to be defined as "now".
protected  long computeTime(boolean val)
          Control whether we compute the time, specifying when the contents of the list were computed.
 DirectoryFilter directoryFilter()
           
 DirectoryFilter directoryFilter(DirectoryFilter f)
           
 boolean doneSearch()
          Accessor for determining whether the contents have been computed.
protected  boolean doneSearch(boolean val)
          Set the status of whether the elements have been computed.
 java.util.Vector entries()
          Get a Vector of the entries in this list.
 java.io.File file()
          Accessor to the file field.
 java.io.File file(java.io.File f)
          Stores the file which is the source of the tables entries determining whether it is an archive or not.
 java.io.File file(java.io.File f, boolean update)
          Sets the target directory/file in which the objects of interest are located, but optionally arranges to assume the entries are up-to-date and that there is no need to recompute them unless the file is changed, etc.
static java.lang.String fileSeparator()
          Static method returning the separator for the different nodes in a directory/file specification, particular to the different operating system being used.
 java.lang.Object find(java.lang.String name)
           
 java.lang.String getDirectory(java.lang.String str)
           
 boolean isArchive()
          Determine whether the source of the list's content is a zip/jar file or not.
 boolean issuedWarning()
           
 boolean issuedWarning(boolean v)
           
protected  int lookup()
          Compute the elements of the list by interrogating the source "file" and processing it recursively.
 int lookupArchive(java.io.File file)
          Compute the contents of the list by reading the elements of the archive file.
protected  int lookupDirectory()
          Simple toplevel method for starting the recursive lookup of directories specifying the top-level source directory.
protected  int lookupDirectory(java.io.File dir)
          Lookup the .class files in the given directory identified by the argument, filtering it through the file name filter , filtering adding each one to the list.
 boolean matchesClassName(java.lang.String name, java.lang.String source)
           
 ObjectList newSubList()
           
protected  ObjectList processDirectoryClasses(java.lang.String[] els, java.lang.String prefix, java.io.File dir)
           
protected  int processSubDirectories(java.lang.String[] els, java.io.File dir)
           
 boolean recursive()
           
 boolean recursive(boolean v)
           
 boolean refresh()
          Mark the list as needing to be recomputed, leaving the rebuilding until the contents are queried in another call.
 boolean refresh(boolean now)
          Mark the list as needing to be recomputed, and optionally perform the rebuilding of the contents now or leave it until they are used.
 boolean sourceIsNewer()
          Determine whether the source of the contents of this list has been changed since the contents were computed from it.
 java.lang.String toClassName(java.lang.String str)
           
 void warn(java.lang.String msg)
           
 void warnDirectory(java.io.File f)
          Internal computation done when a warning is about a container in the lookup that is neither a directory or archive class.
 
Methods inherited from class org.omegahat.Environment.Utils.OrderedTable
add, add, addListListener, assign, assignSubset, attach, clear, copy, copy, detach, elementAt, exists, get, getName, getState, keys, listeners, listeners, notifyListeners, objects, ordered, orderedKeys, put, put, put, remove, remove, removeElement, removeElement, removeElementAt, removeElementAt, removeListListener, setElementAt, setName, setState, subset, subset, subset
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.omegahat.Environment.Databases.Database
size
 

Field Detail

class_filter

protected java.io.FilenameFilter class_filter

dir_filter

protected DirectoryFilter dir_filter

file

protected java.io.File file
The name of the file (directory, etc.) which contains the contents of the list.

compute_time

protected long compute_time
The time the list was dynamically constructed so that we can determine whether the source has been modified since that time and hence may have changes.

recursive

protected boolean recursive
Controls whether sub-directory entries are added (false) to this list or grouped in their own sub-list and this added as a single entry. The benefit of the latter approach is that we can operate on the sublist as a single element, changing the order of lookup and using it in its own right.

archive

protected boolean archive
Flag indicating whether this file which contains the list's contents is an archive (zip or jar) file rather than a regular directory.

doneSearch

protected boolean doneSearch
A flag indicating that the lookup has been done. This is used to ensure that if we have a degenerate/trivial list with no elements, that we don't keep attempting to resolve the elements each time entries() is called.

fileSeparator

public static java.lang.String fileSeparator

issuedWarning

protected static boolean issuedWarning

verbose

public static boolean verbose
Constructor Detail

ObjectList

public ObjectList(java.io.File f)
Constructor which reads the contents of the list from the specified "file", be it a directory or archive file.

ObjectList

public ObjectList()
Default constructor allowing derived classes to avoid calling super(..).
Method Detail

entries

public java.util.Vector entries()
Get a Vector of the entries in this list. This is a reference to the contents, and not a copy. If the contents have not been computed when this is called, it is done at this point.

isArchive

public boolean isArchive()
Determine whether the source of the list's content is a zip/jar file or not.

archive

public boolean archive(boolean val)
Specify whether the source of the list's contents is a zip or jar file or not.

computeTime

public long computeTime()
Return the time when the contents of the list were computed, causing it to be defined as "now". This can be used to determine whether the source "file" has been updated since that time.
See Also:
computeTime(boolean)

computeTime

protected long computeTime(boolean val)
Control whether we compute the time, specifying when the contents of the list were computed. This can only be set by the methods in this and derived classes (and others in this package) to ensure consistency, etc.
Parameters:
val - indicates whether to compute the current time and store it as the time the contents were computed.

sourceIsNewer

public boolean sourceIsNewer()
Determine whether the source of the contents of this list has been changed since the contents were computed from it.

lookup

protected int lookup()
Compute the elements of the list by interrogating the source "file" and processing it recursively. Invokes the appropriate code according to whether the source is a directory or an archive file.
Returns:
the number of elements in the list or negative numbers indicating the nature of the error.
-1 degenerate source file object
-3 source is neither an archive or directory
See Also:
, lookupDirectory(java.io.File)

lookupDirectory

protected int lookupDirectory()
Simple toplevel method for starting the recursive lookup of directories specifying the top-level source directory.

lookupDirectory

protected int lookupDirectory(java.io.File dir)
Lookup the .class files in the given directory identified by the argument, filtering it through the file name filter , filtering adding each one to the list.

processSubDirectories

protected int processSubDirectories(java.lang.String[] els,
                                    java.io.File dir)

processDirectoryClasses

protected ObjectList processDirectoryClasses(java.lang.String[] els,
                                             java.lang.String prefix,
                                             java.io.File dir)

directoryFilter

public DirectoryFilter directoryFilter()

directoryFilter

public DirectoryFilter directoryFilter(DirectoryFilter f)

find

public java.lang.Object find(java.lang.String name)

toClassName

public java.lang.String toClassName(java.lang.String str)

fileSeparator

public static java.lang.String fileSeparator()
Static method returning the separator for the different nodes in a directory/file specification, particular to the different operating system being used.

matchesClassName

public boolean matchesClassName(java.lang.String name,
                                java.lang.String source)

refresh

public boolean refresh()
Mark the list as needing to be recomputed, leaving the rebuilding until the contents are queried in another call.

refresh

public boolean refresh(boolean now)
Mark the list as needing to be recomputed, and optionally perform the rebuilding of the contents now or leave it until they are used.
Parameters:
now - flag indicating whether we should recompute the table immediately or leave it to be done when it is next queried.

newSubList

public ObjectList newSubList()
                      throws java.lang.IllegalAccessException,
                             java.lang.InstantiationException

file

public java.io.File file()
Accessor to the file field.

file

public java.io.File file(java.io.File f)
Stores the file which is the source of the tables entries determining whether it is an archive or not. This does not cause the table's entries to be constructed.

checkIsArchive

public boolean checkIsArchive(java.lang.String f)
Determines whether the file identified by the supplied name is an archive (zip or jar) file or not.

file

public java.io.File file(java.io.File f,
                         boolean update)
Sets the target directory/file in which the objects of interest are located, but optionally arranges to assume the entries are up-to-date and that there is no need to recompute them unless the file is changed, etc. Used in the recursive setup when we don't actually instantiate the object with the file. Hence, when we add the elements, there is no information indicating that we don't have to do this again. This allows us to set the doneSearch flag and compute the current time.
Parameters:
file - the name of the directory or file in which to look for the objects of interest.
update - if true, the entries are assumed to be up-to-date.

doneSearch

public boolean doneSearch()
Accessor for determining whether the contents have been computed.

doneSearch

protected boolean doneSearch(boolean val)
Set the status of whether the elements have been computed.

issuedWarning

public boolean issuedWarning()

issuedWarning

public boolean issuedWarning(boolean v)

recursive

public boolean recursive()

recursive

public boolean recursive(boolean v)

warn

public void warn(java.lang.String msg)

warnDirectory

public void warnDirectory(java.io.File f)
Internal computation done when a warning is about a container in the lookup that is neither a directory or archive class. This ignores errors about entries in the JAVA_HOME directory tree as JDK2 seems to add jre/classes which does not exit to the sun.boot.path

addElement

public void addElement(java.lang.Object el)

lookupArchive

public int lookupArchive(java.io.File file)
Compute the contents of the list by reading the elements of the archive file.

add

public java.lang.Object add(java.util.zip.ZipEntry entry)

add

public java.lang.Object add(java.util.zip.ZipEntry entry,
                            boolean check)

getDirectory

public java.lang.String getDirectory(java.lang.String str)