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.model.parser.builder.impl;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.List;
17 import org.opendaylight.controller.yang.common.QName;
18 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
19 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
20 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
21 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
22 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
23 import org.opendaylight.controller.yang.model.api.SchemaPath;
24 import org.opendaylight.controller.yang.model.api.Status;
25 import org.opendaylight.controller.yang.model.api.TypeDefinition;
26 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
27 import org.opendaylight.controller.yang.model.api.UsesNode;
28 import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder;
29 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder;
30 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
31 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
32 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
33 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
34 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
35 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
37 public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
38 DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder,
39 TypeDefinitionAwareBuilder {
41 private final ListSchemaNodeImpl instance;
42 private final ConstraintsBuilder constraintsBuilder;
44 private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
45 private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
46 private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
48 ListSchemaNodeBuilder(QName qname) {
50 instance = new ListSchemaNodeImpl(qname);
51 constraintsBuilder = new ConstraintsBuilder();
55 public ListSchemaNode build() {
57 Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
58 for (DataSchemaNodeBuilder node : childNodes) {
59 childs.put(node.getQName(), node.build());
61 instance.setChildNodes(childs);
64 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
65 for (TypeDefinitionBuilder entry : addedTypedefs) {
66 typedefs.add(entry.build());
68 instance.setTypeDefinitions(typedefs);
71 Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();
72 for (UsesNodeBuilder builder : usesNodes) {
73 usesNodeDefinitions.add(builder.build());
75 instance.setUses(usesNodeDefinitions);
78 Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();
79 for (GroupingBuilder builder : groupings) {
80 groupingDefinitions.add(builder.build());
82 instance.setGroupings(groupingDefinitions);
84 instance.setConstraints(constraintsBuilder.build());
85 instance.setAvailableAugmentations(augmentations);
91 public void addTypedef(TypeDefinitionBuilder type) {
92 addedTypedefs.add(type);
96 public void setPath(SchemaPath path) {
97 instance.setPath(path);
101 public void setDescription(String description) {
102 instance.setDescription(description);
106 public void setReference(String reference) {
107 instance.setReference(reference);
111 public void setStatus(Status status) {
113 instance.setStatus(status);
118 public void addUsesNode(UsesNodeBuilder usesBuilder) {
119 usesNodes.add(usesBuilder);
123 public void addAugmentation(AugmentationSchema augmentationSchema) {
124 augmentations.add(augmentationSchema);
127 public void setKeyDefinition(List<QName> keyDefinition) {
128 instance.setKeyDefinition(keyDefinition);
132 public void setAugmenting(boolean augmenting) {
133 instance.setAugmenting(augmenting);
137 public void setConfiguration(boolean configuration) {
138 instance.setConfiguration(configuration);
142 public ConstraintsBuilder getConstraintsBuilder() {
143 return constraintsBuilder;
146 public void setUserOrdered(boolean userOrdered) {
147 instance.setUserOrdered(userOrdered);
150 private class ListSchemaNodeImpl implements ListSchemaNode {
151 private final QName qname;
152 private SchemaPath path;
153 private String description;
154 private String reference;
155 private Status status = Status.CURRENT;
156 private List<QName> keyDefinition = Collections.emptyList();
157 private boolean augmenting;
158 private boolean configuration;
159 private ConstraintDefinition constraints;
160 private Set<AugmentationSchema> augmentations = Collections.emptySet();
161 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
162 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
163 private Set<GroupingDefinition> groupings = Collections.emptySet();
164 private Set<UsesNode> uses = Collections.emptySet();
165 private boolean userOrdered;
166 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
168 private ListSchemaNodeImpl(QName qname) {
173 public QName getQName() {
178 public SchemaPath getPath() {
182 private void setPath(SchemaPath path) {
187 public String getDescription() {
191 private void setDescription(String description) {
192 this.description = description;
196 public String getReference() {
200 private void setReference(String reference) {
201 this.reference = reference;
205 public Status getStatus() {
209 private void setStatus(Status status) {
210 this.status = status;
214 public List<QName> getKeyDefinition() {
215 if(keyDefinition == null) {
216 return Collections.emptyList();
218 return keyDefinition;
222 private void setKeyDefinition(List<QName> keyDefinition) {
223 if(keyDefinition != null) {
224 this.keyDefinition = keyDefinition;
229 public boolean isAugmenting() {
233 private void setAugmenting(boolean augmenting) {
234 this.augmenting = augmenting;
238 public boolean isConfiguration() {
239 return configuration;
242 private void setConfiguration(boolean configuration) {
243 this.configuration = configuration;
247 public ConstraintDefinition getConstraints() {
251 private void setConstraints(ConstraintDefinition constraints) {
252 this.constraints = constraints;
256 public Set<AugmentationSchema> getAvailableAugmentations() {
257 return augmentations;
260 private void setAvailableAugmentations(
261 Set<AugmentationSchema> augmentations) {
262 if(augmentations != null) {
263 this.augmentations = augmentations;
268 public Set<DataSchemaNode> getChildNodes() {
269 return new HashSet<DataSchemaNode>(childNodes.values());
272 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
273 if(childNodes != null) {
274 this.childNodes = childNodes;
279 public Set<GroupingDefinition> getGroupings() {
283 private void setGroupings(Set<GroupingDefinition> groupings) {
284 if(groupings != null) {
285 this.groupings = groupings;
290 public Set<TypeDefinition<?>> getTypeDefinitions() {
291 return typeDefinitions;
294 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
295 if(typeDefinitions != null) {
296 this.typeDefinitions = typeDefinitions;
301 public Set<UsesNode> getUses() {
305 private void setUses(Set<UsesNode> uses) {
312 public DataSchemaNode getDataChildByName(QName name) {
313 return childNodes.get(name);
317 public DataSchemaNode getDataChildByName(String name) {
318 DataSchemaNode result = null;
319 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
320 if (entry.getKey().getLocalName().equals(name)) {
321 result = entry.getValue();
329 public boolean isUserOrdered() {
333 private void setUserOrdered(boolean userOrdered) {
334 this.userOrdered = userOrdered;
338 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
339 return unknownSchemaNodes;
343 public int hashCode() {
344 final int prime = 31;
346 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
347 result = prime * result + ((path == null) ? 0 : path.hashCode());
348 result = prime * result
349 + ((description == null) ? 0 : description.hashCode());
350 result = prime * result
351 + ((reference == null) ? 0 : reference.hashCode());
352 result = prime * result
353 + ((status == null) ? 0 : status.hashCode());
354 result = prime * result
355 + ((keyDefinition == null) ? 0 : keyDefinition.hashCode());
356 result = prime * result + (augmenting ? 1231 : 1237);
357 result = prime * result + (configuration ? 1231 : 1237);
358 result = prime * result
359 + ((constraints == null) ? 0 : constraints.hashCode());
360 result = prime * result
361 + ((augmentations == null) ? 0 : augmentations.hashCode());
362 result = prime * result
363 + ((childNodes == null) ? 0 : childNodes.hashCode());
366 + ((typeDefinitions == null) ? 0 : typeDefinitions
368 result = prime * result
369 + ((groupings == null) ? 0 : groupings.hashCode());
370 result = prime * result + ((uses == null) ? 0 : uses.hashCode());
371 result = prime * result + (userOrdered ? 1231 : 1237);
376 public boolean equals(Object obj) {
383 if (getClass() != obj.getClass()) {
386 ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj;
388 if (other.qname != null) {
391 } else if (!qname.equals(other.qname)) {
395 if (other.path != null) {
398 } else if (!path.equals(other.path)) {
401 if (description == null) {
402 if (other.description != null) {
405 } else if (!description.equals(other.description)) {
408 if (reference == null) {
409 if (other.reference != null) {
412 } else if (!reference.equals(other.reference)) {
415 if (status == null) {
416 if (other.status != null) {
419 } else if (!status.equals(other.status)) {
422 if (keyDefinition == null) {
423 if (other.keyDefinition != null) {
426 } else if (!keyDefinition.equals(other.keyDefinition)) {
429 if (augmenting != other.augmenting) {
432 if (configuration != other.configuration) {
435 if (constraints == null) {
436 if (other.constraints != null) {
439 } else if (!constraints.equals(other.constraints)) {
442 if (augmentations == null) {
443 if (other.augmentations != null) {
446 } else if (!augmentations.equals(other.augmentations)) {
449 if (childNodes == null) {
450 if (other.childNodes != null) {
453 } else if (!childNodes.equals(other.childNodes)) {
456 if (typeDefinitions == null) {
457 if (other.typeDefinitions != null) {
460 } else if (!typeDefinitions.equals(other.typeDefinitions)) {
463 if (groupings == null) {
464 if (other.groupings != null) {
467 } else if (!groupings.equals(other.groupings)) {
471 if (other.uses != null) {
474 } else if (!uses.equals(other.uses)) {
477 if (userOrdered != other.userOrdered) {
484 public String toString() {
485 StringBuilder sb = new StringBuilder(
486 ListSchemaNodeImpl.class.getSimpleName());
488 sb.append("qname=" + qname);
489 sb.append(", path=" + path);
490 sb.append(", description=" + description);
491 sb.append(", reference=" + reference);
492 sb.append(", status=" + status);
493 sb.append(", keyDefinition=" + keyDefinition);
494 sb.append(", augmenting=" + augmenting);
495 sb.append(", configuration=" + configuration);
496 sb.append(", constraints=" + constraints);
497 sb.append(", augmentations=" + augmentations);
498 sb.append(", childNodes=" + childNodes.values());
499 sb.append(", typedefinitions=" + typeDefinitions);
500 sb.append(", groupings=" + groupings);
501 sb.append(", uses=" + uses);
502 sb.append(", userOrdered=" + userOrdered);
504 return sb.toString();