X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FListEffectiveStatementImpl.java;h=7dc2c2361e7a082e9e0c12905807cb4fa9cc8e3a;hb=04fa25a4fe8957f6492618aa9a1e9a4f9af39df4;hp=f9629a114cff9d68e18df5d5f6b83b541dad12ee;hpb=40cc734f65f305ecb2d5d7e01b694e5e54f716e1;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java index f9629a114c..7dc2c2361e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java @@ -1,116 +1,79 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; - +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.model.api.stmt.ListStatement; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; - -public class ListEffectiveStatementImpl extends - AbstractEffectiveDocumentedDataNodeContainer - implements ListSchemaNode, DerivableSchemaNode { - private final QName qname; - private final SchemaPath path; - - boolean augmenting; - boolean addedByUses; - ListSchemaNode original; - boolean configuration; - ConstraintDefinition constraints; - boolean userOrdered; - - ImmutableList keyDefinition; - ImmutableSet augmentations; - ImmutableList unknownNodes; +import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ListStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; + +public final class ListEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer implements + ListSchemaNode, DerivableSchemaNode { + + private final boolean userOrdered; + private final List keyDefinition; + private static final String ORDER_BY_USER_KEYWORD = "user"; + private final ListSchemaNode original; public ListEffectiveStatementImpl( - StmtContext> ctx) { + final StmtContext> ctx) { super(ctx); - this.qname = ctx.getStatementArgument(); - this.path = Utils.getSchemaPath(ctx); - // :TODO init other fields - initKeyDefinition(); - initSubstatementCollections(); - } + this.original = ctx.getOriginalCtx() == null ? null : (ListSchemaNode) ctx.getOriginalCtx().buildEffective(); - /** - * - */ - private void initKeyDefinition() { - List keyDefinitionInit = new LinkedList(); - KeyEffectiveStatementImpl key = firstEffective(KeyEffectiveStatementImpl.class); - - if (key != null) { - Collection keyParts = key.argument(); - for (SchemaNodeIdentifier keyPart : keyParts) { - keyDefinitionInit.add(keyPart.getLastComponent()); - } + OrderedByEffectiveStatementImpl orderedByStmt = firstEffective(OrderedByEffectiveStatementImpl.class); + if (orderedByStmt != null && orderedByStmt.argument().equals(ORDER_BY_USER_KEYWORD)) { + this.userOrdered = true; + } else { + this.userOrdered = false; } - this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit); - } - - private void initSubstatementCollections() { - Collection> effectiveSubstatements = effectiveSubstatements(); + // initKeyDefinition + List keyDefinitionInit = new LinkedList<>(); + KeyEffectiveStatementImpl keyEffectiveSubstatement = firstEffective(KeyEffectiveStatementImpl.class); - List unknownNodesInit = new LinkedList(); - Set augmentationsInit = new HashSet(); + if (keyEffectiveSubstatement != null) { + Set possibleLeafQNamesForKey = new HashSet<>(); - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof UnknownSchemaNode) { - UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement; - unknownNodesInit.add(unknownNode); - } - if (effectiveStatement instanceof AugmentationSchema) { - AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement; - augmentationsInit.add(augmentationSchema); + for (final EffectiveStatement effectiveStatement : effectiveSubstatements()) { + if (effectiveStatement instanceof LeafSchemaNode) { + possibleLeafQNamesForKey.add(((LeafSchemaNode) effectiveStatement).getQName()); + } } - } - - this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); - this.augmentations = ImmutableSet.copyOf(augmentationsInit); - } - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } + Collection keys = keyEffectiveSubstatement.argument(); + for (SchemaNodeIdentifier key : keys) { + final QName keyQName = key.getLastComponent(); - @Override - public List getKeyDefinition() { - return keyDefinition; - } + if (!possibleLeafQNamesForKey.contains(keyQName)) { + throw new InferenceException(ctx.getStatementSourceReference(), + "Key '%s' misses node '%s' in list '%s'", keyEffectiveSubstatement.getDeclared().rawArgument(), + keyQName.getLocalName(), ctx.getStatementArgument()); + } - @Override - public boolean isAugmenting() { - return augmenting; - } + keyDefinitionInit.add(keyQName); + } + } - @Override - public boolean isAddedByUses() { - return addedByUses; + this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit); } @Override @@ -119,18 +82,8 @@ public class ListEffectiveStatementImpl extends } @Override - public boolean isConfiguration() { - return configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraints; - } - - @Override - public Set getAvailableAugmentations() { - return augmentations; + public List getKeyDefinition() { + return keyDefinition; } @Override @@ -138,17 +91,12 @@ public class ListEffectiveStatementImpl extends return userOrdered; } - @Override - public List getUnknownSchemaNodes() { - return unknownNodes; - } - @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + Objects.hashCode(getQName()); + result = prime * result + Objects.hashCode(getPath()); return result; } @@ -164,25 +112,11 @@ public class ListEffectiveStatementImpl extends return false; } final ListEffectiveStatementImpl other = (ListEffectiveStatementImpl) obj; - if (qname == null) { - if (other.qname != null) { - return false; - } - } else if (!qname.equals(other.qname)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - return true; + return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath()); } @Override public String toString() { - return "list " + qname.getLocalName(); + return "list " + getQName().getLocalName(); } -} \ No newline at end of file +}