Class PackageNamesScanner
- java.lang.Object
-
- org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter
-
- org.glassfish.jersey.server.internal.scanning.PackageNamesScanner
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.util.Iterator<java.lang.String>
,ResourceFinder
public final class PackageNamesScanner extends AbstractResourceFinderAdapter
A scanner that recursively scans URI-based resources present in a set of package names, and nested package names of that set. (Recursive scanning of nested packages can be disabled using a proper constructor.)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. TheJarZipSchemeResourceFinderFactory
for "jar" or "zip" URI schemes to jar resources. TheVfsSchemeResourceFinderFactory
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 ofUriSchemeResourceFinderFactory
.If a URI scheme is not supported a
ResourceFinderException
will be thrown and package scanning deployment will fail.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PackageNamesScanner.ResourcesProvider
Find resources with a given name and class loader.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description PackageNamesScanner(java.lang.ClassLoader classLoader, java.lang.String[] packages, boolean recursive)
Scan a set of packages using the providedClassLoader
.PackageNamesScanner(java.lang.String[] packages, boolean recursive)
Scan a set of packages using a contextClassLoader
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 theResourceFinder
instance.static void
setResourcesProvider(PackageNamesScanner.ResourcesProvider provider)
Set thePackageNamesScanner.ResourcesProvider
implementation to find resources.private java.lang.String
toExternalForm(java.net.URL u)
private java.net.URI
toURI(java.net.URL url)
-
Methods inherited from class org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter
remove
-
-
-
-
Field Detail
-
recursive
private final boolean recursive
-
packages
private final java.lang.String[] packages
-
classloader
private final java.lang.ClassLoader classloader
-
finderFactories
private final java.util.Map<java.lang.String,UriSchemeResourceFinderFactory> finderFactories
-
compositeResourceFinder
private CompositeResourceFinder compositeResourceFinder
-
-
Constructor Detail
-
PackageNamesScanner
public PackageNamesScanner(java.lang.String[] packages, boolean recursive)
Scan a set of packages using a contextClassLoader
. Therecursive
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
).- Parameters:
packages
- an array of package names.recursive
- if (true
the packages will be scanned recursively together with any nested packages, iffalse
only the explicitly listed packages will be scanned.
-
PackageNamesScanner
public PackageNamesScanner(java.lang.ClassLoader classLoader, java.lang.String[] packages, boolean recursive)
Scan a set of packages using the providedClassLoader
. Therecursive
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
).- Parameters:
classLoader
- theClassLoader
to load classes from.packages
- an array of package names.recursive
- if (true
the packages will be scanned recursively together with any nested packages, iffalse
only the explicitly listed packages will be scanned.
-
-
Method Detail
-
add
private void add(UriSchemeResourceFinderFactory uriSchemeResourceFinderFactory)
-
hasNext
public boolean hasNext()
-
next
public java.lang.String next()
-
open
public java.io.InputStream open()
Description copied from interface:ResourceFinder
Open current resource.- Returns:
- input stream from which current resource can be loaded.
-
close
public void close()
Description copied from class:AbstractResourceFinderAdapter
Default implementation of#close()
which does nothing.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceResourceFinder
- Overrides:
close
in classAbstractResourceFinderAdapter
-
reset
public void reset()
Description copied from interface:ResourceFinder
Reset theResourceFinder
instance. 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 java.lang.SecurityException
Set thePackageNamesScanner.ResourcesProvider
implementation 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:
java.lang.SecurityException
- if the resources provider cannot be set.
-
addResourceFinder
private void addResourceFinder(java.net.URI u)
-
toURI
private java.net.URI toURI(java.net.URL url) throws java.net.URISyntaxException
- Throws:
java.net.URISyntaxException
-
toExternalForm
private java.lang.String toExternalForm(java.net.URL u)
-
-