Deprecate CopyableNode at al.
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / 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.rfc7950.stmt;
9
10 import java.util.Optional;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19
20 public abstract class AbstractEffectiveDataSchemaNode<D extends DeclaredStatement<QName>> extends
21         AbstractEffectiveSchemaNode<D> implements DataSchemaNode {
22
23     private final RevisionAwareXPath whenCondition;
24     private final boolean addedByUses;
25     private final boolean configuration;
26
27     // FIXME: YANGTOOLS-724: this field should be final
28     private boolean augmenting;
29
30     protected AbstractEffectiveDataSchemaNode(final StmtContext<QName, D, ?> ctx) {
31         super(ctx);
32         this.configuration = ctx.isConfiguration();
33         whenCondition = findFirstEffectiveSubstatementArgument(WhenEffectiveStatement.class).orElse(null);
34
35         // initCopyType
36         final CopyHistory originalHistory = ctx.getCopyHistory();
37         if (originalHistory.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
38             this.augmenting = true;
39             this.addedByUses = true;
40         } else {
41             this.augmenting = originalHistory.contains(CopyType.ADDED_BY_AUGMENTATION);
42             this.addedByUses = originalHistory.contains(CopyType.ADDED_BY_USES);
43         }
44     }
45
46     @Deprecated
47     @Override
48     public final boolean isAugmenting() {
49         return augmenting;
50     }
51
52     @Deprecated
53     @Override
54     public final boolean isAddedByUses() {
55         return addedByUses;
56     }
57
58     @Override
59     public final boolean isConfiguration() {
60         return configuration;
61     }
62
63     @Override
64     public final Optional<RevisionAwareXPath> getWhenCondition() {
65         return Optional.ofNullable(whenCondition);
66     }
67
68     /**
69      * Reset {@link #isAugmenting()} to false.
70      *
71      * @deprecated This method is a violation of immutable contract and is a side-effect of bad/incomplete lifecycle,
72      *             which needs to be fixed. Do not introduce new callers. This deficiency is tracked in YANGTOOLS-724.
73      */
74     @Deprecated
75     public final void resetAugmenting() {
76         augmenting = false;
77     }
78 }