BUG-6757: revert fix for BUG-4456
[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     /**
23      * Constructor.
24      *
25      * @param ctx
26      *            context of statement.
27      */
28     protected AbstractEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx) {
29         super(ctx);
30
31         DescriptionEffectiveStatementImpl descStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
32         if (descStmt != null) {
33             description = descStmt.argument();
34         } else {
35             description = null;
36         }
37
38         ReferenceEffectiveStatementImpl refStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
39         if (refStmt != null) {
40             reference = refStmt.argument();
41         } else {
42             RevisionEffectiveStatementImpl revision = firstEffective(RevisionEffectiveStatementImpl.class);
43             if (revision != null) {
44                 reference = revision.getReference();
45             } else {
46                 reference = null;
47             }
48         }
49
50         StatusEffectiveStatementImpl statusStmt = firstEffective(StatusEffectiveStatementImpl.class);
51         if (statusStmt != null) {
52             status = statusStmt.argument();
53         } else {
54             status = Status.CURRENT;
55         }
56     }
57
58     @Override
59     public final String getDescription() {
60         return description;
61     }
62
63     @Override
64     public final String getReference() {
65         return reference;
66     }
67
68     @Override
69     public final Status getStatus() {
70         return status;
71     }
72
73 }