org.ninjasoft.magiccodes.logic
Class PluginDiscoverer

java.lang.Object
  extended byorg.ninjasoft.magiccodes.logic.PluginDiscoverer

public class PluginDiscoverer
extends java.lang.Object

This class will (slightly inefficiently) look for all classes that implement a particular interface. It is useful for plugins. This is done by looking through the contents of all jar files in the classpath, as well as performing a recursive search for *.class files in the classpath directories. This particular class may not work in restrictive ClassLoader environments such as Applets or WebStart. (It may...but unlikely and untested.)

Author:
enigma

Nested Class Summary
 class PluginDiscoverer.classFilter
          File.listFiles filter that only matches class files
 class PluginDiscoverer.directoryFilter
          File.listFiles filter that only matches subdirectories
 
Constructor Summary
PluginDiscoverer()
          Construct the object and parse apart the classpath into directories and jars.
 
Method Summary
 java.lang.String[] findMatchingPlugins(java.lang.Class c)
          Find all classes in the class path that implement the interface defined in the Class object parameter.
static void main(java.lang.String[] argv)
          Simple main function for testing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginDiscoverer

public PluginDiscoverer()
Construct the object and parse apart the classpath into directories and jars. The constructor simple parses and does not search because the parsing is quick and easy. The actual search work should NOT be done in the constructor, but in the findMatchingPlugins class.

Method Detail

findMatchingPlugins

public java.lang.String[] findMatchingPlugins(java.lang.Class c)
Find all classes in the class path that implement the interface defined in the Class object parameter.

Parameters:
c - a Class object representing the interface we are looking for
Returns:
an array of all the class names that implement that interface

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Simple main function for testing

Parameters:
argv - unused
Throws:
java.lang.Exception - if there was a problem


Copyright © 2004 Ninjasoft. All Rights Reserved.