Move SchemaNodeIdentifier to yang-common
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / ModuleEffectiveStatement.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.stmt;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
14 import org.opendaylight.yangtools.yang.common.SchemaNodeIdentifier;
15 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
16 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
17 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19
20 /**
21  * Effective view of a {@link ModuleStatement}.
22  */
23 @Beta
24 public interface ModuleEffectiveStatement
25         extends DataTreeAwareEffectiveStatement<Unqualified, ModuleStatement>, SchemaTreeRoot {
26     /**
27      * Namespace mapping all known prefixes in a module to their modules. Note this namespace includes the module
28      * in which it is instantiated.
29      */
30     abstract class PrefixToEffectiveModuleNamespace
31             extends IdentifierNamespace<String, @NonNull ModuleEffectiveStatement> {
32         private PrefixToEffectiveModuleNamespace() {
33             // This class should never be subclassed
34         }
35     }
36
37     /**
38      * Namespace mapping all known {@link QNameModule}s to their encoding prefixes. This includes the declaration
39      * from prefix/namespace/revision and all imports as they were resolved.
40      */
41     abstract class QNameModuleToPrefixNamespace extends IdentifierNamespace<QNameModule, @NonNull String> {
42         private QNameModuleToPrefixNamespace() {
43             // This class should never be subclassed
44         }
45     }
46
47     /**
48      * Namespace mapping all included submodules. The namespaces is keyed by submodule name.
49      */
50     abstract class NameToEffectiveSubmoduleNamespace
51             extends IdentifierNamespace<String, @NonNull SubmoduleEffectiveStatement> {
52         private NameToEffectiveSubmoduleNamespace() {
53             // This class should never be subclassed
54         }
55     }
56
57     @Override
58     default StatementDefinition statementDefinition() {
59         return YangStmtMapping.MODULE;
60     }
61
62     /**
63      * Get the local QNameModule of this module. All implementations need to override this default method.
64      *
65      * @return Local QNameModule
66      */
67     @NonNull QNameModule localQNameModule();
68
69     /**
70      * {@inheritDoc}
71      *
72      * @implSpec
73      *     Default implementation defers to {@link #findSchemaTreeNode(java.util.List)}.
74      */
75     @Override
76     default Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(final SchemaNodeIdentifier path) {
77         return findSchemaTreeNode(path.getNodeIdentifiers());
78     }
79 }