Add rfc8528-data-api 76/82976/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 9 Jul 2019 09:39:25 +0000 (11:39 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 9 Jul 2019 11:10:02 +0000 (13:10 +0200)
Mount points require a rather complex interaction with
NormalizedNodeStreamWriter, which is defined in a new artifact.

Change-Id: If3063151c7eca561b5382e2da6ddc339cba94e4f
JIRA: YANGTOOLS-1007
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
artifacts/pom.xml
yang/pom.xml
yang/rfc8528-data-api/pom.xml [new file with mode: 0644]
yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/DynamicMountPointSchemaResolver.java [new file with mode: 0644]
yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/MountPointStreamWriter.java [new file with mode: 0644]
yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/MountPointSchemaResolver.java [new file with mode: 0644]
yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/StaticMountPointSchemaResolver.java [new file with mode: 0644]

index 65f73a85337d8297eaa231eb9c4ffbcac889bc46..6a14ff584f7dac353ad9da864e40e41c0e102454 100644 (file)
                 <version>3.0.3-SNAPSHOT</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>rfc8528-data-api</artifactId>
+                <version>3.0.3-SNAPSHOT</version>
+            </dependency>
             <dependency>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>rfc8528-model-api</artifactId>
index de8da46bee5ab8760e661de4d508f22a547e7f86..ad0ce209746260811f0a811903e5966bf7da0375 100644 (file)
@@ -89,6 +89,7 @@
         <module>rfc8040-parser-support</module>
 
         <!-- RFC8528 (mount-point) metamodel support -->
+        <module>rfc8528-data-api</module>
         <module>rfc8528-model-api</module>
         <module>rfc8528-parser-support</module>
     </modules>
diff --git a/yang/rfc8528-data-api/pom.xml b/yang/rfc8528-data-api/pom.xml
new file mode 100644 (file)
index 0000000..9d859ba
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2019 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
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>bundle-parent</artifactId>
+        <version>3.0.3-SNAPSHOT</version>
+        <relativePath>../../bundle-parent</relativePath>
+    </parent>
+
+    <artifactId>rfc8528-data-api</artifactId>
+    <packaging>bundle</packaging>
+    <name>${project.artifactId}</name>
+    <description>RFC8528 data model extensions</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-data-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-parser-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>rfc8528-model-api</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Automatic-Module-Name>org.opendaylight.yangtools.rfc8528.data.api</Automatic-Module-Name>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>com.github.spotbugs</groupId>
+                <artifactId>spotbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/DynamicMountPointSchemaResolver.java b/yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/DynamicMountPointSchemaResolver.java
new file mode 100644 (file)
index 0000000..fda71dd
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaResolver;
+import org.opendaylight.yangtools.rfc8528.model.api.YangLibraryConstants.ContainerName;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
+
+/**
+ * A resolver which can resolve the SchemaContext for use with mount point data based on the
+ * {@code ietf-yang-library} content of the mountpoint itself. This process requires two steps:
+ * <ul>
+ *   <li>{@link #findContainerContext(ContainerName)} is invoked to acquire a SchemaContext in which to interpret
+ *       one of the possible {@code ietf-yang-library} top-level containers.
+ *   </li>
+ *   <li>The container is normalized based on the returned context by the user of this interface and then
+ *       {@link #assembleSchemaContext(ContainerNode)} is invoked to acquire the SchemaContext which will be used
+ *       to interpret the mount point data.
+ *   </li>
+ * </ul>
+ */
+@Beta
+public interface DynamicMountPointSchemaResolver extends MountPointSchemaResolver {
+    /**
+     * Return the schema in which YANG Library container content should be interpreted.
+     *
+     * @param containerName Top-level YANG Library container name
+     * @return The SchemaContext to use when interpreting the specified YANG Library container, or empty
+     * @throws NullPointerException if container is null
+     */
+    Optional<SchemaContext> findContainerContext(@NonNull ContainerName containerName);
+
+    /**
+     * Assemble the SchemaContext for specified normalized YANG Library top-level container.
+     *
+     * @param container Top-level YANG Library container
+     * @return An assembled SchemaContext
+     * @throws NullPointerException if container is null
+     * @throws YangParserException if the schema context cannot be assembled
+     */
+    @NonNull SchemaContext assembleSchemaContext(@NonNull ContainerNode container) throws YangParserException;
+}
diff --git a/yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/MountPointStreamWriter.java b/yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/MountPointStreamWriter.java
new file mode 100644 (file)
index 0000000..5c020ad
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaResolver;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriterExtension;
+
+/**
+ * A {@link NormalizedNodeStreamWriterExtension} exposed by stream writers which can handle mount point data, notably
+ * providing the facilities to resolve a mount point schema and normalize mount point contents into a normalized
+ * structure.
+ */
+@Beta
+public interface MountPointStreamWriter extends NormalizedNodeStreamWriterExtension {
+    /**
+     * Attempt to acquire a {@link MountPointSchemaResolver} to resolve schemas for the purposes of interpreting this
+     * mount point. An empty result indicates the mount point is not attached.
+     *
+     * @param label Mount point label, as defined via the use of {@code mount-point} statement
+     * @return An optional handler for mount point data
+     * @throws NullPointerException if label is null
+     */
+    Optional<MountPointSchemaResolver> findMountPoint(@NonNull QName label);
+}
diff --git a/yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/MountPointSchemaResolver.java b/yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/MountPointSchemaResolver.java
new file mode 100644 (file)
index 0000000..4c7a0dd
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 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.rfc8528.model.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * An entity able to resolve the SchemaContext for embedded mount points. This interface should not be implemented
+ * directly, but rather its domain specializations, like {@link StaticMountPointSchemaResolver} should be provided.
+ */
+@Beta
+@NonNullByDefault
+public interface MountPointSchemaResolver {
+
+}
diff --git a/yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/StaticMountPointSchemaResolver.java b/yang/rfc8528-model-api/src/main/java/org/opendaylight/yangtools/rfc8528/model/api/StaticMountPointSchemaResolver.java
new file mode 100644 (file)
index 0000000..8831c49
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2019 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.rfc8528.model.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+
+/**
+ * A resolver which has static knowledge of the SchemaContext which should be used to interpret mount point data.
+ * Instances of this interface should be used in contexts where the mount point data is expected not to contain
+ * required {@code ietf-yang-library} data, for example due to filtering.
+ */
+@Beta
+public interface StaticMountPointSchemaResolver extends MountPointSchemaResolver, SchemaContextProvider {
+    @Override
+    @NonNull SchemaContext getSchemaContext();
+}