88ed942844aac749b65e860f176510569b6cc44a
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / DeclaredEffectiveStatementBase.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 com.google.common.base.Verify;
11 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
12 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
13 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
15
16 public abstract class DeclaredEffectiveStatementBase<A, D extends DeclaredStatement<A>>
17         extends EffectiveStatementBase<A, D> {
18
19     private final D declaredInstance;
20
21     public DeclaredEffectiveStatementBase(final StmtContext<A, D, ?> ctx) {
22         this(ctx, true);
23     }
24
25     /**
26      * Constructor.
27      *
28      * @param ctx
29      *            context of statement.
30      * @param buildUnknownSubstatements
31      *            if it is false, the unknown substatements are omitted from
32      *            build of effective substatements till the call of either
33      *            effectiveSubstatements or getOmittedUnknownSubstatements
34      *            method of EffectiveStatementBase class. The main purpose of
35      *            this is to allow the build of recursive extension definitions.
36      */
37     protected DeclaredEffectiveStatementBase(final StmtContext<A, D, ?> ctx, boolean buildUnknownSubstatements) {
38         super(ctx, buildUnknownSubstatements);
39         declaredInstance = Verify.verifyNotNull(ctx.buildDeclared(), "Statement %s failed to build declared statement",
40                 ctx);
41     }
42
43     @Override
44     public final StatementDefinition statementDefinition() {
45         return declaredInstance.statementDefinition();
46     }
47
48     @Override
49     public final A argument() {
50         return declaredInstance.argument();
51     }
52
53     @Override
54     public final StatementSource getStatementSource() {
55         return declaredInstance.getStatementSource();
56     }
57
58     @Override
59     public final D getDeclared() {
60         return declaredInstance;
61     }
62 }