public class WekaPackageClassLoaderManager
extends java.lang.Object
WekaPackageLibIsolatingClassLoaders - one
for each package. Utils.forName() and weka.Run use this
classloader to find/instantiate schemes exposed in top-level package jar
files. Client code in a package should do the same, unless directly referring
to classes in other packages, in which case the other packages should be
explicit dependencies. This classloader will not find classes in third-party
libraries inside a package's lib directory.WekaPackageLibIsolatingClassLoader| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,WekaPackageLibIsolatingClassLoader> |
m_classBasedClassLoaderLookup
Lookup for classloaders keyed by class names from top-level package jar
files
|
protected java.util.Map<java.lang.String,WekaPackageLibIsolatingClassLoader> |
m_packageJarClassLoaders
Map of package classloaders keyed by package name
|
protected java.io.File |
m_pathToWekaJarFile
Path to the weka.jar file on the classpath
|
protected static WekaPackageClassLoaderManager |
s_singletonLoader |
| Modifier and Type | Method and Description |
|---|---|
java.lang.ClassLoader |
addPackageToClassLoader(java.io.File packageDir)
Create a class loader for the given package directory
|
protected static boolean |
classExists(java.lang.String className)
Check to see if the named class exists in this classloader
|
protected java.lang.Class<?> |
findClass(java.lang.String name)
Attempts to find the named class.
|
protected java.lang.Class<?> |
findClass(java.lang.String packageName,
java.lang.String className)
Try to find a class from the classloader for the named package.
|
java.lang.ClassLoader |
findClassloaderForResource(java.lang.String name)
Get the classloader that covers the jar that contains the named resource.
|
java.net.URL |
findResource(java.lang.String name)
Find a named resource.
|
protected java.net.URL |
findResource(java.lang.String packageName,
java.lang.String name)
Try to find a resource from the classloader for the named package.
|
java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name)
Find a named resource.
|
protected java.util.Enumeration<java.net.URL> |
findResources(java.lang.String packageName,
java.lang.String name)
Try to find a resource from the classloader for the named package.
|
static java.lang.Class<?> |
forName(java.lang.String className)
Return the class object for the supplied class name.
|
static java.lang.Class<?> |
forName(java.lang.String className,
boolean initialize)
Return the class object for the supplied class name.
|
java.lang.ClassLoader |
getLoaderForClass(java.lang.String className)
Attempts to locate a classloader for the named class.
|
WekaPackageLibIsolatingClassLoader |
getPackageClassLoader(java.lang.String packageName)
Get the classloader for the named package
|
java.util.Set<java.lang.String> |
getPackageJarFileClasses()
Get a set of all classes contained in all top-level jar files from Weka
packages.
|
java.io.File |
getPathToWekaJarFile()
Return the path to the weka.jar file (if found) on the classpath.
|
java.net.URL[] |
getWekaClassloaderClasspathEntries()
Get the entries in the Weka class loader (i.e. the class loader that loads
the core weka classes) as an array of URLs.
|
static WekaPackageClassLoaderManager |
getWekaPackageClassLoaderManager()
Gets the singleton instance of the WekaPackageClassLoaderManager
|
protected static void |
injectAllClassesInFromStream(java.io.InputStream inStream)
Inject all classes from the supplied input stream into the root
classloader.
|
protected static void |
injectAllClassesInJar(java.io.File jarPath)
Inject all classes in the supplied jar file into the root classloader
|
protected static void |
injectAllClassesInJar(java.io.File jarPath,
boolean injectToRootClassLoader)
Inject all classes in the supplied jar file into the parent or root
classloader
|
protected static void |
injectClasses(java.io.File jarPath,
java.util.List<java.lang.String> classJarPaths,
java.util.List<java.lang.String> classes,
boolean injectToRootClassLoader)
Inject classes from the supplied jar file into the Weka or root
classloader.
|
protected static void |
injectClasses(java.io.InputStream jarStream,
java.util.List<java.lang.String> classJarPaths,
java.util.List<java.lang.String> classes,
boolean injectToRootClassLoader)
Inject classes from the supplied stream into the Weka or root classloader.
|
protected void |
injectMTJCoreClasses()
Injects the MTJ core classes into the root classloader.
|
static java.lang.Object |
objectForName(java.lang.String className)
Return an instantiated instance of the supplied class name.
|
protected void |
performIntegrityCheck()
Checks each classloader to make sure that their dependencies are available
(i.e. a classloader for each dependency is present).
|
void |
removeClassLoaderForPackage(java.lang.String packageName)
Removes the named package classloader from those managed by this class.
|
protected static final WekaPackageClassLoaderManager s_singletonLoader
protected java.util.Map<java.lang.String,WekaPackageLibIsolatingClassLoader> m_packageJarClassLoaders
protected java.util.Map<java.lang.String,WekaPackageLibIsolatingClassLoader> m_classBasedClassLoaderLookup
protected java.io.File m_pathToWekaJarFile
protected void injectMTJCoreClasses()
public static WekaPackageClassLoaderManager getWekaPackageClassLoaderManager()
public static java.lang.Object objectForName(java.lang.String className)
throws java.lang.Exception
className - the name of the class to get an instance ofjava.lang.Exception - if the class cannot be found, or a problem occurs during
instantiationpublic static java.lang.Class<?> forName(java.lang.String className)
throws java.lang.ClassNotFoundException
className - the name of hte class to get an instance ofjava.lang.ClassNotFoundException - if the named class cannot be found.public static java.lang.Class<?> forName(java.lang.String className,
boolean initialize)
throws java.lang.ClassNotFoundException
className - the name of hte class to get an instance ofinitialize - true if the class should be initializedjava.lang.ClassNotFoundException - if the named class cannot be found.public java.io.File getPathToWekaJarFile()
public java.net.URL[] getWekaClassloaderClasspathEntries()
public java.util.Set<java.lang.String> getPackageJarFileClasses()
public void removeClassLoaderForPackage(java.lang.String packageName)
packageName - the name of the package to remove the classloader forpublic java.lang.ClassLoader addPackageToClassLoader(java.io.File packageDir)
throws java.lang.Exception
packageDir - the directory of a Weka package to create a class loader
forjava.lang.Exception - if a problem occurspublic java.lang.ClassLoader getLoaderForClass(java.lang.String className)
className - the name of the class to locate a classloader forpublic WekaPackageLibIsolatingClassLoader getPackageClassLoader(java.lang.String packageName)
packageName - the name of the package to get the classloader forprotected java.lang.Class<?> findClass(java.lang.String name)
throws java.lang.ClassNotFoundException
name - the name of the class to findjava.lang.ClassNotFoundException - if the named class cannot be foundpublic java.net.URL findResource(java.lang.String name)
name - the name of the resource to findpublic java.lang.ClassLoader findClassloaderForResource(java.lang.String name)
name - the name of the resource to get the owning classloader forpublic java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
throws java.io.IOException
name - the name of the resource to findjava.io.IOExceptionprotected java.lang.Class<?> findClass(java.lang.String packageName,
java.lang.String className)
packageName - the name of the package to check for the classclassName - the name of the class to search forprotected java.net.URL findResource(java.lang.String packageName,
java.lang.String name)
packageName - the name of the package to check for the resourcename - the name of the resource to search forprotected java.util.Enumeration<java.net.URL> findResources(java.lang.String packageName,
java.lang.String name)
packageName - the name of the package to check for the resourcename - the name of the resource to search forprotected static boolean classExists(java.lang.String className)
className - the name of the class to check forprotected static void injectAllClassesInJar(java.io.File jarPath,
boolean injectToRootClassLoader)
throws java.lang.Exception
jarPath - the path to the jar in questioninjectToRootClassLoader - true to inject right up to the rootjava.lang.Exception - if a problem occursprotected static void injectAllClassesInJar(java.io.File jarPath)
throws java.lang.Exception
jarPath - the path to the jar in questionjava.lang.Exception - if a problem occursprotected static void injectAllClassesInFromStream(java.io.InputStream inStream)
throws java.lang.Exception
inStream - the input stream to processjava.lang.Exception - if a problem occursprotected static void injectClasses(java.io.File jarPath,
java.util.List<java.lang.String> classJarPaths,
java.util.List<java.lang.String> classes,
boolean injectToRootClassLoader)
throws java.lang.Exception
jarPath - the path to the jar file to processclassJarPaths - an optional list of paths to classes in the jar file
to inject (if null then all classes in the jar file are injected)classes - an optional list of fully qualified class names. This should
correspond to the paths in classJarPaths, but contain just the
class name along with slashes replaced by "." and the .class
extension removed.injectToRootClassLoader - true if the classes are to be injected into
the root classloader rather than the Weka classloaderjava.lang.Exception - if a problem occursprotected static void injectClasses(java.io.InputStream jarStream,
java.util.List<java.lang.String> classJarPaths,
java.util.List<java.lang.String> classes,
boolean injectToRootClassLoader)
throws java.lang.Exception
jarStream - input stream to process. Is expected that jar/zip entries
can be read from the streamclassJarPaths - an optional list of paths to classes in the jar file
to inject (if null then all classes in the jar file are injected)classes - an optional list of fully qualified class names. This should
correspond to the paths in classJarPaths, but contain just the
class name along with slashes replaced by "." and the .class
extension removed.injectToRootClassLoader - true if the classes are to be injected into
the root classloader rather than the Weka classloaderjava.lang.Exception - if a problem occursprotected void performIntegrityCheck()