Cleanup DocumentedNode
[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 com.google.common.collect.ImmutableSet;
11 import com.google.common.collect.Sets;
12 import java.net.URI;
13 import java.util.Optional;
14 import java.util.Set;
15 import javax.annotation.Nullable;
16 import javax.annotation.concurrent.Immutable;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.common.Revision;
20
21 /**
22  * The interface represents static view of compiled yang files,
23  * contains the methods for obtaining all the top level context
24  * data (data from all modules) like YANG notifications, extensions,
25  * operations...
26  * Instances MUST be immutable and thus usage in multi threaded
27  * environment is safe.
28  */
29 @Immutable
30 public interface SchemaContext extends ContainerSchemaNode {
31     /**
32      * QName of NETCONF top-level data node.
33      */
34     QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
35
36     /**
37      * Returns data schema node instances which represents direct subnodes (like
38      * leaf, leaf-list, list, container) in all YANG modules in the context.
39      *
40      * @return set of <code>DataSchemaNode</code> instances which represents
41      *         YANG data nodes at the module top level
42      */
43     Set<DataSchemaNode> getDataDefinitions();
44
45     /**
46      * Returns modules which are part of the schema context.
47      *
48      * @return set of the modules which belong to the schema context
49      */
50     Set<Module> getModules();
51
52     /**
53      * Returns rpc definition instances which are defined as the direct
54      * subelements in all YANG modules in the context.
55      *
56      * @return set of <code>RpcDefinition</code> instances which represents
57      *         nodes defined via <code>rpc</code> YANG keyword
58      */
59     Set<RpcDefinition> getOperations();
60
61     /**
62      * Returns extencion definition instances which are defined as the direct
63      * subelements in all YANG modules in the context.
64      *
65      * @return set of <code>ExtensionDefinition</code> instances which
66      *         represents nodes defined via <code>extension</code> YANG keyword
67      */
68     Set<ExtensionDefinition> getExtensions();
69
70     /**
71      * Returns module instance (from the context) with concrete name and revision date.
72      *
73      * @param name
74      *            string with the module name
75      * @param revision
76      *            date of the module revision
77      * @return module instance which has name and revision the same as are the values specified in parameters
78      *         <code>name</code> and <code>revision</code>.
79      */
80     Optional<Module> findModule(String name, Optional<Revision> revision);
81
82     /**
83      * Returns module instance (from the context) with concrete name and revision date.
84      *
85      * @param name
86      *            string with the module name
87      * @return module instance which has name and revision the same as are the values specified in parameters
88      *         <code>name</code> and <code>revision</code>.
89      */
90     default Optional<Module> findModule(final String name) {
91         return findModule(name, Optional.empty());
92     }
93
94     /**
95      * Returns module instance (from the context) with concrete name and revision date.
96      *
97      * @param name
98      *            string with the module name
99      * @param revision
100      *            date of the module revision, may be null
101      * @return module instance which has name and revision the same as are the values specified in parameters
102      *         <code>name</code> and <code>revision</code>.
103      */
104     default Optional<Module> findModule(final String name, @Nullable final Revision revision) {
105         return findModule(name, Optional.ofNullable(revision));
106     }
107
108     default Optional<Module> findModule(final URI namespace) {
109         return findModule(QNameModule.create(namespace));
110     }
111
112     default Optional<Module> findModule(final URI namespace, @Nullable final Revision revision) {
113         return findModule(QNameModule.create(namespace, revision));
114     }
115
116     default Optional<Module> findModule(final URI namespace, final Optional<Revision> revision) {
117         return findModule(QNameModule.create(namespace, revision));
118     }
119
120     default Optional<Module> findModule(final QNameModule qnameModule) {
121         return getModules().stream().filter(m -> qnameModule.equals(m.getQNameModule())).findAny();
122     }
123
124     /**
125      * Returns module instances (from the context) with a concrete name.
126      *
127      * @param name
128      *            string with the module name
129      * @return set of module instances with specified name.
130      */
131     default Set<Module> findModules(final String name) {
132         return Sets.filter(getModules(), m -> name.equals(m.getName()));
133     }
134
135     /**
136      * Returns module instance (from the context) with concrete namespace.
137      *
138      * @param namespace
139      *            URI instance with specified namespace
140      * @return module instance which has namespace equal to the
141      *         <code>namespace</code> or <code>null</code> in other cases
142      */
143     default Set<Module> findModules(final URI namespace) {
144         return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
145     }
146
147     @Override
148     default Set<ActionDefinition> getActions() {
149         return ImmutableSet.of();
150     }
151
152     @Override
153     default Optional<String> getDescription() {
154         return Optional.empty();
155     }
156
157     @Override
158     default Optional<String> getReference() {
159         return Optional.empty();
160     }
161 }