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.processors.validation;
A validation chain

This processor performs the following:

  • perform reference lookup then syntax validation;
  • throw an exception if the previous step fails;
  • then perform schema digesting and keyword building.

A validation chain handles one schema version. Switching schema versions is done by ValidationProcessor.

 public final class ValidationChain
     implements Processor<SchemaContextValidatorList>
     private static final ProcessingMessage MESSAGE = new ProcessingMessage()
         .setExceptionProvider(new ExceptionProvider()
             public ProcessingException doException(
                 final ProcessingMessage message)
                 return new InvalidSchemaException(message);
     private final Processor<SchemaContextValidatorListbuilder;
     public ValidationChain(final RefResolver refResolver,
         final Library libraryfinal boolean useFormat)
         final SyntaxProcessor syntaxProcessor
             = new SyntaxProcessor(library.getSyntaxCheckers());
         final ProcessorChain<ValueHolder<SchemaTree>, ValueHolder<SchemaTree>> chain1
             = ProcessorChain.startWith(refResolver).chainWith(syntaxProcessor)
             chain1.getProcessor(), .
         final SchemaDigester digester = new SchemaDigester(library);
         final ValidatorBuilder keywordBuilder = new ValidatorBuilder(library);
             = ProcessorChain.startWith(digester).chainWith(keywordBuilder);
         if (useFormat) {
             final FormatProcessor format = new FormatProcessor(library);
             chain2 = chain2.chainWith(format);
            chain2.getProcessor(), SchemaContextEquivalence.getInstance()
    public ValidatorList process(final ProcessingReport report,
        final SchemaContext input)
        throws ProcessingException
        final ValueHolder<SchemaTreein
            = ValueHolder.hold("schema"input.getSchema());
         * We have to go through an intermediate report. If we re-enter this
         * function with a report already telling there is an error, we don't
         * want to wrongly report that the schema is invalid.
        final ListProcessingReport r = new ListProcessingReport(report);
        final ValueHolder<SchemaTreeout = .process(rin);
        if (!r.isSuccess())
            return null;
        final SchemaContext output = new SchemaContext(out.getValue(),
        return .process(reportoutput);
    public String toString()
        return  + " -> " + ;
    private static final class SchemaHolderEquivalence
        extends Equivalence<ValueHolder<SchemaTree>>
        private static final Equivalence<ValueHolder<SchemaTree>> INSTANCE
            = new SchemaHolderEquivalence();
        private static final Equivalence<SchemaTreeEQUIVALENCE
            = SchemaTreeEquivalence.getInstance();
        protected boolean doEquivalent(final ValueHolder<SchemaTreea,
            final ValueHolder<SchemaTreeb)
            return .equivalent(a.getValue(), b.getValue());
        protected int doHash(final ValueHolder<SchemaTreet)
            return .hash(t.getValue());
New to GrepCode? Check out our FAQ X