c273cb5862d5018cadef53fe8fa40f6a6ae903b6
[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
31         ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class);
32         this.configuration = (configStmt == null) ? true : configStmt.argument();
33
34         // initCopyType
35         List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
36         if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
37             this.addedByUses = this.augmenting = true;
38         } else {
39             this.augmenting = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION);
40             this.addedByUses = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES);
41         }
42     }
43
44     @Override
45     public boolean isAugmenting() {
46         return augmenting;
47     }
48
49     @Override
50     public boolean isAddedByUses() {
51         return addedByUses;
52     }
53
54     @Override
55     public boolean isConfiguration() {
56         return configuration;
57     }
58
59     @Override
60     public ConstraintDefinition getConstraints() {
61         return constraints;
62     }
63 }