X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Fapi%2FSchemaContext.java;h=0a94ddd3b6d836b30fe7ed863676d66fbcbbf200;hb=ba226275cf36090309af751608491f2bc485ca3b;hp=ecafe233a4fa210b52943408f63a7d0ba7e03964;hpb=3583a98815919107c1c23025957e94b31efcbe30;p=yangtools.git
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
index ecafe233a4..0a94ddd3b6 100644
--- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
+++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
@@ -7,21 +7,40 @@
*/
package org.opendaylight.yangtools.yang.model.api;
-import com.google.common.base.Optional;
-import org.opendaylight.yangtools.yang.common.QName;
+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 java.net.URI;
-import java.util.Date;
-import java.util.Set;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+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.xpath.api.YangXPathExpression.QualifiedBound;
/**
- * The interface contains the methods for manipulating all the top level context
- * data (data from all red modules) like YANG notifications, extensions,
+ * The interface represents static view of compiled yang files,
+ * contains the methods for obtaining all the top level context
+ * data (data from all modules) like YANG notifications, extensions,
* operations...
+ * Instances MUST be immutable and thus usage in multi threaded
+ * environment is safe.
*/
-public interface SchemaContext extends ContainerSchemaNode {
-
- public static final QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "data");
+// FIXME: 7.0.0: ContainerLike is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
+// and possibly DataSchemaNode would reflect SchemaContext traits better.
+// 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.
+ */
+ // FIXME: YANGTOOLS-1074: we do not want this name
+ @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
/**
* Returns data schema node instances which represents direct subnodes (like
@@ -30,25 +49,16 @@ public interface SchemaContext extends ContainerSchemaNode {
* @return set of DataSchemaNode
instances which represents
* YANG data nodes at the module top level
*/
- Set getDataDefinitions();
+ Collection extends DataSchemaNode> getDataDefinitions();
/**
- * Returns modules which are part of the schema context.
+ * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
+ * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
+ * modules having the same attribute are encountered newest revision first.
*
* @return set of the modules which belong to the schema context
*/
- Set getModules();
-
- /**
- *
- * Returns notification definition instances which are defined as the direct
- * subelements in all YANG modules in the context.
- *
- * @return set of NotificationDefinition
instances which
- * represents nodes defined via notification
YANG
- * keyword
- */
- Set getNotifications();
+ Collection extends Module> getModules();
/**
* Returns rpc definition instances which are defined as the direct
@@ -57,68 +67,240 @@ public interface SchemaContext extends ContainerSchemaNode {
* @return set of RpcDefinition
instances which represents
* nodes defined via rpc
YANG keyword
*/
- Set getOperations();
+ Collection extends RpcDefinition> getOperations();
/**
- * Returns extencion definition instances which are defined as the direct
- * subelements in all YANG modules in the context
+ * Returns extension definition instances which are defined as the direct
+ * subelements in all YANG modules in the context.
*
* @return set of ExtensionDefinition
instances which
* represents nodes defined via extension
YANG keyword
*/
- Set getExtensions();
+ Collection extends ExtensionDefinition> getExtensions();
+
+ /**
+ * Returns the module matching specified {@link QNameModule}, if present.
+ *
+ * @param qnameModule requested QNameModule
+ * @return Module, if present.
+ * @throws NullPointerException if qnameModule is null
+ */
+ Optional findModule(@NonNull QNameModule qnameModule);
/**
- * Returns module instance (from the context) with concrete name and
- * revision date.
+ * Returns module instance (from the context) with specified namespace and no revision.
+ *
+ * @param namespace module namespace
+ * @return module instance which has name and revision the same as are the values specified in parameters
+ * namespace
and no revision.
+ */
+ default Optional findModule(final @NonNull URI namespace) {
+ return findModule(QNameModule.create(namespace));
+ }
+
+ /**
+ * Returns module instance (from the context) with specified namespace and revision.
+ *
+ * @param namespace module namespace
+ * @param revision module revision, may be null
+ * @return module instance which has name and revision the same as are the values specified in parameters
+ * namespace
and revision
.
+ */
+ default Optional findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
+ return findModule(QNameModule.create(namespace, revision));
+ }
+
+ /**
+ * Returns module instance (from the context) with specified namespace and revision.
+ *
+ * @param namespace module namespace
+ * @param revision module revision, may be null
+ * @return module instance which has name and revision the same as are the values specified in parameters
+ * namespace
and revision
.
+ */
+ default Optional findModule(final @NonNull URI namespace, final @NonNull Optional revision) {
+ return findModule(QNameModule.create(namespace, revision));
+ }
+
+ /**
+ * Returns module instance (from the context) with specified name and an optional revision.
*
* @param name
* string with the module name
* @param revision
* date of the module revision
- * @return module instance which has name and revision (if specified) the
- * same as are the values specified in parameters name
- * and revision
. In other cases the null
- * value is returned.
+ * @return module instance which has name and revision the same as are the values specified in parameters
+ * name
and revision
.
+ */
+ default Optional extends Module> findModule(final String name, final Optional revision) {
+ return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
+ }
+
+ /**
+ * Returns module instance (from the context) with specified name and revision.
*
+ * @param name
+ * string with the module name
+ * @param revision
+ * date of the module revision, may be null
+ * @return module instance which has name and revision the same as are the values specified in parameters
+ * name
and revision
.
*/
- Module findModuleByName(final String name, final Date revision);
+ default Optional extends Module> findModule(final String name, final @Nullable Revision revision) {
+ return findModule(name, Optional.ofNullable(revision));
+ }
/**
+ * Returns module instance (from the context) with specified name and no revision.
*
- * Returns module instance (from the context) with concrete namespace.
+ * @param name string with the module name
+ * @return module instance which has name and revision the same as are the values specified in name
+ * and no revision.
+ * @throws NullPointerException if name is null
+ */
+ default Optional extends Module> findModule(final String name) {
+ return findModule(name, Optional.empty());
+ }
+
+ /**
+ * 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 namespace
- * URI instance with specified namespace
- * @return module instance which has namespace equal to the
- * namespace
or null
in other cases
+ * @param name
+ * string with the module name
+ * @return set of module instances with specified name.
*/
- Set findModuleByNamespace(final URI namespace);
+ default Collection extends Module> findModules(final String name) {
+ return Collections2.filter(getModules(), m -> name.equals(m.getName()));
+ }
/**
- * Returns module instance based on given namespace and revision. If
- * revision is not specified, returns module with newest revision.
+ * 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
- * @param revision
- * @return
+ * URI instance with specified namespace
+ * @return module instance which has namespace equal to the
+ * namespace
or null
in other cases
*/
- Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision);
+ default Collection extends Module> findModules(final URI namespace) {
+ return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
+ }
+ @Override
+ @Deprecated
+ default Collection extends ActionDefinition> getActions() {
+ return ImmutableSet.of();
+ }
- /**
- * Get yang source code represented as string for matching
- * {@link org.opendaylight.yangtools.yang.model.api.ModuleIdentifier}.
- * @param moduleIdentifier must provide a non-null
- * {@link org.opendaylight.yangtools.yang.model.api.ModuleIdentifier#getName()},
- * other methods might return null.
- * @return value iif matching module is found in schema context.
- */
- Optional getModuleSource(ModuleIdentifier moduleIdentifier);
+ @Override
+ @Deprecated
+ default Optional findAction(final QName qname) {
+ requireNonNull(qname);
+ return Optional.empty();
+ }
+
+ @Override
+ default Optional findNotification(final QName qname) {
+ final Optional> defs = findModule(qname.getModule())
+ .map(Module::getNotifications);
+ if (defs.isPresent()) {
+ for (NotificationDefinition def : defs.get()) {
+ if (qname.equals(def.getQName())) {
+ return Optional.of(def);
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ @Deprecated
+ default Optional getDescription() {
+ return Optional.empty();
+ }
+
+ @Override
+ @Deprecated
+ default Optional getReference() {
+ return Optional.empty();
+ }
+
+ @Override
+ @Deprecated
+ default Collection extends MustDefinition> getMustConstraints() {
+ return ImmutableSet.of();
+ }
+
+ @Override
+ @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 boolean isConfiguration() {
+ return false;
+ }
+
+ @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 findDataTreeChild(final QName name) {
+ return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
+ }
/**
- * Get all module and submodule identifiers.
+ * 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
*/
- Set getAllModuleIdentifiers();
-
+ @Beta
+ @NonNull Collection extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);
}