87c275b0921714775d9d720914a5cd920806ef44
[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<String, EnumStatement> implements EnumPair {
28     private final SchemaPath path;
29     private String description;
30     private String reference;
31     private Status status;
32     private Integer value;
33
34     public EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
35         super(ctx);
36
37         path = Utils.getSchemaPath(ctx);
38
39         for (final EffectiveStatement<?,?> effectiveStatement : effectiveSubstatements()) {
40             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
41                 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
42             }
43             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
44                 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
45             }
46             if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
47                 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
48             }
49             if (effectiveStatement instanceof ValueEffectiveStatementImpl) {
50                 value = ((ValueEffectiveStatementImpl) effectiveStatement).argument();
51             }
52         }
53     }
54
55     @Override
56     public String getName() {
57         return argument();
58     }
59
60     @Override
61     public Integer getValue() {
62         return value;
63     }
64
65     @Override
66     public QName getQName() {
67         return getPath().getLastComponent();
68     }
69
70     @Override
71     public SchemaPath getPath() {
72         return path;
73     }
74
75     @Override
76     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
77         return Collections.emptyList();
78     }
79
80     @Override
81     public String getDescription() {
82         return description;
83     }
84
85     @Override
86     public String getReference() {
87         return reference;
88     }
89
90     @Override
91     public Status getStatus() {
92         return status;
93     }
94 }