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