Class ALfnHierarchicalResourceLocation

java.lang.Object
com.luciad.fusion.platform.resource.ALfnHierarchicalResourceLocation
All Implemented Interfaces:
ILfnResourceLocation

public abstract class ALfnHierarchicalResourceLocation extends Object implements ILfnResourceLocation
A resource location implementation that assumes hierarchical location encoding format. Common examples of resources with such an encoding format are file systems paths and the path component of many URIs.

This base class assumes that hierarchical components are separated by a fixed separator and that the encoded location starts with a fixed prefix.

Since:
2022.1
  • Constructor Details

    • ALfnHierarchicalResourceLocation

      protected ALfnHierarchicalResourceLocation(String aPrefix, String aSeparator)
      Creates a new instance.
      Parameters:
      aPrefix - the fixed prefix (for instance http:// for web resources)
      aSeparator - the separator used to separate hierarchical components (for instance / for URI paths)
  • Method Details

    • relativize

      public String relativize(ILfnResourceLocation aTarget)
      Generates a "relative" location for the given target, using this location as a base.

      The relative location is often encoded using elements like .. to denote a parent and /name to denote a child named name. However, implementations are free to encode the relative location in any way they please. The only requirement is that base.resolve(base.relativize(aTarget)).equals(aTarget).

      If there is no ancestry relationship between the target and this location, implementations must return the full encoded form of the target.

      The implementation in ALfnHierarchicalResourceLocation finds a common ancestor between this location and aTarget. If there is no common ancestor, aTarget's location is returned. If there is a common ancestor, the returned value starts with a number of ".." components equal to the number of times the ILfnResourceLocation.getParent() has to be used to get from this location to the common ancestor. Then the hierarchical components from the common ancestor to aTarget are added. The components are separated using the separator provided to the constructor.

      Specified by:
      relativize in interface ILfnResourceLocation
      Parameters:
      aTarget - the location to provide a relative location for
      Returns:
      the relative location, from this location
      See Also:
    • resolve

      public ILfnResourceLocation resolve(String aRelative)
      Resolve a "relative" location against this resource location.

      The relative location was either produced by ILfnResourceLocation.relativize(ILfnResourceLocation) or a manipulation of another resource location's file name. Note that this means that the "relative" location may actually be the full encoded form of a resource location.

      If the relative location cannot be resolved, implementations should throw IllegalArgumentException.

      The returned resource location must be compatible with this location.

      The implementation in ALfnHierarchicalResourceLocation uses the prefix provided to the constructor to determine whether aRelative is actually an absolute encoded location. If it is absolute, resolution is done on only aRelative. If it is not absolute, resolution is done on the combination of this location's encoded form and the aRelative.

      Resolution is performed by removing the prefix and splitting the remainder by the separator provided to the constructor. Empty components and "." components are considered redundant and removed. Then, consecutive name and ".." components are removed. If at any point the list of hierarchical components starts with "..", this is considered invalid and an exception is thrown. Finally, a new resolved location is constructed using the resulting list of components and returned.

      Specified by:
      resolve in interface ILfnResourceLocation
      Parameters:
      aRelative - the resource location to resolve
      Returns:
      the resolved location
      See Also:
    • createResolvedLocation

      protected abstract ILfnResourceLocation createResolvedLocation(List<String> aResolvedComponents)
      Creates a new resource location from the hierarchical components determined by resolve(String).
      Parameters:
      aResolvedComponents - the hierarchical components
      Returns:
      the resource location
    • equals

      public boolean equals(Object aObject)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object