|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.util.IlvClassLoaderUtil
public class IlvClassLoaderUtil
This class contains utility functions for registering class loaders and for looking up classes and resources.
Class loaders are designed to allow plugins (NetBeans, Eclipse, ...) to live in separate worlds and even to allow incompatible versions of the same class to coexist in the same JVM. Class loaders are opaque objects that can serve requests for classes and resources, given their name.
For resources and classes that are packaged within the same module or plugin,
one can use the class loader of the executing class: Simply use
getClass().getResource(...) or Class.forName(...).
For accessing resources and classes that are packaged in a different module
or plugin, or that are made accessible by the user in his environment (of
which we don't know how it looks like), JViews uses the functions in this
class: forName(java.lang.Class, java.lang.String), getResource(java.lang.Class, java.lang.String), getResourceAsStream(java.lang.Class, java.lang.String).
You can use these functions as well.
Through registerClassLoader(java.lang.ClassLoader) you can specify additional class loaders
to be considered in the lookup process. These can be class loaders of
application modules or plugins.
The functions in this class use the singleton instance of this class. The default lookup order is as follows:
Thread.currentThread().setContextClassLoader(...) before
invoking JViews methods. This class loader is also able to emulate a
list of class loaders: The user can implement a
"MultiplexingClassLoader" if he needs to combine multiple class loaders
into a single one (but this is rarely needed).registerClassLoader(java.lang.ClassLoader).
Using the method setDelegate(IlvClassLoaderUtil), you can replace
the singleton instance of this class with an instance of
your subclass of yours, possibly overriding the methods forNameImpl(java.lang.Class, java.lang.String),
getResourceImpl(java.lang.Class, java.lang.String), getResourceAsStreamImpl(java.lang.Class, java.lang.String).
Background: http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html
| Constructor Summary | |
|---|---|
IlvClassLoaderUtil()
Creates a new instance of IlvClassLoaderUtil. |
|
| Method Summary | |
|---|---|
static Class |
forName(Class callingClass,
String className)
Returns a class put in place by the user. |
Class |
forNameImpl(Class callingClass,
String className)
Returns a class put in place by the user. |
static ClassLoader |
getClassLoaderInstance()
Returns a ClassLoader that uses the lookup mechanism of this class. |
static IlvClassLoaderUtil |
getDefaultInstance()
Returns the default instance of this class. |
static IlvClassLoaderUtil |
getDelegate()
Returns the currently installed instance of this class. |
static List<ClassLoader> |
getRegisteredClassLoaders()
Returns the list of registered class loaders. |
static URL |
getResource(Class callingClass,
String name)
Returns the URL of a resource put in place by the user. |
static InputStream |
getResourceAsStream(Class callingClass,
String name)
Returns a stream opened to read from a resource put in place by the user. |
InputStream |
getResourceAsStreamImpl(Class callingClass,
String name)
Returns a stream opened to read from a resource put in place by the user. |
URL |
getResourceImpl(Class callingClass,
String name)
Returns the URL of a resource put in place by the user. |
static void |
registerClassLoader(ClassLoader cl)
Registers a class loader used for loading classes and resources. |
static void |
setDelegate(IlvClassLoaderUtil newInstance)
Replaces the currently installed instance of this class. |
static void |
unregisterClassLoader(ClassLoader cl)
Unregisters a class loader used for loading classes and resources. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IlvClassLoaderUtil()
IlvClassLoaderUtil.
setDelegate(IlvClassLoaderUtil)| Method Detail |
|---|
public static void registerClassLoader(ClassLoader cl)
cl - classloader used when searching a class or resourceforName(Class, String),
getResource(Class, String),
getResourceAsStream(Class, String)public static void unregisterClassLoader(ClassLoader cl)
cl - classloader used when searching a class or resourceforName(Class, String),
getResource(Class, String),
getResourceAsStream(Class, String)public static List<ClassLoader> getRegisteredClassLoaders()
public Class forNameImpl(Class callingClass,
String className)
throws ClassNotFoundException
registerClassLoader(ClassLoader)./li>
callingClass - the source for current class loaderclassName - the name of class to load
Class object for the class with the specified
name.
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be locatedregisterClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)
public URL getResourceImpl(Class callingClass,
String name)
callingClass - the source for current class loadername - The name of the desired resource, using the same conventions
as for the ClassLoader.getResource method: an
absolute resource name, with the leading slash removed.
java.net.URL object, or null if the
resource was not found
IllegalArgumentException - if the name argument is syntactically
incorrectregisterClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)
public InputStream getResourceAsStreamImpl(Class callingClass,
String name)
callingClass - the source for current class loadername - The name of the desired resource, using the same conventions
as for the ClassLoader.getResource method: an
absolute resource name, with the leading slash removed.
InputStream object, or null if the
resource was not found
IllegalArgumentException - if the name argument is syntactically
incorrectregisterClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)public static IlvClassLoaderUtil getDefaultInstance()
public static IlvClassLoaderUtil getDelegate()
public static void setDelegate(IlvClassLoaderUtil newInstance)
public static Class forName(Class callingClass,
String className)
throws ClassNotFoundException
forNameImpl(java.lang.Class, java.lang.String) of the current instance.
callingClass - the source for current class loaderclassName - the name of class to load
Class object for the class with the specified
name.
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be locatedforNameImpl(Class, String),
registerClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)
public static URL getResource(Class callingClass,
String name)
getResourceImpl(java.lang.Class, java.lang.String) of the current instance.
callingClass - the source for current class loadername - The name of the desired resource, using the same conventions
as for the ClassLoader.getResource method: an
absolute resource name, with the leading slash removed.
java.net.URL object, or null if the
resource was not found
IllegalArgumentException - if the name argument is syntactically
incorrectregisterClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)
public static InputStream getResourceAsStream(Class callingClass,
String name)
getResourceAsStreamImpl(java.lang.Class, java.lang.String) of the current instance.
callingClass - the source for current class loadername - The name of the desired resource, using the same conventions
as for the ClassLoader.getResource method: an
absolute resource name, with the leading slash removed.
InputStream object, or null if the
resource was not found
IllegalArgumentException - if the name argument is syntactically
incorrectregisterClassLoader(ClassLoader),
unregisterClassLoader(ClassLoader)public static ClassLoader getClassLoaderInstance()
null.
|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||