org.omegahat.Environment.Tools.ClassList
Class ClassLocator

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

public class ClassLocator
extends OrderedTable
implements ClassLocatorInt, java.io.Serializable

Find class definitions, more generally and flexibly than in Java

The methods in this class maintain and use a search path for Java classes. Given the name of a class, the findClass method looks it up and returns the class object. It tries harder than the Java method in class ClassLoader, allowing partial specification of the class name. More importantly, the class supports a dynamic list of where to look, with facilities for adding to the list.

The elements in the class list each identify a source for class definitions. That source can be a directory containing class files, a jar file, or a location (URL) on the web. Methods taking strings as input will try to resolve these sources; methods taking files or URLs as arguments accept the arguments as provided. In addition, a ClassList object, however computed, can be an element of the locator's internal list.

The methods provided allow for adding individual elements or appending multiple elements from any of these sources.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
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
ClassLocator()
           
ClassLocator(ClassList list)
          initialize from another list of class lists (see general discussion above)
ClassLocator(java.io.File f)
          initialize from a file or directory (see general discussion above)
ClassLocator(java.lang.String[] els)
          initialize from strings (see general discussion above)
ClassLocator(java.net.URL u)
          initialize from a URL object (see general discussion above)
ClassLocator(java.util.Vector els)
          initialize from objects (see general discussion above)
 
Method Summary
 java.lang.Object add(ClassList list)
          add another list of class lists (see general discussion above)
 java.lang.Object add(java.io.File f)
          add a file or directory (see general discussion above)
 java.lang.Object add(java.io.File[] f)
           
 java.lang.Object add(java.lang.Object o)
          add an object (see general discussion above)
 java.lang.Object add(java.lang.String name)
          add class list identified by a string (see general discussion above)
 java.lang.Object add(java.lang.String[] names)
           
 java.lang.Object add(java.net.URL u)
          add a URL object (see general discussion above)
 java.lang.Object add(java.net.URL[] u)
           
 int append(java.lang.String[] els)
          append from strings (see general discussion above)
 int append(java.util.Vector els)
          append objects (see general discussion above)
 boolean canReadSerializedLists(java.io.File f)
          Determines whether read a serialized version of the list representing the specified file is acceptable.
 ClassList classList(java.io.File f)
          Creates an appropriate ClassList object based on the characteristics of the specified file.
 ClassList classList(java.io.File f, java.lang.String asSub)
           
 ClassList classList(java.net.URL u)
          Constructs a class list based on the contents of the URL.
 ClassList classList(java.net.URL u, java.lang.String asSub)
           
 java.lang.Class findClass(java.lang.String name)
          Find a class by looking through the elements of the list in order and querying them for a match of the name.
 java.util.Vector findClasses(java.lang.String name, java.util.Vector classes)
          Find all the matching classes rather than just the first one
 java.lang.String serializedName(java.io.File f)
          The name of the class property corresponding to the serialized version of the ClassList object for the specified file.
 
Methods inherited from class org.omegahat.Environment.Utils.OrderedTable
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.Tools.ClassList.ClassLocatorInt
containsKey, elements, get, orderedKeys, size
 
Methods inherited from interface org.omegahat.Environment.Databases.Database
size
 

Constructor Detail

ClassLocator

public ClassLocator()

ClassLocator

public ClassLocator(java.lang.String[] els)
initialize from strings (see general discussion above)

ClassLocator

public ClassLocator(java.util.Vector els)
initialize from objects (see general discussion above)

ClassLocator

public ClassLocator(java.io.File f)
initialize from a file or directory (see general discussion above)

ClassLocator

public ClassLocator(java.net.URL u)
initialize from a URL object (see general discussion above)

ClassLocator

public ClassLocator(ClassList list)
initialize from another list of class lists (see general discussion above)
Method Detail

findClass

public java.lang.Class findClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Find a class by looking through the elements of the list in order and querying them for a match of the name. This performs some processing on the name to replace . with the file separator.
Specified by:
findClass in interface ClassLocatorInt

findClasses

public java.util.Vector findClasses(java.lang.String name,
                                    java.util.Vector classes)
Description copied from interface: ClassLocatorInt
Find all the matching classes rather than just the first one
Specified by:
findClasses in interface ClassLocatorInt

add

public java.lang.Object add(java.io.File f)
add a file or directory (see general discussion above)

add

public java.lang.Object add(java.io.File[] f)

add

public java.lang.Object add(java.net.URL u)
add a URL object (see general discussion above)

add

public java.lang.Object add(java.net.URL[] u)

add

public java.lang.Object add(ClassList list)
add another list of class lists (see general discussion above)

add

public java.lang.Object add(java.lang.String name)
add class list identified by a string (see general discussion above)
Specified by:
add in interface ClassLocatorInt

add

public java.lang.Object add(java.lang.String[] names)

add

public java.lang.Object add(java.lang.Object o)
add an object (see general discussion above)
Overrides:
add in class OrderedTable

classList

public ClassList classList(java.io.File f)
Creates an appropriate ClassList object based on the characteristics of the specified file. If first sees if it can read a serialized version associated with this file. It does so by using this class' getResource() method.

classList

public ClassList classList(java.io.File f,
                           java.lang.String asSub)
Parameters:
f - the file.
asSub - indicates whether the created ClassList will be used as part of an import statement with a sub-directory restricting the set of classes.

classList

public ClassList classList(java.net.URL u)
Constructs a class list based on the contents of the URL. This should be a zip or jar file.

classList

public ClassList classList(java.net.URL u,
                           java.lang.String asSub)

append

public int append(java.util.Vector els)
append objects (see general discussion above)

append

public int append(java.lang.String[] els)
append from strings (see general discussion above)

canReadSerializedLists

public boolean canReadSerializedLists(java.io.File f)
Determines whether read a serialized version of the list representing the specified file is acceptable. This can be used to control whether we want to dynamically compute the list now or read it from a pre-computed value. In the case that we are a developer, this should be false.

serializedName

public java.lang.String serializedName(java.io.File f)
The name of the class property corresponding to the serialized version of the ClassList object for the specified file.