Bug 2366 - Effective statements impl for new yang parser.
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / ChoiceStatementImpl.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.parser.stmt.rfc6020.effective.ChoiceEffectiveStatementImpl;
11
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.DefaultStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
29 import javax.annotation.Nonnull;
30 import javax.annotation.Nullable;
31 import java.util.Collection;
32
33 public class ChoiceStatementImpl extends AbstractDeclaredStatement<QName>
34         implements ChoiceStatement {
35
36     protected ChoiceStatementImpl(StmtContext<QName, ChoiceStatement, ?> context) {
37         super(context);
38     }
39
40     public static class Definition
41             extends
42             AbstractStatementSupport<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> {
43
44         public Definition() {
45             super(Rfc6020Mapping.CHOICE);
46         }
47
48         @Override
49         public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
50                 throws SourceException {
51             return Utils.qNameFromArgument(ctx, value);
52         }
53
54         @Override
55         public ChoiceStatement createDeclared(
56                 StmtContext<QName, ChoiceStatement, ?> ctx) {
57             return new ChoiceStatementImpl(ctx);
58         }
59
60         @Override
61         public EffectiveStatement<QName, ChoiceStatement> createEffective(
62                 StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
63             return new ChoiceEffectiveStatementImpl(ctx);
64         }
65     }
66
67     @Nonnull
68     @Override
69     public QName getName() {
70         return argument();
71     }
72
73     @Nullable
74     @Override
75     public DefaultStatement getDefault() {
76         return firstDeclared(DefaultStatement.class);
77     }
78
79     @Nullable
80     @Override
81     public ConfigStatement getConfig() {
82         return firstDeclared(ConfigStatement.class);
83     }
84
85     @Nullable
86     @Override
87     public MandatoryStatement getMandatory() {
88         return firstDeclared(MandatoryStatement.class);
89     }
90
91     @Nonnull
92     @Override
93     public Collection<? extends CaseStatement> getCases() {
94         return allDeclared(CaseStatement.class);
95     }
96
97     @Override
98     public WhenStatement getWhenStatement() {
99         return firstDeclared(WhenStatement.class);
100     }
101
102     @Nonnull
103     @Override
104     public Collection<? extends IfFeatureStatement> getIfFeatures() {
105         return allDeclared(IfFeatureStatement.class);
106     }
107
108     @Nullable
109     @Override
110     public StatusStatement getStatus() {
111         return firstDeclared(StatusStatement.class);
112     }
113
114     @Nullable
115     @Override
116     public DescriptionStatement getDescription() {
117         return firstDeclared(DescriptionStatement.class);
118     }
119
120     @Nullable
121     @Override
122     public ReferenceStatement getReference() {
123         return firstDeclared(ReferenceStatement.class);
124     }
125 }