Refactor AbstractEffectiveDocumentedNodeWithStatus
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / openconfig / stmt / OpenConfigVersionSupport.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.openconfig.stmt;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.concepts.SemVer;
12 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigStatements;
13 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigVersionEffectiveStatement;
14 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigVersionStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
22
23 public final class OpenConfigVersionSupport
24         extends BaseStatementSupport<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> {
25     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
26         OpenConfigStatements.OPENCONFIG_VERSION).build();
27     private static final OpenConfigVersionSupport INSTANCE = new OpenConfigVersionSupport();
28
29     private OpenConfigVersionSupport() {
30         super(OpenConfigStatements.OPENCONFIG_VERSION);
31     }
32
33     public static OpenConfigVersionSupport getInstance() {
34         return INSTANCE;
35     }
36
37     @Override
38     public SemVer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
39         return SemVer.valueOf(value);
40     }
41
42     @Override
43     public void onLinkageDeclared(
44             final Mutable<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> stmt) {
45         stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument());
46     }
47
48     @Override
49     protected SubstatementValidator getSubstatementValidator() {
50         return SUBSTATEMENT_VALIDATOR;
51     }
52
53     @Override
54     protected OpenConfigVersionStatement createDeclared(final StmtContext<SemVer, OpenConfigVersionStatement, ?> ctx,
55             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
56         return new OpenConfigVersionStatementImpl(ctx.coerceStatementArgument(), substatements);
57     }
58
59     @Override
60     protected OpenConfigVersionStatement createEmptyDeclared(
61             final StmtContext<SemVer, OpenConfigVersionStatement, ?> ctx) {
62         return createDeclared(ctx, ImmutableList.of());
63     }
64
65     @Override
66     protected OpenConfigVersionEffectiveStatement createEffective(
67             final StmtContext<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> ctx,
68             final OpenConfigVersionStatement declared,
69             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
70         return new OpenConfigVersionEffectiveStatementImpl(ctx, substatements);
71     }
72
73     @Override
74     protected OpenConfigVersionEffectiveStatement createEmptyEffective(
75             final StmtContext<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> ctx,
76             final OpenConfigVersionStatement declared) {
77         return createEffective(ctx, declared, ImmutableList.of());
78     }
79 }