public class LocationUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
LocationUtils.LocationFinder
An finder or object locations
|
Modifier and Type | Field and Description |
---|---|
static String |
UNKNOWN_STRING
The string representation of an unknown location: "
[unknown location] ". |
Modifier and Type | Method and Description |
---|---|
static void |
addFinder(LocationUtils.LocationFinder finder)
Add a
LocationUtils.LocationFinder to the list of finders that will be queried for an object's
location by getLocation(Object, String) . |
static Location |
getLocation(Object obj)
Get the location of an object.
|
static Location |
getLocation(Object obj,
String description)
Get the location of an object.
|
static boolean |
isKnown(Location location)
Checks if a location is known, i.e.
|
static boolean |
isUnknown(Location location)
Checks if a location is unknown, i.e.
|
static LocationImpl |
parse(String text)
Parse a location string of the form "
uri:line:column " (e.g. |
static String |
toString(Location location)
Builds a string representation of a location, in the
"
descripton - uri:line:column "
format (e.g. |
public static final String UNKNOWN_STRING
[unknown location]
".public static String toString(Location location)
descripton - uri:line:column
"
format (e.g. "foo - file://path/to/file.xml:3:40
"). For an unknown location
, returns
UNKNOWN_STRING
.location
- location objectpublic static LocationImpl parse(String text) throws IllegalArgumentException
uri:line:column
" (e.g.
"path/to/file.xml:3:40
") to a Location object. Additionally, a description may
also optionally be present, separated with an hyphen (e.g. "foo - path/to/file.xml:3.40
").text
- the text to parsenull
if text was null or in an incorrect format)IllegalArgumentException
public static boolean isKnown(Location location)
Location.UNKNOWN
.location
- the location to checktrue
if the location is knownpublic static boolean isUnknown(Location location)
Location.UNKNOWN
.location
- the location to checktrue
if the location is unknownpublic static void addFinder(LocationUtils.LocationFinder finder)
LocationUtils.LocationFinder
to the list of finders that will be queried for an object's
location by getLocation(Object, String)
.
Important: LocationUtils internally stores a weak reference to the finder. This avoids creating strong links between the classloader holding this class and the finder's classloader, which can cause some weird memory leaks if the finder's classloader is to be reloaded. Therefore, you have to keep a strong reference to the finder in the calling code, e.g.:
private static LocationUtils.LocationFinder myFinder = new LocationUtils.LocationFinder() { public Location getLocation(Object obj, String desc) { ... } }; static { LocationUtils.addFinder(myFinder); }
finder
- the location finder to addpublic static Location getLocation(Object obj)
obj
- the object of which to get the locationLocation.UNKNOWN
if no location could be foundpublic static Location getLocation(Object obj, String description)
obj
- the object of which to get the locationdescription
- an optional description of the object's location, used if a Location object
has to be created.Location.UNKNOWN
if no location could be foundCopyright © 2000–2020 Apache Software Foundation. All rights reserved.