public final class PackageNamesScanner extends AbstractResourceFinderAdapter
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
PackageNamesScanner.ResourcesProvider
Find resources with a given name and class loader.
|
| Modifier and Type | Field and Description |
|---|---|
private java.lang.ClassLoader |
classloader |
private CompositeResourceFinder |
compositeResourceFinder |
private java.util.Map<java.lang.String,UriSchemeResourceFinderFactory> |
finderFactories |
private java.lang.String[] |
packages |
private boolean |
recursive |
| Constructor and Description |
|---|
PackageNamesScanner(java.lang.ClassLoader classLoader,
java.lang.String[] packages,
boolean recursive)
Scan a set of packages using the provided
ClassLoader. |
PackageNamesScanner(java.lang.String[] packages,
boolean recursive)
Scan a set of packages using a context
ClassLoader. |
| Modifier and Type | Method and Description |
|---|---|
private void |
add(UriSchemeResourceFinderFactory uriSchemeResourceFinderFactory) |
private void |
addResourceFinder(java.net.URI u) |
void |
close()
Default implementation of
#close() which does nothing. |
boolean |
hasNext() |
private void |
init() |
java.lang.String |
next() |
java.io.InputStream |
open()
Open current resource.
|
void |
reset()
Reset the
ResourceFinder instance. |
static void |
setResourcesProvider(PackageNamesScanner.ResourcesProvider provider)
Set the
PackageNamesScanner.ResourcesProvider implementation to find resources. |
private java.lang.String |
toExternalForm(java.net.URL u) |
private java.net.URI |
toURI(java.net.URL url) |
removeprivate final boolean recursive
private final java.lang.String[] packages
private final java.lang.ClassLoader classloader
private final java.util.Map<java.lang.String,UriSchemeResourceFinderFactory> finderFactories
private CompositeResourceFinder compositeResourceFinder
public PackageNamesScanner(java.lang.String[] packages,
boolean recursive)
ClassLoader.
The recursive flag determines whether the packages will be scanned recursively
together with their nested packages (true) or if only the specified packages
shall be scanned (false).packages - an array of package names.recursive - if (true the packages will be scanned recursively together with
any nested packages, if false only the explicitly listed packages
will be scanned.public PackageNamesScanner(java.lang.ClassLoader classLoader,
java.lang.String[] packages,
boolean recursive)
ClassLoader.
The recursive flag determines whether the packages will be scanned recursively
together with their nested packages (true) or if only the specified packages
shall be scanned (false).classLoader - the ClassLoader to load classes from.packages - an array of package names.recursive - if (true the packages will be scanned recursively together with
any nested packages, if false only the explicitly listed packages
will be scanned.private void add(UriSchemeResourceFinderFactory uriSchemeResourceFinderFactory)
public boolean hasNext()
public java.lang.String next()
public java.io.InputStream open()
ResourceFinderpublic void close()
AbstractResourceFinderAdapter#close() which does nothing.close in interface java.lang.AutoCloseableclose in interface ResourceFinderclose in class AbstractResourceFinderAdapterpublic void reset()
ResourceFinderResourceFinder instance.
Upon calling this method the implementing class MUST reset its internal state to the initial state.private void init()
public static void setResourcesProvider(PackageNamesScanner.ResourcesProvider provider) throws java.lang.SecurityException
PackageNamesScanner.ResourcesProvider implementation to find resources.
This method should be invoked before any package scanning is performed otherwise the functionality method will be utilized.
provider - the resources provider.java.lang.SecurityException - if the resources provider cannot be set.private void addResourceFinder(java.net.URI u)
private java.net.URI toURI(java.net.URL url)
throws java.net.URISyntaxException
java.net.URISyntaxExceptionprivate java.lang.String toExternalForm(java.net.URL u)