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%2FLeafListEffectiveStatementImpl.java;h=de1322110d1db580e560bc9133714a1447976713;hb=9c6cbdaf5bb5e1ea8066558927e9ea674c0b9d51;hp=8840670ea3fb99240708b3a0a06007b7226d9ad3;hpb=30c67c4d780e897d972d60bb79d546b512516f90;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java index 8840670ea3..de1322110d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,122 +7,61 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import java.util.Set; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils; - -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils; import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; +import java.util.Objects; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement; +import org.opendaylight.yangtools.yang.model.util.type.ConcreteTypeBuilder; +import org.opendaylight.yangtools.yang.model.util.type.ConcreteTypes; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode implements +public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode implements LeafListSchemaNode, DerivableSchemaNode { - private final QName qname; - private final SchemaPath path; - - private boolean augmenting; - private boolean addedByUses; - private LeafListSchemaNode original; - private boolean configuration = true; - private ConstraintDefinition constraintsDef; - private TypeDefinition type; - private boolean userOrdered; - private ImmutableList unknownNodes; + private static final String ORDER_BY_USER_KEYWORD = "user"; + private final TypeDefinition type; + private final LeafListSchemaNode original; + private final boolean userOrdered; public LeafListEffectiveStatementImpl( - StmtContext> ctx) { + final StmtContext> ctx) { super(ctx); - this.qname = ctx.getStatementArgument(); - this.path = Utils.getSchemaPath(ctx); - this.constraintsDef = new EffectiveConstraintDefinitionImpl(this); - - // :TODO init TypeDefinition - - initSubstatementCollections(); - initCopyType(ctx); - } - - private void initCopyType( - StmtContext> ctx) { - - Set copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx); - - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) { - augmenting = true; - } - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) { - addedByUses = true; - } - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) { - addedByUses = augmenting = true; - } - - if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) { - original = (LeafListSchemaNode) ctx.getOriginalCtx().buildEffective(); - } - } - private void initSubstatementCollections() { - Collection> effectiveSubstatements = effectiveSubstatements(); - - List unknownNodesInit = new LinkedList<>(); - - boolean configurationInit = false; - boolean userOrderedInit = false; - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof UnknownSchemaNode) { - unknownNodesInit.add((UnknownSchemaNode) effectiveStatement); - } - if (effectiveStatement instanceof TypeDefinition) { - type = TypeUtils.getTypeFromEffectiveStatement(effectiveStatement); - } - if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) { - ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement; - this.configuration = configStmt.argument(); - configurationInit = true; + this.original = ctx.getOriginalCtx() == null ? null : (LeafListSchemaNode) ctx.getOriginalCtx() + .buildEffective(); + + final TypeEffectiveStatement typeStmt = SourceException.throwIfNull( + firstSubstatementOfType(TypeEffectiveStatement.class), ctx.getStatementSourceReference(), + "Leaf-list is missing a 'type' statement"); + + final ConcreteTypeBuilder builder = ConcreteTypes.concreteTypeBuilder(typeStmt.getTypeDefinition(), + ctx.getSchemaPath().get()); + boolean isUserOrdered = false; + for (EffectiveStatement stmt : effectiveSubstatements()) { + if (stmt instanceof OrderedByEffectiveStatementImpl) { + isUserOrdered = ORDER_BY_USER_KEYWORD.equals(stmt.argument()); } - if (!userOrderedInit && effectiveStatement instanceof OrderedByEffectiveStatementImpl) { - OrderedByEffectiveStatementImpl orderedByStmt = (OrderedByEffectiveStatementImpl) effectiveStatement; - this.userOrdered = orderedByStmt.argument().equals("user") ? true : false; - userOrderedInit = true; + + if (stmt instanceof DefaultEffectiveStatementImpl) { + builder.setDefaultValue(stmt.argument()); + } else if (stmt instanceof DescriptionEffectiveStatementImpl) { + builder.setDescription(((DescriptionEffectiveStatementImpl)stmt).argument()); + } else if (stmt instanceof ReferenceEffectiveStatementImpl) { + builder.setReference(((ReferenceEffectiveStatementImpl)stmt).argument()); + } else if (stmt instanceof StatusEffectiveStatementImpl) { + builder.setStatus(((StatusEffectiveStatementImpl)stmt).argument()); + } else if (stmt instanceof UnitsEffectiveStatementImpl) { + builder.setUnits(((UnitsEffectiveStatementImpl)stmt).argument()); } } - this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - - @Override - public boolean isAddedByUses() { - return addedByUses; + type = builder.build(); + userOrdered = isUserOrdered; } @Override @@ -130,16 +69,6 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN return Optional.fromNullable(original); } - @Override - public boolean isConfiguration() { - return configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraintsDef; - } - @Override public TypeDefinition getType() { return type; @@ -150,17 +79,12 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN 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; } @@ -176,29 +100,13 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN return false; } LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) 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() { - StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName()); - sb.append("["); - sb.append(qname); - sb.append("]"); - return sb.toString(); + return LeafListEffectiveStatementImpl.class.getSimpleName() + "[" + + getQName() + + "]"; } -} \ No newline at end of file +}