d381d16928448a0329d50c27b1fdd4b382a98724
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / FeatureStatementImpl.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 static org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator.MAX;
11
12 import java.util.Collection;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.FeatureEffectiveStatementImpl;
27
28 public class FeatureStatementImpl extends AbstractDeclaredStatement<QName>
29         implements FeatureStatement {
30     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
31             .FEATURE)
32             .add(Rfc6020Mapping.DESCRIPTION, 0, 1)
33             .add(Rfc6020Mapping.IF_FEATURE, 0, MAX)
34             .add(Rfc6020Mapping.STATUS, 0, 1)
35             .add(Rfc6020Mapping.REFERENCE, 0, 1)
36             .build();
37
38     protected FeatureStatementImpl(
39             StmtContext<QName, FeatureStatement, ?> context) {
40         super(context);
41     }
42
43     public static class Definition
44             extends
45             AbstractStatementSupport<QName, FeatureStatement, EffectiveStatement<QName, FeatureStatement>> {
46
47         public Definition() {
48             super(Rfc6020Mapping.FEATURE);
49         }
50
51         @Override
52         public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
53             return Utils.qNameFromArgument(ctx, value);
54         }
55
56         @Override
57         public FeatureStatement createDeclared(
58                 StmtContext<QName, FeatureStatement, ?> ctx) {
59             return new FeatureStatementImpl(ctx);
60         }
61
62         @Override
63         public EffectiveStatement<QName, FeatureStatement> createEffective(
64                 StmtContext<QName, FeatureStatement, EffectiveStatement<QName, FeatureStatement>> ctx) {
65             return new FeatureEffectiveStatementImpl(ctx);
66         }
67
68         @Override
69         public void onFullDefinitionDeclared(StmtContext.Mutable<QName, FeatureStatement,
70                 EffectiveStatement<QName, FeatureStatement>> stmt) throws SourceException {
71             super.onFullDefinitionDeclared(stmt);
72             SUBSTATEMENT_VALIDATOR.validate(stmt);
73         }
74     }
75
76     @Override
77     public StatusStatement getStatus() {
78         return firstDeclared(StatusStatement.class);
79     }
80
81     @Override
82     public DescriptionStatement getDescription() {
83         return firstDeclared(DescriptionStatement.class);
84     }
85
86     @Override
87     public ReferenceStatement getReference() {
88         return firstDeclared(ReferenceStatement.class);
89     }
90
91     @Override
92     public Collection<? extends IfFeatureStatement> getIfFeatures() {
93         return allDeclared(IfFeatureStatement.class);
94     }
95
96     @Override
97     public QName getName() {
98         return argument();
99     }
100
101 }