LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);
final var contextTree = DataSchemaContextTree.from(newSchemaContext);
- final var rootContextNode = contextTree.findChild(getRootPath());
- if (!rootContextNode.isPresent()) {
+ final var rootContextNode = contextTree.childByPath(getRootPath());
+ if (rootContextNode == null) {
LOG.warn("Could not find root {} in new schema context, not upgrading", getRootPath());
return;
}
- final var rootSchemaNode = rootContextNode.orElseThrow().dataSchemaNode();
+ final var rootSchemaNode = rootContextNode.dataSchemaNode();
if (!(rootSchemaNode instanceof DataNodeContainer)) {
LOG.warn("Root {} resolves to non-container type {}, not upgrading", getRootPath(), rootSchemaNode);
return;
private static DataSchemaNode getRootSchemaNode(final EffectiveModelContext schemaContext,
final YangInstanceIdentifier rootPath) {
final var contextTree = DataSchemaContextTree.from(schemaContext);
- final var rootContextNode = contextTree.findChild(rootPath);
- checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);
+ final var rootContextNode = contextTree.childByPath(rootPath);
+ checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
- final var rootSchemaNode = rootContextNode.orElseThrow().dataSchemaNode();
+ final var rootSchemaNode = rootContextNode.dataSchemaNode();
checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s",
rootPath, rootSchemaNode);
return rootSchemaNode;
import com.google.common.cache.LoadingCache;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.CheckedValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
return TREES.getUnchecked(ctx);
}
+ /**
+ * Find a child node as identified by an absolute {@link YangInstanceIdentifier}.
+ *
+ * @param path Path towards the child node
+ * @return Child node if present, or {@code null} when corresponding child is not found.
+ * @throws NullPointerException if {@code path} is {@code null}
+ */
+ public @Nullable DataSchemaContext childByPath(final @NonNull YangInstanceIdentifier path) {
+ return root.childByPath(path);
+ }
+
/**
* Find a child node as identified by an absolute {@link YangInstanceIdentifier}.
*
* @param path Path towards the child node
* @return Child node if present, or empty when corresponding child is not found.
- * @throws NullPointerException if {@code path} is null
+ * @throws NullPointerException if {@code path} is {@code null}
*/
public @NonNull Optional<@NonNull DataSchemaContext> findChild(final @NonNull YangInstanceIdentifier path) {
// Optional.ofNullable() inline due to annotations