This patch adds simple RFC7950 namespaces.
JIRA: YANGTOOLS-853
Change-Id: I753a297a782fc3f9f81f9d1659fc12a7c70b8c28
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* 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.
*/
/**
* 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.
* @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);
* @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;
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> {
}
--- /dev/null
+/*
+ * 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
+ }
+}
--- /dev/null
+/*
+ * 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
+ }
+}
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> {
}
--- /dev/null
+/*
+ * 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
+ }
+}
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> {
}
--- /dev/null
+/*
+ * 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
+ }
+}
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> {
}
--- /dev/null
+/*
+ * 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
+ }
+}
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;
}
}
- /**
- * 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.
*
--- /dev/null
+/*
+ * 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());
+ }
+}
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;
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);