public final class ClassPathLocator extends AbstractLocator
A specific Locator
implementation that can obtain resources from
the class path.
This class is initialized with a resource name. The getURL()
method tries to find this resource from the class path (using the
LocatorUtils
class. No caching is performed; each invocation of
getURL()
will look up the resource. Because a lookup might depend
on the context class loader, multiple invocations of getURL()
may
yield different results. In addition, it is possible to specify the
class loader to be used for resource lookup.
Instances of this class are created using the getInstance()
factory method. They are immutable and thus can be shared between multiple
threads.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this object with another one.
|
ClassLoader |
getClassLoader()
Returns the default class loader used by this locator when looking up the
resource name.
|
static ClassPathLocator |
getInstance(String resourceName)
Returns a
ClassPathLocator instance for the specified
resource name. |
static ClassPathLocator |
getInstance(String resourceName,
ClassLoader cl)
Returns a
ClassPathLocator instance which looks up the specified
resource name using the given class loader. |
String |
getResourceName()
Returns the name of the resource represented by this locator.
|
URL |
getURL()
Returns the URL for the represented resource.
|
int |
hashCode()
Returns a hash code for this object.
|
String |
toString()
Returns a string representation of this object.
|
getFile, getInputStream
public String getResourceName()
public ClassLoader getClassLoader()
getInstance()
method. It may be null if no specific class
loader was provided when constructing this object.public static ClassPathLocator getInstance(String resourceName)
ClassPathLocator
instance for the specified
resource name.resourceName
- the name of the resource (must not be null)IllegalArgumentException
- if the resource name is nullpublic static ClassPathLocator getInstance(String resourceName, ClassLoader cl)
ClassPathLocator
instance which looks up the specified
resource name using the given class loader. If a ClassLoader
reference is provided, this class loader is tried first when resolving
the resource name. Otherwise, the default order of class loaders is used
as implemented in LocatorUtils
.resourceName
- the name of the resource (must not be null)cl
- an optional class loader to be used for resource lookupIllegalArgumentException
- if the resource name is nullpublic URL getURL()
LocatorUtils.locateResource(String, ClassLoader)
method to
find the resource on the class path. If this fails, an exception is
thrown.LocatorException
- if the resource URL cannot be obtainedpublic boolean equals(Object obj)
public int hashCode()
Copyright © 2016 The JGUIraffe Team. All rights reserved.