Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
   *
   * 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 <http://www.gnu.org/licenses/>.
  */
 
 package com.github.fge.jsonschema.main;
 
 
 import java.util.List;
 import java.util.Map;
 
 public final class JsonValidator
 {
     private final Dereferencing dereferencing;
     private final ValidationProcessor processor;
     private final ReportProvider reportProvider;
 
     JsonValidator(final JsonSchemaFactory factory)
     {
          = factory.loadingConfiguration.getDereferencing();
          = new ValidationProcessor(buildProcessor(factory));
          = factory.reportProvider;
     }
 
     private void doValidate(final JsonNode schemafinal JsonNode instance,
         final ProcessingReport report)
         throws ProcessingException
     {
         final SchemaTree schemaTree = .newTree(schema);
         final JsonTree tree = new SimpleJsonTree(instance);
         final FullData data = new FullData(schemaTreetree);
         .process(reportdata);
     }
 
     public ProcessingReport validate(final JsonNode schema,
         final JsonNode instance)
         throws ProcessingException
     {
         final ProcessingReport report = .newReport();
         doValidate(schemainstancereport);
         return report;
     }
 
     public ProcessingReport validateUnchecked(final JsonNode schema,
         final JsonNode instance)
     {
         final ProcessingReport report = .newReport();
         try {
             doValidate(schemainstancereport);
             return report;
         } catch (ProcessingException e) {
             return buildUncheckedReport(reporte);
         }
     }
 
         (final ProcessingReport reportfinal ProcessingException e)
     {
         final ProcessingReport ret = .newReport();
         final List<ProcessingMessagemessages = report.getMessages();
         final ProcessingMessage message = e.getProcessingMessage()
             .setLogLevel(.)
             .put("info""other messages follow (if any)");
 
        ret.setExceptionThreshold(.);
        try {
            ret.log(message);
            if (messages != null)
                for (final ProcessingMessage msgmessages)
                    ret.log(msg);
        } catch (ProcessingException ignored) {
        }
        return ret;
    }
    private static Processor<SchemaContextValidatorList>
        buildProcessor(final JsonSchemaFactory factory)
    {
        final SchemaLoader loader
            = new SchemaLoader(factory.loadingConfiguration);
        final RefResolver refResolver
            = new RefResolver(loader);
        final ValidationConfiguration cfg = factory.validationConfiguration;
        final Map<JsonRefLibrarylibraries = cfg.getLibraries();
        final ValidationChain defaultChain
            = new ValidationChain(refResolvercfg.getDefaultLibrary(),
                cfg.getUseFormat());
            = new FullChain().setDefaultProcessor(defaultChain);
        JsonRef ref;
        ValidationChain chain;
        for (final Map.Entry<JsonRefLibraryentrylibraries.entrySet()) {
            ref = entry.getKey();
            chain = new ValidationChain(refResolverentry.getValue(),
                cfg.getUseFormat());
            map = map.addEntry(refchain);
        }
        return map.getProcessor();
    }
    private static final class FullChain
        extends ProcessorMap<JsonRefSchemaContextValidatorList>
    {
        @Override
        protected Function<SchemaContextJsonReff()
        {
            return new Function<SchemaContextJsonRef>()
            {
                @Override
                public JsonRef apply(final SchemaContext input)
                {
                    return input.getSchema().getDollarSchema();
                }
            };
        }
    }
New to GrepCode? Check out our FAQ X