public class ClassFinder
extends java.lang.Object
An INSTANCE of this class scans the classpath and creates a Map with keys the unqualified class name and values the corresponding Class object. The first found Class object is the one stored.
Both jar files and directories on the classpath are scanned. If the user
wishes to skip certain jar files, they are listed in the
config/ClassFinder.properties
file. Also in that file is a
directory specified by the key first
. This directory is expected
to contain jar files that are scanned before any others on the classpath.
This allows the user to add classes that will be found and instantiated by
the ObjectMaker
.
Modifier and Type | Class and Description |
---|---|
private class |
ClassFinder.JarFilter
Filter to only accept files that end with ".jar"
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_EXT_DIR |
private java.util.List<java.net.URL> |
dirURLs |
private java.lang.String |
firstDirectory |
private java.util.Map<java.lang.String,java.lang.Class<?>> |
foundByQualifiedName |
private static ClassFinder |
INSTANCE |
private java.util.List<java.net.URL> |
jarFileURLs |
private java.util.Locale |
locale |
private static java.util.logging.Logger |
LOGGER |
private java.util.Map<java.lang.String,java.lang.Class<? extends RandomNumber>> |
randomNumberClasses |
private java.util.Map<java.lang.String,java.lang.Class<? extends RandomVariate>> |
randomVariateClasses |
private java.util.List<java.lang.String> |
skippedJars |
private java.net.URLClassLoader |
urlClassLoader |
Modifier | Constructor and Description |
---|---|
protected |
ClassFinder() |
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
findClassByUnqualifiedName(java.lang.String unqualifiedName)
This returns the first Class found on the classpath.
|
private void |
findJarFiles()
Finds all the jar files on the class path - first the ones in the "first"
directory, then the ones not listed in skippedJars.properties
|
protected java.lang.String |
findUnqualifiedNameFor(java.lang.Class<?> theClass) |
protected java.lang.String |
fixFullPathName(java.io.File parent,
java.io.File file)
Trims off ".class" from the end of the file name and substitutes "." for
file separators ("/" on Mac and *nix, "\" on Windows)
|
java.util.Map<java.lang.String,java.lang.Class<?>> |
getFoundByQualifiedName() |
static ClassFinder |
getINSTANCE() |
java.util.Map<java.lang.String,java.lang.Class<? extends RandomNumber>> |
getRandomNumberClasses() |
java.util.Map<java.lang.String,java.lang.Class<? extends RandomVariate>> |
getRandomVariateClasses() |
private void |
loadClasses()
Finds and loads all classes on classpath.
|
private void |
loadClassesFromDirectory(java.io.File dirFile,
java.io.File file)
Attempt to load the given file in the class loader, or all the files in
the subdirectory if given file (second argument) is a directory.
|
protected java.lang.Class<?> |
loadClassFromJar(java.util.jar.JarEntry jarEntry)
Loads a class corresponding to a JarEntry into the urlClassLoader.
|
private void |
loadConfigFile()
Load the skipped jar names from config/skippedJars.properties into
skippedJars List
|
private static final java.util.logging.Logger LOGGER
private static final java.lang.String DEFAULT_EXT_DIR
private static final ClassFinder INSTANCE
private java.util.Locale locale
private final java.util.Map<java.lang.String,java.lang.Class<?>> foundByQualifiedName
private final java.util.Map<java.lang.String,java.lang.Class<? extends RandomVariate>> randomVariateClasses
private final java.util.Map<java.lang.String,java.lang.Class<? extends RandomNumber>> randomNumberClasses
private final java.util.List<java.net.URL> jarFileURLs
private final java.util.List<java.net.URL> dirURLs
private final java.util.List<java.lang.String> skippedJars
private java.net.URLClassLoader urlClassLoader
private java.lang.String firstDirectory
public static ClassFinder getINSTANCE()
private void loadConfigFile()
private void findJarFiles()
private void loadClasses()
private void loadClassesFromDirectory(java.io.File dirFile, java.io.File file)
loadClassesFromDirectory(dirFile, dirFile);
where dirFile
is the directory on the classpath.dirFile
- Parent directory from classpathfile
- directory or file; if file, attempt to load it if it is a
.class fileprotected java.lang.String fixFullPathName(java.io.File parent, java.io.File file)
parent
- directory given file is infile
- Given file to fix nameprotected java.lang.Class<?> loadClassFromJar(java.util.jar.JarEntry jarEntry) throws java.lang.ClassNotFoundException
jarEntry
- Given JarEntryjava.lang.ClassNotFoundException
- if can't load the classprotected java.lang.String findUnqualifiedNameFor(java.lang.Class<?> theClass)
theClass
- Given Classpublic java.util.Map<java.lang.String,java.lang.Class<?>> getFoundByQualifiedName()
public java.lang.Class<?> findClassByUnqualifiedName(java.lang.String unqualifiedName)
unqualifiedName
- Name of unqualified classpublic java.util.Map<java.lang.String,java.lang.Class<? extends RandomVariate>> getRandomVariateClasses()
public java.util.Map<java.lang.String,java.lang.Class<? extends RandomNumber>> getRandomNumberClasses()