public class ClassFinder
extends java.lang.Object
Constructor and Description |
---|
ClassFinder() |
Modifier and Type | Method and Description |
---|---|
static java.util.ArrayList<java.lang.Class<?>> |
findClass(java.lang.String pkg,
java.lang.String className)
Searches recursively for any class with the name "className" in pkg
|
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.io.File dir,
java.lang.String pkg,
java.util.regex.Pattern regex,
java.lang.Class<?> T,
boolean recursive)
Searches the directory 'dir', gathering classes of type T that match
regex.
|
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.io.File dir,
java.lang.String pkg,
java.lang.String regex,
java.lang.Class<?> T) |
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.lang.Package pkg,
java.lang.Class<?> T) |
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.lang.String pkg,
java.lang.Class<?> T) |
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.lang.String pkg,
java.lang.String regex,
java.lang.Class<?> T,
boolean recursive)
Scans for all classes accessible from the current one within the supplied
package that are a child of the supplied Class T
|
static java.util.ArrayList<java.lang.Class<?>> |
findClasses(java.net.URL url,
java.lang.String pkg,
java.util.regex.Pattern regex,
java.lang.Class<?> T)
Searches through all "subdirectories" of a URL, gathering classes of type
T that match regex
|
static java.util.ArrayList<java.lang.String> |
findClassNames(java.lang.String pkg,
java.lang.Class<?> base) |
static java.util.ArrayList<java.lang.String> |
findClassNames(java.lang.String pkg,
java.lang.Class<?> base,
boolean recursive) |
static java.util.ArrayList<java.lang.String> |
findClassNames(java.lang.String pkg,
java.lang.String regex,
java.lang.Class<?> base,
boolean recursive) |
static java.io.File |
findPackageDirectory(java.lang.String pkgname)
Find the class directory for a particular package, if it exists, This
will only be true if the package exists and is loaded from a file system
directory instead of a JAR file.
|
static java.lang.Class<?> |
forName(java.lang.String name)
Invokes
Class.forName(name,true,loader) using the context class
loader. |
static java.lang.Class<?> |
forName(java.lang.String name,
boolean initialize)
Invokes
Class.forName(name,initialize,loader) using the context
class loader. |
static java.lang.ClassLoader |
getContextClassLoader()
Returns the class loader to be used by this class.
|
static java.lang.Class<?> |
loadClass(java.lang.String name)
Class
loadClass(name) for the context class loader. |
static void |
main(java.lang.String[] args) |
static boolean |
packageExists(java.lang.String pkgname)
Queries whether a package exists, as indicating by the class loader being
able to find resources for it.
|
static void |
setClassLoader(java.lang.ClassLoader loader)
Explicitly sets the class loader to be used by this class.
|
public static void setClassLoader(java.lang.ClassLoader loader)
null
, the current thread's context class loader will
be used instead.loader
- new class loaderpublic static java.lang.ClassLoader getContextClassLoader()
setClassLoader(java.lang.ClassLoader)
, or the context class
loader of the current thread.public static java.lang.Class<?> forName(java.lang.String name, boolean initialize) throws java.lang.ClassNotFoundException
Class.forName(name,initialize,loader)
using the context
class loader.java.lang.ClassNotFoundException
public static java.lang.Class<?> forName(java.lang.String name) throws java.lang.ClassNotFoundException
Class.forName(name,true,loader)
using the context class
loader.java.lang.ClassNotFoundException
public static java.lang.Class<?> loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
loadClass(name)
for the context class loader.java.lang.ClassNotFoundException
public static java.util.ArrayList<java.lang.String> findClassNames(java.lang.String pkg, java.lang.Class<?> base)
public static java.util.ArrayList<java.lang.String> findClassNames(java.lang.String pkg, java.lang.Class<?> base, boolean recursive)
public static java.util.ArrayList<java.lang.String> findClassNames(java.lang.String pkg, java.lang.String regex, java.lang.Class<?> base, boolean recursive)
public static java.util.ArrayList<java.lang.Class<?>> findClass(java.lang.String pkg, java.lang.String className)
pkg
- The package to searchclassName
- The name of the class to findpublic static java.util.ArrayList<java.lang.Class<?>> findClasses(java.lang.String pkg, java.lang.String regex, java.lang.Class<?> T, boolean recursive)
pkg
- string name of packageregex
- only keep files matching the regex statement (i.e. ) i.e. regex =".*Demo$"
will keep only files ending with "Demo"T
- root class to search forrecursive
- if true
, recursively search subpackages (does not yet work for
JAR files)public static java.util.ArrayList<java.lang.Class<?>> findClasses(java.lang.Package pkg, java.lang.Class<?> T)
public static java.util.ArrayList<java.lang.Class<?>> findClasses(java.lang.String pkg, java.lang.Class<?> T)
public static java.util.ArrayList<java.lang.Class<?>> findClasses(java.io.File dir, java.lang.String pkg, java.lang.String regex, java.lang.Class<?> T)
public static java.util.ArrayList<java.lang.Class<?>> findClasses(java.io.File dir, java.lang.String pkg, java.util.regex.Pattern regex, java.lang.Class<?> T, boolean recursive)
dir
- directory in which to searchpkg
- package nameregex
- regular expression used to filter class namesT
- base type that the class mush be an instance ofrecursive
- if true
, recursively search subdirectoriespublic static java.util.ArrayList<java.lang.Class<?>> findClasses(java.net.URL url, java.lang.String pkg, java.util.regex.Pattern regex, java.lang.Class<?> T)
public static boolean packageExists(java.lang.String pkgname)
public static java.io.File findPackageDirectory(java.lang.String pkgname)
null
if not foundpublic static void main(java.lang.String[] args)