Eliminate SourceException throws declarations
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / DeviationStatementImpl.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.Rfc6020Mapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
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.stmt.rfc6020.effective.DeviationEffectiveStatementImpl;
22
23 public class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements DeviationStatement {
24     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
25             .DEVIATION)
26             .add(Rfc6020Mapping.DESCRIPTION, 0, 1)
27             .add(Rfc6020Mapping.DEVIATE, 0, MAX)
28             .add(Rfc6020Mapping.REFERENCE, 0, 1)
29             .build();
30
31     protected DeviationStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
32         super(context);
33     }
34
35     public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier,DeviationStatement,EffectiveStatement<SchemaNodeIdentifier,DeviationStatement>> {
36
37         public Definition() {
38             super(Rfc6020Mapping.DEVIATION);
39         }
40
41         @Override
42         public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
43             return Utils.nodeIdentifierFromPath(ctx, value);
44         }
45
46         @Override
47         public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
48             return new DeviationStatementImpl(ctx);
49         }
50
51         @Override
52         public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
53                 final StmtContext<SchemaNodeIdentifier, DeviationStatement, EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
54             return new DeviationEffectiveStatementImpl(ctx);
55         }
56
57         @Override
58         public void onFullDefinitionDeclared(StmtContext.Mutable<SchemaNodeIdentifier, DeviationStatement,
59                 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> stmt) {
60             super.onFullDefinitionDeclared(stmt);
61             SUBSTATEMENT_VALIDATOR.validate(stmt);
62         }
63     }
64
65     @Nonnull @Override
66     public SchemaNodeIdentifier getTargetNode() {
67         return argument();
68     }
69 }