org.glassfish.jersey.server.internal.scanning
Class PackageNamesScanner

java.lang.Object
  extended by org.glassfish.jersey.server.internal.scanning.PackageNamesScanner
All Implemented Interfaces:
java.util.Iterator<java.lang.String>, ResourceFinder

public class PackageNamesScanner
extends java.lang.Object
implements ResourceFinder

A scanner that recursively scans URI-based resources present in a set of package names, and sub-package names of that set.

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.

Author:
Paul Sandoz, Jakub Podlesak (jakub.podlesak at oracle.com)

Nested Class Summary
static class PackageNamesScanner.ResourcesProvider
          Find resources with a given name and class loader.
 
Constructor Summary
PackageNamesScanner(java.lang.ClassLoader classloader, java.lang.String[] packages)
          Scan from a set of packages using provided ClassLoader.
PackageNamesScanner(java.lang.String[] packages)
          Scan from a set of packages using the context ClassLoader.
 
Method Summary
 boolean hasNext()
           
 java.lang.String next()
           
 java.io.InputStream open()
          Open current resource.
 void remove()
          

This operation is not supported by ResourceFinder & throws UnsupportedOperationException when invoked.

 void reset()
          Reset the ResourceFinder instance.
static void setResourcesProvider(PackageNamesScanner.ResourcesProvider provider)
          Set the PackageNamesScanner.ResourcesProvider implementation to find resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageNamesScanner

public PackageNamesScanner(java.lang.String[] packages)
Scan from a set of packages using the context ClassLoader.

Parameters:
packages - an array of package names.

PackageNamesScanner

public PackageNamesScanner(java.lang.ClassLoader classloader,
                           java.lang.String[] packages)
Scan from a set of packages using provided ClassLoader.

Parameters:
classloader - the ClassLoader to load classes from.
packages - an array of package names.
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<java.lang.String>

next

public java.lang.String next()
Specified by:
next in interface java.util.Iterator<java.lang.String>

remove

public void remove()
Description copied from interface: ResourceFinder

This operation is not supported by ResourceFinder & throws UnsupportedOperationException when invoked.

Specified by:
remove in interface java.util.Iterator<java.lang.String>
Specified by:
remove in interface ResourceFinder

open

public java.io.InputStream open()
Description copied from interface: ResourceFinder
Open current resource.

Specified by:
open in interface ResourceFinder
Returns:
input stream from which current resource can be loaded.

reset

public void reset()
Description copied from interface: ResourceFinder
Reset the ResourceFinder instance.

Upon calling this method the implementing class MUST reset its internal state to the initial state.

Specified by:
reset in interface ResourceFinder

setResourcesProvider

public static void setResourcesProvider(PackageNamesScanner.ResourcesProvider provider)
                                 throws java.lang.SecurityException
Set the PackageNamesScanner.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.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.