Class URLLocator

  • All Implemented Interfaces:
    Locator

    public final class URLLocator
    extends AbstractLocator

    A specialized Locator implementation that operates on URLs.

    This is a straight forward implementation of the Locator interface that is based on a URL. New instances can be created using one of the getInstance() methods by either passing in a URL or its string representation. The implementation of the getURL() method then directly returns this URL. Other methods defined in the Locator interface are implemented as empty stubs only.

    Instances of this class are immutable and thus can be shared between multiple threads.

    Version:
    $Id: URLLocator.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Method Detail

      • getInstance

        public static URLLocator getInstance​(URL url)
        Returns a URLLocator instance for the specified URL.
        Parameters:
        url - the URL (must not be null)
        Returns:
        the URLLocator instance for this URL
        Throws:
        IllegalArgumentException - if the URL is null
      • getInstance

        public static URLLocator getInstance​(String sUrl)
        Returns a URLLocator instance for the URL specified as string. This method converts the given string into a URL and returns a corresponding URLLocator.
        Parameters:
        sUrl - the URL as string
        Returns:
        the URLLocator for this URL
        Throws:
        LocatorException - if the string cannot be transformed into a URL
        IllegalArgumentException - if the string is null
      • getURL

        public URL getURL()
        Returns the URL represented by this locator. This is simply the URL that was specified when this instance was created.
        Returns:
        the URL represented by this locator
      • equals

        public boolean equals​(Object obj)
        Compares this object with another one. Two instance of this class are equal if an only if they refer to the same URL.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether these objects are equal
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code
      • toString

        public String toString()
        Returns a string representation of this object. This string will contain the URL underlying this locator.
        Overrides:
        toString in class Object
        Returns:
        a string for this object