2 * Copyright (c) 2015 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.parser.stmt.reactor;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
21 final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
22 AbstractResumedStatement<A, D, E> {
23 private final StatementContextBase<?, ?, ?> parent;
24 private final A argument;
26 private SubstatementContext(final SubstatementContext<A, D, E> original,
27 final StatementContextBase<?, ?, ?> parent) {
29 this.parent = requireNonNull(parent, "Parent must not be null");
30 this.argument = original.argument;
33 SubstatementContext(final StatementContextBase<?, ?, ?> parent, final StatementDefinitionContext<A, D, E> def,
34 final StatementSourceReference ref, final String rawArgument) {
35 super(def, ref, rawArgument);
36 this.parent = requireNonNull(parent, "Parent must not be null");
37 this.argument = def.parseArgumentValue(this, rawStatementArgument());
40 // FIXME: YANGTOOLS-784: this constructor is only called in contexts where a different implementation
41 // would be more appropriate
42 SubstatementContext(final StatementContextBase<?, ?, ?> parent, final StatementDefinitionContext<A, D, E> def,
43 final StatementSourceReference ref, final String rawArgument, final A argument, final CopyType copyType) {
44 super(def, ref, rawArgument, copyType);
45 this.parent = requireNonNull(parent, "Parent must not be null");
46 this.argument = argument;
50 SubstatementContext<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
51 return new SubstatementContext<>(this, newParent);
55 * KEEP THINGS ORGANIZED!
57 * below methods exist in the same form in InferredStatementContext. If any adjustment is made here, make sure it is
58 * properly updated there.
62 public Optional<SchemaPath> getSchemaPath() {
63 return substatementGetSchemaPath();
67 public A getStatementArgument() {
72 public StatementContextBase<?, ?, ?> getParentContext() {
77 public StorageNodeType getStorageNodeType() {
78 return StorageNodeType.STATEMENT_LOCAL;
82 public NamespaceStorageNode getParentNamespaceStorage() {
87 public RootStatementContext<?, ?, ?> getRoot() {
88 return parent.getRoot();
92 public boolean isConfiguration() {
93 return isConfiguration(parent);
97 protected boolean isIgnoringIfFeatures() {
98 return isIgnoringIfFeatures(parent);
102 protected boolean isIgnoringConfig() {
103 return isIgnoringConfig(parent);
107 protected boolean isParentSupportedByFeatures() {
108 return parent.isSupportedByFeatures();