Class LocatorWrapper

  • All Implemented Interfaces:
    Locator

    public class LocatorWrapper
    extends Object
    implements Locator

    A wrapper implementation for locators.

    Most concrete Locator implementations in this package cannot be extended. (They do not have public constructors, instances can only be created through static factory methods.) If a custom Locator implementation is to be created that can benefit from an existing locator, composition can be used instead of inheritance. To simplify this, this wrapper class is introduced.

    LocatorWrapper is an implementation of the Locator interface that is based on an underlying Locator object. All methods are implemented to delegate to this wrapped object. This way inheritance can be emulated by implementing desired functionality before or after delegating to the wrapped Locator (or skipping the call to this object at all).

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

      • LocatorWrapper

        public LocatorWrapper​(Locator wrapped)
        Creates a new instance of LocatorWrapper and initializes it with the given wrapped locator. Per default, all methods of this class delegate to this object. It must not be null.
        Parameters:
        wrapped - the wrapped locator (must not be null)
        Throws:
        IllegalArgumentException - if the wrapped locator is null
    • Method Detail

      • getWrappedLocator

        public Locator getWrappedLocator()
        Returns the wrapped Locator. This is the object this instance will delegate to.
        Returns:
        the wrapped Locator
      • getFile

        public File getFile()
        Returns the file this locator points to. This implementation delegates to the wrapped Locator.
        Specified by:
        getFile in interface Locator
        Returns:
        the file
      • getInputStream

        public InputStream getInputStream()
                                   throws IOException
        Returns the input stream this locator points to. This implementation delegates to the wrapped Locator.
        Specified by:
        getInputStream in interface Locator
        Returns:
        the input stream
        Throws:
        IOException - if an error occurs
      • getURL

        public URL getURL()
        Returns the URL this locator points to. This implementation delegates to the wrapped Locator.
        Specified by:
        getURL in interface Locator
        Returns:
        the URL