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.DataSchemaNodeBuilder;
23 import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
24 import org.opendaylight.controller.yang.parser.util.Comparators;
26 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
28 private boolean isBuilt;
29 private final LeafListSchemaNodeImpl instance;
31 private SchemaPath schemaPath;
32 private String description;
33 private String reference;
34 private Status status = Status.CURRENT;
35 // DataSchemaNode args
36 private boolean augmenting;
37 private boolean addedByUses;
38 private Boolean configuration;
39 private final ConstraintsBuilder constraints;
40 // LeafListSchemaNode args
41 private boolean userOrdered;
43 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname,
44 final SchemaPath schemaPath) {
45 super(moduleName, line, qname);
46 this.schemaPath = schemaPath;
47 instance = new LeafListSchemaNodeImpl(qname);
48 constraints = new ConstraintsBuilder(moduleName, line);
51 public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
52 super(b.getModuleName(), b.getLine(), b.getQName());
53 instance = new LeafListSchemaNodeImpl(qname);
56 typedef = b.getTypedef();
58 constraints = b.getConstraints();
59 schemaPath = b.getPath();
60 description = b.getDescription();
61 reference = b.getReference();
62 status = b.getStatus();
63 augmenting = b.isAugmenting();
64 addedByUses = b.isAddedByUses();
65 configuration = b.isConfiguration();
66 userOrdered = b.isUserOrdered();
67 unknownNodes = b.unknownNodes;
68 addedUnknownNodes.addAll(b.getUnknownNodeBuilders());
72 public LeafListSchemaNode build() {
74 instance.setConstraints(constraints.build());
75 instance.setPath(schemaPath);
76 instance.setDescription(description);
77 instance.setReference(reference);
78 instance.setStatus(status);
79 instance.setAugmenting(augmenting);
80 instance.setAddedByUses(addedByUses);
81 instance.setConfiguration(configuration);
82 instance.setUserOrdered(userOrdered);
85 instance.setType(typedef.build());
87 instance.setType(type);
91 if (unknownNodes == null) {
92 unknownNodes = new ArrayList<UnknownSchemaNode>();
93 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
94 unknownNodes.add(b.build());
96 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
98 instance.setUnknownSchemaNodes(unknownNodes);
105 public SchemaPath getPath() {
110 public void setPath(final SchemaPath schemaPath) {
111 this.schemaPath = schemaPath;
114 public String getDescription() {
119 public void setDescription(final String description) {
120 this.description = description;
123 public String getReference() {
128 public void setReference(String reference) {
129 this.reference = reference;
132 public Status getStatus() {
137 public void setStatus(Status status) {
138 if (status != null) {
139 this.status = status;
143 public boolean isAugmenting() {
148 public void setAugmenting(boolean augmenting) {
149 this.augmenting = augmenting;
153 public boolean isAddedByUses() {
158 public void setAddedByUses(final boolean addedByUses) {
159 this.addedByUses = addedByUses;
162 public Boolean isConfiguration() {
163 return configuration;
167 public void setConfiguration(Boolean configuration) {
168 this.configuration = configuration;
172 public ConstraintsBuilder getConstraints() {
176 public boolean isUserOrdered() {
180 public void setUserOrdered(final boolean userOrdered) {
181 this.userOrdered = userOrdered;
185 public int hashCode() {
186 final int prime = 31;
188 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
193 public boolean equals(Object obj) {
200 if (getClass() != obj.getClass()) {
203 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
204 if (schemaPath == null) {
205 if (other.schemaPath != null) {
208 } else if (!schemaPath.equals(other.schemaPath)) {
211 if (parent == null) {
212 if (other.parent != null) {
215 } else if (!parent.equals(other.parent)) {
222 public String toString() {
223 return "leaf-list " + qname.getLocalName();
226 private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
227 private final QName qname;
228 private SchemaPath path;
229 private String description;
230 private String reference;
231 private Status status = Status.CURRENT;
232 private boolean augmenting;
233 private boolean addedByUses;
234 private boolean configuration;
235 private ConstraintDefinition constraintsDef;
236 private TypeDefinition<?> type;
237 private boolean userOrdered;
238 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
240 private LeafListSchemaNodeImpl(final QName qname) {
245 public QName getQName() {
250 public SchemaPath getPath() {
254 private void setPath(final SchemaPath path) {
259 public String getDescription() {
263 private void setDescription(String description) {
264 this.description = description;
268 public String getReference() {
272 private void setReference(String reference) {
273 this.reference = reference;
277 public Status getStatus() {
281 private void setStatus(Status status) {
282 this.status = status;
286 public boolean isAugmenting() {
290 private void setAugmenting(boolean augmenting) {
291 this.augmenting = augmenting;
295 public boolean isAddedByUses() {
299 private void setAddedByUses(final boolean addedByUses) {
300 this.addedByUses = addedByUses;
304 public boolean isConfiguration() {
305 return configuration;
308 private void setConfiguration(boolean configuration) {
309 this.configuration = configuration;
313 public ConstraintDefinition getConstraints() {
314 return constraintsDef;
317 private void setConstraints(ConstraintDefinition constraintsDef) {
318 this.constraintsDef = constraintsDef;
322 public TypeDefinition<?> getType() {
326 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
331 public boolean isUserOrdered() {
335 private void setUserOrdered(boolean userOrdered) {
336 this.userOrdered = userOrdered;
340 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
344 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
345 if (unknownNodes != null) {
346 this.unknownNodes = unknownNodes;
351 public int hashCode() {
352 final int prime = 31;
354 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
355 result = prime * result + ((path == null) ? 0 : path.hashCode());
360 public boolean equals(Object obj) {
367 if (getClass() != obj.getClass()) {
370 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
372 if (other.qname != null) {
375 } else if (!qname.equals(other.qname)) {
379 if (other.path != null) {
382 } else if (!path.equals(other.path)) {
389 public String toString() {
390 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
394 return sb.toString();