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 com.google.common.collect.ImmutableSet;
11 import com.google.common.collect.Sets;
13 import java.util.Collection;
14 import java.util.Optional;
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;
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,
27 * Instances MUST be immutable and thus usage in multi threaded
28 * environment is safe.
31 public interface SchemaContext extends ContainerSchemaNode {
33 * QName of NETCONF top-level data node.
35 QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
38 * Returns data schema node instances which represents direct subnodes (like
39 * leaf, leaf-list, list, container) in all YANG modules in the context.
41 * @return set of <code>DataSchemaNode</code> instances which represents
42 * YANG data nodes at the module top level
44 Set<DataSchemaNode> getDataDefinitions();
47 * Returns modules which are part of the schema context.
49 * @return set of the modules which belong to the schema context
51 Set<Module> getModules();
54 * Returns rpc definition instances which are defined as the direct
55 * subelements in all YANG modules in the context.
57 * @return set of <code>RpcDefinition</code> instances which represents
58 * nodes defined via <code>rpc</code> YANG keyword
60 Set<RpcDefinition> getOperations();
63 * Returns extencion definition instances which are defined as the direct
64 * subelements in all YANG modules in the context.
66 * @return set of <code>ExtensionDefinition</code> instances which
67 * represents nodes defined via <code>extension</code> YANG keyword
69 Set<ExtensionDefinition> getExtensions();
72 * Returns module instance (from the context) with concrete name and revision date.
75 * string with the module name
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>.
81 Optional<Module> findModule(String name, Optional<Revision> revision);
84 * Returns module instance (from the context) with concrete name and revision date.
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>.
91 default Optional<Module> findModule(final String name) {
92 return findModule(name, Optional.empty());
96 * Returns module instance (from the context) with concrete name and revision date.
99 * string with the module name
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>.
105 default Optional<Module> findModule(final String name, @Nullable final Revision revision) {
106 return findModule(name, Optional.ofNullable(revision));
109 default Optional<Module> findModule(final URI namespace) {
110 return findModule(QNameModule.create(namespace));
113 default Optional<Module> findModule(final URI namespace, @Nullable final Revision revision) {
114 return findModule(QNameModule.create(namespace, revision));
117 default Optional<Module> findModule(final URI namespace, final Optional<Revision> revision) {
118 return findModule(QNameModule.create(namespace, revision));
121 default Optional<Module> findModule(final QNameModule qnameModule) {
122 return getModules().stream().filter(m -> qnameModule.equals(m.getQNameModule())).findAny();
126 * Returns module instances (from the context) with a concrete name.
129 * string with the module name
130 * @return set of module instances with specified name.
132 default Set<Module> findModules(final String name) {
133 return Sets.filter(getModules(), m -> name.equals(m.getName()));
137 * Returns module instance (from the context) with concrete 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
144 default Set<Module> findModules(final URI namespace) {
145 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
149 default Set<ActionDefinition> getActions() {
150 return ImmutableSet.of();
154 default Optional<String> getDescription() {
155 return Optional.empty();
159 default Optional<String> getReference() {
160 return Optional.empty();
164 default Collection<MustDefinition> getMustConstraints() {
165 return ImmutableSet.of();
169 default Optional<RevisionAwareXPath> getWhenCondition() {
170 return Optional.empty();