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.annotations.Beta;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.Sets;
14 import java.util.Collection;
15 import java.util.Optional;
17 import javax.annotation.Nullable;
18 import javax.annotation.concurrent.Immutable;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.common.Revision;
24 * The interface represents static view of compiled yang files,
25 * contains the methods for obtaining all the top level context
26 * data (data from all modules) like YANG notifications, extensions,
28 * Instances MUST be immutable and thus usage in multi threaded
29 * environment is safe.
32 // FIXME: 3.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
33 // and possibly DataSchemaNode would reflect SchemaContext traits better.
34 public interface SchemaContext extends ContainerSchemaNode {
36 * QName of NETCONF top-level data node.
38 QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
41 * Returns data schema node instances which represents direct subnodes (like
42 * leaf, leaf-list, list, container) in all YANG modules in the context.
44 * @return set of <code>DataSchemaNode</code> instances which represents
45 * YANG data nodes at the module top level
47 Set<DataSchemaNode> getDataDefinitions();
50 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
51 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
52 * modules having the same attribute are encountered newest revision first.
54 * @return set of the modules which belong to the schema context
56 Set<Module> getModules();
59 * Returns rpc definition instances which are defined as the direct
60 * subelements in all YANG modules in the context.
62 * @return set of <code>RpcDefinition</code> instances which represents
63 * nodes defined via <code>rpc</code> YANG keyword
65 Set<RpcDefinition> getOperations();
68 * Returns extension definition instances which are defined as the direct
69 * subelements in all YANG modules in the context.
71 * @return set of <code>ExtensionDefinition</code> instances which
72 * represents nodes defined via <code>extension</code> YANG keyword
74 Set<ExtensionDefinition> getExtensions();
77 * Returns the module matching specified {@link QNameModule}, if present.
79 * @param qnameModule requested QNameModule
80 * @return Module, if present.
81 * @throws NullPointerException if qnameModule is null
83 Optional<Module> findModule(QNameModule qnameModule);
86 * Returns module instance (from the context) with specified namespace and no revision.
90 * @return module instance which has name and revision the same as are the values specified in parameters
91 * <code>namespace</code> and no revision.
93 default Optional<Module> findModule(final URI namespace) {
94 return findModule(QNameModule.create(namespace));
98 * Returns module instance (from the context) with specified namespace and revision.
103 * module revision, may be null
104 * @return module instance which has name and revision the same as are the values specified in parameters
105 * <code>namespace</code> and <code>revision</code>.
107 default Optional<Module> findModule(final URI namespace, @Nullable final Revision revision) {
108 return findModule(QNameModule.create(namespace, revision));
112 * Returns module instance (from the context) with specified namespace and revision.
117 * module revision, may be null
118 * @return module instance which has name and revision the same as are the values specified in parameters
119 * <code>namespace</code> and <code>revision</code>.
121 default Optional<Module> findModule(final URI namespace, final Optional<Revision> revision) {
122 return findModule(QNameModule.create(namespace, revision));
126 * Returns module instance (from the context) with specified name and an optional revision.
129 * string with the module name
131 * date of the module revision
132 * @return module instance which has name and revision the same as are the values specified in parameters
133 * <code>name</code> and <code>revision</code>.
135 default Optional<Module> findModule(final String name, final Optional<Revision> revision) {
136 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
140 * Returns module instance (from the context) with specified name and revision.
143 * string with the module name
145 * date of the module revision, may be null
146 * @return module instance which has name and revision the same as are the values specified in parameters
147 * <code>name</code> and <code>revision</code>.
149 default Optional<Module> findModule(final String name, @Nullable final Revision revision) {
150 return findModule(name, Optional.ofNullable(revision));
154 * Returns module instance (from the context) with specified name and no revision.
156 * @param name string with the module name
157 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
159 * @throws NullPointerException if name is null
161 default Optional<Module> findModule(final String name) {
162 return findModule(name, Optional.empty());
166 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
167 * order guarantee that the latest revision is encountered first.
170 * string with the module name
171 * @return set of module instances with specified name.
173 default Set<Module> findModules(final String name) {
174 return Sets.filter(getModules(), m -> name.equals(m.getName()));
178 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
179 * iteration order guarantee that the latest revision is encountered first.
182 * URI instance with specified namespace
183 * @return module instance which has namespace equal to the
184 * <code>namespace</code> or <code>null</code> in other cases
186 default Set<Module> findModules(final URI namespace) {
187 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
191 default Set<ActionDefinition> getActions() {
192 return ImmutableSet.of();
196 default Optional<String> getDescription() {
197 return Optional.empty();
201 default Optional<String> getReference() {
202 return Optional.empty();
206 default Collection<MustDefinition> getMustConstraints() {
207 return ImmutableSet.of();
211 default Optional<RevisionAwareXPath> getWhenCondition() {
212 return Optional.empty();
217 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
218 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));