From: Robert Varga Date: Sat, 24 Feb 2018 21:43:04 +0000 (+0100) Subject: Add Case/Extension/Feature/IdentityEffectiveStatementNamespace X-Git-Tag: v2.0.2~19 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0ffea57f86322c5c7fc1adb15e1011dd97e031c7;p=yangtools.git Add Case/Extension/Feature/IdentityEffectiveStatementNamespace This patch adds simple RFC7950 namespaces. JIRA: YANGTOOLS-853 Change-Id: I753a297a782fc3f9f81f9d1659fc12a7c70b8c28 Signed-off-by: Robert Varga --- diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/EffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/EffectiveStatement.java index 2c4ff1d3fb..e2d8fcdb87 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/EffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/EffectiveStatement.java @@ -33,7 +33,6 @@ public interface EffectiveStatement> 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> extends M /** * Returns value associated with supplied identifier. * - * @param - * Identifier type - * @param - * Value type - * @param - * Namespace identifier type - * @param namespace - * Namespace type - * @param identifier - * Identifier of element. + * @param Identifier type + * @param Value type + * @param Namespace identifier type + * @param namespace Namespace type + * @param identifier Identifier of element. * @return Value if present, null otherwise. */ //> V + // FIXME: 3.0.0: make this return an Optional, not a nullable @Nullable - > V get(@Nonnull Class namespace,@Nonnull K identifier); + > V get(@Nonnull Class namespace, @Nonnull K identifier); /** * Returns all local values from supplied namespace. @@ -68,6 +63,7 @@ public interface EffectiveStatement> 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 > Map getAll(@Nonnull Class namespace); @@ -80,6 +76,7 @@ public interface EffectiveStatement> 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 > @NonNull Map findAll(@NonNull final Class namespace) { final Map map = getAll(requireNonNull(namespace)); return map == null ? ImmutableMap.of() : map; diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatement.java index f4f0e67b52..60d25b3fc6 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatement.java @@ -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 { +public interface CaseEffectiveStatement extends NamespacedEffectiveStatement { } 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 index 0000000000..30b7a1d96b --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/CaseEffectiveStatementNamespace.java @@ -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: + *
+ *     All cases within a choice share the same case identifier
+ *     namespace.  This namespace is scoped to the parent choice node.
+ * 
+ * + * @author Robert Varga + */ +@Beta +public abstract class CaseEffectiveStatementNamespace extends EffectiveStatementNamespace { + 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 index 0000000000..188034b144 --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/EffectiveStatementNamespace.java @@ -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 Effective statement type + */ +@Beta +public abstract class EffectiveStatementNamespace> + implements IdentifierNamespace { + + protected EffectiveStatementNamespace() { + // Subclasses should guard against instantiation + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatement.java index 2f92c2a0d1..d8a8586c9a 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatement.java @@ -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 { +public interface ExtensionEffectiveStatement extends NamespacedEffectiveStatement { } 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 index 0000000000..493bcb88c8 --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ExtensionEffectiveStatementNamespace.java @@ -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: + *
+ *     All extension names defined in a module and its submodules share
+ *     the same extension identifier namespace.
+ * 
+ * + * @author Robert Varga + */ +@Beta +public abstract class ExtensionEffectiveStatementNamespace + extends EffectiveStatementNamespace { + private ExtensionEffectiveStatementNamespace() { + // Should never be instantiated + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatement.java index 16384a2234..bb9aa8a738 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatement.java @@ -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 { +public interface FeatureEffectiveStatement extends NamespacedEffectiveStatement { } 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 index 0000000000..ec2856f194 --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/FeatureEffectiveStatementNamespace.java @@ -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: + *
+ *     All feature names defined in a module and its submodules share the
+ *     same feature identifier namespace.
+ * 
+ * + * @author Robert Varga + */ +@Beta +public abstract class FeatureEffectiveStatementNamespace + extends EffectiveStatementNamespace { + private FeatureEffectiveStatementNamespace() { + // Should never be instantiated + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatement.java index 74742e6ae2..f0e94be085 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatement.java @@ -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 { +public interface IdentityEffectiveStatement extends NamespacedEffectiveStatement { } 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 index 0000000000..7c59a91935 --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IdentityEffectiveStatementNamespace.java @@ -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: + *
+ *     All identity names defined in a module and its submodules share
+ *     the same identity identifier namespace.
+ * 
+ * + * @author Robert Varga + */ +@Beta +public abstract class IdentityEffectiveStatementNamespace + extends EffectiveStatementNamespace { + private IdentityEffectiveStatementNamespace() { + // Should never be instantiated + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java index 73e491ec27..5676204aa6 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java @@ -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 { - 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 index 0000000000..3fb7ee28fd --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/NamespacedEffectiveStatement.java @@ -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 Declared statement type + * + * @author Robert Varga + */ +@Beta +public interface NamespacedEffectiveStatement> + extends EffectiveStatement, Identifiable { + + @Override + default QName getIdentifier() { + return verifyNotNull(argument()); + } +} diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java index d57aef083f..6da7e69091 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java @@ -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) nameToSubmodule); } - if (QNameToEffectiveIdentityNamespace.class.equals(namespace)) { + if (IdentityEffectiveStatementNamespace.class.equals(namespace)) { return Optional.of((Map) qnameToIdentity); } return super.getNamespaceContents(namespace);