Add XMLInputFactory to UntrustedXML
[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.stmt.rfc6020.effective.SemanticVersionEffectiveStatementImpl;
20
21 @Beta
22 public final class SemanticVersionStatementImpl extends AbstractDeclaredStatement<SemVer> implements
23         UnknownStatement<SemVer> {
24     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
25             SupportedExtensionsMapping.SEMANTIC_VERSION).build();
26
27     SemanticVersionStatementImpl(
28             final StmtContext<SemVer, UnknownStatement<SemVer>, ?> context) {
29         super(context);
30     }
31
32     public static class SemanticVersionSupport
33             extends
34             AbstractStatementSupport<SemVer, UnknownStatement<SemVer>, EffectiveStatement<SemVer, UnknownStatement<SemVer>>> {
35
36         public SemanticVersionSupport() {
37             super(SupportedExtensionsMapping.SEMANTIC_VERSION);
38         }
39
40         @Override
41         public SemVer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
42             return SemVer.valueOf(value) ;
43         }
44
45         @Override
46         public void onLinkageDeclared(final StmtContext.Mutable<SemVer,UnknownStatement<SemVer>,EffectiveStatement<SemVer,UnknownStatement<SemVer>>> stmt) {
47             stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument());
48         }
49
50         @Override
51         public UnknownStatement<SemVer> createDeclared(
52                 final StmtContext<SemVer, UnknownStatement<SemVer>, ?> ctx) {
53             return new SemanticVersionStatementImpl(ctx);
54         }
55
56         @Override
57         public EffectiveStatement<SemVer, UnknownStatement<SemVer>> createEffective(
58                 final StmtContext<SemVer, UnknownStatement<SemVer>, EffectiveStatement<SemVer, UnknownStatement<SemVer>>> ctx) {
59             return new SemanticVersionEffectiveStatementImpl(ctx);
60         }
61
62         @Override
63         protected SubstatementValidator getSubstatementValidator() {
64             return SUBSTATEMENT_VALIDATOR;
65         }
66     }
67
68     @Override
69     public SemVer getArgument() {
70         return argument();
71     }
72 }