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;
12 import com.google.common.collect.ImmutableSet;
13 import com.google.common.collect.ImmutableList;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
15 import java.util.HashSet;
16 import java.util.LinkedList;
17 import java.util.Collection;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import com.google.common.base.Optional;
22 import java.util.List;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
26 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
27 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
32 public class ContainerEffectiveStatementImpl extends
33 AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
34 implements ContainerSchemaNode, DerivableSchemaNode {
36 private final QName qname;
37 private final SchemaPath path;
39 private boolean presence;
40 private boolean augmenting;
41 private boolean addedByUses;
42 private boolean configuration;
43 private ContainerSchemaNode original;
44 private ConstraintDefinition constraints;
46 private ImmutableSet<AugmentationSchema> augmentations;
47 private ImmutableList<UnknownSchemaNode> unknownNodes;
49 public ContainerEffectiveStatementImpl(
50 StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
53 qname = ctx.getStatementArgument();
54 path = Utils.getSchemaPath(ctx);
58 // :TODO init other fields
61 private void initCopyType(
62 StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
64 TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
66 case ADDED_BY_AUGMENTATION:
68 original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
72 original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
79 private void initFields() {
80 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
82 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
83 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
85 for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
86 if (effectiveSubstatement instanceof UnknownSchemaNode) {
87 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
88 unknownNodesInit.add(unknownNode);
90 if (effectiveSubstatement instanceof AugmentationSchema) {
91 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
92 augmentationsInit.add(augmentationSchema);
94 if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
97 if (effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
98 ConfigEffectiveStatementImpl config = (ConfigEffectiveStatementImpl) effectiveSubstatement;
99 this.configuration = config.argument();
103 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
104 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
108 public QName getQName() {
113 public SchemaPath getPath() {
118 public boolean isAugmenting() {
123 public boolean isAddedByUses() {
128 public Optional<ContainerSchemaNode> getOriginal() {
129 return Optional.fromNullable(original);
133 public boolean isConfiguration() {
134 return configuration;
138 public ConstraintDefinition getConstraints() {
143 public Set<AugmentationSchema> getAvailableAugmentations() {
144 return augmentations;
148 public boolean isPresenceContainer() {
153 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
158 public int hashCode() {
159 final int prime = 31;
161 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
162 result = prime * result + ((path == null) ? 0 : path.hashCode());
167 public boolean equals(final Object obj) {
174 if (getClass() != obj.getClass()) {
177 ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
179 if (other.qname != null) {
182 } else if (!qname.equals(other.qname)) {
186 if (other.path != null) {
189 } else if (!path.equals(other.path)) {
196 public String toString() {
197 return "container " + qname.getLocalName();