|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.github.fge.jsonschema.core.ref.JsonRef
@Immutable public abstract class JsonRef
Representation of a JSON Reference
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).
| Field Summary | |
|---|---|
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 |
| Constructor Summary | |
|---|---|
protected |
JsonRef(URI uri)
Main constructor, protected by design |
| Method Summary | |
|---|---|
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 |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
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()| Constructor Detail |
|---|
protected JsonRef(URI uri)
protected by design
uri - the URI to build that reference| Method Detail |
|---|
public static JsonRef fromURI(URI uri)
uri - the provided URI
NullPointerException - the provided URI is null
public static JsonRef fromString(String s)
throws JsonReferenceException
s - the string
JsonReferenceException - string is not a valid URI
NullPointerException - 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 resolve
public 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 legalJsonPointerpublic final JsonPointer getPointer()
If the reference is not legal, this returns null without
further notice, so beware!
JsonPointerpublic 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
public final int hashCode()
hashCode in class Objectpublic final boolean equals(Object obj)
equals in class Objectpublic final String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||