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.controller.yang.parser.builder.impl;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
16 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.TypeDefinition;
20 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
22 import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
23 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
24 import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
25 import org.opendaylight.controller.yang.parser.util.Comparators;
27 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
28 GroupingMember, ConfigNode {
29 private boolean isBuilt;
30 private final LeafListSchemaNodeImpl instance;
32 private SchemaPath schemaPath;
33 private String description;
34 private String reference;
35 private Status status = Status.CURRENT;
36 private List<UnknownSchemaNode> unknownNodes;
37 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
38 // DataSchemaNode args
39 private boolean augmenting;
40 private boolean addedByUses;
41 private Boolean configuration;
42 private final ConstraintsBuilder constraints;
43 // LeafListSchemaNode args
44 private boolean userOrdered;
46 public LeafListSchemaNodeBuilder(final int line, final QName qname, final SchemaPath schemaPath) {
48 this.schemaPath = schemaPath;
49 instance = new LeafListSchemaNodeImpl(qname);
50 constraints = new ConstraintsBuilder(line);
53 public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
54 super(b.getLine(), b.getQName());
55 instance = new LeafListSchemaNodeImpl(qname);
58 typedef = b.getTypedef();
60 constraints = b.getConstraints();
61 schemaPath = b.getPath();
62 description = b.getDescription();
63 reference = b.getReference();
64 status = b.getStatus();
65 augmenting = b.isAugmenting();
66 addedByUses = b.isAddedByUses();
67 configuration = b.isConfiguration();
68 userOrdered = b.isUserOrdered();
69 unknownNodes = b.unknownNodes;
70 addedUnknownNodes.addAll(b.getUnknownNodes());
74 public LeafListSchemaNode build() {
76 instance.setConstraints(constraints.build());
77 instance.setPath(schemaPath);
78 instance.setDescription(description);
79 instance.setReference(reference);
80 instance.setStatus(status);
81 instance.setAugmenting(augmenting);
82 instance.setAddedByUses(addedByUses);
83 instance.setConfiguration(configuration);
84 instance.setUserOrdered(userOrdered);
87 instance.setType(typedef.build());
89 instance.setType(type);
93 if (unknownNodes == null) {
94 unknownNodes = new ArrayList<UnknownSchemaNode>();
95 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
96 unknownNodes.add(b.build());
98 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
100 instance.setUnknownSchemaNodes(unknownNodes);
107 public SchemaPath getPath() {
112 public void setPath(final SchemaPath schemaPath) {
113 this.schemaPath = schemaPath;
116 public String getDescription() {
121 public void setDescription(final String description) {
122 this.description = description;
125 public String getReference() {
130 public void setReference(String reference) {
131 this.reference = reference;
134 public Status getStatus() {
139 public void setStatus(Status status) {
140 if (status != null) {
141 this.status = status;
145 public boolean isAugmenting() {
150 public void setAugmenting(boolean augmenting) {
151 this.augmenting = augmenting;
155 public boolean isAddedByUses() {
160 public void setAddedByUses(final boolean addedByUses) {
161 this.addedByUses = addedByUses;
164 public Boolean isConfiguration() {
165 return configuration;
169 public void setConfiguration(Boolean configuration) {
170 this.configuration = configuration;
174 public ConstraintsBuilder getConstraints() {
178 public boolean isUserOrdered() {
182 public void setUserOrdered(final boolean userOrdered) {
183 this.userOrdered = userOrdered;
186 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
187 return addedUnknownNodes;
191 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
192 addedUnknownNodes.add(unknownNode);
195 public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
196 this.unknownNodes = unknownNodes;
200 public int hashCode() {
201 final int prime = 31;
203 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
208 public boolean equals(Object obj) {
215 if (getClass() != obj.getClass()) {
218 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
219 if (schemaPath == null) {
220 if (other.schemaPath != null) {
223 } else if (!schemaPath.equals(other.schemaPath)) {
226 if (parent == null) {
227 if (other.parent != null) {
230 } else if (!parent.equals(other.parent)) {
237 public String toString() {
238 return "leaf-list " + qname.getLocalName();
241 private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
242 private final QName qname;
243 private SchemaPath path;
244 private String description;
245 private String reference;
246 private Status status = Status.CURRENT;
247 private boolean augmenting;
248 private boolean addedByUses;
249 private boolean configuration;
250 private ConstraintDefinition constraintsDef;
251 private TypeDefinition<?> type;
252 private boolean userOrdered;
253 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
255 private LeafListSchemaNodeImpl(final QName qname) {
260 public QName getQName() {
265 public SchemaPath getPath() {
269 private void setPath(final SchemaPath path) {
274 public String getDescription() {
278 private void setDescription(String description) {
279 this.description = description;
283 public String getReference() {
287 private void setReference(String reference) {
288 this.reference = reference;
292 public Status getStatus() {
296 private void setStatus(Status status) {
297 this.status = status;
301 public boolean isAugmenting() {
305 private void setAugmenting(boolean augmenting) {
306 this.augmenting = augmenting;
310 public boolean isAddedByUses() {
314 private void setAddedByUses(final boolean addedByUses) {
315 this.addedByUses = addedByUses;
319 public boolean isConfiguration() {
320 return configuration;
323 private void setConfiguration(boolean configuration) {
324 this.configuration = configuration;
328 public ConstraintDefinition getConstraints() {
329 return constraintsDef;
332 private void setConstraints(ConstraintDefinition constraintsDef) {
333 this.constraintsDef = constraintsDef;
337 public TypeDefinition<?> getType() {
341 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
346 public boolean isUserOrdered() {
350 private void setUserOrdered(boolean userOrdered) {
351 this.userOrdered = userOrdered;
355 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
359 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
360 if (unknownNodes != null) {
361 this.unknownNodes = unknownNodes;
366 public int hashCode() {
367 final int prime = 31;
369 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
370 result = prime * result + ((path == null) ? 0 : path.hashCode());
375 public boolean equals(Object obj) {
382 if (getClass() != obj.getClass()) {
385 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
387 if (other.qname != null) {
390 } else if (!qname.equals(other.qname)) {
394 if (other.path != null) {
397 } else if (!path.equals(other.path)) {
404 public String toString() {
405 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
409 return sb.toString();