Class PackageNamesScanner
- java.lang.Object
-
- org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter
-
- org.glassfish.jersey.server.internal.scanning.PackageNamesScanner
-
- All Implemented Interfaces:
AutoCloseable,Iterator<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
UriSchemeResourceFinderFactorythat supports the URI scheme.The following are registered by default. The
FileSchemeResourceFinderFactoryfor "file" URI schemes. TheJarZipSchemeResourceFinderFactoryfor "jar" or "zip" URI schemes to jar resources. TheVfsSchemeResourceFinderFactoryfor the JBoss-based "vfsfile" and "vfszip" URI schemes.Further schemes may be registered by registering an implementation of
UriSchemeResourceFinderFactoryin the META-INF/services file whose name is the fully qualified class name ofUriSchemeResourceFinderFactory.If a URI scheme is not supported a
ResourceFinderExceptionwill be thrown and package scanning deployment will fail.- Author:
- Paul Sandoz, Jakub Podlesak
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPackageNamesScanner.ResourcesProviderFind resources with a given name and class loader.
-
Constructor Summary
Constructors Constructor Description PackageNamesScanner(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Default implementation of#close()which does nothing.ClassLoadergetClassloader()booleanhasNext()Stringnext()InputStreamopen()Open current resource.voidreset()Reset theResourceFinderinstance.static voidsetResourcesProvider(PackageNamesScanner.ResourcesProvider provider)Set thePackageNamesScanner.ResourcesProviderimplementation to find resources.-
Methods inherited from class org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter
remove
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
PackageNamesScanner
public PackageNamesScanner(String[] packages, boolean recursive)
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
public PackageNamesScanner(ClassLoader classLoader, String[] packages, boolean recursive)
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 Detail
-
hasNext
public boolean hasNext()
-
next
public String next()
-
open
public InputStream 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.
-
getClassloader
public ClassLoader getClassloader()
-
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.
-
-