Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013, 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.library;
 
 
 
 import static com.github.fge.jsonschema.messages.ValidationConfigurationMessages.*;

A keyword builder -- the thawed version of a Keyword

Note that you may only supply a com.github.fge.jsonschema.syntax.checkers.SyntaxChecker for a keyword, but if you supply a validator class, the digester must also be present.

 
 public final class KeywordBuilder
     implements Thawed<Keyword>
 {
     final String name;
     Digester digester;
     Constructor<? extends KeywordValidatorconstructor;

    
Create a new, empty keyword builder

 
     KeywordBuilder(final String name)
     {
         if (name == null)
             throw new ValidationConfigurationError(new ProcessingMessage()
                 .message());
         this. = name;
     }

    
Create a thawed version of a frozen keyword

Parameters:
keyword the keyword
See also:
Keyword.thaw()
 
     KeywordBuilder(final Keyword keyword)
     {
          = keyword.name;
          = keyword.syntaxChecker;
          = keyword.digester;
          = keyword.constructor;
     }

    
Add a syntax checker to this builder

Parameters:
syntaxChecker the syntax checker
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError syntax checker is null
 
     public KeywordBuilder withSyntaxChecker(final SyntaxChecker syntaxChecker)
     {
         if (syntaxChecker == null)
             throw new ValidationConfigurationError(new ProcessingMessage()
                 .message());
         this. = syntaxChecker;
         return this;
     }

    
Add a digester to this builder

Parameters:
digester the digester
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError digester is null
    public KeywordBuilder withDigester(final Digester digester)
    {
        if (digester == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        this. = digester;
        return this;
    }

    
Set this keyword's digester to be an com.github.fge.jsonschema.keyword.digest.helpers.IdentityDigester

Parameters:
first the first instance type supported by this keyword
other other instance types supported by this keyword
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError one or more type(s) are null
    public KeywordBuilder withIdentityDigester(final NodeType first,
        final NodeType... other)
    {
         = new IdentityDigester(checkType(first),
            checkTypes(other));
        return this;
    }

    
Set this keyword's digester to be a com.github.fge.jsonschema.keyword.digest.helpers.SimpleDigester

Parameters:
first the first instance type supported by this keyword
other other instance types supported by this keyword
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError one or more type(s) are null
    public KeywordBuilder withSimpleDigester(final NodeType first,
        final NodeType... other)
    {
         = new SimpleDigester(checkType(first),
            checkTypes(other));
        return this;
    }

    
Set the validator class for this keyword

Parameters:
c the class
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError failed to find an appropriate constructor
        final Class<? extends KeywordValidatorc)
    {
         = getConstructor(c);
        return this;
    }

    
Build a frozen version of this builder

    @Override
    public Keyword freeze()
    {
        return new Keyword(this);
    }
    private static Constructor<? extends KeywordValidatorgetConstructor(
        final Class<? extends KeywordValidatorc)
    {
        try {
            return c.getConstructor(JsonNode.class);
        } catch (NoSuchMethodException ignored) {
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        }
    }
    private static NodeType checkType(final NodeType type)
    {
        if (type == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        return type;
    }
    private static NodeType[] checkTypes(final NodeType... types)
    {
        for (final NodeType typetypes)
            if (type == null)
                throw new ValidationConfigurationError(new ProcessingMessage()
                    .message());
        return types;
    }
New to GrepCode? Check out our FAQ X