org.formaria.editor.project.registry
Class JarClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.formaria.editor.project.registry.JarClassLoader

public class JarClassLoader
extends java.net.URLClassLoader

A class loader for loading jar files, both local and remote.


Field Summary
static java.util.jar.Attributes.Name Attributes_Name_JAVA_BEAN
           
static java.util.jar.Attributes.Name Attributes_Name_NAME
           
 
Constructor Summary
JarClassLoader(java.net.URL url)
          Creates a new JarClassLoader for the specified url.
JarClassLoader(java.net.URL url, java.lang.ClassLoader parent)
          Creates a new JarClassLoader for the specified url.
 
Method Summary
 void addJarFile(java.lang.String jarfile)
          Adds a jar file from the filesystems into the jar loader list.
 void addJarFile(java.net.URL url)
          Adds the jar file with the following url into the class loader.
static JarClassLoader getJarClassLoader()
          Returns the shared instance of the class loader.
 java.lang.String getMainClassName()
          Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 void invokeClass(java.lang.String name, java.lang.String[] args)
          Invokes the application in this jar file given the name of the main class and an array of arguments.
static void setJarClassLoader(JarClassLoader cl)
          Sets the static instance of the class loader.
 
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, 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

Attributes_Name_JAVA_BEAN

public static final java.util.jar.Attributes.Name Attributes_Name_JAVA_BEAN

Attributes_Name_NAME

public static final java.util.jar.Attributes.Name Attributes_Name_NAME
Constructor Detail

JarClassLoader

public JarClassLoader(java.net.URL url)
Creates a new JarClassLoader for the specified url.

Parameters:
url - The url of the jar file i.e. http://www.xxx.yyy/jarfile.jar or file:c:\foo\lib\testbeans.jar

JarClassLoader

public JarClassLoader(java.net.URL url,
                      java.lang.ClassLoader parent)
Creates a new JarClassLoader for the specified url.

Parameters:
url - The url of the jar file i.e. http://www.xxx.yyy/jarfile.jar or file:c:\foo\lib\testbeans.jar
parent - the parent classloader
Method Detail

addJarFile

public void addJarFile(java.net.URL url)
Adds the jar file with the following url into the class loader. This can be a local or network resource.

Parameters:
url - The url of the jar file i.e. http://www.xxx.yyy/jarfile.jar or file:c:\foo\lib\testbeans.jar

addJarFile

public void addJarFile(java.lang.String jarfile)
Adds a jar file from the filesystems into the jar loader list.

Parameters:
jarfile - The full path to the jar file.

getJarClassLoader

public static JarClassLoader getJarClassLoader()
Returns the shared instance of the class loader.


setJarClassLoader

public static void setJarClassLoader(JarClassLoader cl)
Sets the static instance of the class loader.


getMainClassName

public java.lang.String getMainClassName()
                                  throws java.io.IOException
Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.

Throws:
java.io.IOException

invokeClass

public void invokeClass(java.lang.String name,
                        java.lang.String[] args)
                 throws java.lang.ClassNotFoundException,
                        java.lang.NoSuchMethodException,
                        java.lang.reflect.InvocationTargetException
Invokes the application in this jar file given the name of the main class and an array of arguments. The class must define a static method "main" which takes an array of String arguemtns and is of return type "void".

Parameters:
name - the name of the main class
args - the arguments for the application
Throws:
java.lang.ClassNotFoundException - if the specified class could not be found
java.lang.NoSuchMethodException - if the specified class does not contain a "main" method
java.lang.reflect.InvocationTargetException - if the application raised an exception