Add XMLNamespace
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / SchemaContext.java
index 9ef5971f8fcbbff832a3425c732d074b5125ce27..fbe0a60287b629d8967342c9638889cf0cfd7b41 100644 (file)
@@ -10,18 +10,19 @@ package org.opendaylight.yangtools.yang.model.api;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-import java.net.URI;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Optional;
-import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
 
 /**
  * The interface represents static view of compiled yang files,
@@ -31,14 +32,15 @@ import org.opendaylight.yangtools.yang.common.Revision;
  * Instances MUST be immutable and thus usage in multi threaded
  * environment is safe.
  */
-// FIXME: 5.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
+// FIXME: 7.0.0: ContainerLike is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
 //               and possibly DataSchemaNode would reflect SchemaContext traits better.
-// FIXME: 5.0.0: consider deprecating this class in favor of EffectiveModelContext
-public interface SchemaContext extends ContainerSchemaNode, Immutable {
+// FIXME: 7.0.0: consider deprecating this class in favor of EffectiveModelContext
+public interface SchemaContext extends ContainerLike, Immutable {
     /**
      * QName of NETCONF top-level data node.
      */
-    @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
+    // FIXME: YANGTOOLS-1074: we do not want this name
+    @NonNull QName NAME = QName.create(XMLNamespace.of("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
 
     /**
      * Returns data schema node instances which represents direct subnodes (like
@@ -47,7 +49,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return set of <code>DataSchemaNode</code> instances which represents
      *         YANG data nodes at the module top level
      */
-    Set<DataSchemaNode> getDataDefinitions();
+    @NonNull Collection<? extends @NonNull DataSchemaNode> getDataDefinitions();
 
     /**
      * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
@@ -56,7 +58,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      *
      * @return set of the modules which belong to the schema context
      */
-    Set<Module> getModules();
+    @NonNull Collection<? extends @NonNull Module> getModules();
 
     /**
      * Returns rpc definition instances which are defined as the direct
@@ -65,7 +67,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return set of <code>RpcDefinition</code> instances which represents
      *         nodes defined via <code>rpc</code> YANG keyword
      */
-    Set<RpcDefinition> getOperations();
+    @NonNull Collection<? extends @NonNull RpcDefinition> getOperations();
 
     /**
      * Returns extension definition instances which are defined as the direct
@@ -74,7 +76,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return set of <code>ExtensionDefinition</code> instances which
      *         represents nodes defined via <code>extension</code> YANG keyword
      */
-    Set<ExtensionDefinition> getExtensions();
+    @NonNull Collection<? extends ExtensionDefinition> getExtensions();
 
     /**
      * Returns the module matching specified {@link QNameModule}, if present.
@@ -92,7 +94,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return module instance which has name and revision the same as are the values specified in parameters
      *         <code>namespace</code> and no revision.
      */
-    default Optional<Module> findModule(final @NonNull URI namespace) {
+    default Optional<Module> findModule(final @NonNull XMLNamespace namespace) {
         return findModule(QNameModule.create(namespace));
     }
 
@@ -104,7 +106,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return module instance which has name and revision the same as are the values specified in parameters
      *         <code>namespace</code> and <code>revision</code>.
      */
-    default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
+    default Optional<Module> findModule(final @NonNull XMLNamespace namespace, final @Nullable Revision revision) {
         return findModule(QNameModule.create(namespace, revision));
     }
 
@@ -116,7 +118,8 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return module instance which has name and revision the same as are the values specified in parameters
      *         <code>namespace</code> and <code>revision</code>.
      */
-    default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
+    default Optional<Module> findModule(final @NonNull XMLNamespace namespace,
+            final @NonNull Optional<Revision> revision) {
         return findModule(QNameModule.create(namespace, revision));
     }
 
@@ -130,7 +133,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return module instance which has name and revision the same as are the values specified in parameters
      *                <code>name</code> and <code>revision</code>.
      */
-    default Optional<Module> findModule(final String name, final Optional<Revision> revision) {
+    default Optional<? extends Module> findModule(final String name, final Optional<Revision> revision) {
         return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
     }
 
@@ -144,7 +147,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * @return module instance which has name and revision the same as are the values specified in parameters
      *         <code>name</code> and <code>revision</code>.
      */
-    default Optional<Module> findModule(final String name, final @Nullable Revision revision) {
+    default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
         return findModule(name, Optional.ofNullable(revision));
     }
 
@@ -156,7 +159,7 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      *                and no revision.
      * @throws NullPointerException if name is null
      */
-    default Optional<Module> findModule(final String name) {
+    default Optional<? extends Module> findModule(final String name) {
         return findModule(name, Optional.empty());
     }
 
@@ -164,33 +167,32 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
      * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
      * order guarantee that the latest revision is encountered first.
      *
-     * @param name
-     *            string with the module name
+     * @param name string with the module name
      * @return set of module instances with specified name.
      */
-    default Set<Module> findModules(final String name) {
-        return Sets.filter(getModules(), m -> name.equals(m.getName()));
+    default @NonNull Collection<? extends @NonNull Module> findModules(final String name) {
+        return Collections2.filter(getModules(), m -> name.equals(m.getName()));
     }
 
     /**
      * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
      * iteration order guarantee that the latest revision is encountered first.
      *
-     * @param namespace
-     *            URI instance with specified namespace
-     * @return module instance which has namespace equal to the
-     *         <code>namespace</code> or <code>null</code> in other cases
+     * @param namespace XMLNamespace instance with specified namespace
+     * @return module instance which has namespace equal to the {@code namespace} or {@code null} in other cases
      */
-    default Set<Module> findModules(final URI namespace) {
-        return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
+    default @NonNull Collection<? extends @NonNull Module> findModules(final XMLNamespace namespace) {
+        return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
     }
 
     @Override
-    default Set<ActionDefinition> getActions() {
+    @Deprecated
+    default Collection<? extends ActionDefinition> getActions() {
         return ImmutableSet.of();
     }
 
     @Override
+    @Deprecated
     default Optional<ActionDefinition> findAction(final QName qname) {
         requireNonNull(qname);
         return Optional.empty();
@@ -198,7 +200,8 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
 
     @Override
     default Optional<NotificationDefinition> findNotification(final QName qname) {
-        final Optional<Set<NotificationDefinition>> defs = findModule(qname.getModule()).map(Module::getNotifications);
+        final Optional<Collection<? extends @NonNull NotificationDefinition>> defs = findModule(qname.getModule())
+                .map(Module::getNotifications);
         if (defs.isPresent()) {
             for (NotificationDefinition def : defs.get()) {
                 if (qname.equals(def.getQName())) {
@@ -210,28 +213,92 @@ public interface SchemaContext extends ContainerSchemaNode, Immutable {
     }
 
     @Override
+    @Deprecated
     default Optional<String> getDescription() {
         return Optional.empty();
     }
 
     @Override
+    @Deprecated
     default Optional<String> getReference() {
         return Optional.empty();
     }
 
     @Override
-    default Collection<MustDefinition> getMustConstraints() {
+    @Deprecated
+    default Collection<? extends @NonNull MustDefinition> getMustConstraints() {
         return ImmutableSet.of();
     }
 
     @Override
-    default Optional<RevisionAwareXPath> getWhenCondition() {
+    @Deprecated
+    default Optional<? extends QualifiedBound> getWhenCondition() {
         return Optional.empty();
     }
 
+    @Override
+    @Deprecated
+    default boolean isAugmenting() {
+        return false;
+    }
+
+    @Override
+    @Deprecated
+    default boolean isAddedByUses() {
+        return false;
+    }
+
+    @Override
+    @Deprecated
+    default Optional<Boolean> effectiveConfig() {
+        return Optional.empty();
+    }
+
+    @Override
+    @Deprecated
+    default QName getQName() {
+        // FIXME: YANGTOOLS-1074: we do not want this name
+        return NAME;
+    }
+
+    @Override
+    @Deprecated
+    default SchemaPath getPath() {
+        return SchemaPath.ROOT;
+    }
+
+    @Override
+    @Deprecated
+    default Status getStatus() {
+        return Status.CURRENT;
+    }
+
+    @Override
+    @Deprecated
+    default Collection<? extends UsesNode> getUses() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    @Deprecated
+    default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
+        return Collections.emptySet();
+    }
+
     @Beta
     @Override
     default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
         return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
     }
+
+    /**
+     * Get identities derived from a selected identity.
+     *
+     * @param identity base identity
+     * @return collection of identities derived from this identity
+     * @throws NullPointerException if identity is null
+     * @throws IllegalArgumentException if the specified identity is not present in this context
+     */
+    @Beta
+    @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);
 }