net.yagga.util
Class BootstrapJarClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--net.yagga.util.BootstrapJarClassLoader

public class BootstrapJarClassLoader
extends java.lang.ClassLoader

A META class loader for loading jar files. interesting the class can load jar classes from different JARs and from the same jar (if this class is jarred with other jars...
This class is a collection of methods and features found in class MetaJarClassLoader, MetaJarResource, JarClassLoader and MetaUt. THey are reduced and compacted here for convenience.

Author:
Walter Gamba
See Also:
MetaJarResource, JarClassLoader, MetaUt, MetaJarClassLoader

Inner classes inherited from class java.lang.ClassLoader
java.lang.ClassLoader.NativeLibrary
 
Field Summary
private  boolean executingFromJar
           
private  java.util.Hashtable htSizes
           
private  java.lang.String jarFile
           
private  java.lang.String jarJarFile
           
private  java.util.Hashtable metaJarContent
           
private  java.util.jar.Manifest metaManifest
           
 
Fields inherited from class java.lang.ClassLoader
bootstrapClassPath, classes, defaultDomain, defaultPermissions, domains, getClassLoaderPerm, initialized, loadedLibraryNames, nativeLibraries, nativeLibraryContext, nocerts, package2certs, packages, parent, scl, sclSet, sys_paths, systemNativeLibraries, usr_paths
 
Constructor Summary
BootstrapJarClassLoader(java.lang.String jFile)
          constructor: decides if the jar filename passed belongs to a jar that: a) is outside the current class/jar file b) is inside the JAR file where this class is also stored.
 
Method Summary
protected  java.lang.Class findClass(java.lang.String className)
          method taht actually reads the class from raw bytes
 java.lang.String getActualJarName()
          Legge l'attributo actualJarName dell object BootstrapJarClassLoader
 java.lang.String getMainClassName()
          Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
private  java.util.jar.JarInputStream getTopJIS()
          get top level JAR input stream
private  void initTopJarSizes()
          read sizes fror top-level JAR file.
 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 main(java.lang.String[] argv)
          Descrizione del metodo
private  java.io.InputStream openResource(java.lang.String filename)
          Descrizione del metodo
 byte[] readBytesFromTopJar(java.lang.String entryName)
          reads bytes from Top Jar file.
private  void readJarInJar()
          reads in self contained jar file this is the case if this class is jarred with other jar files so: FOO.jar +--Installer.class +--MetaJarClassLoader.class +--PACK1.jar +--ClassIWantToInvoke.class <===
 
Methods inherited from class java.lang.ClassLoader
, addClass, check, checkCerts, checkPackageAccess, compareCerts, defineClass, defineClass, defineClass, defineClass0, definePackage, findBootstrapClass, findBootstrapClass0, findLibrary, findLoadedClass, findNative, findResource, findResources, findSystemClass, getBootstrapClassPath, getBootstrapResource, getBootstrapResources, getCallerClassLoader, getDefaultDomain, getGetClassLoaderPerm, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, initializePath, isAncestor, loadClass, loadClass, loadClassInternal, loadLibrary, loadLibrary0, resolveClass, resolveClass0, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

jarFile

private java.lang.String jarFile

htSizes

private java.util.Hashtable htSizes

executingFromJar

private boolean executingFromJar

metaJarContent

private java.util.Hashtable metaJarContent

jarJarFile

private java.lang.String jarJarFile

metaManifest

private java.util.jar.Manifest metaManifest
Constructor Detail

BootstrapJarClassLoader

public BootstrapJarClassLoader(java.lang.String jFile)
constructor: decides if the jar filename passed belongs to a jar that: a) is outside the current class/jar file b) is inside the JAR file where this class is also stored.
Parameters:
jFile - jar file to load and use in classpath
Method Detail

main

public static void main(java.lang.String[] argv)
Descrizione del metodo
Parameters:
argv - Description of the Parameter

getActualJarName

public java.lang.String getActualJarName()
Legge l'attributo actualJarName dell object BootstrapJarClassLoader
Returns:
Il valore di actualJarName

readJarInJar

private void readJarInJar()
reads in self contained jar file this is the case if this class is jarred with other jar files so: FOO.jar +--Installer.class +--MetaJarClassLoader.class +--PACK1.jar +--ClassIWantToInvoke.class <===

getMainClassName

public java.lang.String getMainClassName()
Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
Returns:
Il valore di mainClassName

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 - Description of the Parameter
args - Description of the Parameter
Throws:
java.lang.ClassNotFoundException - Description of the Exception
java.lang.NoSuchMethodException - Description of the Exception
java.lang.reflect.InvocationTargetException - Description of the Exception

findClass

protected java.lang.Class findClass(java.lang.String className)
                             throws java.lang.ClassNotFoundException
method taht actually reads the class from raw bytes
Overrides:
findClass in class java.lang.ClassLoader
Parameters:
className - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.lang.ClassNotFoundException - Description of the Exception

initTopJarSizes

private void initTopJarSizes()
read sizes fror top-level JAR file. This can be the sole JAR file, or it can be used to read further into the JAR, for another JAR file JARRED :)

readBytesFromTopJar

public byte[] readBytesFromTopJar(java.lang.String entryName)
reads bytes from Top Jar file. Can be used standalone, or to read in another JAr file and then, using readJarInJar, filling the metaJarContent hashtable
Parameters:
entryName - Description of the Parameter
Returns:
Description of the Return Value

getTopJIS

private java.util.jar.JarInputStream getTopJIS()
get top level JAR input stream
Returns:
Il valore di topJIS

openResource

private java.io.InputStream openResource(java.lang.String filename)
Descrizione del metodo
Parameters:
filename - Description of the Parameter
Returns:
Description of the Return Value