1 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
3 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
5 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
6 import java.util.Collection;
7 import java.util.HashSet;
8 import java.util.LinkedList;
9 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
10 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
12 import org.opendaylight.yangtools.yang.model.api.stmt.ListStatement;
13 import com.google.common.base.Optional;
14 import com.google.common.collect.ImmutableList;
15 import com.google.common.collect.ImmutableSet;
16 import java.util.List;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 public class ListEffectiveStatementImpl extends
27 AbstractEffectiveDocumentedDataNodeContainer<QName, ListStatement>
28 implements ListSchemaNode, DerivableSchemaNode {
29 private final QName qname;
30 private final SchemaPath path;
34 ListSchemaNode original;
35 boolean configuration;
36 ConstraintDefinition constraints;
39 ImmutableList<QName> keyDefinition;
40 ImmutableSet<AugmentationSchema> augmentations;
41 ImmutableList<UnknownSchemaNode> unknownNodes;
43 public ListEffectiveStatementImpl(
44 StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
46 this.qname = ctx.getStatementArgument();
47 this.path = Utils.getSchemaPath(ctx);
48 // :TODO init other fields
51 initSubstatementCollections();
55 private void initCopyType(
56 StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
58 TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
60 case ADDED_BY_AUGMENTATION:
62 original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
66 original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
76 private void initKeyDefinition() {
77 List<QName> keyDefinitionInit = new LinkedList<QName>();
78 KeyEffectiveStatementImpl key = firstEffective(KeyEffectiveStatementImpl.class);
81 Collection<SchemaNodeIdentifier> keyParts = key.argument();
82 for (SchemaNodeIdentifier keyPart : keyParts) {
83 keyDefinitionInit.add(keyPart.getLastComponent());
87 this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit);
90 private void initSubstatementCollections() {
91 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
93 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<UnknownSchemaNode>();
94 Set<AugmentationSchema> augmentationsInit = new HashSet<AugmentationSchema>();
96 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
97 if (effectiveStatement instanceof UnknownSchemaNode) {
98 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
99 unknownNodesInit.add(unknownNode);
101 if (effectiveStatement instanceof AugmentationSchema) {
102 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
103 augmentationsInit.add(augmentationSchema);
107 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
108 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
112 public QName getQName() {
117 public SchemaPath getPath() {
122 public List<QName> getKeyDefinition() {
123 return keyDefinition;
127 public boolean isAugmenting() {
132 public boolean isAddedByUses() {
137 public Optional<ListSchemaNode> getOriginal() {
138 return Optional.fromNullable(original);
142 public boolean isConfiguration() {
143 return configuration;
147 public ConstraintDefinition getConstraints() {
152 public Set<AugmentationSchema> getAvailableAugmentations() {
153 return augmentations;
157 public boolean isUserOrdered() {
162 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
167 public int hashCode() {
168 final int prime = 31;
170 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
171 result = prime * result + ((path == null) ? 0 : path.hashCode());
176 public boolean equals(final Object obj) {
183 if (getClass() != obj.getClass()) {
186 final ListEffectiveStatementImpl other = (ListEffectiveStatementImpl) obj;
188 if (other.qname != null) {
191 } else if (!qname.equals(other.qname)) {
195 if (other.path != null) {
198 } else if (!path.equals(other.path)) {
205 public String toString() {
206 return "list " + qname.getLocalName();