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 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 {
34 private final QName qname;
35 private final SchemaPath path;
36 private final boolean presence;
40 boolean configuration;
41 ContainerSchemaNode original;
42 ConstraintDefinition constraints;
44 private ImmutableSet<AugmentationSchema> augmentations;
45 private ImmutableList<UnknownSchemaNode> unknownNodes;
47 public ContainerEffectiveStatementImpl(
48 StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
51 qname = ctx.getStatementArgument();
52 path = Utils.getSchemaPath(ctx);
53 presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
55 // :TODO init other fields
57 initSubstatementCollections();
60 private void initSubstatementCollections() {
61 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
63 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
64 HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
66 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
67 if (effectiveStatement instanceof UnknownSchemaNode) {
68 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
69 unknownNodes.add(unknownNode);
71 if (effectiveStatement instanceof AugmentationSchema) {
72 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
73 augmentations.add(augmentationSchema);
77 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
78 this.augmentations = ImmutableSet.copyOf(augmentations);
82 public QName getQName() {
87 public SchemaPath getPath() {
92 public boolean isAugmenting() {
97 public boolean isAddedByUses() {
102 public Optional<ContainerSchemaNode> getOriginal() {
103 return Optional.fromNullable(original);
107 public boolean isConfiguration() {
108 return configuration;
112 public ConstraintDefinition getConstraints() {
117 public Set<AugmentationSchema> getAvailableAugmentations() {
118 return augmentations;
122 public boolean isPresenceContainer() {
127 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
132 public int hashCode() {
133 final int prime = 31;
135 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
136 result = prime * result + ((path == null) ? 0 : path.hashCode());
141 public boolean equals(final Object obj) {
148 if (getClass() != obj.getClass()) {
151 ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
153 if (other.qname != null) {
156 } else if (!qname.equals(other.qname)) {
160 if (other.path != null) {
163 } else if (!path.equals(other.path)) {
170 public String toString() {
171 return "container " + qname.getLocalName();