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