BUG-6757: revert fix for BUG-4456
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / MustStatementImpl.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 javax.annotation.Nullable;
12 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
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.DescriptionStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.MustEffectiveStatementImpl;
26
27 public class MustStatementImpl extends AbstractDeclaredStatement<RevisionAwareXPath> implements MustStatement {
28     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
29             .MUST)
30             .add(Rfc6020Mapping.DESCRIPTION, 0, 1)
31             .add(Rfc6020Mapping.ERROR_APP_TAG, 0, 1)
32             .add(Rfc6020Mapping.ERROR_MESSAGE, 0, 1)
33             .add(Rfc6020Mapping.REFERENCE, 0, 1)
34             .build();
35
36     protected MustStatementImpl(final StmtContext<RevisionAwareXPath, MustStatement, ?> context) {
37         super(context);
38     }
39
40     public static class Definition extends
41             AbstractStatementSupport<RevisionAwareXPath, MustStatement, EffectiveStatement<RevisionAwareXPath, MustStatement>> {
42
43         public Definition() {
44             super(Rfc6020Mapping.MUST);
45         }
46
47         @Override
48         public RevisionAwareXPath parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
49             return Utils.parseXPath(ctx, value);
50         }
51
52         @Override
53         public MustStatement createDeclared(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
54             return new MustStatementImpl(ctx);
55         }
56
57         @Override
58         public EffectiveStatement<RevisionAwareXPath, MustStatement> createEffective(
59                 final StmtContext<RevisionAwareXPath, MustStatement, EffectiveStatement<RevisionAwareXPath, MustStatement>> ctx) {
60             return new MustEffectiveStatementImpl(ctx);
61         }
62
63         @Override
64         public void onFullDefinitionDeclared(StmtContext.Mutable<RevisionAwareXPath, MustStatement,
65                 EffectiveStatement<RevisionAwareXPath, MustStatement>> stmt) throws SourceException {
66             super.onFullDefinitionDeclared(stmt);
67             SUBSTATEMENT_VALIDATOR.validate(stmt);
68         }
69     }
70
71     @Nonnull
72     @Override
73     public RevisionAwareXPath getCondition() {
74         return argument();
75     }
76
77     @Nullable
78     @Override
79     public ErrorAppTagStatement getErrorAppTagStatement() {
80         return firstDeclared(ErrorAppTagStatement.class);
81     }
82
83     @Nullable
84     @Override
85     public ErrorMessageStatement getErrorMessageStatement() {
86         return firstDeclared(ErrorMessageStatement.class);
87     }
88
89     @Nullable
90     @Override
91     public DescriptionStatement getDescription() {
92         return firstDeclared(DescriptionStatement.class);
93     }
94
95     @Nullable
96     @Override
97     public ReferenceStatement getReference() {
98         return firstDeclared(ReferenceStatement.class);
99     }
100 }