Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
   *
   * This software is dual-licensed under:
   *
   * - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
   *   later version;
   * - the Apache Software License (ASL) version 2.0.
   *
  * The text of this file and of both licenses is available at the root of this
  * project or, if you have the jar distribution, in directory META-INF/, under
  * the names LGPL-3.0.txt and ASL-2.0.txt respectively.
  *
  * Direct link to the sources:
  *
  * - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
  * - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
  */
 
 package com.github.fge.jsonschema.main;
 
 
 import java.util.Map;

The main validator provider

From an instance of this factory, you can obtain the following:

 
 public final class JsonSchemaFactory
     implements Frozen<JsonSchemaFactoryBuilder>
 {
     private static final MessageBundle BUNDLE
         = MessageBundles.getBundle(JsonSchemaConfigurationBundle.class);
     private static final MessageBundle CORE_BUNDLE
         = MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
 
     private static final Function<SchemaContextJsonRefFUNCTION
         = new Function<SchemaContextJsonRef>()
     {
         @Override
         public JsonRef apply(final SchemaContext input)
         {
             return input.getSchema().getDollarSchema();
         }
     };
 
     /*
      * Elements provided by the builder
      */
     final ReportProvider reportProvider;
 
     /*
      * Generated elements
      */
     private final SchemaLoader loader;
     private final JsonValidator validator;
     private final SyntaxValidator syntaxValidator;

    
Return a default factory

This default factory has validators for both draft v4 and draft v3. It defaults to draft v4.

Returns:
a factory with default settings
See also:
JsonSchemaFactoryBuilder.JsonSchemaFactoryBuilder.()
    public static JsonSchemaFactory byDefault()
    {
        return newBuilder().freeze();
    }

    
Return a factory builder

    public static JsonSchemaFactoryBuilder newBuilder()
    {
        return new JsonSchemaFactoryBuilder();
    }

    
Package private constructor to build a factory out of a builder

Parameters:
builder the builder
See also:
JsonSchemaFactoryBuilder.freeze()
    {
         = builder.reportProvider;
         = builder.loadingCfg;
         = builder.validationCfg;
         = new SchemaLoader();
        final Processor<SchemaContextValidatorListprocessor
            = buildProcessor();
         = new JsonValidator(,
            new ValidationProcessor(processor), );
    }

    
Return the main schema/instance validator provided by this factory

Returns:
a JsonValidator
    public JsonValidator getValidator()
    {
        return ;
    }

    
Return the syntax validator provided by this factory

    {
        return ;
    }

    
Build an instance validator tied to a schema

Note that the validity of the schema is not checked. Use getSyntaxValidator() if you are not sure.

    public JsonSchema getJsonSchema(final JsonNode schema)
        throws ProcessingException
    {
        .checkNotNull(schema"nullSchema");
        return .buildJsonSchema(schema, JsonPointer.empty());
    }

    
Build an instance validator tied to a subschema from a main schema

Note that the validity of the schema is not checked. Use getSyntaxValidator() if you are not sure.

Parameters:
schema the schema
ptr a JSON Pointer as a string
Returns:
a JsonSchema
Throws:
com.github.fge.jsonschema.core.exceptions.ProcessingException ptr is not a valid JSON Pointer, or resolving the pointer against the schema leads to a com.fasterxml.jackson.databind.node.MissingNode
java.lang.NullPointerException schema is null, or pointer is null
    public JsonSchema getJsonSchema(final JsonNode schemafinal String ptr)
        throws ProcessingException
    {
        .checkNotNull(schema"nullSchema");
        .checkNotNull(ptr"nullPointer");
        final JsonPointer pointer;
        try {
            pointer = new JsonPointer(ptr);
            return .buildJsonSchema(schemapointer);
        } catch (JsonPointerException ignored) {
            // Cannot happen
        }
        throw new IllegalStateException("How did I get there??");
    }

    
Build an instance validator out of a schema loaded from a URI

Parameters:
uri the URI
Returns:
a JsonSchema
Throws:
com.github.fge.jsonschema.core.exceptions.ProcessingException failed to load from this URI
java.lang.NullPointerException URI is null
    public JsonSchema getJsonSchema(final String uri)
        throws ProcessingException
    {
        .checkNotNull(uri"nullURI");
        return .buildJsonSchema(uri);
    }

    
Return the raw validation processor

This will allow you to chain the full validation processor with other processors of your choice. Useful if, for instance, you wish to add post checking which JSON Schema cannot do by itself.

Returns:
the processor.
    {
        return .getProcessor();
    }

    
Return a thawed instance of that factory

    @Override
    {
        return new JsonSchemaFactoryBuilder(this);
    }
    {
        final RefResolver resolver = new RefResolver();
        final Map<JsonRefLibrarylibraries = .getLibraries();
        final Library defaultLibrary = .getDefaultLibrary();
        final ValidationChain defaultChain
            = new ValidationChain(resolverdefaultLibrary);
        final ProcessorMap<JsonRefSchemaContextValidatorListmap
            = new ProcessorMap<JsonRefSchemaContextValidatorList>();
        map.setDefaultProcessor(defaultChain);
        JsonRef ref;
        ValidationChain chain;
        for (final Map.Entry<JsonRefLibraryentrylibraries.entrySet()) {
            ref = entry.getKey();
            chain = new ValidationChain(resolverentry.getValue(),
                );
            map.addEntry(refchain);
        }
        return map.getProcessor();
    }
New to GrepCode? Check out our FAQ X