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 one important way: normally, the fragment part of a JSON Reference must be a JSON Pointer; however, this means you cannot use a reference for addressing inner schemas when inline addressing mode is used. We therefore choose to accept all possible fragment parts.
The implementation is a wrapper over Java's URI
, with the
following differences:
It also special cases the following:
jar
scheme (the resolving algorithm differs --
please note that this breaks URI resolution rules).This class is thread safe and immutable.
AddressingMode.INLINE
,
InlineSchemaContainer
Modifier and Type | Field and Description |
---|---|
protected JsonFragment |
fragment
The fragment of this reference.
|
protected static URI |
HASHONLY_URI |
protected URI |
locator
The locator of this reference.
|
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
|
JsonFragment |
getFragment()
Return this JSON Reference's fragment
|
URI |
getLocator()
Return this JSON Reference's locator
|
int |
hashCode() |
abstract boolean |
isAbsolute()
Tell whether this reference is an absolute reference
|
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
protected final URI uri
protected final URI locator
protected final JsonFragment fragment
JsonFragment
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 JsonSchemaException
s
- the stringJsonSchemaException
- 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()
A JSON Reference is considered absolute iif the underlying URI is itself absolute and it has an empty, or no, fragment part.
public abstract JsonRef resolve(JsonRef other)
other
- the reference to resolvepublic final URI getLocator()
This returns the reference with an empty fragment.
public final JsonFragment getFragment()
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 referenceCopyright © 2013. All Rights Reserved.