Add Case/Extension/Feature/IdentityEffectiveStatementNamespace 05/68805/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 24 Feb 2018 21:43:04 +0000 (22:43 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 27 Feb 2018 08:43:25 +0000 (09:43 +0100)
This patch adds simple RFC7950 namespaces.

JIRA: YANGTOOLS-853
Change-Id: I753a297a782fc3f9f81f9d1659fc12a7c70b8c28
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
13 files changed:
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/EffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatementNamespace.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/EffectiveStatementNamespace.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatementNamespace.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatementNamespace.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatementNamespace.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/NamespacedEffectiveStatement.java [new file with mode: 0644]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java

index 2c4ff1d3fbdcd6d7f8dd49c21d96a12b7d7fffa8..e2d8fcdb87aa9eb7bebce1e022e507c742a0c3ea 100644 (file)
@@ -33,7 +33,6 @@ public interface EffectiveStatement<A, S extends DeclaredStatement<A>> extends M
      * Returns statement, which was explicit declaration of this effective
      * statement.
      *
-     *
      * @return statement, which was explicit declaration of this effective
      *         statement or null if statement was inferred from context.
      */
@@ -43,21 +42,17 @@ public interface EffectiveStatement<A, S extends DeclaredStatement<A>> extends M
     /**
      * Returns value associated with supplied identifier.
      *
-     * @param <K>
-     *            Identifier type
-     * @param <V>
-     *            Value type
-     * @param <N>
-     *            Namespace identifier type
-     * @param namespace
-     *            Namespace type
-     * @param identifier
-     *            Identifier of element.
+     * @param <K> Identifier type
+     * @param <V> Value type
+     * @param <N> Namespace identifier type
+     * @param namespace Namespace type
+     * @param identifier Identifier of element.
      * @return Value if present, null otherwise.
      */
     //<K, V, N extends IdentifierNamespace<? super K, ? extends V>> V
+    // FIXME: 3.0.0: make this return an Optional, not a nullable
     @Nullable
-    <K,V,N extends IdentifierNamespace<K, V>> V get(@Nonnull Class<N> namespace,@Nonnull  K identifier);
+    <K, V, N extends IdentifierNamespace<K, V>> V get(@Nonnull Class<N> namespace, @Nonnull K identifier);
 
     /**
      * Returns all local values from supplied namespace.
@@ -68,6 +63,7 @@ public interface EffectiveStatement<A, S extends DeclaredStatement<A>> extends M
      * @param namespace Namespace type
      * @return Value if present, null otherwise.
      */
+    // FIXME: 3.0.0: make this contract return empty maps on non-presence
     @Nullable
     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(@Nonnull Class<N> namespace);
 
@@ -80,6 +76,7 @@ public interface EffectiveStatement<A, S extends DeclaredStatement<A>> extends M
      * @param namespace Namespace type
      * @return Key-value mappings, empty if the namespace does not exist.
      */
+    // FIXME: 3.0.0: remove this in favor of fixed getAll()
     default <K, V, N extends IdentifierNamespace<K, V>> @NonNull Map<K, V> findAll(@NonNull final Class<N> namespace) {
         final Map<K, V> map = getAll(requireNonNull(namespace));
         return map == null ? ImmutableMap.of() : map;
index f4f0e67b528c2ea18af36f00a465b0b335b50049..60d25b3fc6d7d38725e03c8760cf03e36d547c1a 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 @Beta
-public interface CaseEffectiveStatement extends EffectiveStatement<QName, CaseStatement> {
+public interface CaseEffectiveStatement extends NamespacedEffectiveStatement<CaseStatement> {
 
 }
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatementNamespace.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatementNamespace.java
new file mode 100644 (file)
index 0000000..30b7a1d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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;
+
+/**
+ * Namespace of available cases in a choice node. According to RFC7950 section 6.2.1:
+ * <pre>
+ *     All cases within a choice share the same case identifier
+ *     namespace.  This namespace is scoped to the parent choice node.
+ * </pre>
+ *
+ * @author Robert Varga
+ */
+@Beta
+public abstract class CaseEffectiveStatementNamespace extends EffectiveStatementNamespace<CaseEffectiveStatement> {
+    private CaseEffectiveStatementNamespace() {
+        // Should never be instantiated
+    }
+}
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/EffectiveStatementNamespace.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/EffectiveStatementNamespace.java
new file mode 100644 (file)
index 0000000..188034b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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 org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ * Common super-interface for {@link IdentifierNamespace}s which hold {@link EffectiveStatement}s.
+ *
+ * @author Robert Varga
+ *
+ * @param <E> Effective statement type
+ */
+@Beta
+public abstract class EffectiveStatementNamespace<E extends NamespacedEffectiveStatement<?>>
+    implements IdentifierNamespace<QName, E> {
+
+    protected EffectiveStatementNamespace() {
+        // Subclasses should guard against instantiation
+    }
+}
index 2f92c2a0d1c38abe18ae248be374a062a09e3cfa..d8a8586c9a171608fa689dfa56564415c9bbe2f2 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 @Beta
-public interface ExtensionEffectiveStatement extends EffectiveStatement<QName, ExtensionStatement> {
+public interface ExtensionEffectiveStatement extends NamespacedEffectiveStatement<ExtensionStatement> {
 
 }
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatementNamespace.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatementNamespace.java
new file mode 100644 (file)
index 0000000..493bcb8
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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;
+
+/**
+ * Namespace of available extensions. According to RFC7950 section 6.2.1:
+ * <pre>
+ *     All extension names defined in a module and its submodules share
+ *     the same extension identifier namespace.
+ * </pre>
+ *
+ * @author Robert Varga
+ */
+@Beta
+public abstract class ExtensionEffectiveStatementNamespace
+        extends EffectiveStatementNamespace<ExtensionEffectiveStatement> {
+    private ExtensionEffectiveStatementNamespace() {
+        // Should never be instantiated
+    }
+}
index 16384a2234c355ca494828de0f0671614ce85bc3..bb9aa8a73883111ec5dea93f0e375ea0e05c7490 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 @Beta
-public interface FeatureEffectiveStatement extends EffectiveStatement<QName, FeatureStatement> {
+public interface FeatureEffectiveStatement extends NamespacedEffectiveStatement<FeatureStatement> {
 
 }
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatementNamespace.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatementNamespace.java
new file mode 100644 (file)
index 0000000..ec2856f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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;
+
+/**
+ * Namespace of available extensions. According to RFC7950 section 6.2.1:
+ * <pre>
+ *     All feature names defined in a module and its submodules share the
+ *     same feature identifier namespace.
+ * </pre>
+ *
+ * @author Robert Varga
+ */
+@Beta
+public abstract class FeatureEffectiveStatementNamespace
+        extends EffectiveStatementNamespace<FeatureEffectiveStatement> {
+    private FeatureEffectiveStatementNamespace() {
+        // Should never be instantiated
+    }
+}
index 74742e6ae28f94da91a916ff89f07d5fc6eb42c6..f0e94be085f663ddff61636b4366c0c5028f7a0a 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 @Beta
-public interface IdentityEffectiveStatement extends EffectiveStatement<QName, IdentityStatement> {
+public interface IdentityEffectiveStatement extends NamespacedEffectiveStatement<IdentityStatement> {
 
 }
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatementNamespace.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatementNamespace.java
new file mode 100644 (file)
index 0000000..7c59a91
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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;
+
+/**
+ * Namespace of available identities. According to RFC7950 section 6.2.1:
+ * <pre>
+ *     All identity names defined in a module and its submodules share
+ *     the same identity identifier namespace.
+ * </pre>
+ *
+ * @author Robert Varga
+ */
+@Beta
+public abstract class IdentityEffectiveStatementNamespace
+        extends EffectiveStatementNamespace<IdentityEffectiveStatement> {
+    private IdentityEffectiveStatementNamespace() {
+        // Should never be instantiated
+    }
+}
index 73e491ec27081c5938bf1062e7d264eb333ffe84..5676204aa68d8151796adbe7bb0d61f26669f7ff 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
@@ -50,17 +49,6 @@ public interface ModuleEffectiveStatement extends EffectiveStatement<String, Mod
         }
     }
 
-    /**
-     * Namespace mapping all identities defined in this module (and its submodules). Identities are keyed by their
-     * QNameModule.
-     */
-    abstract class QNameToEffectiveIdentityNamespace
-            implements IdentifierNamespace<QName, @NonNull SubmoduleEffectiveStatement> {
-        private QNameToEffectiveIdentityNamespace() {
-            // This class should never be subclassed
-        }
-    }
-
     /**
      * Get the local QNameModule of this module. All implementations need to override this default method.
      *
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/NamespacedEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/NamespacedEffectiveStatement.java
new file mode 100644 (file)
index 0000000..3fb7ee2
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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 static com.google.common.base.Verify.verifyNotNull;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.concepts.Identifiable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+/**
+ * Common super-interface for all statements which can be held in one of the {@link EffectiveStatementNamespace}s.
+ *
+ * @param <D> Declared statement type
+ *
+ * @author Robert Varga
+ */
+@Beta
+public interface NamespacedEffectiveStatement<D extends DeclaredStatement<QName>>
+    extends EffectiveStatement<QName, D>, Identifiable<QName> {
+
+    @Override
+    default QName getIdentifier() {
+        return verifyNotNull(argument());
+    }
+}
index d57aef083ff907d96c2dc09ca1a055dd3afa4502..6da7e690915d2e8470ce9b3643311c3838a8cfd9 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatementNamespace;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
@@ -105,7 +106,7 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleS
         if (NameToEffectiveSubmoduleNamespace.class.equals(namespace)) {
             return Optional.of((Map<K, V>) nameToSubmodule);
         }
-        if (QNameToEffectiveIdentityNamespace.class.equals(namespace)) {
+        if (IdentityEffectiveStatementNamespace.class.equals(namespace)) {
             return Optional.of((Map<K, V>) qnameToIdentity);
         }
         return super.getNamespaceContents(namespace);