
com.github.fge.jsonschema.load.SchemaLoader Maven / Gradle / Ivy
/*
* Copyright (c) 2013, Francis Galiegue
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.github.fge.jsonschema.load;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jsonschema.cfg.LoadingConfiguration;
import com.github.fge.jsonschema.cfg.LoadingConfigurationBuilder;
import com.github.fge.jsonschema.exceptions.ProcessingException;
import com.github.fge.jsonschema.exceptions.unchecked.JsonReferenceError;
import com.github.fge.jsonschema.exceptions.unchecked.ProcessingError;
import com.github.fge.jsonschema.ref.JsonRef;
import com.github.fge.jsonschema.report.ProcessingMessage;
import com.github.fge.jsonschema.tree.SchemaTree;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.jcip.annotations.ThreadSafe;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import static com.github.fge.jsonschema.messages.LoadingConfigurationMessages.*;
import static com.github.fge.jsonschema.messages.RefProcessingMessages.*;
import com.google.common.cache.CacheBuilderSpec;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
/**
* JSON Schema loader
*
* All schema registering and downloading is done through this class.
*
* Note that if the id of a schema is not absolute (that is, the URI itself
* is absolute and it has no fragment part, or an empty fragment), then the
* whole schema will be considered anonymous.
*
*/
@ThreadSafe
public final class SchemaLoader
{
/**
* The URI manager
*/
private final URIManager manager;
/**
* The default namespace
*/
private final JsonRef namespace;
/**
* 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(final LoadingConfiguration cfg)
{
namespace = JsonRef.fromURI(cfg.getNamespace());
dereferencing = cfg.getDereferencing();
manager = new URIManager(cfg);
preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas());
final CacheBuilder
© 2015 - 2025 Weber Informatics LLC | Privacy Policy