Add YangFeatureProvider 50/102050/15
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Aug 2022 23:23:51 +0000 (01:23 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 16 Aug 2022 09:29:37 +0000 (11:29 +0200)
YangFeatureProvider is a counterpart to YangModuleInfoProvider,
providing the runtime with the ability to introspect what features
should be supported in an EffectiveModelContext.

JIRA: MDSAL-767
Change-Id: I6d08772c96eead79b4c88ae9ac27c57901dc70a8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-test-model/pom.xml
binding/mdsal-binding-test-model/src/main/java/org/opendaylight/mdsal/binding/test/model/util/Mdsal767Support.java [new file with mode: 0644]
binding/mdsal-binding-test-model/src/main/yang/mdsal767.yang [new file with mode: 0644]
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/YangFeatureProvider.java [new file with mode: 0644]

index 2b2f33dc44a69930d89296857ebc84587f38c0e3..d3f019e3a6603fa0e5f419d3964b0f2de07179e8 100644 (file)
@@ -43,5 +43,9 @@
             <groupId>org.opendaylight.mdsal.model</groupId>
             <artifactId>yang-ext</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.kohsuke.metainf-services</groupId>
+            <artifactId>metainf-services</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/binding/mdsal-binding-test-model/src/main/java/org/opendaylight/mdsal/binding/test/model/util/Mdsal767Support.java b/binding/mdsal-binding-test-model/src/main/java/org/opendaylight/mdsal/binding/test/model/util/Mdsal767Support.java
new file mode 100644 (file)
index 0000000..45188aa
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2022 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.mdsal.binding.test.model.util;
+
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.kohsuke.MetaInfServices;
+import org.opendaylight.yang.gen.v1.mdsal767.norev.Mdsal767Data;
+import org.opendaylight.yang.gen.v1.mdsal767.norev.One$F;
+import org.opendaylight.yangtools.yang.binding.YangFeature;
+import org.opendaylight.yangtools.yang.binding.YangFeatureProvider;
+
+@MetaInfServices
+@NonNullByDefault
+public final class Mdsal767Support implements YangFeatureProvider<Mdsal767Data> {
+    @Override
+    public Class<Mdsal767Data> boundModule() {
+        return Mdsal767Data.class;
+    }
+
+    @Override
+    public Set<? extends YangFeature<?, Mdsal767Data>> supportedFeatures() {
+        return Set.of(One$F.VALUE);
+    }
+}
diff --git a/binding/mdsal-binding-test-model/src/main/yang/mdsal767.yang b/binding/mdsal-binding-test-model/src/main/yang/mdsal767.yang
new file mode 100644 (file)
index 0000000..980c715
--- /dev/null
@@ -0,0 +1,16 @@
+module mdsal767 {
+  namespace mdsal767;
+  prefix mdsal767;
+
+  feature one;
+
+  feature two;
+
+  container one {
+    if-feature one;
+  }
+
+  container two {
+    if-feature two;
+  }
+}
diff --git a/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/YangFeatureProvider.java b/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/YangFeatureProvider.java
new file mode 100644 (file)
index 0000000..90e882f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 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.binding;
+
+import java.util.ServiceLoader;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Run-time feature discovery service. Implementations of this interface are required to be registered with the
+ * {@link ServiceLoader} framework.
+ */
+@NonNullByDefault
+public interface YangFeatureProvider<R extends DataRoot> {
+    /**
+     * Return the module this provider recognizes. It is implied that any feature defined in this module and not
+     * advertized by any provider is unavailable.
+     *
+     * @return {@link DataRoot} class this provider binds to
+     */
+    Class<R> boundModule();
+
+    /**
+     * Return the set of supported features.
+     *
+     * @return Supported features.
+     */
+    Set<? extends YangFeature<?, R>> supportedFeatures();
+}