Fixup yang-model-api javadoc warnings
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / SchemaContext.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.Collections2;
14 import com.google.common.collect.ImmutableSet;
15 import java.net.URI;
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
26 /**
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,
30  * operations...
31  * Instances MUST be immutable and thus usage in multi threaded
32  * environment is safe.
33  */
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 {
38     /**
39      * QName of NETCONF top-level data node.
40      */
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();
43
44     /**
45      * Returns data schema node instances which represents direct subnodes (like
46      * leaf, leaf-list, list, container) in all YANG modules in the context.
47      *
48      * @return set of <code>DataSchemaNode</code> instances which represents
49      *         YANG data nodes at the module top level
50      */
51     Collection<? extends DataSchemaNode> getDataDefinitions();
52
53     /**
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.
57      *
58      * @return set of the modules which belong to the schema context
59      */
60     Collection<? extends Module> getModules();
61
62     /**
63      * Returns rpc definition instances which are defined as the direct
64      * subelements in all YANG modules in the context.
65      *
66      * @return set of <code>RpcDefinition</code> instances which represents
67      *         nodes defined via <code>rpc</code> YANG keyword
68      */
69     Collection<? extends RpcDefinition> getOperations();
70
71     /**
72      * Returns extension definition instances which are defined as the direct
73      * subelements in all YANG modules in the context.
74      *
75      * @return set of <code>ExtensionDefinition</code> instances which
76      *         represents nodes defined via <code>extension</code> YANG keyword
77      */
78     Collection<? extends ExtensionDefinition> getExtensions();
79
80     /**
81      * Returns the module matching specified {@link QNameModule}, if present.
82      *
83      * @param qnameModule requested QNameModule
84      * @return Module, if present.
85      * @throws NullPointerException if qnameModule is null
86      */
87     Optional<Module> findModule(@NonNull QNameModule qnameModule);
88
89     /**
90      * Returns module instance (from the context) with specified namespace and no revision.
91      *
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.
95      */
96     default Optional<Module> findModule(final @NonNull URI namespace) {
97         return findModule(QNameModule.create(namespace));
98     }
99
100     /**
101      * Returns module instance (from the context) with specified namespace and revision.
102      *
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>.
107      */
108     default Optional<Module> findModule(final @NonNull URI namespace, final @Nullable Revision revision) {
109         return findModule(QNameModule.create(namespace, revision));
110     }
111
112     /**
113      * Returns module instance (from the context) with specified namespace and revision.
114      *
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>.
119      */
120     default Optional<Module> findModule(final @NonNull URI namespace, final @NonNull Optional<Revision> revision) {
121         return findModule(QNameModule.create(namespace, revision));
122     }
123
124     /**
125      * Returns module instance (from the context) with specified name and an optional revision.
126      *
127      * @param name
128      *            string with the module name
129      * @param revision
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>.
133      */
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();
136     }
137
138     /**
139      * Returns module instance (from the context) with specified name and revision.
140      *
141      * @param name
142      *            string with the module name
143      * @param revision
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>.
147      */
148     default Optional<? extends Module> findModule(final String name, final @Nullable Revision revision) {
149         return findModule(name, Optional.ofNullable(revision));
150     }
151
152     /**
153      * Returns module instance (from the context) with specified name and no revision.
154      *
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>
157      *                and no revision.
158      * @throws NullPointerException if name is null
159      */
160     default Optional<? extends Module> findModule(final String name) {
161         return findModule(name, Optional.empty());
162     }
163
164     /**
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.
167      *
168      * @param name
169      *            string with the module name
170      * @return set of module instances with specified name.
171      */
172     default Collection<? extends Module> findModules(final String name) {
173         return Collections2.filter(getModules(), m -> name.equals(m.getName()));
174     }
175
176     /**
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.
179      *
180      * @param namespace
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
184      */
185     default Collection<? extends Module> findModules(final URI namespace) {
186         return Collections2.filter(getModules(), m -> namespace.equals(m.getNamespace()));
187     }
188
189     @Override
190     @Deprecated
191     default Collection<? extends ActionDefinition> getActions() {
192         return ImmutableSet.of();
193     }
194
195     @Override
196     @Deprecated
197     default Optional<ActionDefinition> findAction(final QName qname) {
198         requireNonNull(qname);
199         return Optional.empty();
200     }
201
202     @Override
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);
210                 }
211             }
212         }
213         return Optional.empty();
214     }
215
216     @Override
217     @Deprecated
218     default Optional<String> getDescription() {
219         return Optional.empty();
220     }
221
222     @Override
223     @Deprecated
224     default Optional<String> getReference() {
225         return Optional.empty();
226     }
227
228     @Override
229     @Deprecated
230     default Collection<? extends MustDefinition> getMustConstraints() {
231         return ImmutableSet.of();
232     }
233
234     @Override
235     @Deprecated
236     default Optional<RevisionAwareXPath> getWhenCondition() {
237         return Optional.empty();
238     }
239
240     @Override
241     @Deprecated
242     default boolean isAugmenting() {
243         return false;
244     }
245
246     @Override
247     @Deprecated
248     default boolean isAddedByUses() {
249         return false;
250     }
251
252     @Override
253     @Deprecated
254     default boolean isConfiguration() {
255         return false;
256     }
257
258     @Override
259     @Deprecated
260     default QName getQName() {
261         // FIXME: YANGTOOLS-1074: we do not want this name
262         return NAME;
263     }
264
265     @Override
266     @Deprecated
267     default SchemaPath getPath() {
268         return SchemaPath.ROOT;
269     }
270
271     @Override
272     @Deprecated
273     default Status getStatus() {
274         return Status.CURRENT;
275     }
276
277     @Override
278     @Deprecated
279     default Collection<? extends UsesNode> getUses() {
280         return Collections.emptySet();
281     }
282
283     @Override
284     @Deprecated
285     default boolean isPresenceContainer() {
286         return false;
287     }
288
289     @Override
290     @Deprecated
291     default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
292         return Collections.emptySet();
293     }
294
295     @Beta
296     @Override
297     default Optional<DataSchemaNode> findDataTreeChild(final QName name) {
298         return findModule(name.getModule()).flatMap(mod -> mod.findDataTreeChild(name));
299     }
300
301     /**
302      * Get identities derived from a selected identity.
303      *
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
308      */
309     @Beta
310     @NonNull Collection<? extends IdentitySchemaNode> getDerivedIdentities(IdentitySchemaNode identity);
311 }