- public static SchemaTracker create(final SchemaContext context, final SchemaPath path) {
- return new SchemaTracker(context, path);
+ public static @NonNull SchemaTracker create(final SchemaContext context, final SchemaPath path) {
+ final Collection<SchemaNode> schemaNodes = SchemaUtils.findParentSchemaNodesOnPath(context, path);
+ checkArgument(!schemaNodes.isEmpty(), "Unable to find schema node for supplied schema path: %s", path);
+ if (schemaNodes.size() > 1) {
+ LOG.warn("More possible schema nodes {} for supplied schema path {}", schemaNodes, path);
+ }
+ final Optional<DataNodeContainer> current = schemaNodes.stream()
+ .filter(node -> node instanceof DataNodeContainer).map(DataNodeContainer.class::cast)
+ .findFirst();
+ checkArgument(current.isPresent(),
+ "Schema path must point to container or list or an rpc input/output. Supplied path %s pointed to: %s",
+ path, current);
+ return new SchemaTracker(current.get());