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.Sets;
12 import java.util.Date;
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;
21 * The interface represents static view of compiled yang files,
22 * contains the methods for obtaining all the top level context
23 * data (data from all modules) like YANG notifications, extensions,
25 * Instances MUST be immutable and thus usage in multi threaded
26 * environment is safe.
29 public interface SchemaContext extends ContainerSchemaNode {
31 * QName of NETCONF top-level data node.
33 QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "data").intern();
36 * Returns data schema node instances which represents direct subnodes (like
37 * leaf, leaf-list, list, container) in all YANG modules in the context.
39 * @return set of <code>DataSchemaNode</code> instances which represents
40 * YANG data nodes at the module top level
42 Set<DataSchemaNode> getDataDefinitions();
45 * Returns modules which are part of the schema context.
47 * @return set of the modules which belong to the schema context
49 Set<Module> getModules();
52 * Returns rpc definition instances which are defined as the direct
53 * subelements in all YANG modules in the context.
55 * @return set of <code>RpcDefinition</code> instances which represents
56 * nodes defined via <code>rpc</code> YANG keyword
58 Set<RpcDefinition> getOperations();
61 * Returns extencion definition instances which are defined as the direct
62 * subelements in all YANG modules in the context.
64 * @return set of <code>ExtensionDefinition</code> instances which
65 * represents nodes defined via <code>extension</code> YANG keyword
67 Set<ExtensionDefinition> getExtensions();
70 * Returns module instance (from the context) with concrete name and revision date.
73 * string with the module name
75 * date of the module revision, may be null
76 * @return module instance which has name and revision the same as are the values specified in parameters
77 * <code>name</code> and <code>revision</code>.
79 Optional<Module> findModule(String name, @Nullable Date revision);
81 default Optional<Module> findModule(final URI namespace, @Nullable final Date revision) {
82 return findModule(QNameModule.create(namespace, revision));
85 default Optional<Module> findModule(final QNameModule qnameModule) {
86 return getModules().stream().filter(m -> qnameModule.equals(m.getQNameModule())).findAny();
90 * Returns module instances (from the context) with a concrete name.
93 * string with the module name
94 * @return set of module instances with specified name.
96 default Set<Module> findModules(final String name) {
97 return Sets.filter(getModules(), m -> name.equals(m.getName()));
101 * Returns module instance (from the context) with concrete namespace.
104 * URI instance with specified namespace
105 * @return module instance which has namespace equal to the
106 * <code>namespace</code> or <code>null</code> in other cases
108 default Set<Module> findModules(final URI namespace) {
109 return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));