606008b6d62f7699f07612db78eb79418a223594
[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 java.util.Collection;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl;
20
21 public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
22         implements TypeStatement.UnionSpecification {
23     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
24             .TYPE)
25             .addMultiple(YangStmtMapping.TYPE)
26             .build();
27
28     protected UnionSpecificationImpl(
29             final StmtContext<String, TypeStatement.UnionSpecification, ?> context) {
30         super(context);
31     }
32
33     public static class Definition extends AbstractStatementSupport<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> {
34
35         public Definition() {
36             super(YangStmtMapping.TYPE);
37         }
38
39         @Override
40         public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
41             return value;
42         }
43
44         @Override
45         public TypeStatement.UnionSpecification createDeclared(
46                 final StmtContext<String, TypeStatement.UnionSpecification, ?> ctx) {
47             return new UnionSpecificationImpl(ctx);
48         }
49
50         @Override
51         public EffectiveStatement<String, TypeStatement.UnionSpecification> createEffective(
52                 final StmtContext<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> ctx) {
53             return new UnionSpecificationEffectiveStatementImpl(ctx);
54         }
55
56         @Override
57         public void onFullDefinitionDeclared(final StmtContext.Mutable<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> stmt) {
58             super.onFullDefinitionDeclared(stmt);
59             SUBSTATEMENT_VALIDATOR.validate(stmt);
60         }
61     }
62
63     @Nonnull
64     @Override
65     public String getName() {
66         return argument();
67     }
68
69     @Nonnull
70     @Override
71     public Collection<? extends TypeStatement> getTypes() {
72         return allDeclared(TypeStatement.class);
73     }
74
75 }