2 * Copyright (c) 2017 Pantheon Technologies, 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.openconfig.stmt;
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;
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();
29 private OpenConfigVersionSupport() {
30 super(OpenConfigStatements.OPENCONFIG_VERSION);
33 public static OpenConfigVersionSupport getInstance() {
38 public SemVer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
39 return SemVer.valueOf(value);
43 public void onLinkageDeclared(
44 final Mutable<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> stmt) {
45 stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument());
49 protected SubstatementValidator getSubstatementValidator() {
50 return SUBSTATEMENT_VALIDATOR;
54 protected OpenConfigVersionStatement createDeclared(final StmtContext<SemVer, OpenConfigVersionStatement, ?> ctx,
55 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
56 return new OpenConfigVersionStatementImpl(ctx.coerceStatementArgument(), substatements);
60 protected OpenConfigVersionStatement createEmptyDeclared(
61 final StmtContext<SemVer, OpenConfigVersionStatement, ?> ctx) {
62 return createDeclared(ctx, ImmutableList.of());
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);
74 protected OpenConfigVersionEffectiveStatement createEmptyEffective(
75 final StmtContext<SemVer, OpenConfigVersionStatement, OpenConfigVersionEffectiveStatement> ctx,
76 final OpenConfigVersionStatement declared) {
77 return createEffective(ctx, declared, ImmutableList.of());