in curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java [133:175]
private void readNode(
ImmutableList.Builder<Schema> builder, JsonNode node, SchemaValidatorMapper schemaValidatorMapper) {
String name = getText(node, "name", null);
String path = getText(node, "path", null);
boolean isRegex = getBoolean(node, "isRegex");
if (name == null) {
throw new RuntimeException("name is required at: " + node);
}
if (path == null) {
throw new RuntimeException("path is required at: " + node);
}
SchemaBuilder schemaBuilder = isRegex ? Schema.builder(Pattern.compile(path)) : Schema.builder(path);
String schemaValidatorName = getText(node, "schemaValidator", null);
if (schemaValidatorName != null) {
if (schemaValidatorMapper == null) {
throw new RuntimeException("No SchemaValidatorMapper provided but needed at: " + node);
}
schemaBuilder.dataValidator(schemaValidatorMapper.getSchemaValidator(schemaValidatorName));
}
Map<String, String> metadata = Maps.newHashMap();
if (node.has("metadata")) {
JsonNode metadataNode = node.get("metadata");
Iterator<String> fieldNameIterator = metadataNode.fieldNames();
while (fieldNameIterator.hasNext()) {
String fieldName = fieldNameIterator.next();
metadata.put(fieldName, getText(metadataNode, fieldName, ""));
}
}
Schema schema = schemaBuilder
.name(name)
.documentation(getText(node, "documentation", ""))
.ephemeral(getAllowance(node, "ephemeral"))
.sequential(getAllowance(node, "sequential"))
.watched(getAllowance(node, "watched"))
.canBeDeleted(getBoolean(node, "canBeDeleted"))
.metadata(metadata)
.build();
builder.add(schema);
}