8c665d7a0a89d1b8688d8737f2e62bf389e01ab4
[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         this(ctx, true);
24     }
25
26     /**
27      * Constructor.
28      *
29      * @param ctx
30      *            context of statement.
31      * @param buildUnknownSubstatements
32      *            if it is false, the unknown substatements are omitted from
33      *            build of effective substatements till the call of either
34      *            effectiveSubstatements or getOmittedUnknownSubstatements
35      *            method of EffectiveStatementBase class. The main purpose of
36      *            this is to allow the build of recursive extension definitions.
37      */
38     AbstractEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx, boolean buildUnknownSubstatements) {
39         super(ctx, buildUnknownSubstatements);
40
41         DescriptionEffectiveStatementImpl descStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
42         if (descStmt != null) {
43             description = descStmt.argument();
44         } else {
45             description = null;
46         }
47
48         ReferenceEffectiveStatementImpl refStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
49         if (refStmt != null) {
50             reference = refStmt.argument();
51         } else {
52             RevisionEffectiveStatementImpl revision = firstEffective(RevisionEffectiveStatementImpl.class);
53             if (revision != null) {
54                 reference = revision.getReference();
55             } else {
56                 reference = null;
57             }
58         }
59
60         StatusEffectiveStatementImpl statusStmt = firstEffective(StatusEffectiveStatementImpl.class);
61         if (statusStmt != null) {
62             status = statusStmt.argument();
63         } else {
64             status = Status.CURRENT;
65         }
66     }
67
68     @Override
69     public final String getDescription() {
70         return description;
71     }
72
73     @Override
74     public final String getReference() {
75         return reference;
76     }
77
78     @Override
79     public final Status getStatus() {
80         return status;
81     }
82
83 }