com.github.fge.jsonschema.cfg.ValidationConfiguration 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.cfg;
import com.github.fge.jsonschema.library.Keyword;
import com.github.fge.jsonschema.library.Library;
import com.github.fge.jsonschema.ref.JsonRef;
import com.github.fge.jsonschema.util.Frozen;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
/**
* Validation configuration (frozen instance)
*
* This allows you to configure the following aspects of validation:
*
*
* - add your own schema keywords via libraries, with an associated {@code
* $schema} value;
* - whether to use {@code format};
* - what default keyword library should be used.
*
*
* The default configuration has both draft v4 and draft v3 libraries
* preloaded, and {@code format} validation is enabled; the default library to
* use is draft v4.
*
* @see ValidationConfigurationBuilder
* @see Keyword
* @see Library
*/
public final class ValidationConfiguration
implements Frozen
{
/**
* Map of keyword libraries and their associated URIs
*
* The URIs here are what is expected in {@code $schema}.
*/
final Map libraries;
/**
* Default keyword library to use
*
* This is the library used when no {@code $schema} could be found in
* a submitted/downloaded schema.
*/
final Library defaultLibrary;
/**
* Whether to use {@code format} in the resulting factory
*/
final boolean useFormat;
/**
* Return a new thawed instance of the default configuration
*
* @return a new configuration builder
* @see ValidationConfigurationBuilder#ValidationConfigurationBuilder()
*/
public static ValidationConfigurationBuilder newBuilder()
{
return new ValidationConfigurationBuilder();
}
/**
* Return a default, frozen configuration
*
* @return a new configuration
*/
public static ValidationConfiguration byDefault()
{
return newBuilder().freeze();
}
/**
* Build a new frozen configuration out of a thawed one
*
* @param cfg the source configuration
* @see ValidationConfigurationBuilder#freeze()
*/
ValidationConfiguration(final ValidationConfigurationBuilder cfg)
{
libraries = ImmutableMap.copyOf(cfg.libraries);
defaultLibrary = cfg.defaultLibrary;
useFormat = cfg.useFormat;
}
/**
* Return the map of libraries for this configuration
*
* @return an immutable map
*/
public Map getLibraries()
{
return libraries;
}
/**
* Return the default library to use
*
* @return a library
*/
public Library getDefaultLibrary()
{
return defaultLibrary;
}
/**
* Whether {@code format} should be used
*
* @return {@code true} if the answer is yes
*/
public boolean getUseFormat()
{
return useFormat;
}
/**
* Return a thawed instance out of this frozen configuration
*
* @return a {@link ValidationConfigurationBuilder}
* @see ValidationConfigurationBuilder#ValidationConfigurationBuilder(ValidationConfiguration)
*/
@Override
public ValidationConfigurationBuilder thaw()
{
return new ValidationConfigurationBuilder(this);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy