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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.Collections2;
14 import com.google.common.collect.ImmutableSet;
16 import java.util.Collection;
17 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.common.QNameModule;
23 import org.opendaylight.yangtools.yang.common.Revision;
26 * The interface represents static view of compiled yang files,
27 * contains the methods for obtaining all the top level context
28 * data (data from all modules) like YANG notifications, extensions,
30 * Instances MUST be immutable and thus usage in multi threaded
31 * environment is safe.
33 // FIXME: 5.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
34 // and possibly DataSchemaNode would reflect SchemaContext traits better.
35 // FIXME: 5.0.0: consider deprecating this class in favor of EffectiveModelContext
36 public interface SchemaContext extends ContainerSchemaNode, Immutable {
38 * QName of NETCONF top-level data node.
40 @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
43 * Returns data schema node instances which represents direct subnodes (like
44 * leaf, leaf-list, list, container) in all YANG modules in the context.
46 * @return set of <code>DataSchemaNode</code> instances which represents
47 * YANG data nodes at the module top level
49 Collection<? extends DataSchemaNode> getDataDefinitions();
52 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
53 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
54 * modules having the same attribute are encountered newest revision first.
56 * @return set of the modules which belong to the schema context
58 Collection<? extends Module> getModules();
61 * Returns rpc definition instances which are defined as the direct
62 * subelements in all YANG modules in the context.
64 * @return set of <code>RpcDefinition</code> instances which represents
65 * nodes defined via <code>rpc</code> YANG keyword
67 Collection<? extends RpcDefinition> getOperations();
70 * Returns extension definition instances which are defined as the direct
71 * subelements in all YANG modules in the context.
73 * @return set of <code>ExtensionDefinition</code> instances which
74 * represents nodes defined via <code>extension</code> YANG keyword
76 Collection<? extends ExtensionDefinition> getExtensions();
79 * Returns the module matching specified {@link QNameModule}, if present.
81 * @param qnameModule requested QNameModule
82 * @return Module, if present.
83 * @throws NullPointerException if qnameModule is null
85 Optional<Module> findModule(@NonNull QNameModule qnameModule);
88 * Returns module instance (from the context) with specified namespace and no revision.
90 * @param namespace module namespace
91 * @return module instance which has name and revision the same as are the values specified in parameters
92 * <code>namespace</code> and no revision.
94 default Optional<Module> findModule(final @NonNull URI namespace) {
95 return findModule(QNameModule.create(namespace));
99 * Returns module instance (from the context) with specified namespace and revision.
101 * @param namespace module namespace
102 * @param revision 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 @NonNull URI namespace, final @Nullable Revision revision) {
107 return findModule(QNameModule.create(namespace, revision));
111 * Returns module instance (from the context) with specified namespace and revision.
113 * @param namespace module namespace
114 * @param revision module revision, may be null
115 * @return module instance which has name and revision the same as are the values specified in parameters
116 * <code>namespace</code> and <code>revision</code>.
118 default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
119 return findModule(QNameModule.create(namespace, revision));
123 * Returns module instance (from the context) with specified name and an optional revision.
126 * string with the module name
128 * date of the module revision
129 * @return module instance which has name and revision the same as are the values specified in parameters
130 * <code>name</code> and <code>revision</code>.
132 default Optional<? extends Module> findModule(final String name, final Optional<Revision> revision) {
133 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
137 * Returns module instance (from the context) with specified name and revision.
140 * string with the module name
142 * date of the module revision, may be null
143 * @return module instance which has name and revision the same as are the values specified in parameters
144 * <code>name</code> and <code>revision</code>.
146 default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
147 return findModule(name, Optional.ofNullable(revision));
151 * Returns module instance (from the context) with specified name and no revision.
153 * @param name string with the module name
154 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
156 * @throws NullPointerException if name is null
158 default Optional<? extends Module> findModule(final String name) {
159 return findModule(name, Optional.empty());
163 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
164 * order guarantee that the latest revision is encountered first.
167 * string with the module name
168 * @return set of module instances with specified name.
170 default Collection<? extends Module> findModules(final String name) {
171 return Collections2.filter(getModules(), m -> name.equals(m.getName()));
175 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
176 * iteration order guarantee that the latest revision is encountered first.
179 * URI instance with specified namespace
180 * @return module instance which has namespace equal to the
181 * <code>namespace</code> or <code>null</code> in other cases
183 default Collection<? extends Module> findModules(final URI namespace) {
184 return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
188 default Collection<? extends ActionDefinition> getActions() {
189 return ImmutableSet.of();
193 default Optional<ActionDefinition> findAction(final QName qname) {
194 requireNonNull(qname);
195 return Optional.empty();
199 default Optional<NotificationDefinition> findNotification(final QName qname) {
200 final Optional<Collection<? extends NotificationDefinition>> defs = findModule(qname.getModule())
201 .map(Module::getNotifications);
202 if (defs.isPresent()) {
203 for (NotificationDefinition def : defs.get()) {
204 if (qname.equals(def.getQName())) {
205 return Optional.of(def);
209 return Optional.empty();
213 default Optional<String> getDescription() {
214 return Optional.empty();
218 default Optional<String> getReference() {
219 return Optional.empty();
223 default Collection<? extends MustDefinition> getMustConstraints() {
224 return ImmutableSet.of();
228 default Optional<RevisionAwareXPath> getWhenCondition() {
229 return Optional.empty();
234 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
235 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
239 * Get identities derived from a selected identity.
241 * @return collection of identities derived from this identity
242 * @throws NullPointerException if identity is null
243 * @throws IllegalArgumentException if the specified identity is not present in this context
246 @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);