org.limitless.util
Class GroupClassLoader

java.lang.Object
  extended by org.limitless.util.GroupClassLoader

public class GroupClassLoader
extends java.lang.Object

This loads a group of classes by regex pattern in a directory that share a common interface.

It's meant to be used as follows:

     GroupClassLoader gcl = new GroupClassLoader();
     Class[] matching = gcl.loadClasses(
       new File( directoryName ),
       "org.limiitless.", 
       interfaceExpected.class );
   

The loader can be re-used as often as desired, even threaded, as it uses no stateful data.

The path specifier is required because it is prepended to each name found in the directory, which ensures that no hanky-panky takes place (the class loader used to do the loading is the standard loader, and it looks for things by full package naming, and in their proper places).

Version:
$Header: /repository/nmc/java/org/limitless/util/GroupClassLoader.java,v 1.2 2004/07/08 18:17:39 brianj Exp $
Author:
Brian Jones

Nested Class Summary
private static class GroupClassLoader.Worker
          Objects of this class will populate the destination list.
 
Field Summary
private static FileVisitor fileVisitor
          This is used freely by any threads as needed without harm.
private static org.apache.log4j.Logger logger
          Log4J Logger for the class
 
Constructor Summary
GroupClassLoader()
          The object has no protected state.
 
Method Summary
 java.lang.Class[] loadClasses(java.io.File startingDirectory, java.lang.String packagePreface, java.lang.Class expectedInterface)
          Cause all classes in the package (directory) with a given interface to be loaded and their Class objects returned.
static void main(java.lang.String[] args)
          Testing main.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger
Log4J Logger for the class


fileVisitor

private static final FileVisitor fileVisitor
This is used freely by any threads as needed without harm.

Constructor Detail

GroupClassLoader

public GroupClassLoader()
The object has no protected state.

Method Detail

loadClasses

public java.lang.Class[] loadClasses(java.io.File startingDirectory,
                                     java.lang.String packagePreface,
                                     java.lang.Class expectedInterface)
Cause all classes in the package (directory) with a given interface to be loaded and their Class objects returned.


main

public static void main(java.lang.String[] args)
Testing main.



Copyright © 1995, 2004 Limitless Knowledge Association, All Rights Reserved.