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.base.Optional;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collection;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
18 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
30 public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements
31 LeafListSchemaNode, DerivableSchemaNode {
32 private final QName qname;
33 private final SchemaPath path;
36 private boolean addedByUses;
37 private LeafListSchemaNode original;
38 private boolean configuration = true;
39 private ConstraintDefinition constraintsDef;
40 private TypeDefinition<?> type;
41 private boolean userOrdered;
43 private ImmutableList<UnknownSchemaNode> unknownNodes;
45 public LeafListEffectiveStatementImpl(
46 StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
48 this.qname = ctx.getStatementArgument();
49 this.path = Utils.getSchemaPath(ctx);
50 this.constraintsDef = new EffectiveConstraintDefinitionImpl(this);
52 // :TODO init TypeDefinition
54 initSubstatementCollections();
58 private void initCopyType(
59 StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
61 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
63 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
66 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
69 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
70 addedByUses = augmenting = true;
73 if (ctx.getOriginalCtx() != null) {
74 original = (LeafListSchemaNode) ctx.getOriginalCtx().buildEffective();
77 private void initSubstatementCollections() {
78 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
80 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
82 boolean configurationInit = false;
83 boolean userOrderedInit = false;
84 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
85 if (effectiveStatement instanceof UnknownSchemaNode) {
86 unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
88 if (effectiveStatement instanceof TypeDefinition) {
89 type = TypeUtils.getTypeFromEffectiveStatement(effectiveStatement);
91 if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
92 ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
93 this.configuration = configStmt.argument();
94 configurationInit = true;
96 if (!userOrderedInit && effectiveStatement instanceof OrderedByEffectiveStatementImpl) {
97 OrderedByEffectiveStatementImpl orderedByStmt = (OrderedByEffectiveStatementImpl) effectiveStatement;
98 this.userOrdered = orderedByStmt.argument().equals("user") ? true : false;
99 userOrderedInit = true;
103 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
107 public QName getQName() {
112 public SchemaPath getPath() {
117 public boolean isAugmenting() {
122 public boolean isAddedByUses() {
127 public Optional<LeafListSchemaNode> getOriginal() {
128 return Optional.fromNullable(original);
132 public boolean isConfiguration() {
133 return configuration;
137 public ConstraintDefinition getConstraints() {
138 return constraintsDef;
142 public TypeDefinition<?> getType() {
147 public boolean isUserOrdered() {
152 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
157 public int hashCode() {
158 final int prime = 31;
160 result = prime * result + Objects.hashCode(qname);
161 result = prime * result + Objects.hashCode(path);
166 public boolean equals(final Object obj) {
173 if (getClass() != obj.getClass()) {
176 LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) obj;
178 if (other.qname != null) {
181 } else if (!qname.equals(other.qname)) {
185 if (other.path != null) {
188 } else if (!path.equals(other.path)) {
195 public String toString() {
196 StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
200 return sb.toString();