Split off DeclaredEffectiveStatementBase
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / AbstractEffectiveDocumentedNode.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;
9
10 import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
11 import org.opendaylight.yangtools.yang.model.api.Status;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
14
15 abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
16         extends DeclaredEffectiveStatementBase<A, D> implements DocumentedNode {
17
18     private final String description;
19     private final String reference;
20     private final Status status;
21
22     AbstractEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx) {
23         super(ctx);
24
25         DescriptionEffectiveStatementImpl descStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
26         if (descStmt != null) {
27             description = descStmt.argument();
28         } else {
29             description = null;
30         }
31
32         ReferenceEffectiveStatementImpl refStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
33         if (refStmt != null) {
34             reference = refStmt.argument();
35         } else {
36             RevisionEffectiveStatementImpl revision = firstEffective(RevisionEffectiveStatementImpl.class);
37             if (revision != null) {
38                 reference = revision.getReference();
39             } else {
40                 reference = null;
41             }
42         }
43
44         StatusEffectiveStatementImpl statusStmt = firstEffective(StatusEffectiveStatementImpl.class);
45         if (statusStmt != null) {
46             status = statusStmt.argument();
47         } else {
48             status = Status.CURRENT;
49         }
50     }
51
52     @Override
53     public final String getDescription() {
54         return description;
55     }
56
57     @Override
58     public final String getReference() {
59         return reference;
60     }
61
62     @Override
63     public final Status getStatus() {
64         return status;
65     }
66
67 }