org.apache.camel.impl
Class DefaultPackageScanClassResolver

java.lang.Object
  extended by org.apache.camel.impl.DefaultPackageScanClassResolver
All Implemented Interfaces:
PackageScanClassResolver
Direct Known Subclasses:
EclipsePackageScanClassResolver, OsgiPackageScanClassResolver, WebSpherePackageScanClassResolver

public class DefaultPackageScanClassResolver
extends Object
implements PackageScanClassResolver

Default implement of PackageScanClassResolver


Field Summary
protected  org.slf4j.Logger log
           
 
Constructor Summary
DefaultPackageScanClassResolver()
           
 
Method Summary
 void addClassLoader(ClassLoader classLoader)
          Adds the class loader to the existing loaders
 void addFilter(PackageScanFilter filter)
          Add a filter that will be applied to all scan operations
protected  void addIfMatching(PackageScanFilter test, String fqn, Set<Class<?>> classes)
          Add the class designated by the fully qualified class name provided to the set of resolved classes if and only if it is approved by the Test supplied.
protected  URL customResourceLocator(URL url)
           
protected  void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes)
           
protected  void find(PackageScanFilter test, String packageName, Set<Class<?>> classes)
           
 Set<Class<?>> findAnnotated(Class<? extends Annotation> annotation, String... packageNames)
          Attempts to discover classes that are annotated with to the annotation.
 Set<Class<?>> findAnnotated(Set<Class<? extends Annotation>> annotations, String... packageNames)
          Attempts to discover classes that are annotated with to the annotation.
 Set<Class<?>> findByFilter(PackageScanFilter filter, String... packageNames)
          Attempts to discover classes filter by the provided filter
 Set<Class<?>> findImplementations(Class parent, String... packageNames)
          Attempts to discover classes that are assignable to the type provided.
 Set<ClassLoader> getClassLoaders()
          Gets the ClassLoader instances that should be used when scanning for classes.
protected  Enumeration<URL> getResources(ClassLoader loader, String packageName)
          Strategy to get the resources by the given classloader.
 boolean isAcceptableScheme(String urlPath)
           
 void removeFilter(PackageScanFilter filter)
          Removes the filter
 void setAcceptableSchemes(String schemes)
           
 void setClassLoaders(Set<ClassLoader> classLoaders)
          Sets the ClassLoader instances that should be used when scanning for classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final transient org.slf4j.Logger log
Constructor Detail

DefaultPackageScanClassResolver

public DefaultPackageScanClassResolver()
Method Detail

addClassLoader

public void addClassLoader(ClassLoader classLoader)
Description copied from interface: PackageScanClassResolver
Adds the class loader to the existing loaders

Specified by:
addClassLoader in interface PackageScanClassResolver
Parameters:
classLoader - the loader to add

addFilter

public void addFilter(PackageScanFilter filter)
Description copied from interface: PackageScanClassResolver
Add a filter that will be applied to all scan operations

Specified by:
addFilter in interface PackageScanClassResolver
Parameters:
filter - filter to filter desired classes in all scan operations

removeFilter

public void removeFilter(PackageScanFilter filter)
Description copied from interface: PackageScanClassResolver
Removes the filter

Specified by:
removeFilter in interface PackageScanClassResolver
Parameters:
filter - filter to filter desired classes in all scan operations

setAcceptableSchemes

public void setAcceptableSchemes(String schemes)

isAcceptableScheme

public boolean isAcceptableScheme(String urlPath)

getClassLoaders

public Set<ClassLoader> getClassLoaders()
Description copied from interface: PackageScanClassResolver
Gets the ClassLoader instances that should be used when scanning for classes.

This implementation will return a new unmodifiable set containing the classloaders. Use the PackageScanClassResolver.addClassLoader(ClassLoader) method if you want to add new classloaders to the class loaders list.

Specified by:
getClassLoaders in interface PackageScanClassResolver
Returns:
the class loaders to use

setClassLoaders

public void setClassLoaders(Set<ClassLoader> classLoaders)
Description copied from interface: PackageScanClassResolver
Sets the ClassLoader instances that should be used when scanning for classes. If none is set then the context classloader will be used.

Specified by:
setClassLoaders in interface PackageScanClassResolver
Parameters:
classLoaders - loaders to use when scanning for classes

findAnnotated

public Set<Class<?>> findAnnotated(Class<? extends Annotation> annotation,
                                   String... packageNames)
Description copied from interface: PackageScanClassResolver
Attempts to discover classes that are annotated with to the annotation.

Specified by:
findAnnotated in interface PackageScanClassResolver
Parameters:
annotation - the annotation that should be present on matching classes
packageNames - one or more package names to scan (including subpackages) for classes
Returns:
the classes found, returns an empty set if none found

findAnnotated

public Set<Class<?>> findAnnotated(Set<Class<? extends Annotation>> annotations,
                                   String... packageNames)
Description copied from interface: PackageScanClassResolver
Attempts to discover classes that are annotated with to the annotation.

Specified by:
findAnnotated in interface PackageScanClassResolver
Parameters:
annotations - the annotations that should be present (any of them) on matching classes
packageNames - one or more package names to scan (including subpackages) for classes
Returns:
the classes found, returns an empty set if none found

findImplementations

public Set<Class<?>> findImplementations(Class parent,
                                         String... packageNames)
Description copied from interface: PackageScanClassResolver
Attempts to discover classes that are assignable to the type provided. In the case that an interface is provided this method will collect implementations. In the case of a non-interface class, subclasses will be collected.

Specified by:
findImplementations in interface PackageScanClassResolver
Parameters:
parent - the class of interface to find subclasses or implementations of
packageNames - one or more package names to scan (including subpackages) for classes
Returns:
the classes found, returns an empty set if none found

findByFilter

public Set<Class<?>> findByFilter(PackageScanFilter filter,
                                  String... packageNames)
Description copied from interface: PackageScanClassResolver
Attempts to discover classes filter by the provided filter

Specified by:
findByFilter in interface PackageScanClassResolver
Parameters:
filter - filter to filter desired classes.
packageNames - one or more package names to scan (including subpackages) for classes
Returns:
the classes found, returns an empty set if none found

find

protected void find(PackageScanFilter test,
                    String packageName,
                    Set<Class<?>> classes)

find

protected void find(PackageScanFilter test,
                    String packageName,
                    ClassLoader loader,
                    Set<Class<?>> classes)

customResourceLocator

protected URL customResourceLocator(URL url)
                             throws IOException
Throws:
IOException

getResources

protected Enumeration<URL> getResources(ClassLoader loader,
                                        String packageName)
                                 throws IOException
Strategy to get the resources by the given classloader.

Notice that in WebSphere platforms there is a WebSpherePackageScanClassResolver to take care of WebSphere's odditiy of resource loading.

Parameters:
loader - the classloader
packageName - the packagename for the package to load
Returns:
URL's for the given package
Throws:
IOException - is thrown by the classloader

addIfMatching

protected void addIfMatching(PackageScanFilter test,
                             String fqn,
                             Set<Class<?>> classes)
Add the class designated by the fully qualified class name provided to the set of resolved classes if and only if it is approved by the Test supplied.

Parameters:
test - the test used to determine if the class matches
fqn - the fully qualified name of a class


Apache CAMEL