org.pentaho.reporting.libraries.base.util
Class ClassQueryTool

java.lang.Object
  extended by org.pentaho.reporting.libraries.base.util.ClassQueryTool

public abstract class ClassQueryTool
extends java.lang.Object

The class-query tool loads classes using a classloader and calls "processClass" for each class encountered. This is highly expensive and sometimes dangerous excercise as the classloading may trigger static initializers and may exhaust the "permgen" space of the Virtual machine. If possible anyhow, do not use this class.

Author:
Thomas Morgner

Constructor Summary
protected ClassQueryTool()
          The default constructor.
 
Method Summary
protected  boolean isValidClass(java.lang.String className)
          Checks, whether the class is valid.
protected abstract  void processClass(java.lang.ClassLoader classLoader, java.lang.Class c)
          The handler method that is called for every class encountered on the classpath.
 void processDirectory(java.io.File directory)
          Processes all entries from a given directory, ignoring any subdirectory contents.
protected  void processEntry(java.lang.ClassLoader classLoader, java.lang.String entryName)
          Processes a single class-file entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassQueryTool

protected ClassQueryTool()
The default constructor.

Method Detail

processEntry

protected void processEntry(java.lang.ClassLoader classLoader,
                            java.lang.String entryName)
Processes a single class-file entry. The method will try to load the given entry as java-class and if that successeds will then call the "processClass" method to let the real implementation handle the class.

Parameters:
classLoader - the classloader that should be used for class- and resource loading.
entryName - the file name in the classpath.

isValidClass

protected boolean isValidClass(java.lang.String className)
Checks, whether the class is valid. If the class-name is not considered valid by this method, the class will not be processed. Use this to pre-filter the class-stream as loading classes is expensive.

Parameters:
className - the name of the class.
Returns:
true, if the class should be processed, false otherwise.

processClass

protected abstract void processClass(java.lang.ClassLoader classLoader,
                                     java.lang.Class c)
The handler method that is called for every class encountered on the classpath.

Parameters:
classLoader - the classloader used to load the class.
c - the class that should be handled.

processDirectory

public void processDirectory(java.io.File directory)
                      throws java.io.IOException
Processes all entries from a given directory, ignoring any subdirectory contents. If the directory contains sub-directories these directories are not searched for JAR or ZIP files.

In addition to the directory given as parameter, the direcories and JAR/ZIP-files on the classpath are also searched for entries.

If directory is null, only the classpath is searched.

Parameters:
directory - the directory to be searched, or null to just use the classpath.
Throws:
java.io.IOException - if an error occured while loading the resources from the directory.
java.lang.SecurityException - if access to the system properties or access to the classloader is restricted.