org.vostok.lang.classes
Class ClassFinder

java.lang.Object
  extended by org.vostok.lang.classes.ClassFinder

public class ClassFinder
extends java.lang.Object

this class provide method to look for classes implementing, or extending a specific class, interface or annotation.

ClassFinder has a cache implementation. Scanning is memmory and cpu consuming process, so don't disable the cache unless it's really important.

for annoation, only able to locate annotation set on a specific class (therefore not on a super class) and must be RetentionPolicy.RUNTIME and ElementType.CONSTRUCTOR

Version:
1.2
Author:
levreau.jerome@vostoksystem.eu
See Also:
ClassLoader

Constructor Summary
ClassFinder(boolean cache)
          create a new finder using the default class loader.
ClassFinder(java.lang.ClassLoader loader, boolean cache)
          create a new finder using a specific class loader.
ClassFinder(java.lang.ClassLoader loader, java.lang.String path, boolean cache)
          create a new finder using a specific class loader.
ClassFinder(java.lang.String path)
          create a new class finder, using cahce and stating scanning down to 'path'
 
Method Summary
static boolean doesImplement(java.lang.Class cl, java.lang.Class target)
          check if a class - or its parents - implement or extend an other class.
 java.lang.Class doMatch(java.lang.String key, java.io.InputStream is, java.lang.Class target)
          You don't have to use this method. public from interface but only for internal use.
 java.lang.ClassLoader getClassLoader()
          return the current ClassLoader this ClassFinder uses.
static ClassFinder getDefaultInstance()
          return the default ClasssFinder.
 java.lang.Class[] whoImplement(java.lang.Class target)
          Find all classes using 'target'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFinder

public ClassFinder(java.lang.String path)
create a new class finder, using cahce and stating scanning down to 'path'

Parameters:
path - package to start scanning from. Can be null and dot or slash formed (ie foo.bar or foo/bar)
Since:
1.2

ClassFinder

public ClassFinder(java.lang.ClassLoader loader,
                   java.lang.String path,
                   boolean cache)
create a new finder using a specific class loader.

Parameters:
loader -
path - package to start scanning from. Can be null and dot or slash formed (ie foo.bar or foo/bar)
cache - if false, will no cache result
Since:
1.2

ClassFinder

public ClassFinder(java.lang.ClassLoader loader,
                   boolean cache)
create a new finder using a specific class loader.

Parameters:
loader -
cache - if false, will no cache result

ClassFinder

public ClassFinder(boolean cache)
create a new finder using the default class loader.

if cache==true, any result will be cached for further request.

nota : scanning is mempory and cpu consuming process. disabling the cache is not recommended.

if you need it, prefer ClassFinder(ClassLoader loader, boolean cache)

Parameters:
cache - if false, will no cache result
Method Detail

getDefaultInstance

public static ClassFinder getDefaultInstance()
return the default ClasssFinder.

Use this method unled you really want to extend your own ClassLoader, or you want to extend the application with non system classes directory

Returns:
default ClassFinder
See Also:
DynamicClassLoader

getClassLoader

public java.lang.ClassLoader getClassLoader()
return the current ClassLoader this ClassFinder uses.

Returns:
ClassLoader

whoImplement

public java.lang.Class[] whoImplement(java.lang.Class target)
                               throws java.io.IOException
Find all classes using 'target'. Can mean implementing an interface, extending a class or using an annoation (since 1.2). For annoation, must be RetentionPolicy.RUNTIME and ElementType.CONSTRUCTOR

Parameters:
target - base class / interface to look for
Returns:
list of matches ; can be empty but never null
Throws:
java.io.IOException

doMatch

public java.lang.Class doMatch(java.lang.String key,
                               java.io.InputStream is,
                               java.lang.Class target)
                        throws java.io.IOException
You don't have to use this method. public from interface but only for internal use.

Parameters:
key -
is -
target -
Returns:
Throws:
java.io.IOException

doesImplement

public static boolean doesImplement(java.lang.Class cl,
                                    java.lang.Class target)
check if a class - or its parents - implement or extend an other class.

Parameters:
cl - class to look at
target - class to look for
Returns: