Class LocationImpl

java.lang.Object
org.apache.struts2.util.location.LocationImpl
All Implemented Interfaces:
Serializable, Location

public class LocationImpl extends Object implements Location, Serializable
A simple immutable and serializable implementation of Location.
See Also:
  • Constructor Details

    • LocationImpl

      public LocationImpl(String description, String uri)
      Build a location for a given URI, with unknown line and column numbers.
      Parameters:
      description - description for location
      uri - the resource URI
    • LocationImpl

      public LocationImpl(String description, String uri, int line, int column)
      Build a location for a given URI and line and column numbers.
      Parameters:
      description - description for location
      uri - the resource URI
      line - the line number (starts at 1)
      column - the column number (starts at 1)
    • LocationImpl

      public LocationImpl(Location location)
      Copy constructor.
      Parameters:
      location - the location to be copied
    • LocationImpl

      public LocationImpl(String description, Location location)
      Create a location from an existing one, but with a different description
      Parameters:
      description - description for location
      location - location object
  • Method Details

    • get

      public static LocationImpl get(Location location)
      Obtain a LocationImpl from a Location. If location is already a LocationImpl, it is returned, otherwise it is copied.

      This method is useful when an immutable and serializable location is needed, such as in locatable exceptions.

      Parameters:
      location - the location
      Returns:
      an immutable and serializable version of location
    • getDescription

      public String getDescription()
      Get the description of this location
      Specified by:
      getDescription in interface Location
      Returns:
      the description (can be null)
    • getURI

      public String getURI()
      Get the URI of this location
      Specified by:
      getURI in interface Location
      Returns:
      the URI (null if unknown).
    • getLineNumber

      public int getLineNumber()
      Get the line number of this location
      Specified by:
      getLineNumber in interface Location
      Returns:
      the line number (-1 if unknown)
    • getColumnNumber

      public int getColumnNumber()
      Get the column number of this location
      Specified by:
      getColumnNumber in interface Location
      Returns:
      the column number (-1 if unknown)
    • getSnippet

      public List<String> getSnippet(int padding)
      Description copied from interface: Location
      Gets a source code snippet with the default padding
      Specified by:
      getSnippet in interface Location
      Parameters:
      padding - The amount of lines before and after the error to include
      Returns:
      a source code snippet with the default padding
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object