2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.parser.stmt.reactor;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import java.util.Collection;
14 import java.util.Optional;
15 import java.util.stream.Stream;
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.StatementDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * A replica of a different statement. It does not allow modification, but produces an effective statement from a
30 final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
31 extends StatementContextBase<A, D, E> {
32 private static final Logger LOG = LoggerFactory.getLogger(ReplicaStatementContext.class);
34 private final StatementContextBase<?, ?, ?> parent;
35 private final StatementContextBase<A, D, E> source;
37 private final boolean haveRef;
39 ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final StatementContextBase<A, D, E> source) {
41 this.parent = requireNonNull(parent);
42 this.source = requireNonNull(source);
43 if (source.isSupportedToBuildEffective()) {
47 setIsSupportedToBuildEffective(false);
54 return source.buildEffective();
58 public boolean isConfiguration() {
59 return source.isConfiguration();
63 public D buildDeclared() {
64 return source.buildDeclared();
69 return source.argument();
73 public StatementSourceReference sourceReference() {
74 return source.sourceReference();
78 public String rawArgument() {
79 return source.rawArgument();
83 public Optional<StmtContext<A, D, E>> getOriginalCtx() {
84 return source.getOriginalCtx();
88 public Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements() {
89 return source.mutableDeclaredSubstatements();
93 public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
94 return source.mutableEffectiveSubstatements();
98 boolean hasEmptySubstatements() {
99 return source.hasEmptySubstatements();
103 Iterable<StatementContextBase<?, ?, ?>> effectiveChildrenToComplete() {
104 return ImmutableList.of();
108 int sweepSubstatements() {
116 public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
117 throw new UnsupportedOperationException();
121 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
122 throw new UnsupportedOperationException();
126 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
127 final String statementArg) {
128 throw new UnsupportedOperationException();
132 public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
133 throw new UnsupportedOperationException();
137 void addEffectiveSubstatementsImpl(final Collection<? extends Mutable<?, ?, ?>> statements) {
138 throw new UnsupportedOperationException();
142 Stream<? extends StmtContext<?, ?, ?>> streamDeclared() {
143 throw new UnsupportedOperationException();
147 Stream<? extends StmtContext<?, ?, ?>> streamEffective() {
148 throw new UnsupportedOperationException();
152 StatementContextBase<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
153 throw new UnsupportedOperationException();
157 * KEEP THINGS ORGANIZED!
159 * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
160 * here, make sure it is properly updated there.
164 Optional<SchemaPath> schemaPath() {
165 return substatementGetSchemaPath();
169 public StatementContextBase<?, ?, ?> getParentContext() {
174 public StorageNodeType getStorageNodeType() {
175 return StorageNodeType.STATEMENT_LOCAL;
179 public StatementContextBase<?, ?, ?> getParentNamespaceStorage() {
184 public RootStatementContext<?, ?, ?> getRoot() {
185 return parent.getRoot();
189 protected boolean isIgnoringIfFeatures() {
190 return isIgnoringIfFeatures(parent);
194 protected boolean isIgnoringConfig() {
195 return isIgnoringConfig(parent);
199 protected boolean isParentSupportedByFeatures() {
200 return parent.isSupportedByFeatures();