com.github.fge.jsonschema.core.keyword.syntax.checkers
Class AbstractSyntaxChecker

java.lang.Object
  extended by com.github.fge.jsonschema.core.keyword.syntax.checkers.AbstractSyntaxChecker
All Implemented Interfaces:
SyntaxChecker
Direct Known Subclasses:
AdditionalSyntaxChecker, DependenciesSyntaxChecker, DivisorSyntaxChecker, DraftV3TypeKeywordSyntaxChecker, DraftV4TypeSyntaxChecker, EnumSyntaxChecker, ExclusiveMaximumSyntaxChecker, ExclusiveMinimumSyntaxChecker, LinksSyntaxChecker, MediaSyntaxChecker, NotSyntaxChecker, PatternSyntaxChecker, PositiveIntegerSyntaxChecker, RequiredSyntaxChecker, SchemaArraySyntaxChecker, SchemaMapSyntaxChecker, SchemaOrSchemaArraySyntaxChecker, TypeOnlySyntaxChecker, URISyntaxChecker

public abstract class AbstractSyntaxChecker
extends Object
implements SyntaxChecker

Base abstract syntax checker

Apart from providing a convenient base to create a syntax checker of your own, it also provides message templates with the appropriate information and a customized exception provider (throwing a InvalidSchemaException instead of the base ProcessingException.


Field Summary
protected  String keyword
          The keyword name
 
Constructor Summary
protected AbstractSyntaxChecker(String keyword, NodeType first, NodeType... other)
          Main constructor
 
Method Summary
 void checkSyntax(Collection<JsonPointer> pointers, MessageBundle bundle, ProcessingReport report, SchemaTree tree)
          Main syntax checking function
protected abstract  void checkValue(Collection<JsonPointer> pointers, MessageBundle bundle, ProcessingReport report, SchemaTree tree)
          Method which all syntax checkers extending this class must implement
protected  JsonNode getNode(SchemaTree tree)
          Convenience method to retrieve the keyword's value
 EnumSet<NodeType> getValidTypes()
           
protected  ProcessingMessage newMsg(SchemaTree tree, MessageBundle bundle, String key)
          Provide a new message for reporting purposes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyword

protected final String keyword
The keyword name

Constructor Detail

AbstractSyntaxChecker

protected AbstractSyntaxChecker(String keyword,
                                NodeType first,
                                NodeType... other)
Main constructor

Parameters:
keyword - the keyword name
first - the first valid type for this keyword's value
other - other valid types for this keyword's value (if any)
Method Detail

getValidTypes

public final EnumSet<NodeType> getValidTypes()
Specified by:
getValidTypes in interface SyntaxChecker

checkSyntax

public final void checkSyntax(Collection<JsonPointer> pointers,
                              MessageBundle bundle,
                              ProcessingReport report,
                              SchemaTree tree)
                       throws ProcessingException
Main syntax checking function

This method only checks that the keyword's type is of the correct type, and reports an error if it isn't; if it is, it handles the rest of syntax checking to checkValue(Collection, MessageBundle, ProcessingReport, SchemaTree).

Specified by:
checkSyntax in interface SyntaxChecker
Parameters:
pointers - the list of JSON Pointers to fill (see description)
bundle - the message bundle to use
report - the processing report to use
tree - the schema
Throws:
InvalidSchemaException - keyword is invalid
ProcessingException - an error is detected, and the report is configured to throw an exception on error.

checkValue

protected abstract void checkValue(Collection<JsonPointer> pointers,
                                   MessageBundle bundle,
                                   ProcessingReport report,
                                   SchemaTree tree)
                            throws ProcessingException
Method which all syntax checkers extending this class must implement

At this point, it is known that the keyword's value has at least the correct type.

Parameters:
pointers - the list of JSON Pointers to fill (see description)
bundle - the message bundle to use
report - the processing report to use
tree - the schema
Throws:
InvalidSchemaException - keyword is invalid
ProcessingException

newMsg

protected final ProcessingMessage newMsg(SchemaTree tree,
                                         MessageBundle bundle,
                                         String key)
Provide a new message for reporting purposes

Parameters:
tree - the schema tree
bundle - the message bundle to use
key - the message
Returns:
a new ProcessingMessage
See Also:
ProcessingMessage.setMessage(String)

getNode

protected final JsonNode getNode(SchemaTree tree)
Convenience method to retrieve the keyword's value

Parameters:
tree - the tree to extract the keyword's value from
Returns:
the keyword's value