xpertss.json.schema.core.load.SchemaLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema Show documentation
Show all versions of json-schema Show documentation
A Java implementation of the JSON Schema specification.
The newest version!
package xpertss.json.schema.core.load;
import com.fasterxml.jackson.databind.JsonNode;
import xpertss.json.schema.core.exceptions.ProcessingException;
import xpertss.json.schema.core.load.configuration.LoadingConfiguration;
import xpertss.json.schema.core.load.configuration.LoadingConfigurationBuilder;
import xpertss.json.schema.core.load.uri.URITranslator;
import xpertss.json.schema.core.load.uri.URITranslatorConfiguration;
import xpertss.json.schema.core.messages.JsonSchemaCoreMessageBundle;
import xpertss.json.schema.core.ref.JsonRef;
import xpertss.json.schema.core.report.ProcessingMessage;
import xpertss.json.schema.core.tree.SchemaTree;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* JSON Schema loader
*
* This class is the central loading point for generating a {@link
* SchemaTree} out of a "raw" JSON Schema (ie, a {@link JsonNode}); it handles
* the creation of both anonymous (ie, no loading URI) and non anonymous JSON
* schemas.
*
* Depending on your configuration, you may, or may not, be able to use
* relative URIs to load your schemas; see {@link URITranslator} and {@link
* LoadingConfigurationBuilder#setURITranslatorConfiguration(URITranslatorConfiguration)}
* for more details.
*/
@ThreadSafe
public final class SchemaLoader {
private static final MessageBundle BUNDLE = MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
/**
* The URI manager
*/
private final URIManager manager;
/**
* The URI translator
*/
private final URITranslator translator;
/**
* Schema cache
*/
private final LoadingCache cache;
/**
* Our dereferencing mode
*/
private final Dereferencing dereferencing;
/**
* Map of preloaded schemas
*/
private final Map preloadedSchemas;
/**
* Create a new schema loader with a given loading configuration
*
* @param cfg the configuration
* @see LoadingConfiguration
* @see LoadingConfigurationBuilder
*/
public SchemaLoader(LoadingConfiguration cfg)
{
translator = new URITranslator(cfg.getTranslatorConfiguration());
dereferencing = cfg.getDereferencing();
manager = new URIManager(cfg);
preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas());
CacheBuilder