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 org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.yangtools.concepts.Immutable;
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.
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, Immutable {
36 * QName of NETCONF top-level data node.
38 @NonNull 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(@NonNull QNameModule qnameModule);
86 * Returns module instance (from the context) with specified namespace and no revision.
88 * @param namespace module namespace
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 @NonNull URI namespace) {
93 return findModule(QNameModule.create(namespace));
97 * Returns module instance (from the context) with specified namespace and revision.
99 * @param namespace module namespace
100 * @param revision module revision, may be null
101 * @return module instance which has name and revision the same as are the values specified in parameters
102 * <code>namespace</code> and <code>revision</code>.
104 default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
105 return findModule(QNameModule.create(namespace, revision));
109 * Returns module instance (from the context) with specified namespace and revision.
111 * @param namespace module namespace
112 * @param revision module revision, may be null
113 * @return module instance which has name and revision the same as are the values specified in parameters
114 * <code>namespace</code> and <code>revision</code>.
116 default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
117 return findModule(QNameModule.create(namespace, revision));
121 * Returns module instance (from the context) with specified name and an optional revision.
124 * string with the module name
126 * date of the module revision
127 * @return module instance which has name and revision the same as are the values specified in parameters
128 * <code>name</code> and <code>revision</code>.
130 default Optional<Module> findModule(final String name, final Optional<Revision> revision) {
131 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
135 * Returns module instance (from the context) with specified name and revision.
138 * string with the module name
140 * date of the module revision, may be null
141 * @return module instance which has name and revision the same as are the values specified in parameters
142 * <code>name</code> and <code>revision</code>.
144 default Optional<Module> findModule(final String name, final @Nullable Revision revision) {
145 return findModule(name, Optional.ofNullable(revision));
149 * Returns module instance (from the context) with specified name and no revision.
151 * @param name string with the module name
152 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
154 * @throws NullPointerException if name is null
156 default Optional<Module> findModule(final String name) {
157 return findModule(name, Optional.empty());
161 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
162 * order guarantee that the latest revision is encountered first.
165 * string with the module name
166 * @return set of module instances with specified name.
168 default Set<Module> findModules(final String name) {
169 return Sets.filter(getModules(), m -> name.equals(m.getName()));
173 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
174 * iteration order guarantee that the latest revision is encountered first.
177 * URI instance with specified namespace
178 * @return module instance which has namespace equal to the
179 * <code>namespace</code> or <code>null</code> in other cases
181 default Set<Module> findModules(final URI namespace) {
182 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
186 default Set<ActionDefinition> getActions() {
187 return ImmutableSet.of();
191 default Optional<String> getDescription() {
192 return Optional.empty();
196 default Optional<String> getReference() {
197 return Optional.empty();
201 default Collection<MustDefinition> getMustConstraints() {
202 return ImmutableSet.of();
206 default Optional<RevisionAwareXPath> getWhenCondition() {
207 return Optional.empty();
212 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
213 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));