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;
27 * The interface represents static view of compiled yang files,
28 * contains the methods for obtaining all the top level context
29 * data (data from all modules) like YANG notifications, extensions,
31 * Instances MUST be immutable and thus usage in multi threaded
32 * environment is safe.
34 // FIXME: 6.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
35 // and possibly DataSchemaNode would reflect SchemaContext traits better.
36 // FIXME: 6.0.0: consider deprecating this class in favor of EffectiveModelContext
37 public interface SchemaContext extends ContainerSchemaNode, Immutable {
39 * QName of NETCONF top-level data node.
41 // FIXME: YANGTOOLS-1074: we do not want this name
42 @NonNull QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
45 * Returns data schema node instances which represents direct subnodes (like
46 * leaf, leaf-list, list, container) in all YANG modules in the context.
48 * @return set of <code>DataSchemaNode</code> instances which represents
49 * YANG data nodes at the module top level
51 Collection<? extends DataSchemaNode> getDataDefinitions();
54 * Returns modules which are part of the schema context. Returned set is required to have its iteration ordered
55 * by module revision, so that if modules are filtered by {@link Module#getName()} or {@link Module#getNamespace()},
56 * modules having the same attribute are encountered newest revision first.
58 * @return set of the modules which belong to the schema context
60 Collection<? extends Module> getModules();
63 * Returns rpc definition instances which are defined as the direct
64 * subelements in all YANG modules in the context.
66 * @return set of <code>RpcDefinition</code> instances which represents
67 * nodes defined via <code>rpc</code> YANG keyword
69 Collection<? extends RpcDefinition> getOperations();
72 * Returns extension definition instances which are defined as the direct
73 * subelements in all YANG modules in the context.
75 * @return set of <code>ExtensionDefinition</code> instances which
76 * represents nodes defined via <code>extension</code> YANG keyword
78 Collection<? extends ExtensionDefinition> getExtensions();
81 * Returns the module matching specified {@link QNameModule}, if present.
83 * @param qnameModule requested QNameModule
84 * @return Module, if present.
85 * @throws NullPointerException if qnameModule is null
87 Optional<Module> findModule(@NonNull QNameModule qnameModule);
90 * Returns module instance (from the context) with specified namespace and no revision.
92 * @param namespace module namespace
93 * @return module instance which has name and revision the same as are the values specified in parameters
94 * <code>namespace</code> and no revision.
96 default Optional<Module> findModule(final @NonNull URI namespace) {
97 return findModule(QNameModule.create(namespace));
101 * Returns module instance (from the context) with specified namespace and revision.
103 * @param namespace module namespace
104 * @param revision module revision, may be null
105 * @return module instance which has name and revision the same as are the values specified in parameters
106 * <code>namespace</code> and <code>revision</code>.
108 default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
109 return findModule(QNameModule.create(namespace, revision));
113 * Returns module instance (from the context) with specified namespace and revision.
115 * @param namespace module namespace
116 * @param revision module revision, may be null
117 * @return module instance which has name and revision the same as are the values specified in parameters
118 * <code>namespace</code> and <code>revision</code>.
120 default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
121 return findModule(QNameModule.create(namespace, revision));
125 * Returns module instance (from the context) with specified name and an optional revision.
128 * string with the module name
130 * date of the module revision
131 * @return module instance which has name and revision the same as are the values specified in parameters
132 * <code>name</code> and <code>revision</code>.
134 default Optional<? extends Module> findModule(final String name, final Optional<Revision> revision) {
135 return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny();
139 * Returns module instance (from the context) with specified name and revision.
142 * string with the module name
144 * date of the module revision, may be null
145 * @return module instance which has name and revision the same as are the values specified in parameters
146 * <code>name</code> and <code>revision</code>.
148 default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
149 return findModule(name, Optional.ofNullable(revision));
153 * Returns module instance (from the context) with specified name and no revision.
155 * @param name string with the module name
156 * @return module instance which has name and revision the same as are the values specified in <code>name</code>
158 * @throws NullPointerException if name is null
160 default Optional<? extends Module> findModule(final String name) {
161 return findModule(name, Optional.empty());
165 * Returns module instances (from the context) with a concrete name. Returned Set is required to have its iteration
166 * order guarantee that the latest revision is encountered first.
169 * string with the module name
170 * @return set of module instances with specified name.
172 default Collection<? extends Module> findModules(final String name) {
173 return Collections2.filter(getModules(), m -> name.equals(m.getName()));
177 * Returns module instance (from the context) with concrete namespace. Returned Set is required to have its
178 * iteration order guarantee that the latest revision is encountered first.
181 * URI instance with specified namespace
182 * @return module instance which has namespace equal to the
183 * <code>namespace</code> or <code>null</code> in other cases
185 default Collection<? extends Module> findModules(final URI 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 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 MustDefinition> getMustConstraints() {
231 return ImmutableSet.of();
236 default Optional<RevisionAwareXPath> getWhenCondition() {
237 return Optional.empty();
242 default boolean isAugmenting() {
248 default boolean isAddedByUses() {
254 default boolean isConfiguration() {
260 default QName getQName() {
261 // FIXME: YANGTOOLS-1074: we do not want this name
267 default SchemaPath getPath() {
268 return SchemaPath.ROOT;
273 default Status getStatus() {
274 return Status.CURRENT;
279 default Collection<? extends UsesNode> getUses() {
280 return Collections.emptySet();
285 default boolean isPresenceContainer() {
291 default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
292 return Collections.emptySet();
297 default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
298 return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
302 * Get identities derived from a selected identity.
304 * @param identity base identity
305 * @return collection of identities derived from this identity
306 * @throws NullPointerException if identity is null
307 * @throws IllegalArgumentException if the specified identity is not present in this context
310 @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);