Convert trivial CopyPolicy users to StatementPolicy
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / config / 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.config;
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.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseBooleanStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
19
20 public final class ConfigStatementSupport
21         extends BaseBooleanStatementSupport<ConfigStatement, ConfigEffectiveStatement> {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
23         YangStmtMapping.CONFIG).build();
24     private static final ConfigStatementSupport INSTANCE = new ConfigStatementSupport();
25
26     private ConfigStatementSupport() {
27         super(YangStmtMapping.CONFIG,
28             new EmptyConfigEffectiveStatement(new EmptyConfigStatement(Boolean.FALSE)),
29             new EmptyConfigEffectiveStatement(new EmptyConfigStatement(Boolean.TRUE)),
30             // FIXME: This is not quite true. If we are instantiated in a context which ignores config, which should
31             //        really fizzle. This needs some more analysis.
32             StatementPolicy.contextIndependent());
33     }
34
35     public static ConfigStatementSupport getInstance() {
36         return INSTANCE;
37     }
38
39     @Override
40     protected SubstatementValidator getSubstatementValidator() {
41         return SUBSTATEMENT_VALIDATOR;
42     }
43
44     @Override
45     protected ConfigStatement createDeclared(final StmtContext<Boolean, ConfigStatement, ?> ctx,
46             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
47         return new RegularConfigStatement(ctx.getArgument(), substatements);
48     }
49
50     @Override
51     protected ConfigEffectiveStatement createEffective(final ConfigStatement declared,
52             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
53         return new RegularConfigEffectiveStatement(declared, substatements);
54     }
55
56     @Override
57     protected EmptyConfigEffectiveStatement createEmptyEffective(final ConfigStatement declared) {
58         return new EmptyConfigEffectiveStatement(declared);
59     }
60 }