org.sonatype.guice.bean.reflect
Class URLClassSpace

java.lang.Object
  extended by org.sonatype.guice.bean.reflect.URLClassSpace
All Implemented Interfaces:
ClassSpace

public final class URLClassSpace
extends Object
implements ClassSpace

ClassSpace backed by a strongly-referenced ClassLoader and a URL class path.


Constructor Summary
URLClassSpace(ClassLoader loader)
          Creates a ClassSpace backed by a ClassLoader and its default class path.
For URLClassLoaders this is their expanded Class-Path; otherwise it is empty.
URLClassSpace(ClassLoader loader, URL[] path)
          Creates a ClassSpace backed by a ClassLoader with a restricted class path.
 
Method Summary
 DeferredClass<?> deferLoadClass(String name)
          Defers loading of the named class from the surrounding class space.
 boolean equals(Object rhs)
           
 Enumeration<URL> findEntries(String path, String glob, boolean recurse)
          Queries local class space content for entries matching the given pattern.
 URL getResource(String name)
          Queries the surrounding class space for the resource with the given name.
 Enumeration<URL> getResources(String name)
          Queries the surrounding class space for all resources with the given name.
 URL[] getURLs()
           
 int hashCode()
           
 Class<?> loadClass(String name)
          Loads the named class from the surrounding class space.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLClassSpace

public URLClassSpace(ClassLoader loader)
Creates a ClassSpace backed by a ClassLoader and its default class path.
For URLClassLoaders this is their expanded Class-Path; otherwise it is empty.

Parameters:
loader - The class loader to use when getting/finding resources

URLClassSpace

public URLClassSpace(ClassLoader loader,
                     URL[] path)
Creates a ClassSpace backed by a ClassLoader with a restricted class path.

Parameters:
loader - The class loader to use when getting resources
path - The class path to use when finding resources
See Also:
getResources(String), findEntries(String, String, boolean)
Method Detail

loadClass

public Class<?> loadClass(String name)
Description copied from interface: ClassSpace
Loads the named class from the surrounding class space.

Specified by:
loadClass in interface ClassSpace
Parameters:
name - The class name
Returns:
Class instance
See Also:
ClassLoader.loadClass(String)

deferLoadClass

public DeferredClass<?> deferLoadClass(String name)
Description copied from interface: ClassSpace
Defers loading of the named class from the surrounding class space.

Specified by:
deferLoadClass in interface ClassSpace
Parameters:
name - The class name
Returns:
Deferred class
See Also:
ClassLoader.loadClass(String)

getResource

public URL getResource(String name)
Description copied from interface: ClassSpace
Queries the surrounding class space for the resource with the given name.

Specified by:
getResource in interface ClassSpace
Parameters:
name - The resource name
Returns:
URL pointing to the resource; null if it wasn't found
See Also:
ClassLoader.getResource(String)

getResources

public Enumeration<URL> getResources(String name)
Description copied from interface: ClassSpace
Queries the surrounding class space for all resources with the given name.

Specified by:
getResources in interface ClassSpace
Parameters:
name - The resource name
Returns:
Sequence of URLs, one for each matching resource
See Also:
ClassLoader.getResources(String)

findEntries

public Enumeration<URL> findEntries(String path,
                                    String glob,
                                    boolean recurse)
Description copied from interface: ClassSpace
Queries local class space content for entries matching the given pattern.

Specified by:
findEntries in interface ClassSpace
Parameters:
path - The initial search directory; for example "META-INF"
glob - The filename glob pattern; for example "*.xml"
recurse - If true recurse into sub-directories; otherwise only search initial directory
Returns:
Sequence of URLs, one for each matching entry
See Also:
Bundle.findEntries(String, String, boolean)

getURLs

public URL[] getURLs()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object rhs)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010-2011 Sonatype, Inc.. All Rights Reserved.