Package edu.gvsu.kurmasz.warszawa.dl
Class ClassFinder
java.lang.Object
edu.gvsu.kurmasz.warszawa.dl.ClassFinder
public class ClassFinder
extends java.lang.Object
Find and generate the
Class
object for a class given its name. (Such
a Class
object is typically used to instantiate an object of a class
that isn't known at compile time.)- Author:
- Zachary Kurmas
-
Method Summary
Modifier and Type Method Description static <T> java.lang.Class<T>
getClass(java.lang.String className, java.lang.Class<T> parentClass)
Get theClass
object for the named class and verify thatclassName
is a subclass ofparentClass
.static java.lang.Class
loadClassByFile(java.lang.String path, java.io.PrintStream err, int programmer_error, int invalid_parameters, int invalid_class)
Loads the class contained in the specified .class file.static java.lang.Class
loadClassByName(java.lang.String testClassName, java.lang.String[] strings, java.io.PrintStream err, int programmer_error, int invalid_class)
-
Method Details
-
getClass
public static <T> java.lang.Class<T> getClass(java.lang.String className, java.lang.Class<T> parentClass) throws DLExceptionGet theClass
object for the named class and verify thatclassName
is a subclass ofparentClass
. Internally this method callsClass.forName(String)
. (SeeSimpleFactory.make(String, Class, Object...)
for a discussion of the purpose ofT
andparentClass
.)- Type Parameters:
T
- The type ofparentClass
- Parameters:
className
- the fully qualified name of the desired classparentClass
- a superclass ofclassName
- Returns:
- the
Class
object for the classclassName
- Throws:
DLException
- if the named class isn't found, or is not a subclass ofparentClass
java.lang.IllegalArgumentException
- ifclassName
orparentClass
arenull
-
loadClassByFile
public static java.lang.Class loadClassByFile(java.lang.String path, java.io.PrintStream err, int programmer_error, int invalid_parameters, int invalid_class)Loads the class contained in the specified .class file.- Parameters:
path
- The path of the class file.err
- the PrintStream to which any error messages should be writtenprogrammer_error
- the return value in the event of a programmer errorinvalid_parameters
- the return value in the even that the specified file can't be foundinvalid_class
- the return value in the event that the specified file is not a valid java .class file- Returns:
- Returns the class object after the class has been loaded.
-
loadClassByName
public static java.lang.Class loadClassByName(java.lang.String testClassName, java.lang.String[] strings, java.io.PrintStream err, int programmer_error, int invalid_class)
-