a3d5feddbc01e2d0a32da39173794edc7343553c
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / EnumEffectiveStatementImpl.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.effective.type;
9
10 import java.util.Collections;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.Status;
15 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
18 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
26
27 public class EnumEffectiveStatementImpl extends EffectiveStatementBase<QName, EnumStatement> implements EnumPair {
28     private final QName qName;
29     private final SchemaPath path;
30     private String description;
31     private String reference;
32     private Status status;
33     private Integer value;
34
35     public EnumEffectiveStatementImpl(final StmtContext<QName, EnumStatement, ?> ctx) {
36         super(ctx);
37
38         qName = ctx.getStatementArgument();
39         path = Utils.getSchemaPath(ctx);
40
41         for (final EffectiveStatement<?,?> effectiveStatement : effectiveSubstatements()) {
42             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
43                 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
44             }
45             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
46                 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
47             }
48             if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
49                 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
50             }
51             if (effectiveStatement instanceof ValueEffectiveStatementImpl) {
52                 value = ((ValueEffectiveStatementImpl) effectiveStatement).argument();
53             }
54         }
55     }
56
57     @Override
58     public String getName() {
59         return qName.getLocalName();
60     }
61
62     @Override
63     public Integer getValue() {
64         return value;
65     }
66
67     @Override
68     public QName getQName() {
69         return qName;
70     }
71
72     @Override
73     public SchemaPath getPath() {
74         return path;
75     }
76
77     @Override
78     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
79         return Collections.emptyList();
80     }
81
82     @Override
83     public String getDescription() {
84         return description;
85     }
86
87     @Override
88     public String getReference() {
89         return reference;
90     }
91
92     @Override
93     public Status getStatus() {
94         return status;
95     }
96 }