org.reflections.util
Class ConfigurationBuilder

java.lang.Object
  extended by org.reflections.util.ConfigurationBuilder
All Implemented Interfaces:
Configuration

public class ConfigurationBuilder
extends Object
implements Configuration

a fluent builder for Configuration, to be used for constructing a Reflections instance

usage:

      new Reflections(
          new ConfigurationBuilder()
              .filterInputsBy(new FilterBuilder().include("your project's common package prefix here..."))
              .setUrls(ClasspathHelper.forClassLoader())
              .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));
 

executorService is used optionally used for parallel scanning. if value is null then scanning is done in a simple for loop

defaults: accept all for inputsFilter, executorService is null, serializer is XmlSerializer


Field Summary
protected  MetadataAdapter metadataAdapter
           
 
Constructor Summary
ConfigurationBuilder()
           
 
Method Summary
 boolean acceptsInput(String inputFqn)
          the fully qualified name filter used to filter types to be scanned
 ConfigurationBuilder addClassLoader(ClassLoader classLoader)
          add class loader, might be used for resolving methods/fields
 ConfigurationBuilder addClassLoaders(ClassLoader... classLoaders)
          add class loader, might be used for resolving methods/fields
 ConfigurationBuilder addClassLoaders(Collection<ClassLoader> classLoaders)
          add class loader, might be used for resolving methods/fields
 ConfigurationBuilder addScanners(Scanner... scanners)
          set the scanners instances for scanning different metadata
 ConfigurationBuilder addUrls(Collection<URL> urls)
          add urls to be scanned
 ConfigurationBuilder addUrls(URL... urls)
          add urls to be scanned
 Reflections build()
          instantiates a Reflections object using this Configuration
static ConfigurationBuilder build(Object... params)
          constructs a ConfigurationBuilder using the given parameters, in a non statically typed way.
 ConfigurationBuilder filterInputsBy(com.google.common.base.Predicate<? super String> inputsFilter)
          sets the input filter for all resources to be scanned
 ClassLoader[] getClassLoaders()
          get class loader, might be used for scanning or resolving methods/fields
 ExecutorService getExecutorService()
          executor service used to scan files if null, scanning is done in a simple for loop
 MetadataAdapter getMetadataAdapter()
          returns the metadata adapter.
 Set<Scanner> getScanners()
          the scanner instances used for scanning different metadata
 Serializer getSerializer()
          the default serializer to use when saving Reflection
 Set<URL> getUrls()
          the urls to be scanned
 ConfigurationBuilder setExecutorService(ExecutorService executorService)
          sets the executor service used for scanning.
 ConfigurationBuilder setMetadataAdapter(MetadataAdapter metadataAdapter)
          sets the metadata adapter used to fetch metadata from classes
 ConfigurationBuilder setScanners(Scanner... scanners)
          set the scanners instances for scanning different metadata
 ConfigurationBuilder setSerializer(Serializer serializer)
          sets the serializer used when issuing Reflections.save(java.lang.String)
 ConfigurationBuilder setUrls(Collection<URL> urls)
          set the urls to be scanned
 ConfigurationBuilder setUrls(URL... urls)
          set the urls to be scanned
 ConfigurationBuilder useParallelExecutor()
          sets the executor service used for scanning to ThreadPoolExecutor with core size as Runtime.availableProcessors()
 ConfigurationBuilder useParallelExecutor(int availableProcessors)
          sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metadataAdapter

protected MetadataAdapter metadataAdapter
Constructor Detail

ConfigurationBuilder

public ConfigurationBuilder()
Method Detail

build

public static ConfigurationBuilder build(@Nullable
                                         Object... params)
constructs a ConfigurationBuilder using the given parameters, in a non statically typed way. that is, each element in params is guessed by it's type and populated into the configuration. use any parameter type in any order. this constructor uses instanceof on each param and instantiate a ConfigurationBuilder appropriately.


build

public Reflections build()
instantiates a Reflections object using this Configuration


getScanners

public Set<Scanner> getScanners()
Description copied from interface: Configuration
the scanner instances used for scanning different metadata

Specified by:
getScanners in interface Configuration

setScanners

public ConfigurationBuilder setScanners(Scanner... scanners)
set the scanners instances for scanning different metadata


addScanners

public ConfigurationBuilder addScanners(Scanner... scanners)
set the scanners instances for scanning different metadata


getUrls

public Set<URL> getUrls()
Description copied from interface: Configuration
the urls to be scanned

Specified by:
getUrls in interface Configuration

setUrls

public ConfigurationBuilder setUrls(Collection<URL> urls)
set the urls to be scanned

use ClasspathHelper convenient methods to get the relevant urls


setUrls

public ConfigurationBuilder setUrls(URL... urls)
set the urls to be scanned

use ClasspathHelper convenient methods to get the relevant urls


addUrls

public ConfigurationBuilder addUrls(Collection<URL> urls)
add urls to be scanned

use ClasspathHelper convenient methods to get the relevant urls


addUrls

public ConfigurationBuilder addUrls(URL... urls)
add urls to be scanned

use ClasspathHelper convenient methods to get the relevant urls


getMetadataAdapter

public MetadataAdapter getMetadataAdapter()
returns the metadata adapter. if javassist library exists in the classpath, this method returns JavassistAdapter otherwise defaults to JavaReflectionAdapter.

the JavassistAdapter is preferred in terms of performance and class loading.

Specified by:
getMetadataAdapter in interface Configuration

setMetadataAdapter

public ConfigurationBuilder setMetadataAdapter(MetadataAdapter metadataAdapter)
sets the metadata adapter used to fetch metadata from classes


acceptsInput

public boolean acceptsInput(String inputFqn)
Description copied from interface: Configuration
the fully qualified name filter used to filter types to be scanned

Specified by:
acceptsInput in interface Configuration

filterInputsBy

public ConfigurationBuilder filterInputsBy(com.google.common.base.Predicate<? super String> inputsFilter)
sets the input filter for all resources to be scanned

supply a Predicate or use the FilterBuilder


getExecutorService

public ExecutorService getExecutorService()
Description copied from interface: Configuration
executor service used to scan files if null, scanning is done in a simple for loop

Specified by:
getExecutorService in interface Configuration

setExecutorService

public ConfigurationBuilder setExecutorService(ExecutorService executorService)
sets the executor service used for scanning.


useParallelExecutor

public ConfigurationBuilder useParallelExecutor()
sets the executor service used for scanning to ThreadPoolExecutor with core size as Runtime.availableProcessors()

default is ThreadPoolExecutor with a single core


useParallelExecutor

public ConfigurationBuilder useParallelExecutor(int availableProcessors)
sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter

default is ThreadPoolExecutor with a single core


getSerializer

public Serializer getSerializer()
Description copied from interface: Configuration
the default serializer to use when saving Reflection

Specified by:
getSerializer in interface Configuration

setSerializer

public ConfigurationBuilder setSerializer(Serializer serializer)
sets the serializer used when issuing Reflections.save(java.lang.String)


getClassLoaders

public ClassLoader[] getClassLoaders()
get class loader, might be used for scanning or resolving methods/fields

Specified by:
getClassLoaders in interface Configuration

addClassLoader

public ConfigurationBuilder addClassLoader(ClassLoader classLoader)
add class loader, might be used for resolving methods/fields


addClassLoaders

public ConfigurationBuilder addClassLoaders(ClassLoader... classLoaders)
add class loader, might be used for resolving methods/fields


addClassLoaders

public ConfigurationBuilder addClassLoaders(Collection<ClassLoader> classLoaders)
add class loader, might be used for resolving methods/fields



Copyright © 2013. All Rights Reserved.