org.mule.util.scan
Class ClasspathScanner

java.lang.Object
  extended by org.mule.util.scan.ClasspathScanner

public class ClasspathScanner
extends Object

This class can be used to scan the classpath for classtypes (or interfaces they implement) or for annotations on the classpath. The type of scanner used depends on the class type passed in. There are currently 3 types of scanner;

This scanner uses ASM to search class byte code rather than the classes themselves making orders of magnitude more performant and uses a lot less memory. ASM is the fasted of the byte code manipulation libraries i.e. JavaAssist or BCEL


Field Summary
protected  Log logger
          logger used by this class
 
Constructor Summary
ClasspathScanner(ClassLoader classLoader, String... basepaths)
           
ClasspathScanner(String... basepaths)
           
 
Method Summary
protected  ClassScanner getScanner(Class clazz)
          Works out the correct scanner based on the class passed in

Note that these could be better architected by breaking out filters into strategy objects, but for now this suits my needs

protected  Class loadClass(String name)
           
protected  Set<Class> processFileUrl(URL url, String basepath, Class clazz)
           
protected  Set<Class> processJarUrl(URL url, String basepath, Class clazz)
           
 Set<Class> scanFor(Class clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final transient Log logger
logger used by this class

Constructor Detail

ClasspathScanner

public ClasspathScanner(String... basepaths)

ClasspathScanner

public ClasspathScanner(ClassLoader classLoader,
                        String... basepaths)
Method Detail

scanFor

public Set<Class> scanFor(Class clazz)
                   throws IOException
Throws:
IOException

processJarUrl

protected Set<Class> processJarUrl(URL url,
                                   String basepath,
                                   Class clazz)
                            throws IOException
Throws:
IOException

processFileUrl

protected Set<Class> processFileUrl(URL url,
                                    String basepath,
                                    Class clazz)
                             throws IOException
Throws:
IOException

loadClass

protected Class loadClass(String name)

getScanner

protected ClassScanner getScanner(Class clazz)
Works out the correct scanner based on the class passed in

Note that these could be better architected by breaking out filters into strategy objects, but for now this suits my needs

Parameters:
clazz - the type to scan for
Returns:
a scanner suitable for handling the type passed in
See Also:
AnnotationsScanner, InterfaceClassScanner, ImplementationClassScanner


Copyright © 2003-2009 MuleSource, Inc.. All Rights Reserved.