Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2012, Francis Galiegue <fgaliegue@gmail.com>
   *
   * 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 <http://www.gnu.org/licenses/>.
  */
 
 package com.github.fge.jsonschema.main;
 
Representation of a schema keyword: its name, syntax checker and validator

The process is as follows:

It is perfectly legal to register a keyword with only a syntax checker, or only a keyword validator. An example is $schema, which must be a valid URI (therefore it has a syntax checker) but does not play any role in instance validation (therefore it has no keyword validator).

This class is thread safe and immutable.

 
 public final class Keyword
 {
     private final String name;
     private final SyntaxChecker syntaxChecker;
     private final Class<? extends KeywordValidatorvalidatorClass;
 
     private Keyword(final Builder builder)
     {
          = builder.keyword;
          = builder.syntaxChecker;
          = builder.validatorClass;
     }

    
Create a new Keyword.Builder for a keyword with a given name

Parameters:
name the name
Returns:
the newly created builder
 
     public static Keyword.Builder withName(final String name)
     {
         return new Builder(name);
     }
 
     public String getName()
     {
         return ;
     }
 
     public SyntaxChecker getSyntaxChecker()
     {
         return ;
     }
 
     public Class<? extends KeywordValidatorgetValidatorClass()
     {
         return ;
     }

    
Builder class for a new keyword
 
     public static final class Builder
     {
         private final String keyword;
         private SyntaxChecker syntaxChecker;
         private Class<? extends KeywordValidatorvalidatorClass;

        
The only constructor, private by design

Parameters:
keyword the keyword name
Throws:
java.lang.NullPointerException the keyword name is null (illegal)
        private Builder(final String keyword)
        {
            Preconditions.checkNotNull(keyword"keyword name must not be null");
            this. = keyword;
        }

        
Add a syntax checker to this keyword

Parameters:
syntaxChecker the syntax checker, already instantiated
Returns:
this
        public Builder withSyntaxChecker(final SyntaxChecker syntaxChecker)
        {
            this. = syntaxChecker;
            return this;
        }

        
Add the keyword validator class

We add the class, not an instance, since the generated object is dependent on the schema being passed.

Parameters:
validatorClass the class
Returns:
this
        public Builder withValidatorClass(
            final Class<? extends KeywordValidatorvalidatorClass)
        {
            this. = validatorClass;
            return this;
        }

        
Build the Keyword

Returns:
the keyword
        public Keyword build()
        {
            return new Keyword(this);
        }
    }
New to GrepCode? Check out our FAQ X