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.Optional;
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;
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,
26 * Instances MUST be immutable and thus usage in multi threaded
27 * environment is safe.
30 public interface SchemaContext extends ContainerSchemaNode {
32 * QName of NETCONF top-level data node.
34 QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), "data").intern();
37 * Returns data schema node instances which represents direct subnodes (like
38 * leaf, leaf-list, list, container) in all YANG modules in the context.
40 * @return set of <code>DataSchemaNode</code> instances which represents
41 * YANG data nodes at the module top level
43 Set<DataSchemaNode> getDataDefinitions();
46 * Returns modules which are part of the schema context.
48 * @return set of the modules which belong to the schema context
50 Set<Module> getModules();
53 * Returns rpc definition instances which are defined as the direct
54 * subelements in all YANG modules in the context.
56 * @return set of <code>RpcDefinition</code> instances which represents
57 * nodes defined via <code>rpc</code> YANG keyword
59 Set<RpcDefinition> getOperations();
62 * Returns extencion definition instances which are defined as the direct
63 * subelements in all YANG modules in the context.
65 * @return set of <code>ExtensionDefinition</code> instances which
66 * represents nodes defined via <code>extension</code> YANG keyword
68 Set<ExtensionDefinition> getExtensions();
71 * Returns module instance (from the context) with concrete name and revision date.
74 * string with the module name
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>.
80 Optional<Module> findModule(String name, Optional<Revision> revision);
83 * Returns module instance (from the context) with concrete name and revision date.
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>.
90 default Optional<Module> findModule(final String name) {
91 return findModule(name, Optional.empty());
95 * Returns module instance (from the context) with concrete name and revision date.
98 * string with the module name
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>.
104 default Optional<Module> findModule(final String name, @Nullable final Revision revision) {
105 return findModule(name, Optional.ofNullable(revision));
108 default Optional<Module> findModule(final URI namespace) {
109 return findModule(QNameModule.create(namespace));
112 default Optional<Module> findModule(final URI namespace, @Nullable final Revision revision) {
113 return findModule(QNameModule.create(namespace, revision));
116 default Optional<Module> findModule(final URI namespace, final Optional<Revision> revision) {
117 return findModule(QNameModule.create(namespace, revision));
120 default Optional<Module> findModule(final QNameModule qnameModule) {
121 return getModules().stream().filter(m -> qnameModule.equals(m.getQNameModule())).findAny();
125 * Returns module instances (from the context) with a concrete name.
128 * string with the module name
129 * @return set of module instances with specified name.
131 default Set<Module> findModules(final String name) {
132 return Sets.filter(getModules(), m -> name.equals(m.getName()));
136 * Returns module instance (from the context) with concrete 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
143 default Set<Module> findModules(final URI namespace) {
144 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
148 default Set<ActionDefinition> getActions() {
149 return ImmutableSet.of();
153 default Optional<String> getDescription() {
154 return Optional.empty();
158 default Optional<String> getReference() {
159 return Optional.empty();