|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.openbp.common.classloader.XClassLoaderBase
public abstract class XClassLoaderBase
This class implements a sophisticated classloader that supports
loading from classes from various repositories (which might be
\.jar, \.zip-files or directories) and a caching mechanism for
loaded classes.
To avoid multi-threading problems, this class loader is immutable after having
been constructed. This means, all configuration data necessary is passed as
argument to the constructor, and changing the configuration object
(see XClassLoaderConfiguration) after being passed to the constructor
doesn't influence the class loader any more (which is achieved by cloning the
configuration). Consequentially, the configuration can and should be reused.
In order to support a broad field of applications for this class,
it is kept free of specific logging code, instead, own logging levels together
with an abstract logging method are used to allow easy integration of
the appropriate logging mechanism.
Implementation note: Actually, the class loader wouldn't have to extend URLClassLoader.
This is done only to make the Tomcat Jasper JSP engine happy, which hard-wiredly expects an URLClassLoader.
| Field Summary | |
|---|---|
protected XClassLoaderConfiguration |
configuration
A clone of the configuration passed during construction of the class loader. |
static boolean |
DEBUG_LOAD_TIME
Class loading time debug flag |
| Constructor Summary | |
|---|---|
protected |
XClassLoaderBase()
Protected constructor. |
|
XClassLoaderBase(XClassLoaderConfiguration configuration)
Constructor. |
| Method Summary | |
|---|---|
protected void |
addClassToCache(java.lang.String className,
java.lang.Class cls)
Adds a class to the class cache. |
void |
addResourceEntry(java.lang.String key,
ResourceEntry entry)
Adds a resource entry to the class loader. |
protected void |
addResourceEntryForClass(java.lang.String resourceName,
ResourceEntry entry)
Adds the given resource entry as class mapping of the entry specifies a class file. |
java.lang.Class |
createClass(java.lang.String className,
byte[] data,
boolean resolve)
Creates a class object from its binary data. |
XClassLoaderConfiguration |
getConfiguration()
Gets the a clone of the configuration passed during construction of the class loader.. |
java.lang.ClassLoader |
getParentClassLoader()
This returns the parent class loader of this class loader |
java.net.URL |
getResource(java.lang.String name)
Determines the URL of a resource with a given name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Finds a resource with a given name. |
ResourceEntry |
getResourceEntry(java.lang.String key)
Gets a resource entry by its key. |
protected java.net.URL |
getResourceFromPath(java.lang.String resourceName)
Loads a resource from the class path. |
protected void |
init(XClassLoaderConfiguration configuration)
This method initializes the class loader with the configuration passed. |
protected abstract boolean |
isLogEnabled(java.lang.String logLevel)
Checks if the specified log level is enabled. |
java.lang.Class |
loadClass(java.lang.String className,
boolean resolve)
Overrides the loadClass method from the standard java class loader. |
protected java.lang.Class |
loadClassFromCache(java.lang.String className)
Tries to load the class from the cache. |
protected java.lang.Class |
loadClassFromPath(java.lang.String className,
boolean resolve)
Loads a class from a directory or zip file in the class path of the custom class loader. |
protected java.io.InputStream |
loadResourceFromPath(java.lang.String resourceName)
Loads a resource from the class path. |
protected void |
log(java.lang.String logLevel,
java.lang.String msg)
A convenience method that allows logging without an exception. |
protected void |
log(java.lang.String logLevel,
java.lang.String msg,
java.lang.Exception e)
Logs a message. |
protected void |
log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg)
Logs a message. |
protected void |
log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg,
java.lang.Exception e)
Logs a message. |
protected void |
log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg,
java.lang.String arg2)
Logs a message. |
static byte[] |
readContent(java.io.File file)
Reads the resource from the repository. |
void |
rescan()
Clears all information about classes in the path and rescans the specified class path. |
protected void |
scanRepositories()
This method scans all repositories in the configuration for classes. |
protected abstract void |
setupLogger()
Initializes the logger. |
java.lang.String |
toString()
Overridden toString method. |
protected abstract void |
writeLog(java.lang.String logLevel,
java.lang.String msg,
java.lang.Exception e)
Writes a message to the log. |
| Methods inherited from class java.net.URLClassLoader |
|---|
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance |
| Methods inherited from class java.security.SecureClassLoader |
|---|
defineClass, defineClass |
| Methods inherited from class java.lang.ClassLoader |
|---|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static boolean DEBUG_LOAD_TIME
protected XClassLoaderConfiguration configuration
| Constructor Detail |
|---|
public XClassLoaderBase(XClassLoaderConfiguration configuration)
throws java.lang.Exception
configuration - The configuration to be used for this class loader. Must not be null.
java.lang.Exception - On any error that occurs while scanning the repositories specified in the class loader configurationprotected XClassLoaderBase()
init(org.openbp.common.classloader.XClassLoaderConfiguration)!
| Method Detail |
|---|
protected void init(XClassLoaderConfiguration configuration)
throws java.lang.Exception
configuration - The configuration to be used for this class loader. Must not be null.
java.lang.Exception - On any error that occurs while scanning the repositories specified in the class loader configuration
public void rescan()
throws java.lang.Exception
java.lang.Exception - On any error that occurs while scanning the repositories specified in the class loader configurationpublic java.lang.ClassLoader getParentClassLoader()
public XClassLoaderConfiguration getConfiguration()
public ResourceEntry getResourceEntry(java.lang.String key)
key - Key
public void addResourceEntry(java.lang.String key,
ResourceEntry entry)
key - Key of the entry (e. g. a fully qualified class name)entry - Entry to add
protected void addResourceEntryForClass(java.lang.String resourceName,
ResourceEntry entry)
resourceName - Resource name (relative path name or zip entry name)entry - Entry to add
public java.lang.Class loadClass(java.lang.String className,
boolean resolve)
throws java.lang.ClassNotFoundException
loadClass in class java.lang.ClassLoaderclassName - Name of the class to be loadedresolve - If true, all dependents are loaded too
java.lang.ClassNotFoundException - If the class was not foundpublic java.net.URL getResource(java.lang.String name)
getResource in class java.lang.ClassLoadername - Name of the desired resource
public java.io.InputStream getResourceAsStream(java.lang.String name)
getResourceAsStream in class java.lang.ClassLoadername - Name of the desired resource
protected java.lang.Class loadClassFromPath(java.lang.String className,
boolean resolve)
className - Fully qualified name of the class to be loadedresolve - If true, classes referenced by the class should be loaded, too
public java.lang.Class createClass(java.lang.String className,
byte[] data,
boolean resolve)
className - Name of the classdata - Class data (from file)resolve - If true, all dependents are loaded too
protected java.io.InputStream loadResourceFromPath(java.lang.String resourceName)
resourceName - Name of the resource file
protected java.net.URL getResourceFromPath(java.lang.String resourceName)
resourceName - Name of the resource file
protected void addClassToCache(java.lang.String className,
java.lang.Class cls)
className - Fully qualified class namecls - Class objectprotected java.lang.Class loadClassFromCache(java.lang.String className)
className - Fully qualified name of the class
protected void scanRepositories()
throws java.lang.Exception
java.lang.Exception - On any error that occurs while scanning the repositories specified in the class loader configuration
public static byte[] readContent(java.io.File file)
throws java.lang.Exception
file - File to read
java.lang.Exception - On any error that occurs while scanning the repositories specified in the class loader configuration
protected void log(java.lang.String logLevel,
java.lang.String msg,
java.lang.Exception e)
logLevel - Log level as defined by LogLevelmsg - The message to be loggede - An exception that should be logged together with the message (might be null)
protected void log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg,
java.lang.Exception e)
logLevel - Log level as defined by LogLevelmsg - The message to be loggedarg - message argumente - An exception that should be logged together with the message (might be null)
protected void log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg)
logLevel - Log level as defined by LogLevelmsg - The message to be loggedarg - message argument
protected void log(java.lang.String logLevel,
java.lang.String msg,
java.lang.String arg,
java.lang.String arg2)
logLevel - Log level as defined by LogLevelmsg - The message to be loggedarg - message argumentarg2 - message argument
protected void log(java.lang.String logLevel,
java.lang.String msg)
logLevel - Log level as defined by LogLevelmsg - The message to be loggedprotected abstract void setupLogger()
protected abstract void writeLog(java.lang.String logLevel,
java.lang.String msg,
java.lang.Exception e)
logLevel - Log level as defined by LogLevelmsg - Message to be loggede - An exception that should be logged together with the message (might be null)protected abstract boolean isLogEnabled(java.lang.String logLevel)
logLevel - Log level as defined by LogLevel
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||