2 * Copyright (c) 2013 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.builder.impl;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
15 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.YangNode;
21 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractTypeAwareBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
23 import org.opendaylight.yangtools.yang.parser.util.Comparators;
25 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
26 private boolean isBuilt;
27 private final LeafListSchemaNodeImpl instance;
29 private SchemaPath schemaPath;
30 private String description;
31 private String reference;
32 private Status status = Status.CURRENT;
33 // DataSchemaNode args
34 private boolean augmenting;
35 private boolean addedByUses;
36 private Boolean configuration;
37 private final ConstraintsBuilder constraints;
38 // LeafListSchemaNode args
39 private boolean userOrdered;
41 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname,
42 final SchemaPath schemaPath) {
43 super(moduleName, line, qname);
44 this.schemaPath = schemaPath;
45 instance = new LeafListSchemaNodeImpl(qname);
46 constraints = new ConstraintsBuilder(moduleName, line);
50 public LeafListSchemaNode build(YangNode parent) {
52 instance.setParent(parent);
53 instance.setConstraints(constraints.build());
54 instance.setPath(schemaPath);
55 instance.setDescription(description);
56 instance.setReference(reference);
57 instance.setStatus(status);
58 instance.setAugmenting(augmenting);
59 instance.setAddedByUses(addedByUses);
60 instance.setConfiguration(configuration);
61 instance.setUserOrdered(userOrdered);
64 instance.setType(typedef.build(instance));
66 instance.setType(type);
70 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
71 unknownNodes.add(b.build(instance));
73 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
74 instance.setUnknownSchemaNodes(unknownNodes);
82 public void setQName(QName qname) {
87 public SchemaPath getPath() {
92 public void setPath(final SchemaPath schemaPath) {
93 this.schemaPath = schemaPath;
97 public String getDescription() {
102 public void setDescription(final String description) {
103 this.description = description;
107 public String getReference() {
112 public void setReference(String reference) {
113 this.reference = reference;
117 public Status getStatus() {
122 public void setStatus(Status status) {
123 if (status != null) {
124 this.status = status;
129 public boolean isAugmenting() {
134 public void setAugmenting(boolean augmenting) {
135 this.augmenting = augmenting;
139 public boolean isAddedByUses() {
144 public void setAddedByUses(final boolean addedByUses) {
145 this.addedByUses = addedByUses;
149 public Boolean isConfiguration() {
150 return configuration;
154 public void setConfiguration(Boolean configuration) {
155 this.configuration = configuration;
159 public ConstraintsBuilder getConstraints() {
163 public boolean isUserOrdered() {
167 public void setUserOrdered(final boolean userOrdered) {
168 this.userOrdered = userOrdered;
172 public int hashCode() {
173 final int prime = 31;
175 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
180 public boolean equals(Object obj) {
187 if (getClass() != obj.getClass()) {
190 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
191 if (schemaPath == null) {
192 if (other.schemaPath != null) {
195 } else if (!schemaPath.equals(other.schemaPath)) {
198 if (parentBuilder == null) {
199 if (other.parentBuilder != null) {
202 } else if (!parentBuilder.equals(other.parentBuilder)) {
209 public String toString() {
210 return "leaf-list " + qname.getLocalName();
213 private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
214 private final QName qname;
215 private SchemaPath path;
216 private YangNode parent;
217 private String description;
218 private String reference;
219 private Status status = Status.CURRENT;
220 private boolean augmenting;
221 private boolean addedByUses;
222 private boolean configuration;
223 private ConstraintDefinition constraintsDef;
224 private TypeDefinition<?> type;
225 private boolean userOrdered;
226 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
228 private LeafListSchemaNodeImpl(final QName qname) {
233 public QName getQName() {
238 public SchemaPath getPath() {
242 private void setPath(final SchemaPath path) {
247 public YangNode getParent() {
251 private void setParent(YangNode parent) {
252 this.parent = parent;
256 public String getDescription() {
260 private void setDescription(String description) {
261 this.description = description;
265 public String getReference() {
269 private void setReference(String reference) {
270 this.reference = reference;
274 public Status getStatus() {
278 private void setStatus(Status status) {
279 this.status = status;
283 public boolean isAugmenting() {
287 private void setAugmenting(boolean augmenting) {
288 this.augmenting = augmenting;
292 public boolean isAddedByUses() {
296 private void setAddedByUses(final boolean addedByUses) {
297 this.addedByUses = addedByUses;
301 public boolean isConfiguration() {
302 return configuration;
305 private void setConfiguration(boolean configuration) {
306 this.configuration = configuration;
310 public ConstraintDefinition getConstraints() {
311 return constraintsDef;
314 private void setConstraints(ConstraintDefinition constraintsDef) {
315 this.constraintsDef = constraintsDef;
319 public TypeDefinition<?> getType() {
323 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
328 public boolean isUserOrdered() {
332 private void setUserOrdered(boolean userOrdered) {
333 this.userOrdered = userOrdered;
337 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
341 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
342 if (unknownNodes != null) {
343 this.unknownNodes = unknownNodes;
348 public int hashCode() {
349 final int prime = 31;
351 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
352 result = prime * result + ((path == null) ? 0 : path.hashCode());
357 public boolean equals(Object obj) {
364 if (getClass() != obj.getClass()) {
367 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
369 if (other.qname != null) {
372 } else if (!qname.equals(other.qname)) {
376 if (other.path != null) {
379 } else if (!path.equals(other.path)) {
386 public String toString() {
387 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
391 return sb.toString();