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=1e64e5d532aedbc4d09a79e663e3984b08ce8c57;hb=3e8882b8933feec0e47c4b17d44f5342bb8c84b1;hp=9a5c88593c2b9a155fcefb8fb2b65f05a5493eee;hpb=bd56d9164cd2c1dd943a347a728433c57dff22d3;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 9a5c88593c..1e64e5d532 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,14 +7,18 @@ */ 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 javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; +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; @@ -27,14 +31,15 @@ import org.opendaylight.yangtools.yang.common.Revision; * Instances MUST be immutable and thus usage in multi threaded * environment is safe. */ -@Immutable -// FIXME: 3.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer +// FIXME: 6.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer // and possibly DataSchemaNode would reflect SchemaContext traits better. -public interface SchemaContext extends ContainerSchemaNode { +// FIXME: 6.0.0: consider deprecating this class in favor of EffectiveModelContext +public interface SchemaContext extends ContainerSchemaNode, Immutable { /** * QName of NETCONF top-level data node. */ - 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(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern(); /** * Returns data schema node instances which represents direct subnodes (like @@ -43,7 +48,7 @@ public interface SchemaContext extends ContainerSchemaNode { * @return set of DataSchemaNode instances which represents * YANG data nodes at the module top level */ - Set getDataDefinitions(); + Collection getDataDefinitions(); /** * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered @@ -52,7 +57,7 @@ public interface SchemaContext extends ContainerSchemaNode { * * @return set of the modules which belong to the schema context */ - Set getModules(); + Collection getModules(); /** * Returns rpc definition instances which are defined as the direct @@ -61,7 +66,7 @@ public interface SchemaContext extends ContainerSchemaNode { * @return set of RpcDefinition instances which represents * nodes defined via rpc YANG keyword */ - Set getOperations(); + Collection getOperations(); /** * Returns extension definition instances which are defined as the direct @@ -70,7 +75,7 @@ public interface SchemaContext extends ContainerSchemaNode { * @return set of ExtensionDefinition instances which * represents nodes defined via extension YANG keyword */ - Set getExtensions(); + Collection getExtensions(); /** * Returns the module matching specified {@link QNameModule}, if present. @@ -79,45 +84,40 @@ public interface SchemaContext extends ContainerSchemaNode { * @return Module, if present. * @throws NullPointerException if qnameModule is null */ - Optional findModule(QNameModule qnameModule); + Optional findModule(@NonNull QNameModule qnameModule); /** * Returns module instance (from the context) with specified namespace and no revision. * - * @param namespace - * module namespace + * @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 URI namespace) { + 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 + * @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 URI namespace, @Nullable final Revision 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 + * @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 URI namespace, final Optional revision) { + default Optional findModule(final @NonNull URI namespace, final @NonNull Optional revision) { return findModule(QNameModule.create(namespace, revision)); } @@ -131,7 +131,7 @@ public interface SchemaContext extends ContainerSchemaNode { * @return module instance which has name and revision the same as are the values specified in parameters * name and revision. */ - default Optional findModule(final String name, final Optional revision) { + default Optional findModule(final String name, final Optional revision) { return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny(); } @@ -145,7 +145,7 @@ public interface SchemaContext extends ContainerSchemaNode { * @return module instance which has name and revision the same as are the values specified in parameters * name and revision. */ - default Optional findModule(final String name, @Nullable final Revision revision) { + default Optional findModule(final String name, final @Nullable Revision revision) { return findModule(name, Optional.ofNullable(revision)); } @@ -157,7 +157,7 @@ public interface SchemaContext extends ContainerSchemaNode { * and no revision. * @throws NullPointerException if name is null */ - default Optional findModule(final String name) { + default Optional findModule(final String name) { return findModule(name, Optional.empty()); } @@ -169,8 +169,8 @@ public interface SchemaContext extends ContainerSchemaNode { * string with the module name * @return set of module instances with specified name. */ - default Set findModules(final String name) { - return Sets.filter(getModules(), m -> name.equals(m.getName())); + default Collection findModules(final String name) { + return Collections2.filter(getModules(), m -> name.equals(m.getName())); } /** @@ -182,32 +182,129 @@ public interface SchemaContext extends ContainerSchemaNode { * @return module instance which has namespace equal to the * namespace or null in other cases */ - default Set findModules(final URI namespace) { - return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace())); + default Collection findModules(final URI namespace) { + return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace())); } @Override - default Set getActions() { + @Deprecated + default Collection getActions() { return ImmutableSet.of(); } @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 - default Collection getMustConstraints() { + @Deprecated + default Collection getMustConstraints() { return ImmutableSet.of(); } @Override + @Deprecated default Optional 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 getUses() { + return Collections.emptySet(); + } + + @Override + @Deprecated + default boolean isPresenceContainer() { + return false; + } + + @Override + @Deprecated + default Collection getAvailableAugmentations() { + return Collections.emptySet(); + } + + @Beta + @Override + default Optional findDataTreeChild(final QName name) { + return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name)); + } + + /** + * Get identities derived from a selected 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 getDerivedIdentities(IdentitySchemaNode identity); }