eb4ab7b41597411a3483f026ed4396538aaaf33d
[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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
11 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
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.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
19
20 public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
21         implements TypeStatement.LeafrefSpecification {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
23             .TYPE)
24             .addMandatory(Rfc6020Mapping.PATH)
25             .addOptional(Rfc6020Mapping.REQUIRE_INSTANCE)
26             .build();
27
28     protected LeafrefSpecificationImpl(
29             final StmtContext<String, TypeStatement.LeafrefSpecification, ?> context) {
30         super(context);
31     }
32
33     public static class Definition
34             extends
35             AbstractStatementSupport<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> {
36
37         public Definition() {
38             super(Rfc6020Mapping.TYPE);
39         }
40
41         @Override
42         public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
43             return value;
44         }
45
46         @Override
47         public TypeStatement.LeafrefSpecification createDeclared(
48                 final StmtContext<String, TypeStatement.LeafrefSpecification, ?> ctx) {
49             return new LeafrefSpecificationImpl(ctx);
50         }
51
52         @Override
53         public EffectiveStatement<String, TypeStatement.LeafrefSpecification> createEffective(
54                 final StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
55             return new LeafrefSpecificationEffectiveStatementImpl(ctx);
56         }
57
58         @Override
59         public void onFullDefinitionDeclared(final StmtContext.Mutable<String, LeafrefSpecification,
60                 EffectiveStatement<String, LeafrefSpecification>> stmt) {
61             super.onFullDefinitionDeclared(stmt);
62             SUBSTATEMENT_VALIDATOR.validate(stmt);
63         }
64     }
65
66     @Override
67     public String getName() {
68         return argument();
69     }
70
71     @Override
72     public PathStatement getPath() {
73         return firstDeclared(PathStatement.class);
74     }
75
76 }