import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeRoot;
/**
* {@link EffectiveStatement}-based result of YANG parser compilation. Unlike a SchemaContext, which it extends,
- * it gives access to individual {@link ModuleEffectiveStatement}s that comprise it.
+ * it gives access to individual {@link ModuleEffectiveStatement}s that comprise it. It also supports resolution of
+ * {@link Absolute} schema node identifiers via {@link #findSchemaTreeNode(Absolute)}.
*
* @author Robert Varga
*/
@Beta
-// FIXME: 7.0.0: evaluate if we still need to extend SchemaContext here
-public interface EffectiveModelContext extends SchemaContext {
+// FIXME: 8.0.0: evaluate if we still need to extend SchemaContext here
+public interface EffectiveModelContext extends SchemaContext, SchemaTreeRoot {
- Map<QNameModule, ModuleEffectiveStatement> getModuleStatements();
+ @NonNull Map<QNameModule, ModuleEffectiveStatement> getModuleStatements();
- default Optional<ModuleEffectiveStatement> findModuleStatement(final QNameModule moduleName) {
+ default @NonNull Optional<ModuleEffectiveStatement> findModuleStatement(final QNameModule moduleName) {
return Optional.ofNullable(getModuleStatements().get(requireNonNull(moduleName)));
}
- default Optional<ModuleEffectiveStatement> findModuleStatement(final QName moduleName) {
+ default @NonNull Optional<ModuleEffectiveStatement> findModuleStatement(final QName moduleName) {
return findModuleStatement(moduleName.getModule());
}
default @NonNull ModuleEffectiveStatement getModuleStatement(final QName moduleName) {
return getModuleStatement(moduleName.getModule());
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @implSpec
+ * Default implementation defers locates the module corresponding to the first element of path and then defers
+ * to {@link ModuleEffectiveStatement#findSchemaTreeNode(Absolute)}.
+ */
+ @Override
+ default Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(final Absolute path) {
+ return findModuleStatement(path.firstNodeIdentifier().getModule())
+ .flatMap(module -> module.findSchemaTreeNode(path));
+ }
}
package org.opendaylight.yangtools.yang.model.api.stmt;
import com.google.common.annotations.Beta;
+import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
/**
* Effective view of a {@link ModuleStatement}.
*/
@Beta
-public interface ModuleEffectiveStatement extends DataTreeAwareEffectiveStatement<UnqualifiedQName, ModuleStatement> {
+public interface ModuleEffectiveStatement
+ extends DataTreeAwareEffectiveStatement<UnqualifiedQName, ModuleStatement>, SchemaTreeRoot {
/**
* Namespace mapping all known prefixes in a module to their modules. Note this namespace includes the module
* in which it is instantiated.
* @return Local QNameModule
*/
@NonNull QNameModule localQNameModule();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @implSpec
+ * Default implementation defers to {@link #findSchemaTreeNode(java.util.List)}.
+ */
+ @Override
+ default Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(final Absolute path) {
+ return findSchemaTreeNode(path.getNodeIdentifiers());
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api.stmt;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+
+/**
+ * Common interface implemented by entities which act as the root of the {@code schema tree} and are able to resolve an
+ * {@code Absolute absolute schema node identifier} to a {@link SchemaTreeEffectiveStatement}.
+ */
+@Beta
+public interface SchemaTreeRoot {
+ /**
+ * Find a {@code schema tree} node based on its absolute schema node identifier.
+ *
+ * @param path Absolute schema node identifier
+ * @return Found node, or empty
+ * @throws NullPointerException if {@code path} is null
+ */
+ @NonNull Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(@NonNull Absolute path);
+}