All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.everit.json.schema.loader.SubschemaRegistry Maven / Gradle / Ivy

Go to download

Implementation of the JSON Schema Core Draft v4 specification built with the org.json API

There is a newer version: 1.14.4
Show newest version
package org.everit.json.schema.loader;

import java.util.HashMap;
import java.util.Map;

class SubschemaRegistry {

    final Map storage = new HashMap<>();


    SubschemaRegistry(JsonValue rootJson) {
        collectObjectsWithId(rootJson);
    }

    void collectObjectsWithId(JsonValue val) {
        String idKeyword = val.ls.specVersion().idKeyword();
        if (val instanceof JsonObject) {
            JsonObject obj = (JsonObject) val;
            if (obj.containsKey(idKeyword)
                && obj.require(idKeyword).typeOfValue() == String.class) {
                storage.put(obj.require(idKeyword).requireString(), obj);
            }
            for (String key : obj.keySet()) {
                collectObjectsWithId(obj.require(key));
            }
        } else if (val instanceof JsonArray) {
            JsonArray arr = (JsonArray) val;
            for (int i = 0; i < arr.length(); ++i) {
                collectObjectsWithId(arr.at(i));
            }
        }
    }

    JsonObject getById(String id) {
        return storage.get(id);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy