public final class Reflection extends java.lang.Object implements TrueStatic
Dynamic Class Overloading system and miscellaneous reflection tools.
Modifier and Type | Class and Description |
---|---|
static interface |
Reflection.ClassLoaderFactory
ClassLoaderFactory interface should produce some ClassLoader for
given ClassLoader identifier.
|
static class |
Reflection.DynamicClassOverloader |
static interface |
Reflection.WithClassPath
This interface should be implemented by a ClassLoader ineritor
that allows to get list of all class paths where it searches the classes.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASSES_TEMPORARY_SUBDIRECTORY_PREFIX |
static int |
DEBUG_LEVEL |
static java.util.Set |
JAVA_CLASS_PATH
The result of
System.getProperty("java.class.path","")
call splitted into a set of String objects (one path in one String). |
static boolean |
USE_SYSTEM_CLASS_LOADER_AT_FIRST
If true, then loadClass(String) call (without
loaderId )
will always use the system class loader (Class.forName(className) call)
until first call of invalidateClasses() |
Modifier and Type | Method and Description |
---|---|
static java.util.Map |
getAllClassesId()
getAllClassesId() returns an unmodifiable map containing
getClassesId(...) values for all class loaders
known to DCO system. |
static long |
getClassesId(java.lang.Object loaderId)
getClassesId(loaderId) allows to check whether DCO class loader with given
identifier has been invalidated.
|
static java.io.File |
getClassFile(java.lang.Class clazz) |
static java.lang.ClassLoader |
getClassLoader(java.lang.Object loaderId)
Returns DCO class loader used by loadClass(...,loaderId)
|
static Reflection.ClassLoaderFactory |
getClassLoaderFactory() |
static java.lang.String |
getClassName(java.lang.Class clazz,
char nestedClassSeparator) |
static java.net.URL |
getClassURL(java.lang.Class clazz) |
static java.lang.StackTraceElement[] |
getCurrentStackTrace() |
static java.lang.StackTraceElement[] |
getCurrentStackTrace(int beginIndex,
int len) |
static java.util.Set |
getFileSystemJavaClassPath()
Returns a part of the defaultJava CLASSPATH that corresponds
to usual subdirectories, not ZIP or JAR.
|
static long |
getSummaryClassesId()
Allows to check whether class loading system has been invalidated
It returns 0 after first loading
Reflection class;
it's result increments after each call of invalidateClasses()
or invalidateClasses(Object) . |
static java.io.File |
getTempClassesDirectory()
Returns the special "temp classes directory" that is added to CLASSPATH
by all DCO class loaders.
|
static void |
invalidateClasses()
Invalidates all classes loaded by DCO system
All class files will be reloaded by the next
loadClass() |
static void |
invalidateClasses(java.lang.Object loaderId)
Invalidates all classes loaded by the given DCO class loader
All these class files will be reloaded by the next
loadClass() |
static boolean |
isTempClassesDirectoryPropertySet()
Returns true if "net.algart.lib.Reflection.TEMP_CLASSES_DIRECTORY" system property
(more precisely, the result of
call)
is not null. |
static boolean |
isTrueStatic(java.lang.Class clazz) |
static boolean |
isTrueStaticImplemented(java.lang.Class clazz)
Returns true if the given class (or some ot it's ancestors)
implements an interface called "
<some_package>.TrueStatic ". |
static java.lang.Class |
loadClass(java.lang.String name,
boolean initialize,
java.lang.Object loaderId)
Loads a .class file by DCO system; allows to specify whether static
initializing is required.
|
static void |
setClassLoaderFactory(Reflection.ClassLoaderFactory classLoaderFactory) |
static java.util.Set |
splitClassPath(java.lang.String classPath) |
public static final int DEBUG_LEVEL
public static final boolean USE_SYSTEM_CLASS_LOADER_AT_FIRST
loaderId
)
will always use the system class loader (Class.forName(className)
call)
until first call of invalidateClasses()
public static final java.util.Set JAVA_CLASS_PATH
System.getProperty("java.class.path","")
call splitted into a set of String objects (one path in one String).
If Java CLASSPATH cannot be got due to security reasons, this constant
contains an empty set.public static final java.lang.String CLASSES_TEMPORARY_SUBDIRECTORY_PREFIX
public static java.util.Set splitClassPath(java.lang.String classPath)
public static java.io.File getTempClassesDirectory() throws java.io.IOException
GlobalProperties.getClassProperty
(Reflection.class,"TEMP_CLASSES_DIRECTORY")
call if it is not null;
Directory.createTempDirectory
(CLASSES_TEMPORARY_SUBDIRECTORY_PREFIX
,
"").getPath()}
call in other case.
In the first case this directory must be included in
the standard Java CLASSPATH. In other case, Reflection
class will produce an assertion exception while static initialization.
In the second case this directory is automatically created,
as a secondary effect of calling this method, and will be
automatically deleted on the program shutdown. I/O exception
can occur while creating temp directory. If it is occurred
while creating an instance of Reflection.DynamicClassOverloader
,
then the exception is ignored, but the created class loader
will not include "temp classes directory" into it's CLASSPATH.
java.io.IOException
public static boolean isTempClassesDirectoryPropertySet()
GlobalProperties.getClassProperty
(Reflection.class,"TEMP_CLASSES_DIRECTORY")
call)
is not null. In this case, you can get it's value by getTempClassesDirectory()
method.getTempClassesDirectory()
public static long getSummaryClassesId()
Reflection
class;
it's result increments after each call of invalidateClasses()
or invalidateClasses(Object)
.public static long getClassesId(java.lang.Object loaderId)
public static java.util.Map getAllClassesId()
getClassesId(...)
values for all class loaders
known to DCO system. This map contains instances of ClassesId
class, that contains only 1 field: "long value"public static void invalidateClasses()
loadClass()
public static void invalidateClasses(java.lang.Object loaderId)
loadClass()
loaderId
- Identifier of class loader that should be invalidated.
Can be null; it is not equivalent to invalidateClasses()
public static java.lang.Class loadClass(java.lang.String name, boolean initialize, java.lang.Object loaderId) throws java.lang.ClassNotFoundException
Do not use this method for true-static classes!
name
- Full class name (with package)initialize
- whether the class must be initializedloaderId
- Identifier of class loader that should be usedjava.lang.ClassNotFoundException
public static java.lang.ClassLoader getClassLoader(java.lang.Object loaderId)
public static java.util.Set getFileSystemJavaClassPath()
public static boolean isTrueStaticImplemented(java.lang.Class clazz)
<some_package>.TrueStatic
".
See TrueStatic
interface.clazz
- Some checked class is true-static: DCO system
will not overload it.TrueStatic
"public static boolean isTrueStatic(java.lang.Class clazz)
public static void setClassLoaderFactory(Reflection.ClassLoaderFactory classLoaderFactory)
public static Reflection.ClassLoaderFactory getClassLoaderFactory()
public static java.net.URL getClassURL(java.lang.Class clazz)
public static java.io.File getClassFile(java.lang.Class clazz)
public static java.lang.String getClassName(java.lang.Class clazz, char nestedClassSeparator)
public static java.lang.StackTraceElement[] getCurrentStackTrace()
public static java.lang.StackTraceElement[] getCurrentStackTrace(int beginIndex, int len)