2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.ImmutableList;
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
14 import java.util.HashSet;
15 import java.util.LinkedList;
16 import java.util.Collection;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import com.google.common.base.Optional;
21 import java.util.List;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
25 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
26 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
29 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
31 public class ContainerEffectiveStatementImpl extends
32 AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
33 implements ContainerSchemaNode, DerivableSchemaNode {
35 private final QName qname;
36 private final SchemaPath path;
38 private boolean presence;
40 private boolean addedByUses;
41 private boolean configuration = true;
42 private ContainerSchemaNode original;
43 private ConstraintDefinition constraints;
45 private ImmutableSet<AugmentationSchema> augmentations;
46 private ImmutableList<UnknownSchemaNode> unknownNodes;
48 public ContainerEffectiveStatementImpl(
49 StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
52 qname = ctx.getStatementArgument();
53 path = Utils.getSchemaPath(ctx);
54 this.constraints = new EffectiveConstraintDefinitionImpl(this);
57 initSubstatementCollectionsAndFields();
60 private void initCopyType(
61 StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
63 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
65 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
68 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
71 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
72 addedByUses = augmenting = true;
75 if (ctx.getOriginalCtx() != null) {
76 original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
80 private void initSubstatementCollectionsAndFields() {
81 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
83 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
84 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
86 boolean configurationInit = false;
87 for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
88 if (effectiveSubstatement instanceof UnknownSchemaNode) {
89 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
90 unknownNodesInit.add(unknownNode);
92 if (effectiveSubstatement instanceof AugmentationSchema) {
93 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
94 augmentationsInit.add(augmentationSchema);
96 if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
99 if (!configurationInit
100 && effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
101 ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveSubstatement;
102 this.configuration = configStmt.argument();
103 configurationInit = true;
107 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
108 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
112 public QName getQName() {
117 public SchemaPath getPath() {
122 public boolean isAugmenting() {
127 public boolean isAddedByUses() {
132 public Optional<ContainerSchemaNode> getOriginal() {
133 return Optional.fromNullable(original);
137 public boolean isConfiguration() {
138 return configuration;
142 public ConstraintDefinition getConstraints() {
147 public Set<AugmentationSchema> getAvailableAugmentations() {
148 return augmentations;
152 public boolean isPresenceContainer() {
157 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
162 public int hashCode() {
163 final int prime = 31;
165 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
166 result = prime * result + ((path == null) ? 0 : path.hashCode());
171 public boolean equals(final Object obj) {
178 if (getClass() != obj.getClass()) {
181 ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
183 if (other.qname != null) {
186 } else if (!qname.equals(other.qname)) {
190 if (other.path != null) {
193 } else if (!path.equals(other.path)) {
200 public String toString() {
201 return "container " + qname.getLocalName();