Bug 6867: Extend yang statement parser to support different yang versions
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
1 /*
2  * Copyright (c) 2015 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.parser.spi.meta;
9
10 import com.google.common.base.Optional;
11 import java.util.Collection;
12 import java.util.Map;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.YangVersion;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
26
27 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
28
29     @Nonnull
30     StatementSource getStatementSource();
31
32     @Nonnull
33     StatementSourceReference getStatementSourceReference();
34
35     @Nonnull
36     StatementDefinition getPublicDefinition();
37
38     @Nullable
39     StmtContext<?, ?, ?> getParentContext();
40
41     @Nullable
42     String rawStatementArgument();
43
44     @Nullable
45     A getStatementArgument();
46
47     /**
48      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
49      * {@link Optional#absent()} is returned.
50      *
51      * @return Optional SchemaPath
52      */
53     @Nonnull Optional<SchemaPath> getSchemaPath();
54
55     boolean isConfiguration();
56
57     boolean isEnabledSemanticVersioning();
58
59     @Nonnull
60     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
61             Class<N> type, KT key) throws NamespaceNotAvailableException;
62
63     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
64             Class<N> type);
65
66     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
67
68     @Nonnull
69     StmtContext<?, ?, ?> getRoot();
70
71     /**
72      * Return declared substatements. These are the statements which are explicitly written in the source model.
73      *
74      * @return Collection of declared substatements
75      */
76     @Nonnull
77     Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
78
79     /**
80      * Return effective substatements. These are the statements which are added as this statement's substatements
81      * complete their effective model phase.
82      *
83      * @return Collection of declared substatements
84      */
85     @Nonnull
86     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
87
88     D buildDeclared();
89
90     E buildEffective();
91
92     boolean isSupportedToBuildEffective();
93
94     void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
95
96     Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
97
98     void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
99
100     void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
101
102     StatementContextBase<?, ?, ?> createCopy(
103             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
104             throws SourceException;
105
106     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
107             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
108             throws SourceException;
109
110     CopyHistory getCopyHistory();
111
112     enum SupportedByFeatures {
113         UNDEFINED, SUPPORTED, NOT_SUPPORTED
114     }
115
116     SupportedByFeatures getSupportedByFeatures();
117
118     void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
119
120     StatementContextBase<?, ?, ?> getOriginalCtx();
121
122     void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
123
124     boolean isRootContext();
125
126     void setOrder(int order);
127
128     int getOrder();
129
130     void setCompletedPhase(ModelProcessingPhase completedPhase);
131
132     ModelProcessingPhase getCompletedPhase();
133
134     /**
135      * Return version of root statement context.
136      *
137      * @return version of root statement context
138      */
139     @Nonnull YangVersion getRootVersion();
140
141     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
142             extends StmtContext<A, D, E> {
143
144         @Override
145         StmtContext.Mutable<?, ?, ?> getParentContext();
146
147         <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
148                 Class<N> type, KT key, VT value)
149                 throws NamespaceNotAvailableException;
150
151         @Nonnull
152         @Override
153         StmtContext.Mutable<?, ?, ?> getRoot();
154
155         ModelActionBuilder newInferenceAction(ModelProcessingPhase phase);
156
157         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
158                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
159
160         void setSupportedByFeatures(boolean isSupported);
161
162         /**
163          * Set version of root statement context.
164          *
165          * @param version
166          *            of root statement context
167          */
168         void setRootVersion(YangVersion version);
169     }
170
171 }