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 int line, final QName qname, final SchemaPath schemaPath) {
45 this.schemaPath = schemaPath;
46 instance = new LeafListSchemaNodeImpl(qname);
47 constraints = new ConstraintsBuilder(line);
50 public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
51 super(b.getLine(), b.getQName());
52 instance = new LeafListSchemaNodeImpl(qname);
55 typedef = b.getTypedef();
57 constraints = b.getConstraints();
58 schemaPath = b.getPath();
59 description = b.getDescription();
60 reference = b.getReference();
61 status = b.getStatus();
62 augmenting = b.isAugmenting();
63 addedByUses = b.isAddedByUses();
64 configuration = b.isConfiguration();
65 userOrdered = b.isUserOrdered();
66 unknownNodes = b.unknownNodes;
67 addedUnknownNodes.addAll(b.getUnknownNodeBuilders());
71 public LeafListSchemaNode build() {
73 instance.setConstraints(constraints.build());
74 instance.setPath(schemaPath);
75 instance.setDescription(description);
76 instance.setReference(reference);
77 instance.setStatus(status);
78 instance.setAugmenting(augmenting);
79 instance.setAddedByUses(addedByUses);
80 instance.setConfiguration(configuration);
81 instance.setUserOrdered(userOrdered);
84 instance.setType(typedef.build());
86 instance.setType(type);
90 if (unknownNodes == null) {
91 unknownNodes = new ArrayList<UnknownSchemaNode>();
92 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
93 unknownNodes.add(b.build());
95 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
97 instance.setUnknownSchemaNodes(unknownNodes);
104 public SchemaPath getPath() {
109 public void setPath(final SchemaPath schemaPath) {
110 this.schemaPath = schemaPath;
113 public String getDescription() {
118 public void setDescription(final String description) {
119 this.description = description;
122 public String getReference() {
127 public void setReference(String reference) {
128 this.reference = reference;
131 public Status getStatus() {
136 public void setStatus(Status status) {
137 if (status != null) {
138 this.status = status;
142 public boolean isAugmenting() {
147 public void setAugmenting(boolean augmenting) {
148 this.augmenting = augmenting;
152 public boolean isAddedByUses() {
157 public void setAddedByUses(final boolean addedByUses) {
158 this.addedByUses = addedByUses;
161 public Boolean isConfiguration() {
162 return configuration;
166 public void setConfiguration(Boolean configuration) {
167 this.configuration = configuration;
171 public ConstraintsBuilder getConstraints() {
175 public boolean isUserOrdered() {
179 public void setUserOrdered(final boolean userOrdered) {
180 this.userOrdered = userOrdered;
184 public int hashCode() {
185 final int prime = 31;
187 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
192 public boolean equals(Object obj) {
199 if (getClass() != obj.getClass()) {
202 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
203 if (schemaPath == null) {
204 if (other.schemaPath != null) {
207 } else if (!schemaPath.equals(other.schemaPath)) {
210 if (parent == null) {
211 if (other.parent != null) {
214 } else if (!parent.equals(other.parent)) {
221 public String toString() {
222 return "leaf-list " + qname.getLocalName();
225 private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
226 private final QName qname;
227 private SchemaPath path;
228 private String description;
229 private String reference;
230 private Status status = Status.CURRENT;
231 private boolean augmenting;
232 private boolean addedByUses;
233 private boolean configuration;
234 private ConstraintDefinition constraintsDef;
235 private TypeDefinition<?> type;
236 private boolean userOrdered;
237 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
239 private LeafListSchemaNodeImpl(final QName qname) {
244 public QName getQName() {
249 public SchemaPath getPath() {
253 private void setPath(final SchemaPath path) {
258 public String getDescription() {
262 private void setDescription(String description) {
263 this.description = description;
267 public String getReference() {
271 private void setReference(String reference) {
272 this.reference = reference;
276 public Status getStatus() {
280 private void setStatus(Status status) {
281 this.status = status;
285 public boolean isAugmenting() {
289 private void setAugmenting(boolean augmenting) {
290 this.augmenting = augmenting;
294 public boolean isAddedByUses() {
298 private void setAddedByUses(final boolean addedByUses) {
299 this.addedByUses = addedByUses;
303 public boolean isConfiguration() {
304 return configuration;
307 private void setConfiguration(boolean configuration) {
308 this.configuration = configuration;
312 public ConstraintDefinition getConstraints() {
313 return constraintsDef;
316 private void setConstraints(ConstraintDefinition constraintsDef) {
317 this.constraintsDef = constraintsDef;
321 public TypeDefinition<?> getType() {
325 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
330 public boolean isUserOrdered() {
334 private void setUserOrdered(boolean userOrdered) {
335 this.userOrdered = userOrdered;
339 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
343 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
344 if (unknownNodes != null) {
345 this.unknownNodes = unknownNodes;
350 public int hashCode() {
351 final int prime = 31;
353 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
354 result = prime * result + ((path == null) ? 0 : path.hashCode());
359 public boolean equals(Object obj) {
366 if (getClass() != obj.getClass()) {
369 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
371 if (other.qname != null) {
374 } else if (!qname.equals(other.qname)) {
378 if (other.path != null) {
381 } else if (!path.equals(other.path)) {
388 public String toString() {
389 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
393 return sb.toString();