Bug 4656: Yang parser does not determine configuration true or false properly
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / AbstractEffectiveDataSchemaNode.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 java.util.List;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
13 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
17
18 abstract class AbstractEffectiveDataSchemaNode<D extends DeclaredStatement<QName>> extends
19         AbstractEffectiveSchemaNode<D> implements DataSchemaNode {
20
21     // :FIXME should be private and final
22     boolean augmenting;
23     private final boolean addedByUses;
24     private final boolean configuration;
25     private final ConstraintDefinition constraints;
26
27     public AbstractEffectiveDataSchemaNode(final StmtContext<QName, D, ?> ctx) {
28         super(ctx);
29         this.constraints = EffectiveConstraintDefinitionImpl.forParent(this);
30         this.configuration = ctx.isConfiguration();
31
32         // initCopyType
33         List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
34         if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
35             this.addedByUses = this.augmenting = true;
36         } else {
37             this.augmenting = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION);
38             this.addedByUses = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES);
39         }
40     }
41
42     @Override
43     public boolean isAugmenting() {
44         return augmenting;
45     }
46
47     @Override
48     public boolean isAddedByUses() {
49         return addedByUses;
50     }
51
52     @Override
53     public boolean isConfiguration() {
54         return configuration;
55     }
56
57     @Override
58     public ConstraintDefinition getConstraints() {
59         return constraints;
60     }
61 }