Bug 6897: Adding getSubstatementValidator() method to AbstractStatementSupport
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / SemanticVersionStatementImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.rfc6020;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.yangtools.concepts.SemVer;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.SemanticVersionEffectiveStatementImpl;
22
23 @Beta
24 public final class SemanticVersionStatementImpl extends AbstractDeclaredStatement<SemVer> implements
25         UnknownStatement<SemVer> {
26     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
27             SupportedExtensionsMapping.SEMANTIC_VERSION).build();
28
29     SemanticVersionStatementImpl(
30             final StmtContext<SemVer, UnknownStatement<SemVer>, ?> context) {
31         super(context);
32     }
33
34     public static class SemanticVersionSupport
35             extends
36             AbstractStatementSupport<SemVer, UnknownStatement<SemVer>, EffectiveStatement<SemVer, UnknownStatement<SemVer>>> {
37
38         public SemanticVersionSupport() {
39             super(SupportedExtensionsMapping.SEMANTIC_VERSION);
40         }
41
42         @Override
43         public SemVer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
44             return SemVer.valueOf(value) ;
45         }
46
47         @Override
48         public void onLinkageDeclared(final StmtContext.Mutable<SemVer,UnknownStatement<SemVer>,EffectiveStatement<SemVer,UnknownStatement<SemVer>>> stmt) {
49             stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument());
50         }
51
52         @Override
53         public void onFullDefinitionDeclared(
54                 final Mutable<SemVer, UnknownStatement<SemVer>, EffectiveStatement<SemVer, UnknownStatement<SemVer>>> stmt)
55                 throws SourceException {
56             getSubstatementValidator().validate(stmt);
57         }
58
59         @Override
60         public UnknownStatement<SemVer> createDeclared(
61                 final StmtContext<SemVer, UnknownStatement<SemVer>, ?> ctx) {
62             return new SemanticVersionStatementImpl(ctx);
63         }
64
65         @Override
66         public EffectiveStatement<SemVer, UnknownStatement<SemVer>> createEffective(
67                 final StmtContext<SemVer, UnknownStatement<SemVer>, EffectiveStatement<SemVer, UnknownStatement<SemVer>>> ctx) {
68             return new SemanticVersionEffectiveStatementImpl(ctx);
69         }
70
71         @Override
72         protected SubstatementValidator getSubstatementValidator() {
73             return SUBSTATEMENT_VALIDATOR;
74         }
75     }
76
77     @Override
78     public SemVer getArgument() {
79         return argument();
80     }
81 }