net.sf.farrago.plugin
Class FarragoPluginClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by net.sf.farrago.plugin.FarragoPluginClassLoader

public class FarragoPluginClassLoader
extends URLClassLoader

FarragoPluginClassLoader allows plugin jars to be added to the ClassLoader dynamically.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/plugin/FarragoPluginClassLoader.java#16 $
Author:
John V. Sichi

Field Summary
static String LIBRARY_CLASS_PREFIX1
          Prefix used to indicate that a wrapper library is loaded directly from a class rather than a jar.
static String LIBRARY_CLASS_PREFIX2
          New alternative to LIBRARY_CLASS_PREFIX1.
static String PLUGIN_FACTORY_CLASS_ATTRIBUTE
          Attribute name used in jar manifest for identifying the class to be used as a plugin factory.
static String PLUGIN_MODEL_ATTRIBUTE
          Attribute name used in jar manifest for identifying the XMI file to be used as a model extension.
private static Logger tracer
           
private  Set urlSet
           
 
Constructor Summary
FarragoPluginClassLoader()
           
FarragoPluginClassLoader(ClassLoader parentClassLoader)
           
 
Method Summary
 void addPluginUrl(URL url)
          Adds a URL from which plugins can be loaded.
protected  Class<?> findClass(String name)
           
static String getLibraryClassReference(String libraryName)
          From a library name which references a Java class directly, obtains the class reference (possibly with trailing context such as a method name).
static boolean isLibraryClass(String libraryName)
          Tests whether a library name references a Java class directly rather than a jar.
 Class loadClassFromJarUrl(String jarUrl, String className)
          Loads a Java class from a jar URL.
 Class loadClassFromJarUrlManifest(String jarUrl, String jarAttributeName)
          Loads a Java class from a jar URL, using the manifest to determine the classname.
 Class loadClassFromLibraryManifest(String libraryName, String jarAttributeName)
          Loads a Java class from a library (either a jarfile using a manifest to get the classname, or else a named class from the classpath).
 Object newPluginInstance(Class pluginClass)
          Constructs a new object instance of a plugin class, making sure the thread's context ClassLoader is set to this for the duration of the construction.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, 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, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tracer

private static final Logger tracer

LIBRARY_CLASS_PREFIX1

public static final String LIBRARY_CLASS_PREFIX1
Prefix used to indicate that a wrapper library is loaded directly from a class rather than a jar. TODO: get rid of this and use only LIBRARY_CLASS_PREFIX2.

See Also:
Constant Field Values

LIBRARY_CLASS_PREFIX2

public static final String LIBRARY_CLASS_PREFIX2
New alternative to LIBRARY_CLASS_PREFIX1.

See Also:
Constant Field Values

PLUGIN_FACTORY_CLASS_ATTRIBUTE

public static final String PLUGIN_FACTORY_CLASS_ATTRIBUTE
Attribute name used in jar manifest for identifying the class to be used as a plugin factory.

See Also:
Constant Field Values

PLUGIN_MODEL_ATTRIBUTE

public static final String PLUGIN_MODEL_ATTRIBUTE
Attribute name used in jar manifest for identifying the XMI file to be used as a model extension.

See Also:
Constant Field Values

urlSet

private final Set urlSet
Constructor Detail

FarragoPluginClassLoader

public FarragoPluginClassLoader()

FarragoPluginClassLoader

public FarragoPluginClassLoader(ClassLoader parentClassLoader)
Method Detail

addPluginUrl

public void addPluginUrl(URL url)
Adds a URL from which plugins can be loaded.

Parameters:
url - URL to add

loadClassFromLibraryManifest

public Class loadClassFromLibraryManifest(String libraryName,
                                          String jarAttributeName)
Loads a Java class from a library (either a jarfile using a manifest to get the classname, or else a named class from the classpath).

Parameters:
libraryName - filename of jar containing plugin implementation
jarAttributeName - name of jar attribute to use to determine class name
Returns:
loaded class

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Overrides:
findClass in class URLClassLoader
Throws:
ClassNotFoundException

loadClassFromJarUrlManifest

public Class loadClassFromJarUrlManifest(String jarUrl,
                                         String jarAttributeName)
Loads a Java class from a jar URL, using the manifest to determine the classname.

Parameters:
jarUrl - URL of jar containing plugin implementation
jarAttributeName - name of jar attribute to use to determine class name
Returns:
loaded class

loadClassFromJarUrl

public Class loadClassFromJarUrl(String jarUrl,
                                 String className)
Loads a Java class from a jar URL.

Parameters:
jarUrl - URL for jar containing class implementation
className - name of class to load
Returns:
loaded class

newPluginInstance

public Object newPluginInstance(Class pluginClass)
                         throws InstantiationException,
                                IllegalAccessException
Constructs a new object instance of a plugin class, making sure the thread's context ClassLoader is set to this for the duration of the construction.

Parameters:
pluginClass - class to instantiate
Returns:
new object
Throws:
InstantiationException
IllegalAccessException

isLibraryClass

public static boolean isLibraryClass(String libraryName)
Tests whether a library name references a Java class directly rather than a jar.

Parameters:
libraryName - library name to be tested
Returns:
true iff libraryName references a Java class

getLibraryClassReference

public static String getLibraryClassReference(String libraryName)
From a library name which references a Java class directly, obtains the class reference (possibly with trailing context such as a method name).

Parameters:
libraryName - library name to be parsed
Returns:
class name