public final class JsonValidatorCache extends Object
This class plays a critically important role in the performance of the whole validation process, since it is the class responsible for instantiating validators and caching them for future reuse.
As it uses a LoadingCache, it is totally thread safe and also
very efficient.
SchemaNode| Modifier and Type | Class and Description |
|---|---|
private static class |
JsonValidatorCache.FailingValidator
Class instantiated when a schema node fails to pass ref resolution or
syntax checking
|
| Modifier and Type | Field and Description |
|---|---|
private static JsonValidator |
ALWAYS_TRUE |
private LoadingCache<SchemaNode,JsonValidator> |
cache
Cache for all validators, even failing ones
|
private KeywordFactory |
keywordFactory |
private JsonResolver |
resolver |
private SyntaxValidator |
syntaxValidator |
| Constructor and Description |
|---|
JsonValidatorCache(KeywordBundle bundle,
SchemaRegistry registry)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
private CacheLoader<SchemaNode,JsonValidator> |
cacheLoader()
The cache loader function
|
JsonValidator |
getValidator(SchemaNode schemaNode) |
private static final JsonValidator ALWAYS_TRUE
private final LoadingCache<SchemaNode,JsonValidator> cache
JsonValidatorCache.FailingValidatorprivate final JsonResolver resolver
private final SyntaxValidator syntaxValidator
private final KeywordFactory keywordFactory
public JsonValidatorCache(KeywordBundle bundle, SchemaRegistry registry)
Instantiate the syntax validator, the keyword factory, the JSON ref resolver and the validator cache.
bundle - the keyword bundleregistry - the schema registrypublic JsonValidator getValidator(SchemaNode schemaNode)
private CacheLoader<SchemaNode,JsonValidator> cacheLoader()
The implemented CacheLoader.load(Object) method is the
critical part. It will try and check if ref resolution succeeds, if so it
checks the schema syntax, and finally it returns a validator.
If any of the preliminary checks fail, it returns a JsonValidatorCache.FailingValidator, else it returns an InstanceValidator.
Copyright © 2012. All Rights Reserved.