@Override public void validate( final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); final JsonNode schemas = tree.getNode().get(keyword); final int size = schemas.size(); final ObjectNode fullReport = FACTORY.objectNode(); int nrSuccess = 0; ListProcessingReport subReport; JsonPointer ptr; FullData newData; for (int index = 0; index < size; index++) { subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson()); if (subReport.isSuccess()) nrSuccess++; } if (nrSuccess == 0) report.error( newMsg(data, bundle, "err.common.schema.noMatch") .putArgument("nrSchemas", size) .put("reports", fullReport)); }
private <T> void walkTree( final JsonPointer pwd, final SchemaTree tree, final SchemaListener<T> listener, final ProcessingReport report) throws ProcessingException { listener.enteringPath(pwd, report); final SchemaTree resolvedTree = resolveTree(tree, report); listener.visiting(resolvedTree, report); /* * Grab pointer collectors */ final Map<String, PointerCollector> map = Maps.newTreeMap(); map.putAll(collectors); map.keySet().retainAll(Sets.newHashSet(resolvedTree.getNode().fieldNames())); /* * Collect pointers to visit next */ final List<JsonPointer> pointers = Lists.newArrayList(); for (final PointerCollector collector : map.values()) collector.collect(pointers, resolvedTree); /* * Now, visit the collected set of pointers */ for (final JsonPointer ptr : pointers) { walkTree(pwd.append(ptr), resolvedTree.append(ptr), listener, report); } listener.exitingPath(pwd, report); }