public class URIManager extends Object
This uses a map of URIDownloader instances to fetch the contents
of a URI as an InputStream, then tries and turns this content into
JSON using an ObjectMapper.
Normally, you will never use this class directly.
SchemaRegistry,
JsonLoader| Modifier and Type | Field and Description |
|---|---|
private Map<String,URIDownloader> |
downloaders
Map of downloaders (schemes as keys,
URIDownloader instances
as values) |
private static ObjectMapper |
mapper
Our object mapper
|
private Map<URI,URI> |
URIRedirections
Map for URI redirections
|
| Constructor and Description |
|---|
URIManager() |
| Modifier and Type | Method and Description |
|---|---|
void |
addRedirection(String from,
String to)
Add a URI rediction
|
JsonNode |
getContent(URI uri)
Get the content at a given URI as a
JsonNode |
void |
registerScheme(String scheme,
URIDownloader downloader)
Register a new downloader for a given URI scheme
|
void |
unregisterScheme(String scheme)
Unregister a downloader for a given scheme
|
private static final ObjectMapper mapper
Note that it uses DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS to deserialize,
for accuracy reasons.
NumericKeywordValidatorprivate final Map<String,URIDownloader> downloaders
URIDownloader instances
as values)private final Map<URI,URI> URIRedirections
This map will be used if you wish for an absolute URI to be redirected to another URI of your choice, which must also be absolute.
Note that this map requires URIs to be exact. Currently, you cannot, for example, redirect a whole namespace this way.
public void registerScheme(String scheme, URIDownloader downloader)
scheme - the schemedownloader - the URIDownloader instanceNullPointerException - scheme is nullIllegalArgumentException - scheme is empty, or is already
registeredpublic void unregisterScheme(String scheme)
scheme - the schemeNullPointerException - scheme is nullpublic void addRedirection(String from, String to)
The typical use case for this is if you have a local copy of a schema whose id is normally unreachable. You can transform all references to this schema's URI to another URI which is reachable by your application.
Note that the given strings will be considered as JSON References, and that both arguments must be valid absolute JSON References. For the recall, there is more to it than URIs being absolute: their fragment part must also be empty or null.
from - the original URIto - an URI which is reachableIllegalArgumentException - either of from or to are
invalid URIs, or are not absolute JSON Referencespublic JsonNode getContent(URI uri) throws JsonSchemaException
JsonNodeuri - the URIJsonSchemaException - scheme is not registered, failed to get
content, or content is not JSONCopyright © 2012. All Rights Reserved.