0e0886f729ee2bb3aaa9d92d24607cf8c1926227
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / DeviateStatementImpl.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 javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.model.api.Deviation;
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.DeviateStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviateEffectiveStatementImpl;
23
24 public class DeviateStatementImpl extends AbstractDeclaredStatement<Deviation.Deviate> implements DeviateStatement {
25     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
26             .DEVIATE)
27             .add(Rfc6020Mapping.CONFIG, 0, 1)
28             .add(Rfc6020Mapping.DEFAULT, 0, 1)
29             .add(Rfc6020Mapping.MANDATORY, 0, 1)
30             .add(Rfc6020Mapping.MAX_ELEMENTS, 0, 1)
31             .add(Rfc6020Mapping.MIN_ELEMENTS, 0, 1)
32             .add(Rfc6020Mapping.MUST, 0, MAX)
33             .add(Rfc6020Mapping.TYPE, 0, 1)
34             .add(Rfc6020Mapping.UNIQUE, 0, MAX)
35             .add(Rfc6020Mapping.UNITS, 0, 1)
36             .build();
37
38     protected DeviateStatementImpl(
39             StmtContext<Deviation.Deviate, DeviateStatement, ?> context) {
40         super(context);
41     }
42
43     public static class Definition extends AbstractStatementSupport<Deviation.Deviate, DeviateStatement,
44             EffectiveStatement<Deviation.Deviate, DeviateStatement>> {
45
46         public Definition() {
47             super(Rfc6020Mapping.DEVIATE);
48         }
49
50         @Override public Deviation.Deviate parseArgumentValue(
51                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
52             return Utils.parseDeviateFromString(ctx, value);
53         }
54
55         @Override public DeviateStatement createDeclared(
56                 StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
57             return new DeviateStatementImpl(ctx);
58         }
59
60         @Override public EffectiveStatement<Deviation.Deviate, DeviateStatement> createEffective(
61                 StmtContext<Deviation.Deviate, DeviateStatement, EffectiveStatement<Deviation.Deviate,
62                         DeviateStatement>> ctx) {
63             return new DeviateEffectiveStatementImpl(ctx);
64         }
65
66         @Override
67         public void onFullDefinitionDeclared(StmtContext.Mutable<Deviation.Deviate, DeviateStatement,
68                 EffectiveStatement<Deviation.Deviate, DeviateStatement>> stmt) throws SourceException {
69             super.onFullDefinitionDeclared(stmt);
70             SUBSTATEMENT_VALIDATOR.validate(stmt);
71         }
72     }
73
74     @Nonnull @Override
75     public Deviation.Deviate getValue() {
76         return argument();
77     }
78 }