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.Collections;
18 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.opendaylight.yangtools.concepts.Immutable;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.QNameModule;
24 import org.opendaylight.yangtools.yang.common.Revision;
25 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
28 * The interface represents static view of compiled yang files,
29 * contains the methods for obtaining all the top level context
30 * data (data from all modules) like YANG notifications, extensions,
32 * Instances MUST be immutable and thus usage in multi threaded
33 * environment is safe.
35 // FIXME: 7.0.0: ContainerLike is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
36 // and possibly DataSchemaNode would reflect SchemaContext traits better.
37 // FIXME: 7.0.0: consider deprecating this class in favor of EffectiveModelContext
38 public interface SchemaContext extends ContainerLike, Immutable {
40 * QName of NETCONF top-level data node.
42 // FIXME: YANGTOOLS-1074: we do not want this name
43 @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
46 * Returns data schema node instances which represents direct subnodes (like
47 * leaf, leaf-list, list, container) in all YANG modules in the context.
49 * @return set of <code>DataSchemaNode</code> instances which represents
50 * YANG data nodes at the module top level
52 @NonNull Collection<? extends @NonNull DataSchemaNode> getDataDefinitions();
55 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
56 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
57 * modules having the same attribute are encountered newest revision first.
59 * @return set of the modules which belong to the schema context
61 @NonNull Collection<? extends @NonNull Module> getModules();
64 * Returns rpc definition instances which are defined as the direct
65 * subelements in all YANG modules in the context.
67 * @return set of <code>RpcDefinition</code> instances which represents
68 * nodes defined via <code>rpc</code> YANG keyword
70 @NonNull Collection<? extends @NonNull RpcDefinition> getOperations();
73 * Returns extension definition instances which are defined as the direct
74 * subelements in all YANG modules in the context.
76 * @return set of <code>ExtensionDefinition</code> instances which
77 * represents nodes defined via <code>extension</code> YANG keyword
79 @NonNull Collection<? extends ExtensionDefinition> getExtensions();
82 * Returns the module matching specified {@link QNameModule}, if present.
84 * @param qnameModule requested QNameModule
85 * @return Module, if present.
86 * @throws NullPointerException if qnameModule is null
88 Optional<Module> findModule(@NonNull QNameModule qnameModule);
91 * Returns module instance (from the context) with specified namespace and no revision.
93 * @param namespace module namespace
94 * @return module instance which has name and revision the same as are the values specified in parameters
95 * <code>namespace</code> and no revision.
97 default Optional<Module> findModule(final @NonNull URI namespace) {
98 return findModule(QNameModule.create(namespace));
102 * Returns module instance (from the context) with specified namespace and revision.
104 * @param namespace module namespace
105 * @param revision module revision, may be null
106 * @return module instance which has name and revision the same as are the values specified in parameters
107 * <code>namespace</code> and <code>revision</code>.
109 default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
110 return findModule(QNameModule.create(namespace, revision));
114 * Returns module instance (from the context) with specified namespace and revision.
116 * @param namespace module namespace
117 * @param revision 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 @NonNull URI namespace, final @NonNull 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<? extends 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<? extends Module> findModule(final String name, final @Nullable 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<? extends 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 @NonNull Collection<? extends @NonNull Module> findModules(final String name) {
174 return Collections2.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 @NonNull Collection<? extends @NonNull Module> findModules(final URI namespace) {
187 return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
192 default Collection<? extends ActionDefinition> getActions() {
193 return ImmutableSet.of();
198 default Optional<ActionDefinition> findAction(final QName qname) {
199 requireNonNull(qname);
200 return Optional.empty();
204 default Optional<NotificationDefinition> findNotification(final QName qname) {
205 final Optional<Collection<? extends @NonNull NotificationDefinition>> defs = findModule(qname.getModule())
206 .map(Module::getNotifications);
207 if (defs.isPresent()) {
208 for (NotificationDefinition def : defs.get()) {
209 if (qname.equals(def.getQName())) {
210 return Optional.of(def);
214 return Optional.empty();
219 default Optional<String> getDescription() {
220 return Optional.empty();
225 default Optional<String> getReference() {
226 return Optional.empty();
231 default Collection<? extends @NonNull MustDefinition> getMustConstraints() {
232 return ImmutableSet.of();
237 default Optional<? extends QualifiedBound> getWhenCondition() {
238 return Optional.empty();
243 default boolean isAugmenting() {
249 default boolean isAddedByUses() {
255 default boolean isConfiguration() {
261 default QName getQName() {
262 // FIXME: YANGTOOLS-1074: we do not want this name
268 default SchemaPath getPath() {
269 return SchemaPath.ROOT;
274 default Status getStatus() {
275 return Status.CURRENT;
280 default Collection<? extends UsesNode> getUses() {
281 return Collections.emptySet();
286 default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
287 return Collections.emptySet();
292 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
293 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
297 * Get identities derived from a selected identity.
299 * @param identity base identity
300 * @return collection of identities derived from this identity
301 * @throws NullPointerException if identity is null
302 * @throws IllegalArgumentException if the specified identity is not present in this context
305 @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);