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