Populate xpath/ hierarchy
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / meta / ConfigStatementSupport.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.parser.rfc7950.stmt.meta;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
17 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
18 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
19 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
20 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractBooleanStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
23
24 public final class ConfigStatementSupport
25         extends AbstractBooleanStatementSupport<ConfigStatement, ConfigEffectiveStatement> {
26     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
27         SubstatementValidator.builder(YangStmtMapping.CONFIG).build();
28
29     public ConfigStatementSupport(final YangParserConfiguration config) {
30         super(YangStmtMapping.CONFIG,
31             EffectiveStatements.createConfig(false), EffectiveStatements.createConfig(true),
32             // FIXME: This is not quite true. If we are instantiated in a context which ignores config, which should
33             //        really fizzle. This needs some more analysis.
34             StatementPolicy.contextIndependent(), config, SUBSTATEMENT_VALIDATOR);
35     }
36
37     @Override
38     protected ConfigStatement createDeclared(final Boolean argument,
39             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
40         return DeclaredStatements.createConfig(argument, substatements);
41     }
42
43     @Override
44     protected ConfigStatement attachDeclarationReference(final ConfigStatement stmt,
45             final DeclarationReference reference) {
46         return DeclaredStatementDecorators.decorateConfig(stmt, reference);
47     }
48
49     @Override
50     protected ConfigEffectiveStatement createEffective(final ConfigStatement declared,
51             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
52         return EffectiveStatements.createConfig(declared, substatements);
53     }
54
55     @Override
56     protected ConfigEffectiveStatement createEmptyEffective(final ConfigStatement declared) {
57         return EffectiveStatements.createConfig(declared);
58     }
59 }