ca.infoway.messagebuilder.j5goodies
Class ClassFinder

Package class diagram package ClassFinder
java.lang.Object
  extended by ca.infoway.messagebuilder.j5goodies.ClassFinder

public class ClassFinder
extends Object

Find classes on the class path.

One of the sad limitations of Java is that you can't, say, find all classes in a particular package. Sometimes some forms of reflection would be easier if you didn't hafta have a master list of class names that you can consult. (An example might be the hibernate.cfg.xml file that lists all of your persistent entities).

One strategy for getting around this limitation of Java is to manually scan an entire target directory or jar file, looking for all of the classes and then using some rules ("predicates") to decide if it's a class that you want.

Finding the jar or directory that contains your classes is a tricky exercise, but this utility attempts to help with that.

Author:
Intelliware Development

Constructor Summary
ClassFinder()
           
 
Method Summary
 List<Class<?>> findClasses(Class<?> context, ClassPredicate predicate)
          Find all classes in the same jar as the contextual class.
 List<Class<?>> findClasses(URL pathToManifest, ClassPredicate predicate)
          Find all classes in the same jar as the given manifest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFinder

public ClassFinder()
Method Detail

findClasses

public List<Class<?>> findClasses(Class<?> context,
                                  ClassPredicate predicate)

Find all classes in the same jar as the contextual class.

Parameters:
context - - the class whose location helps us determine the path to the jar.
predicate - - a class that determines which classes should be included in the result
Returns:
- the list of classes found.

findClasses

public List<Class<?>> findClasses(URL pathToManifest,
                                  ClassPredicate predicate)

Find all classes in the same jar as the given manifest.

Parameters:
pathToManifest - - the resource path to the manifest file
predicate - - a class that determines which classes should be included in the result
Returns:
- the list of classes found.


Copyright © 2013. All Rights Reserved.