@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); }
private static final class DummyProcessor implements Processor<FullData, FullData> { private static final JsonPointer PTR = JsonPointer.of("not"); private final WantedState wanted; private DummyProcessor(final WantedState wanted) { this.wanted = wanted; } @Override public FullData process(final ProcessingReport report, final FullData input) throws ProcessingException { assertEquals(input.getSchema().getPointer(), PTR); wanted.doIt(report); return input; } }
ObjectNode newOp(final JsonPointer ptr) { final ObjectNode ret = JacksonUtils.nodeFactory().objectNode(); ret.put("op", opName); ret.put("path", ptr.toString()); return ret; }
/** * Walk a tree with a listener * * @param tree the schema tree to walk * @param listener the listener * @param report the processing report to use * @param <T> the value type produced by the listener * @throws ProcessingException processing failure */ public final <T> void walk( final SchemaTree tree, final SchemaListener<T> listener, final ProcessingReport report) throws ProcessingException { walkTree(JsonPointer.empty(), tree, listener, report); }