Bug 6897: Adding getSubstatementValidator() method to AbstractStatementSupport
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / LeafrefSpecificationImpl.java
1 /*
2  * Copyright (c) 2015 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 javax.annotation.Nonnull;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
20
21 public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
22         implements TypeStatement.LeafrefSpecification {
23     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
24             .TYPE)
25             .addMandatory(YangStmtMapping.PATH)
26             .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
27             .build();
28
29     protected LeafrefSpecificationImpl(
30             final StmtContext<String, TypeStatement.LeafrefSpecification, ?> context) {
31         super(context);
32     }
33
34     public static class Definition
35             extends
36             AbstractStatementSupport<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> {
37
38         public Definition() {
39             super(YangStmtMapping.TYPE);
40         }
41
42         @Override
43         public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
44             return value;
45         }
46
47         @Override
48         public TypeStatement.LeafrefSpecification createDeclared(
49                 final StmtContext<String, TypeStatement.LeafrefSpecification, ?> ctx) {
50             return new LeafrefSpecificationImpl(ctx);
51         }
52
53         @Override
54         public EffectiveStatement<String, TypeStatement.LeafrefSpecification> createEffective(
55                 final StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
56             return new LeafrefSpecificationEffectiveStatementImpl(ctx);
57         }
58
59         @Override
60         public void onFullDefinitionDeclared(final StmtContext.Mutable<String, LeafrefSpecification,
61                 EffectiveStatement<String, LeafrefSpecification>> stmt) {
62             super.onFullDefinitionDeclared(stmt);
63             getSubstatementValidator().validate(stmt);
64         }
65
66         @Override
67         protected SubstatementValidator getSubstatementValidator() {
68             return SUBSTATEMENT_VALIDATOR;
69         }
70     }
71
72     @Nonnull
73     @Override
74     public String getName() {
75         return argument();
76     }
77
78     @Nonnull
79     @Override
80     public PathStatement getPath() {
81         return firstDeclared(PathStatement.class);
82     }
83
84 }