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.*;

Mutable version of a library

This is what you will use when you wish to create your own metaschema and add either new keywords or format attributes to it.

Important note: if you add a keyword which already existed in this builder, all traces of its previous definition, if any, will be removed.

 
 public final class LibraryBuilder
     implements Thawed<Library>
 {
    
Dictionary builder of syntax checkers
 
Dictionary builder of digesters
 
     final DictionaryBuilder<Digesterdigesters;

    
Dictionary builder of keyword validator constructors
 
     final DictionaryBuilder<Constructor<? extends KeywordValidator>> validators;

    
Dictionary builder of format attributes
 
No-arg constructor providing an empty library builder
 
     LibraryBuilder()
     {
          = Dictionary.newBuilder();
          = Dictionary.newBuilder();
          = Dictionary.newBuilder();
          = Dictionary.newBuilder();
     }

    
Constructor from an already existing library

Parameters:
library the library
See also:
Library.thaw()
 
     LibraryBuilder(final Library library)
     {
          = library.syntaxCheckers.thaw();
          = library.digesters.thaw();
          = library.validators.thaw();
          = library.formatAttributes.thaw();
     }

    
Add a new keyword to this library

Parameters:
keyword the keyword
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError keyword is null
 
     public LibraryBuilder addKeyword(final Keyword keyword)
     {
         if (keyword == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        final String name = keyword.name;
        removeKeyword(name);
        .addEntry(namekeyword.syntaxChecker);
        if (keyword.constructor != null) {
            .addEntry(namekeyword.digester);
            .addEntry(namekeyword.constructor);
        }
        return this;
    }

    
Remove a keyword by its name

Parameters:
name the name
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError name is null
    public LibraryBuilder removeKeyword(final String name)
    {
        if (name == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        .removeEntry(name);
        .removeEntry(name);
        .removeEntry(name);
        return this;
    }

    
Add a format attribute

Parameters:
name the name for this attribute
attribute the format attribute
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError the name or attribute is null
    public LibraryBuilder addFormatAttribute(final String name,
        final FormatAttribute attribute)
    {
        removeFormatAttribute(name);
        if (attribute == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        .addEntry(nameattribute);
        return this;
    }

    
Remove a format attribute by its name

Parameters:
name the format attribute name
Returns:
this
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ValidationConfigurationError name is null
    public LibraryBuilder removeFormatAttribute(final String name)
    {
        if (name == null)
            throw new ValidationConfigurationError(new ProcessingMessage()
                .message());
        .removeEntry(name);
        return this;
    }

    
Return a frozen version of this builder

    @Override
    public Library freeze()
    {
        return new Library(this);
    }
New to GrepCode? Check out our FAQ X