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.concurrent.Immutable;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.common.Revision;
25 * The interface represents static view of compiled yang files,
26 * contains the methods for obtaining all the top level context
27 * data (data from all modules) like YANG notifications, extensions,
29 * Instances MUST be immutable and thus usage in multi threaded
30 * environment is safe.
33 // FIXME: 3.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
34 // and possibly DataSchemaNode would reflect SchemaContext traits better.
35 public interface SchemaContext extends ContainerSchemaNode {
37 * QName of NETCONF top-level data node.
39 @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
42 * Returns data schema node instances which represents direct subnodes (like
43 * leaf, leaf-list, list, container) in all YANG modules in the context.
45 * @return set of <code>DataSchemaNode</code> instances which represents
46 * YANG data nodes at the module top level
48 Set<DataSchemaNode> getDataDefinitions();
51 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
52 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
53 * modules having the same attribute are encountered newest revision first.
55 * @return set of the modules which belong to the schema context
57 Set<Module> getModules();
60 * Returns rpc definition instances which are defined as the direct
61 * subelements in all YANG modules in the context.
63 * @return set of <code>RpcDefinition</code> instances which represents
64 * nodes defined via <code>rpc</code> YANG keyword
66 Set<RpcDefinition> getOperations();
69 * Returns extension definition instances which are defined as the direct
70 * subelements in all YANG modules in the context.
72 * @return set of <code>ExtensionDefinition</code> instances which
73 * represents nodes defined via <code>extension</code> YANG keyword
75 Set<ExtensionDefinition> getExtensions();
78 * Returns the module matching specified {@link QNameModule}, if present.
80 * @param qnameModule requested QNameModule
81 * @return Module, if present.
82 * @throws NullPointerException if qnameModule is null
84 Optional<Module> findModule(@NonNull QNameModule qnameModule);
87 * Returns module instance (from the context) with specified namespace and no revision.
89 * @param namespace module namespace
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 @NonNull URI namespace) {
94 return findModule(QNameModule.create(namespace));
98 * Returns module instance (from the context) with specified namespace and revision.
100 * @param namespace module namespace
101 * @param revision module revision, may be null
102 * @return module instance which has name and revision the same as are the values specified in parameters
103 * <code>namespace</code> and <code>revision</code>.
105 default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
106 return findModule(QNameModule.create(namespace, revision));
110 * Returns module instance (from the context) with specified namespace and revision.
112 * @param namespace module namespace
113 * @param revision module revision, may be null
114 * @return module instance which has name and revision the same as are the values specified in parameters
115 * <code>namespace</code> and <code>revision</code>.
117 default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
118 return findModule(QNameModule.create(namespace, revision));
122 * Returns module instance (from the context) with specified name and an optional revision.
125 * string with the module name
127 * date of the module revision
128 * @return module instance which has name and revision the same as are the values specified in parameters
129 * <code>name</code> and <code>revision</code>.
131 default Optional<Module> findModule(final String name, final Optional<Revision> revision) {
132 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
136 * Returns module instance (from the context) with specified name and revision.
139 * string with the module name
141 * date of the module revision, may be null
142 * @return module instance which has name and revision the same as are the values specified in parameters
143 * <code>name</code> and <code>revision</code>.
145 default Optional<Module> findModule(final String name, final @Nullable Revision revision) {
146 return findModule(name, Optional.ofNullable(revision));
150 * Returns module instance (from the context) with specified name and no revision.
152 * @param name string with the module name
153 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
155 * @throws NullPointerException if name is null
157 default Optional<Module> findModule(final String name) {
158 return findModule(name, Optional.empty());
162 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
163 * order guarantee that the latest revision is encountered first.
166 * string with the module name
167 * @return set of module instances with specified name.
169 default Set<Module> findModules(final String name) {
170 return Sets.filter(getModules(), m -> name.equals(m.getName()));
174 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
175 * iteration order guarantee that the latest revision is encountered first.
178 * URI instance with specified namespace
179 * @return module instance which has namespace equal to the
180 * <code>namespace</code> or <code>null</code> in other cases
182 default Set<Module> findModules(final URI namespace) {
183 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
187 default Set<ActionDefinition> getActions() {
188 return ImmutableSet.of();
192 default Optional<String> getDescription() {
193 return Optional.empty();
197 default Optional<String> getReference() {
198 return Optional.empty();
202 default Collection<MustDefinition> getMustConstraints() {
203 return ImmutableSet.of();
207 default Optional<RevisionAwareXPath> getWhenCondition() {
208 return Optional.empty();
213 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
214 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));