@Immutable public abstract class JsonRef extends Object
JSON Reference, currently a draft, is a way to define a path within a JSON document.
To quote the draft, "A JSON Reference is a JSON object, which contains a member named "$ref", which has a JSON string value." This string value must be a URI. Example:
{ "$ref": "http://example.com/example.json#/foo/bar" }
This class differs from the JSON Reference draft in that it accepts to
process illegal references, in the sense that they are URIs, but their
fragment parts are not JSON Pointers (in which case isLegal()
returns false
.
The implementation is a wrapper over Java's URI
, with the
following characteristics:
It also special cases the following:
jar
scheme (the resolving algorithm differs --
please note that this breaks URI resolution rules).Modifier and Type | Field and Description |
---|---|
protected static URI |
HASHONLY_URI
A "hash only" URI -- used by
EmptyJsonRef |
protected boolean |
legal
Whether this JSON Reference is legal
|
protected URI |
locator
The locator of this reference.
|
protected JsonPointer |
pointer
The pointer of this reference, if any
|
protected URI |
uri
The URI, as provided by the input, with an appended empty fragment if
no fragment was provided
|
Modifier | Constructor and Description |
---|---|
protected |
JsonRef(URI uri)
Main constructor,
protected by design |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(JsonRef other)
Tell whether the current JSON Reference "contains" another
|
static JsonRef |
emptyRef()
Return an empty reference
|
boolean |
equals(Object obj) |
static JsonRef |
fromString(String s)
Build a JSON Reference from a string input
|
static JsonRef |
fromURI(URI uri)
Build a JSON Reference from a URI
|
URI |
getLocator()
Return this JSON Reference's locator
|
JsonPointer |
getPointer()
Return the fragment part of this JSON Reference as a JSON Pointer
|
int |
hashCode() |
abstract boolean |
isAbsolute()
Tell whether this reference is an absolute reference
|
boolean |
isLegal()
Tell whether this JSON Reference is legal
|
abstract JsonRef |
resolve(JsonRef other)
Resolve this reference against another reference
|
String |
toString() |
URI |
toURI()
Return the underlying URI for this JSON Reference
|
protected static final URI HASHONLY_URI
EmptyJsonRef
protected final boolean legal
protected final URI uri
protected final URI locator
protected final JsonPointer pointer
Initialized to null if the fragment part is not a JSON Pointer.
isLegal()
protected JsonRef(URI uri)
protected
by designuri
- the URI to build that referencepublic static JsonRef fromURI(URI uri)
uri
- the provided URINullPointerException
- the provided URI is nullpublic static JsonRef fromString(String s) throws JsonReferenceException
s
- the stringJsonReferenceException
- string is not a valid URINullPointerException
- provided string is nullpublic static JsonRef emptyRef()
An empty reference is a reference which only has an empty fragment.
public final URI toURI()
public abstract boolean isAbsolute()
See description.
true
if the JSON Reference is absolutepublic abstract JsonRef resolve(JsonRef other)
other
- the reference to resolvepublic final URI getLocator()
This returns the reference with an empty fragment, ie the URI of the document itself.
public final boolean isLegal()
Recall: it is legal if and only if its fragment part is a JSON pointer.
true
if legalJsonPointer
public final JsonPointer getPointer()
If the reference is not legal, this returns null
without
further notice, so beware!
JsonPointer
public final boolean contains(JsonRef other)
This is considered true iif both references have the same locator, in other words, if they differ only by their fragment part.
other
- the other reference