net.sf.jguiraffe.locators
Class ClassPathLocator

java.lang.Object
  extended by net.sf.jguiraffe.locators.AbstractLocator
      extended by net.sf.jguiraffe.locators.ClassPathLocator
All Implemented Interfaces:
Locator

public 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 takes the context class loader into account, multiple invocations of getURL() may yield different results.

Instances of this class are created using the getInstance() factory method. They are immutable and thus can be shared between multiple threads.

Version:
$Id: ClassPathLocator.java 156 2009-03-03 21:04:47Z oheger $
Author:
Oliver Heger

Method Summary
 boolean equals(java.lang.Object obj)
          Compares this object with another one.
static ClassPathLocator getInstance(java.lang.String resourceName)
          Returns a ClassPathLocator instance for the specified resource name.
 java.lang.String getResourceName()
          Returns the name of the resource represented by this locator.
 java.net.URL getURL()
          Returns the URL for the represented resource.
 int hashCode()
          Returns a hash code for this object.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class net.sf.jguiraffe.locators.AbstractLocator
getFile, getInputStream
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getResourceName

public java.lang.String getResourceName()
Returns the name of the resource represented by this locator.

Returns:
the resource's name

getInstance

public static ClassPathLocator getInstance(java.lang.String resourceName)
Returns a ClassPathLocator instance for the specified resource name.

Parameters:
resourceName - the name of the resource (must not be null)
Returns:
the instance with this resource name
Throws:
java.lang.IllegalArgumentException - if the resource name is null

getURL

public java.net.URL getURL()
Returns the URL for the represented resource. This implementation uses the locateResource() method of LocatorUtils to find the resource on the class path. If this fails, an exception is thrown.

Returns:
the URL to the resource
Throws:
LocatorException - if the resource URL cannot be obtained

equals

public boolean equals(java.lang.Object obj)
Compares this object with another one. Two instances of this class are equal if and only if they refer to the same resource name.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code

toString

public java.lang.String toString()
Returns a string representation of this object. This string will at least contain the resource name used by this locator.

Overrides:
toString in class java.lang.Object
Returns:
a string for this object


Copyright © 2009 The JGUIraffe Team. All Rights Reserved.