Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
   *
   * This software is dual-licensed under:
   *
   * - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
   *   later version;
   * - the Apache Software License (ASL) version 2.0.
   *
  * The text of both licenses is available under the src/resources/ directory of
  * this project (under the names LGPL-3.0.txt and ASL-2.0.txt respectively).
  *
  * Direct link to the sources:
  *
  * - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
  * - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
  */
 
 package com.github.fge.jsonschema.library;
 
 
A keyword builder -- the thawed version of a Keyword

Note that you may only supply a com.github.fge.jsonschema.core.keyword.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>
 {
     private static final MessageBundle BUNDLE
         = MessageBundles.getBundle(JsonSchemaConfigurationBundle.class);
     final String name;
     Digester digester;
     Constructor<? extends KeywordValidatorconstructor;

    
Create a new, empty keyword builder

Parameters:
name the name of this keyword
Throws:
java.lang.NullPointerException name is null
See also:
Keyword.newBuilder(java.lang.String)
 
     KeywordBuilder(final String name)
     {
         .checkNotNull(name"nullName");
         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:
java.lang.NullPointerException syntax checker is null
 
     public KeywordBuilder withSyntaxChecker(final SyntaxChecker syntaxChecker)
     {
         .checkNotNullPrintf(syntaxChecker"nullSyntaxChecker");
         this. = syntaxChecker;
         return this;
     }

    
Add a digester to this builder

Parameters:
digester the digester
Returns:
this
Throws:
java.lang.NullPointerException digester is null
 
    public KeywordBuilder withDigester(final Digester digester)
    {
        .checkNotNullPrintf(digester"nullDigester");
        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:
java.lang.NullPointerException 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:
java.lang.NullPointerException 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:
java.lang.NullPointerException class is null
java.lang.IllegalArgumentException failed to find an appropriate constructor
        final Class<? extends KeywordValidatorc)
    {
         = getConstructor(c);
        return this;
    }

    
Build a frozen version of this builder

Returns:
a Keyword
Throws:
java.lang.IllegalArgumentException no syntax checker; or a constructor has been supplied without a digester
See also:
Keyword.Keyword.(com.github.fge.jsonschema.library.KeywordBuilder)
    @Override
    public Keyword freeze()
    {
        .checkArgumentPrintf( != null"noChecker");
        /*
         * We can have a keyword without a validator; however, if there is one,
         * there must be a digester.
         */
        .checkArgumentPrintf( == null ||  != null,
            "malformedKeyword");
        return new Keyword(this);
    }
    private static Constructor<? extends KeywordValidatorgetConstructor(
        final String namefinal Class<? extends KeywordValidatorc)
    {
        try {
            return c.getConstructor(JsonNode.class);
        } catch (NoSuchMethodException ignored) {
            throw new IllegalArgumentException(.printf(
                "noAppropriateConstructor"namec.getCanonicalName()
            ));
        }
    }
    private static NodeType checkType(final NodeType type)
    {
        return .checkNotNull(type"nullType");
    }
    private static NodeType[] checkTypes(final NodeType... types)
    {
        for (final NodeType typetypes)
            .checkNotNull(type"nullType");
        return types;
    }
New to GrepCode? Check out our FAQ X