Eliminate SourceException throws declarations
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / UniqueStatementImpl.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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
10
11 import java.util.Collection;
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.SchemaNodeIdentifier;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relative;
17 import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UniqueEffectiveStatementImpl;
23
24 public class UniqueStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier.Relative>> implements UniqueStatement {
25     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
26             .UNIQUE)
27             .build();
28
29     protected UniqueStatementImpl(StmtContext<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement, ?> context) {
30         super(context);
31     }
32
33     public static class Definition
34             extends
35             AbstractStatementSupport<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement,
36                     EffectiveStatement<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement>> {
37
38         public Definition() {
39             super(Rfc6020Mapping.UNIQUE);
40         }
41
42         @Override
43         public Collection<SchemaNodeIdentifier.Relative> parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
44             return Utils.transformKeysStringToKeyNodes(ctx, value);
45         }
46
47         @Override
48         public UniqueStatement createDeclared(StmtContext<Collection<Relative>, UniqueStatement, ?> ctx) {
49             return new UniqueStatementImpl(ctx);
50         }
51
52         @Override
53         public EffectiveStatement<Collection<Relative>, UniqueStatement> createEffective
54                 (StmtContext<Collection<Relative>, UniqueStatement, EffectiveStatement<Collection<Relative>,
55                         UniqueStatement>> ctx) {
56             return new UniqueEffectiveStatementImpl(ctx);
57         }
58
59         @Override
60         public void onFullDefinitionDeclared(StmtContext.Mutable<Collection<Relative>, UniqueStatement,
61                 EffectiveStatement<Collection<Relative>, UniqueStatement>> stmt) {
62             super.onFullDefinitionDeclared(stmt);
63             SUBSTATEMENT_VALIDATOR.validate(stmt);
64         }
65     }
66
67     @Nonnull
68     @Override
69     public Collection<Relative> getTag() {
70         return argument();
71     }
72 }