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;
15 import java.util.Collection;
16 import java.util.Collections;
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;
24 import org.opendaylight.yangtools.yang.common.XMLNamespace;
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(XMLNamespace.of("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 XMLNamespace 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 XMLNamespace 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 XMLNamespace namespace,
122 final @NonNull Optional<Revision> revision) {
123 return findModule(QNameModule.create(namespace, revision));
127 * Returns module instance (from the context) with specified name and an optional revision.
130 * string with the module name
132 * date of the module revision
133 * @return module instance which has name and revision the same as are the values specified in parameters
134 * <code>name</code> and <code>revision</code>.
136 default Optional<? extends Module> findModule(final String name, final Optional<Revision> revision) {
137 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
141 * Returns module instance (from the context) with specified name and revision.
144 * string with the module name
146 * date of the module revision, may be null
147 * @return module instance which has name and revision the same as are the values specified in parameters
148 * <code>name</code> and <code>revision</code>.
150 default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
151 return findModule(name, Optional.ofNullable(revision));
155 * Returns module instance (from the context) with specified name and no revision.
157 * @param name string with the module name
158 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
160 * @throws NullPointerException if name is null
162 default Optional<? extends Module> findModule(final String name) {
163 return findModule(name, Optional.empty());
167 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
168 * order guarantee that the latest revision is encountered first.
170 * @param name 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.
181 * @param namespace XMLNamespace instance with specified namespace
182 * @return module instance which has namespace equal to the {@code namespace} or {@code null} in other cases
184 default @NonNull Collection<? extends @NonNull Module> findModules(final XMLNamespace namespace) {
185 return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
190 default Collection<? extends ActionDefinition> getActions() {
191 return ImmutableSet.of();
196 default Optional<ActionDefinition> findAction(final QName qname) {
197 requireNonNull(qname);
198 return Optional.empty();
202 default Optional<NotificationDefinition> findNotification(final QName qname) {
203 final Optional<Collection<? extends @NonNull NotificationDefinition>> defs = findModule(qname.getModule())
204 .map(Module::getNotifications);
205 if (defs.isPresent()) {
206 for (NotificationDefinition def : defs.get()) {
207 if (qname.equals(def.getQName())) {
208 return Optional.of(def);
212 return Optional.empty();
217 default Optional<String> getDescription() {
218 return Optional.empty();
223 default Optional<String> getReference() {
224 return Optional.empty();
229 default Collection<? extends @NonNull MustDefinition> getMustConstraints() {
230 return ImmutableSet.of();
235 default Optional<? extends QualifiedBound> getWhenCondition() {
236 return Optional.empty();
241 default boolean isAugmenting() {
247 default boolean isAddedByUses() {
253 default Optional<Boolean> effectiveConfig() {
254 return Optional.empty();
259 default QName getQName() {
260 // FIXME: YANGTOOLS-1074: we do not want this name
266 default SchemaPath getPath() {
267 return SchemaPath.ROOT;
272 default Status getStatus() {
273 return Status.CURRENT;
278 default Collection<? extends UsesNode> getUses() {
279 return Collections.emptySet();
284 default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
285 return Collections.emptySet();
290 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
291 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
295 * Get identities derived from a selected identity.
297 * @param identity base identity
298 * @return collection of identities derived from this identity
299 * @throws NullPointerException if identity is null
300 * @throws IllegalArgumentException if the specified identity is not present in this context
303 @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);