2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.api;
10 import com.google.common.collect.ImmutableSet;
11 import com.google.common.collect.Sets;
13 import java.util.Collection;
14 import java.util.Optional;
16 import javax.annotation.Nullable;
17 import javax.annotation.concurrent.Immutable;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.common.Revision;
23 * The interface represents static view of compiled yang files,
24 * contains the methods for obtaining all the top level context
25 * data (data from all modules) like YANG notifications, extensions,
27 * Instances MUST be immutable and thus usage in multi threaded
28 * environment is safe.
31 // FIXME: 3.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
32 // and possibly DataSchemaNode would reflect SchemaContext traits better.
33 public interface SchemaContext extends ContainerSchemaNode {
35 * QName of NETCONF top-level data node.
37 QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
40 * Returns data schema node instances which represents direct subnodes (like
41 * leaf, leaf-list, list, container) in all YANG modules in the context.
43 * @return set of <code>DataSchemaNode</code> instances which represents
44 * YANG data nodes at the module top level
46 Set<DataSchemaNode> getDataDefinitions();
49 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
50 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
51 * modules having the same attribute are encountered newest revision first.
53 * @return set of the modules which belong to the schema context
55 Set<Module> getModules();
58 * Returns rpc definition instances which are defined as the direct
59 * subelements in all YANG modules in the context.
61 * @return set of <code>RpcDefinition</code> instances which represents
62 * nodes defined via <code>rpc</code> YANG keyword
64 Set<RpcDefinition> getOperations();
67 * Returns extension definition instances which are defined as the direct
68 * subelements in all YANG modules in the context.
70 * @return set of <code>ExtensionDefinition</code> instances which
71 * represents nodes defined via <code>extension</code> YANG keyword
73 Set<ExtensionDefinition> getExtensions();
76 * Returns the module matching specified {@link QNameModule}, if present.
78 * @param qnameModule requested QNameModule
79 * @return Module, if present.
80 * @throws NullPointerException if qnameModule is null
82 Optional<Module> findModule(QNameModule qnameModule);
85 * Returns module instance (from the context) with specified namespace and no revision.
89 * @return module instance which has name and revision the same as are the values specified in parameters
90 * <code>namespace</code> and no revision.
92 default Optional<Module> findModule(final URI namespace) {
93 return findModule(QNameModule.create(namespace));
97 * Returns module instance (from the context) with specified namespace and revision.
102 * module revision, may be null
103 * @return module instance which has name and revision the same as are the values specified in parameters
104 * <code>namespace</code> and <code>revision</code>.
106 default Optional<Module> findModule(final URI namespace, @Nullable final Revision revision) {
107 return findModule(QNameModule.create(namespace, revision));
111 * Returns module instance (from the context) with specified namespace and revision.
116 * module revision, may be null
117 * @return module instance which has name and revision the same as are the values specified in parameters
118 * <code>namespace</code> and <code>revision</code>.
120 default Optional<Module> findModule(final URI namespace, final Optional<Revision> revision) {
121 return findModule(QNameModule.create(namespace, revision));
125 * Returns module instance (from the context) with specified name and an optional revision.
128 * string with the module name
130 * date of the module revision
131 * @return module instance which has name and revision the same as are the values specified in parameters
132 * <code>name</code> and <code>revision</code>.
134 default Optional<Module> findModule(final String name, final Optional<Revision> revision) {
135 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
139 * Returns module instance (from the context) with specified name and revision.
142 * string with the module name
144 * date of the module revision, may be null
145 * @return module instance which has name and revision the same as are the values specified in parameters
146 * <code>name</code> and <code>revision</code>.
148 default Optional<Module> findModule(final String name, @Nullable final Revision revision) {
149 return findModule(name, Optional.ofNullable(revision));
153 * Returns module instance (from the context) with specified name and no revision.
155 * @param name string with the module name
156 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
158 * @throws NullPointerException if name is null
160 default Optional<Module> findModule(final String name) {
161 return findModule(name, Optional.empty());
165 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
166 * order guarantee that the latest revision is encountered first.
169 * string with the module name
170 * @return set of module instances with specified name.
172 default Set<Module> findModules(final String name) {
173 return Sets.filter(getModules(), m -> name.equals(m.getName()));
177 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
178 * iteration order guarantee that the latest revision is encountered first.
181 * URI instance with specified namespace
182 * @return module instance which has namespace equal to the
183 * <code>namespace</code> or <code>null</code> in other cases
185 default Set<Module> findModules(final URI namespace) {
186 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
190 default Set<ActionDefinition> getActions() {
191 return ImmutableSet.of();
195 default Optional<String> getDescription() {
196 return Optional.empty();
200 default Optional<String> getReference() {
201 return Optional.empty();
205 default Collection<MustDefinition> getMustConstraints() {
206 return ImmutableSet.of();
210 default Optional<RevisionAwareXPath> getWhenCondition() {
211 return Optional.empty();