Class PackageNamesScanner
- All Implemented Interfaces:
AutoCloseable, Iterator<String>, ResourceFinder
The URIs for a package name are obtained, by default, by invoking
ClassLoader.getResources(java.lang.String) with the parameter that
is the package name with "." replaced by "/".
Each URI is then scanned using a registered UriSchemeResourceFinderFactory that
supports the URI scheme.
The following are registered by default.
The FileSchemeResourceFinderFactory for "file" URI schemes.
The JarZipSchemeResourceFinderFactory for "jar" or "zip" URI schemes to jar
resources.
The VfsSchemeResourceFinderFactory for the JBoss-based "vfsfile" and "vfszip"
URI schemes.
Further schemes may be registered by registering an implementation of
UriSchemeResourceFinderFactory in the META-INF/services file whose name is the
the fully qualified class name of UriSchemeResourceFinderFactory.
If a URI scheme is not supported a ResourceFinderException will be thrown
and package scanning deployment will fail.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFind resources with a given name and class loader. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassLoaderprivate CompositeResourceFinderprivate final Map<String, UriSchemeResourceFinderFactory> private final String[]private final boolean -
Constructor Summary
ConstructorsConstructorDescriptionPackageNamesScanner(ClassLoader classLoader, String[] packages, boolean recursive) Scan a set of packages using the providedClassLoader.PackageNamesScanner(String[] packages, boolean recursive) Scan a set of packages using a contextClassLoader. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidadd(UriSchemeResourceFinderFactory uriSchemeResourceFinderFactory) private voidvoidclose()Default implementation of#close()which does nothing.booleanhasNext()private voidinit()next()open()Open current resource.voidreset()Reset theResourceFinderinstance.static voidSet thePackageNamesScanner.ResourcesProviderimplementation to find resources.private Stringprivate URIMethods inherited from class AbstractResourceFinderAdapter
removeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
Field Details
-
recursive
private final boolean recursive -
packages
-
classloader
-
finderFactories
-
compositeResourceFinder
-
-
Constructor Details
-
PackageNamesScanner
Scan a set of packages using a contextClassLoader. Therecursiveflag determines whether the packages will be scanned recursively together with their nested packages (true) or if only the specified packages shall be scanned (false).- Parameters:
packages- an array of package names.recursive- if (truethe packages will be scanned recursively together with any nested packages, iffalseonly the explicitly listed packages will be scanned.
-
PackageNamesScanner
Scan a set of packages using the providedClassLoader. Therecursiveflag determines whether the packages will be scanned recursively together with their nested packages (true) or if only the specified packages shall be scanned (false).- Parameters:
classLoader- theClassLoaderto load classes from.packages- an array of package names.recursive- if (truethe packages will be scanned recursively together with any nested packages, iffalseonly the explicitly listed packages will be scanned.
-
-
Method Details
-
add
-
hasNext
public boolean hasNext() -
next
-
open
Description copied from interface:ResourceFinderOpen current resource.- Returns:
- input stream from which current resource can be loaded.
-
close
public void close()Description copied from class:AbstractResourceFinderAdapterDefault implementation of#close()which does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceResourceFinder- Overrides:
closein classAbstractResourceFinderAdapter
-
reset
public void reset()Description copied from interface:ResourceFinderReset theResourceFinderinstance. Upon calling this method the implementing class MUST reset its internal state to the initial state. -
init
private void init() -
setResourcesProvider
public static void setResourcesProvider(PackageNamesScanner.ResourcesProvider provider) throws SecurityException Set thePackageNamesScanner.ResourcesProviderimplementation to find resources.This method should be invoked before any package scanning is performed otherwise the functionality method will be utilized.
- Parameters:
provider- the resources provider.- Throws:
SecurityException- if the resources provider cannot be set.
-
addResourceFinder
-
toURI
- Throws:
URISyntaxException
-
toExternalForm
-