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 this file and of both licenses is available at the root of this
  * project or, if you have the jar distribution, in directory META-INF/, 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.keyword.validator.common;
 
 
 import java.util.Map;
 import java.util.Set;
 
 /*
  * In spite of syntax differences, the digested data is the same, which is why
  * this validator is in common/
  */
Keyword validator for draft v4 and v3 dependencies

In spite of syntax differences, the digested data used to build the validator is the same, which is why this validator is located here.

 
 public final class DependenciesValidator
     extends AbstractKeywordValidator
 {
     private final Multimap<StringStringpropertyDeps;
     private final Set<StringschemaDeps;
 
     public DependenciesValidator(final JsonNode digest)
     {
         super("dependencies");
 
         /*
          * Property dependencies
          */
         final ImmutableMultimap.Builder<StringStringmapBuilder
             = ImmutableMultimap.builder();
         final Map<StringJsonNodemap
             = JacksonUtils.asMap(digest.get("propertyDeps"));
 
         String key;
         for (final Map.Entry<StringJsonNodeentrymap.entrySet()) {
             key = entry.getKey();
             for (final JsonNode elemententry.getValue())
                 mapBuilder.put(keyelement.textValue());
         }
 
          = mapBuilder.build();
 
         /*
          * Schema dependencies
          */
         final ImmutableSet.Builder<StringsetBuilder
             = ImmutableSet.builder();
 
         for (final JsonNode nodedigest.get("schemaDeps"))
             setBuilder.add(node.textValue());
 
          = setBuilder.build();
     }
 
     @Override
     public void validate(final Processor<FullDataFullDataprocessor,
         final ProcessingReport reportfinal MessageBundle bundle,
         final FullData data)
         throws ProcessingException
     {
         final JsonNode instance = data.getInstance().getNode();
         final Set<Stringfields = Sets.newHashSet(instance.fieldNames());
 
         Collection<Stringcollection;
        Set<Stringset;
        for (final String field.keySet()) {
            if (!fields.contains(field))
                continue;
            collection = .get(field);
            set = Sets.newLinkedHashSet(collection);
            set.removeAll(fields);
            if (!set.isEmpty())
                report.error(newMsg(databundle,
                    "err.common.dependencies.missingPropertyDeps")
                    .putArgument("property"field)
                    .putArgument("required"toArrayNode(collection))
                    .putArgument("missing"toArrayNode(set)));
        }
        if (.isEmpty())
            return;
        final SchemaTree tree = data.getSchema();
        FullData newData;
        JsonPointer pointer;
        for (final String field) {
            if (!fields.contains(field))
                continue;
            pointer = JsonPointer.of(field);
            newData = data.withSchema(tree.append(pointer));
            processor.process(reportnewData);
        }
    }
    @Override
    public String toString()
    {
        return  + ": " + .size() + " property dependencies, "
            + .size() + " schema dependencies";
    }
New to GrepCode? Check out our FAQ X