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.ArrayList;
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.HashSet;
14 import java.util.List;
18 import org.opendaylight.controller.yang.common.QName;
19 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
20 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
23 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
24 import org.opendaylight.controller.yang.model.api.SchemaPath;
25 import org.opendaylight.controller.yang.model.api.Status;
26 import org.opendaylight.controller.yang.model.api.TypeDefinition;
27 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
28 import org.opendaylight.controller.yang.model.api.UsesNode;
29 import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder;
30 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
31 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder;
32 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
33 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
34 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
35 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
36 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
38 public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
39 implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
40 DataSchemaNodeBuilder {
42 private final ContainerSchemaNodeImpl instance;
43 private final ConstraintsBuilder constraints;
44 private SchemaPath schemaPath;
45 private String description;
46 private String reference;
47 private Status status = Status.CURRENT;
48 private boolean presence;
49 private boolean augmenting;
50 private boolean configuration;
52 private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
53 private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
54 private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
55 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
57 public ContainerSchemaNodeBuilder(QName qname) {
59 instance = new ContainerSchemaNodeImpl(qname);
60 constraints = new ConstraintsBuilder();
64 public ContainerSchemaNode build() {
65 instance.setPath(schemaPath);
66 instance.setDescription(description);
67 instance.setReference(reference);
68 instance.setStatus(status);
69 instance.setPresenceContainer(presence);
70 instance.setAugmenting(augmenting);
71 instance.setConfiguration(configuration);
74 final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
75 for (DataSchemaNodeBuilder node : childNodes) {
76 childs.put(node.getQName(), node.build());
78 instance.setChildNodes(childs);
81 final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
82 for (GroupingBuilder builder : groupings) {
83 groupingDefs.add(builder.build());
85 instance.setGroupings(groupingDefs);
88 final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
89 for (TypeDefinitionBuilder entry : addedTypedefs) {
90 typedefs.add(entry.build());
92 instance.setTypeDefinitions(typedefs);
95 final Set<UsesNode> uses = new HashSet<UsesNode>();
96 for (UsesNodeBuilder builder : addedUsesNodes) {
97 uses.add(builder.build());
99 instance.setUses(uses);
102 final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
103 for(AugmentationSchemaBuilder builder : addedAugmentations) {
104 augmentations.add(builder.build());
106 instance.setAvailableAugmentations(augmentations);
109 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
110 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
111 unknownNodes.add(b.build());
113 instance.setUnknownSchemaNodes(unknownNodes);
115 instance.setConstraints(constraints.build());
116 instance.setAvailableAugmentations(augmentations);
121 public Set<TypeDefinitionBuilder> getTypedefs() {
122 return addedTypedefs;
126 public void addTypedef(final TypeDefinitionBuilder type) {
127 addedTypedefs.add(type);
130 public Set<AugmentationSchemaBuilder> getAugmentations() {
131 return addedAugmentations;
135 public void addAugmentation(AugmentationSchemaBuilder augment) {
136 addedAugmentations.add(augment);
139 public SchemaPath getPath() {
144 public void setPath(final SchemaPath schemaPath) {
145 this.schemaPath = schemaPath;
148 public String getDescription() {
153 public void setDescription(final String description) {
154 this.description = description;
157 public String getReference() {
162 public void setReference(String reference) {
163 this.reference = reference;
166 public Status getStatus() {
171 public void setStatus(Status status) {
173 this.status = status;
177 public boolean isAugmenting() {
182 public void setAugmenting(boolean augmenting) {
183 this.augmenting = augmenting;
186 public boolean isConfiguration() {
187 return configuration;
191 public void setConfiguration(boolean configuration) {
192 this.configuration = configuration;
196 public ConstraintsBuilder getConstraints() {
200 public Set<UsesNodeBuilder> getUsesNodes() {
201 return addedUsesNodes;
205 public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {
206 addedUsesNodes.add(usesNodeBuilder);
209 public boolean isPresence() {
213 public void setPresence(boolean presence) {
214 this.presence = presence;
217 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
218 return addedUnknownNodes;
222 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
223 addedUnknownNodes.add(unknownNode);
226 private class ContainerSchemaNodeImpl implements ContainerSchemaNode {
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 configuration;
234 private ConstraintDefinition constraints;
235 private Set<AugmentationSchema> augmentations = Collections.emptySet();
236 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
237 private Set<GroupingDefinition> groupings = Collections.emptySet();
238 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
239 private Set<UsesNode> uses = Collections.emptySet();
240 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
241 private boolean presence;
243 private ContainerSchemaNodeImpl(QName qname) {
248 public QName getQName() {
253 public SchemaPath getPath() {
257 private void setPath(SchemaPath path) {
262 public String getDescription() {
266 private void setDescription(String description) {
267 this.description = description;
271 public String getReference() {
275 private void setReference(String reference) {
276 this.reference = reference;
280 public Status getStatus() {
284 private void setStatus(Status status) {
286 this.status = status;
291 public boolean isAugmenting() {
295 private void setAugmenting(boolean augmenting) {
296 this.augmenting = augmenting;
300 public boolean isConfiguration() {
301 return configuration;
304 private void setConfiguration(boolean configuration) {
305 this.configuration = configuration;
309 public ConstraintDefinition getConstraints() {
313 private void setConstraints(ConstraintDefinition constraints) {
314 this.constraints = constraints;
318 public Set<AugmentationSchema> getAvailableAugmentations() {
319 return augmentations;
322 private void setAvailableAugmentations(
323 Set<AugmentationSchema> augmentations) {
324 if (augmentations != null) {
325 this.augmentations = augmentations;
330 public Set<DataSchemaNode> getChildNodes() {
331 return new HashSet<DataSchemaNode>(childNodes.values());
334 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
335 if (childNodes != null) {
336 this.childNodes = childNodes;
341 public Set<GroupingDefinition> getGroupings() {
345 private void setGroupings(Set<GroupingDefinition> groupings) {
346 if (groupings != null) {
347 this.groupings = groupings;
352 public DataSchemaNode getDataChildByName(QName name) {
353 return childNodes.get(name);
357 public DataSchemaNode getDataChildByName(String name) {
358 DataSchemaNode result = null;
359 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
360 if (entry.getKey().getLocalName().equals(name)) {
361 result = entry.getValue();
369 public Set<UsesNode> getUses() {
373 private void setUses(Set<UsesNode> uses) {
380 public boolean isPresenceContainer() {
384 private void setPresenceContainer(boolean presence) {
385 this.presence = presence;
389 public Set<TypeDefinition<?>> getTypeDefinitions() {
390 return typeDefinitions;
393 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
394 if (typeDefinitions != null) {
395 this.typeDefinitions = typeDefinitions;
400 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
404 private void setUnknownSchemaNodes(
405 List<UnknownSchemaNode> unknownSchemaNodes) {
406 if (unknownSchemaNodes != null) {
407 this.unknownNodes = unknownSchemaNodes;
412 public int hashCode() {
413 final int prime = 31;
415 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
416 result = prime * result + ((path == null) ? 0 : path.hashCode());
421 public boolean equals(Object obj) {
428 if (getClass() != obj.getClass()) {
431 ContainerSchemaNodeImpl other = (ContainerSchemaNodeImpl) obj;
433 if (other.qname != null) {
436 } else if (!qname.equals(other.qname)) {
440 if (other.path != null) {
443 } else if (!path.equals(other.path)) {
450 public String toString() {
451 StringBuilder sb = new StringBuilder(
452 ContainerSchemaNodeImpl.class.getSimpleName());
454 sb.append("qname=" + qname);
456 return sb.toString();