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.common.YangConstants;
26 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
29 * The interface represents static view of compiled yang files,
30 * contains the methods for obtaining all the top level context
31 * data (data from all modules) like YANG notifications, extensions,
33 * Instances MUST be immutable and thus usage in multi threaded
34 * environment is safe.
36 // FIXME: 7.0.0: ContainerLike is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
37 // and possibly DataSchemaNode would reflect SchemaContext traits better.
38 // FIXME: 7.0.0: consider deprecating this class in favor of EffectiveModelContext
39 public interface SchemaContext extends ContainerLike, Immutable {
41 * QName of NETCONF top-level data node.
43 // FIXME: YANGTOOLS-1074: we do not want this name
44 @NonNull QName NAME = QName.create(YangConstants.NETCONF_NAMESPACE, "data").intern();
47 * Returns data schema node instances which represents direct subnodes (like
48 * leaf, leaf-list, list, container) in all YANG modules in the context.
50 * @return set of <code>DataSchemaNode</code> instances which represents
51 * YANG data nodes at the module top level
53 @NonNull Collection<? extends @NonNull DataSchemaNode> getDataDefinitions();
56 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
57 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
58 * modules having the same attribute are encountered newest revision first.
60 * @return set of the modules which belong to the schema context
62 @NonNull Collection<? extends @NonNull Module> getModules();
65 * Returns rpc definition instances which are defined as the direct
66 * subelements in all YANG modules in the context.
68 * @return set of <code>RpcDefinition</code> instances which represents
69 * nodes defined via <code>rpc</code> YANG keyword
71 @NonNull Collection<? extends @NonNull RpcDefinition> getOperations();
74 * Returns extension definition instances which are defined as the direct
75 * subelements in all YANG modules in the context.
77 * @return set of <code>ExtensionDefinition</code> instances which
78 * represents nodes defined via <code>extension</code> YANG keyword
80 @NonNull Collection<? extends ExtensionDefinition> getExtensions();
83 * Returns the module matching specified {@link QNameModule}, if present.
85 * @param qnameModule requested QNameModule
86 * @return Module, if present.
87 * @throws NullPointerException if qnameModule is null
89 Optional<Module> findModule(@NonNull QNameModule qnameModule);
92 * Returns module instance (from the context) with specified namespace and no revision.
94 * @param namespace module namespace
95 * @return module instance which has name and revision the same as are the values specified in parameters
96 * <code>namespace</code> and no revision.
98 default Optional<Module> findModule(final @NonNull XMLNamespace namespace) {
99 return findModule(QNameModule.create(namespace));
103 * Returns module instance (from the context) with specified namespace and revision.
105 * @param namespace module namespace
106 * @param revision module revision, may be null
107 * @return module instance which has name and revision the same as are the values specified in parameters
108 * <code>namespace</code> and <code>revision</code>.
110 default Optional<Module> findModule(final @NonNull XMLNamespace namespace, final @Nullable Revision revision) {
111 return findModule(QNameModule.create(namespace, revision));
115 * Returns module instance (from the context) with specified namespace and revision.
117 * @param namespace module namespace
118 * @param revision module revision, may be null
119 * @return module instance which has name and revision the same as are the values specified in parameters
120 * <code>namespace</code> and <code>revision</code>.
122 default Optional<Module> findModule(final @NonNull XMLNamespace namespace,
123 final @NonNull Optional<Revision> revision) {
124 return findModule(QNameModule.create(namespace, revision));
128 * Returns module instance (from the context) with specified name and an optional revision.
131 * string with the module name
133 * date of the module revision
134 * @return module instance which has name and revision the same as are the values specified in parameters
135 * <code>name</code> and <code>revision</code>.
137 default Optional<? extends Module> findModule(final String name, final Optional<Revision> revision) {
138 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
142 * Returns module instance (from the context) with specified name and revision.
145 * string with the module name
147 * date of the module revision, may be null
148 * @return module instance which has name and revision the same as are the values specified in parameters
149 * <code>name</code> and <code>revision</code>.
151 default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
152 return findModule(name, Optional.ofNullable(revision));
156 * Returns module instance (from the context) with specified name and no revision.
158 * @param name string with the module name
159 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
161 * @throws NullPointerException if name is null
163 default Optional<? extends Module> findModule(final String name) {
164 return findModule(name, Optional.empty());
168 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
169 * order guarantee that the latest revision is encountered first.
171 * @param name string with the module name
172 * @return set of module instances with specified name.
174 default @NonNull Collection<? extends @NonNull Module> findModules(final String name) {
175 return Collections2.filter(getModules(), m -> name.equals(m.getName()));
179 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
180 * iteration order guarantee that the latest revision is encountered first.
182 * @param namespace XMLNamespace instance with specified namespace
183 * @return module instance which has namespace equal to the {@code namespace} or {@code null} in other cases
185 default @NonNull Collection<? extends @NonNull Module> findModules(final XMLNamespace namespace) {
186 return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
191 default Collection<? extends ActionDefinition> getActions() {
192 return ImmutableSet.of();
197 default Optional<ActionDefinition> findAction(final QName qname) {
198 requireNonNull(qname);
199 return Optional.empty();
203 default Optional<NotificationDefinition> findNotification(final QName qname) {
204 final Optional<Collection<? extends @NonNull NotificationDefinition>> defs = findModule(qname.getModule())
205 .map(Module::getNotifications);
206 if (defs.isPresent()) {
207 for (NotificationDefinition def : defs.get()) {
208 if (qname.equals(def.getQName())) {
209 return Optional.of(def);
213 return Optional.empty();
218 default Optional<String> getDescription() {
219 return Optional.empty();
224 default Optional<String> getReference() {
225 return Optional.empty();
230 default Collection<? extends @NonNull MustDefinition> getMustConstraints() {
231 return ImmutableSet.of();
236 default Optional<? extends QualifiedBound> getWhenCondition() {
237 return Optional.empty();
242 default boolean isAugmenting() {
248 default boolean isAddedByUses() {
254 default Optional<Boolean> effectiveConfig() {
255 return Optional.empty();
260 default QName getQName() {
261 // FIXME: YANGTOOLS-1074: we do not want this name
267 default Status getStatus() {
268 return Status.CURRENT;
273 default Collection<? extends UsesNode> getUses() {
274 return Collections.emptySet();
279 default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
280 return Collections.emptySet();
285 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
286 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
290 * Get identities derived from a selected identity.
292 * @param identity base identity
293 * @return collection of identities derived from this identity
294 * @throws NullPointerException if identity is null
295 * @throws IllegalArgumentException if the specified identity is not present in this context
298 @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);