se.hirt.plugin
Class JarScanner

java.lang.Object
  extended by se.hirt.plugin.JarScanner

public class JarScanner
extends java.lang.Object

Class for scanning Jar's. Provides methods for scanning a Jar and applying a user defined callback on each entry.

Author:
Marcus Hirt

Nested Class Summary
static interface JarScanner.EntryApplier
          Callback interface to be used with the scanner.
 
Constructor Summary
JarScanner()
           
 
Method Summary
static java.util.Set<java.lang.Class> getClassesFromJar(java.lang.ClassLoader loader, java.util.jar.JarFile file)
          Attempts to load all the class files found in the specified jar, using the specified loader.
static java.lang.String getClassNameFromEntry(java.util.jar.JarEntry entry)
          Returns the class name from a JarEntry, or null if it isn't a class.
static void scanJar(java.util.jar.JarFile file, JarScanner.EntryApplier appl)
          Sifts through a jar file, applying the entry applier on every entry discovered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarScanner

public JarScanner()
Method Detail

scanJar

public static void scanJar(java.util.jar.JarFile file,
                           JarScanner.EntryApplier appl)
Sifts through a jar file, applying the entry applier on every entry discovered.

Parameters:
file - the file to look through.
appl - the entry applier to apply on every entry.

getClassNameFromEntry

public static java.lang.String getClassNameFromEntry(java.util.jar.JarEntry entry)
Returns the class name from a JarEntry, or null if it isn't a class.

Parameters:
entry - the JarEntry to convert to a class name.
Returns:
the class name.

getClassesFromJar

public static java.util.Set<java.lang.Class> getClassesFromJar(java.lang.ClassLoader loader,
                                                               java.util.jar.JarFile file)
Attempts to load all the class files found in the specified jar, using the specified loader. If none could be loaded, the Empty Set is returned.

Parameters:
loader - the loader to try to load the classes from.
file - the jar file to load the classes from.
Returns:
the set of classes in the JAR that can be loaded using the supplied class loader.


Copyright © 2005 Marcus Hirt