BUG-6757: revert fix for BUG-4456
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / UnionSpecificationImpl.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 java.util.Collection;
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.TypeStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl;
22
23 public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
24         implements TypeStatement.UnionSpecification {
25     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
26             .TYPE)
27             .add(Rfc6020Mapping.TYPE, 1, MAX)
28             .build();
29
30     protected UnionSpecificationImpl(
31             StmtContext<String, TypeStatement.UnionSpecification, ?> context) {
32         super(context);
33     }
34
35     public static class Definition extends AbstractStatementSupport<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> {
36
37         public Definition() {
38             super(Rfc6020Mapping.TYPE);
39         }
40
41         @Override
42         public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
43                 throws SourceException {
44             return value;
45         }
46
47         @Override
48         public TypeStatement.UnionSpecification createDeclared(
49                 StmtContext<String, TypeStatement.UnionSpecification, ?> ctx) {
50             return new UnionSpecificationImpl(ctx);
51         }
52
53         @Override
54         public EffectiveStatement<String, TypeStatement.UnionSpecification> createEffective(
55                 StmtContext<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> ctx) {
56             return new UnionSpecificationEffectiveStatementImpl(ctx);
57         }
58
59         @Override
60         public void onFullDefinitionDeclared(StmtContext.Mutable<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> stmt) throws SourceException {
61             super.onFullDefinitionDeclared(stmt);
62             SUBSTATEMENT_VALIDATOR.validate(stmt);
63         }
64     }
65
66     @Override
67     public String getName() {
68         return argument();
69     }
70
71     @Override
72     public Collection<? extends TypeStatement> getTypes() {
73         return allDeclared(TypeStatement.class);
74     }
75
76 }