Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * 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
  * 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 static com.github.fge.jsonschema.messages.RefProcessingMessages.*;

A JSON Schema registry

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.

This class is thread safe.

 public final class SchemaLoader
The URI manager
     private final URIManager manager;

The default namespace
     private final JsonRef namespace;

Schema cache
     private final LoadingCache<URIJsonNodecache;

Our dereferencing mode
     private final Dereferencing dereferencing;
     public SchemaLoader(final LoadingConfiguration cfg)
          = JsonRef.fromURI(cfg.getNamespace());
          = cfg.getDereferencing();
          = new URIManager(cfg);
          = CacheBuilder.newBuilder().maximumSize(100L)
             .build(new CacheLoader<URIJsonNode>()
                 public JsonNode load(final URI key)
                     throws ProcessingException
                     return .getContent(key);
     public SchemaLoader()
     public SchemaTree load(final JsonNode schema)
         Preconditions.checkNotNull(schema"cannot register null schema");
         return .newTree(schema);

Get a schema tree from the given URI

Note that if the URI is relative, it will be resolved against this registry's namespace, if any.

uri the URI
a schema tree
    public SchemaTree get(final URI uri)
        throws ProcessingException
        final JsonRef ref = .resolve(JsonRef.fromURI(uri));
        final ProcessingMessage msg = new ProcessingMessage()
        if (!ref.isAbsolute())
            throw new ProcessingException(msg.message());
        final URI realURI = ref.toURI();
        try {
            final JsonNode node = .get(realURI);
            return .newTree(refnode);
        } catch (ExecutionException e) {
            throw (ProcessingExceptione.getCause();
    public String toString()
        return .stats().toString();
New to GrepCode? Check out our FAQ X