2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.model.parser.builder;
\r
10 import java.util.HashMap;
\r
11 import java.util.HashSet;
\r
12 import java.util.Map;
\r
13 import java.util.Set;
\r
15 import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder;
\r
16 import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder;
\r
17 import org.opendaylight.controller.model.parser.api.GroupingBuilder;
\r
18 import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder;
\r
19 import org.opendaylight.controller.model.parser.api.UsesNodeBuilder;
\r
20 import org.opendaylight.controller.model.parser.util.YangModelBuilderHelper;
\r
21 import org.opendaylight.controller.yang.common.QName;
\r
22 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
\r
23 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
\r
24 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
\r
25 import org.opendaylight.controller.yang.model.api.SchemaPath;
\r
26 import org.opendaylight.controller.yang.model.api.Status;
\r
27 import org.opendaylight.controller.yang.model.api.TypeDefinition;
\r
28 import org.opendaylight.controller.yang.model.api.UsesNode;
\r
31 public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder {
\r
33 private final AugmentationSchemaImpl instance;
\r
34 private final SchemaPath augmentTarget;
\r
35 final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
\r
36 final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
\r
37 private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
\r
39 AugmentationSchemaBuilderImpl(String augmentPath) {
\r
40 SchemaPath targetPath = YangModelBuilderHelper.parsePath(augmentPath);
\r
41 augmentTarget = targetPath;
\r
42 instance = new AugmentationSchemaImpl(targetPath);
\r
46 public void addChildNode(DataSchemaNodeBuilder childNode) {
\r
47 childNodes.add(childNode);
\r
51 public void addGrouping(GroupingBuilder grouping) {
\r
52 groupings.add(grouping);
\r
56 * Always returns null.
\r
59 public QName getQName() {
\r
64 public AugmentationSchema build() {
\r
67 Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
\r
68 for(DataSchemaNodeBuilder node : childNodes) {
\r
69 childs.put(node.getQName(), node.build());
\r
71 instance.setChildNodes(childs);
\r
74 Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();
\r
75 for(GroupingBuilder builder : groupings) {
\r
76 groupingDefinitions.add(builder.build());
\r
78 instance.setGroupings(groupingDefinitions);
\r
81 Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();
\r
82 for(UsesNodeBuilder builder : usesNodes) {
\r
83 usesNodeDefinitions.add(builder.build());
\r
85 instance.setUses(usesNodeDefinitions);
\r
91 public void addUsesNode(UsesNodeBuilder usesBuilder) {
\r
92 usesNodes.add(usesBuilder);
\r
96 public void addTypedef(TypeDefinitionBuilder type) {
\r
97 throw new UnsupportedOperationException("Augmentation can not contains type definitions");
\r
101 public void setDescription(String description) {
\r
102 instance.setDescription(description);
\r
106 public void setReference(String reference) {
\r
107 instance.setReference(reference);
\r
111 public void setStatus(Status status) {
\r
112 instance.setStatus(status);
\r
116 public SchemaPath getTargetPath() {
\r
117 return augmentTarget;
\r
121 private static class AugmentationSchemaImpl implements AugmentationSchema {
\r
123 private final SchemaPath targetPath;
\r
124 private Map<QName, DataSchemaNode> childNodes;
\r
125 private Set<GroupingDefinition> groupings;
\r
126 private Set<UsesNode> uses;
\r
128 private String description;
\r
129 private String reference;
\r
130 private Status status;
\r
132 private AugmentationSchemaImpl(SchemaPath targetPath) {
\r
133 this.targetPath = targetPath;
\r
138 public SchemaPath getTargetPath() {
\r
143 public Set<DataSchemaNode> getChildNodes() {
\r
144 return new HashSet<DataSchemaNode>(childNodes.values());
\r
146 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
\r
147 this.childNodes = childNodes;
\r
151 public Set<GroupingDefinition> getGroupings() {
\r
154 private void setGroupings(Set<GroupingDefinition> groupings) {
\r
155 this.groupings = groupings;
\r
159 public Set<UsesNode> getUses() {
\r
162 private void setUses(Set<UsesNode> uses) {
\r
167 * This method always returns null, because augmentation can not contains type definitions.
\r
170 public Set<TypeDefinition<?>> getTypeDefinitions() {
\r
175 public String getDescription() {
\r
176 return description;
\r
178 private void setDescription(String description) {
\r
179 this.description = description;
\r
183 public String getReference() {
\r
186 private void setReference(String reference) {
\r
187 this.reference = reference;
\r
191 public Status getStatus() {
\r
194 private void setStatus(Status status) {
\r
195 this.status = status;
\r
199 public DataSchemaNode getDataChildByName(QName name) {
\r
200 return childNodes.get(name);
\r
204 public DataSchemaNode getDataChildByName(String name) {
\r
205 DataSchemaNode result = null;
\r
206 for(Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
\r
207 if(entry.getKey().getLocalName().equals(name)) {
\r
208 result = entry.getValue();
\r
216 public int hashCode() {
\r
217 final int prime = 17;
\r
219 result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
\r
220 result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
\r
221 result = prime * result + ((groupings == null) ? 0 : groupings.hashCode());
\r
222 result = prime * result + ((uses == null) ? 0 : uses.hashCode());
\r
223 result = prime * result + ((description == null) ? 0 : description.hashCode());
\r
224 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
\r
225 result = prime * result + ((status == null) ? 0 : status.hashCode());
\r
230 public boolean equals(Object obj) {
\r
237 if (getClass() != obj.getClass()) {
\r
240 AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
\r
241 if (targetPath == null) {
\r
242 if (other.targetPath != null) {
\r
245 } else if (!targetPath.equals(other.targetPath)) {
\r
248 if (childNodes == null) {
\r
249 if (other.childNodes != null) {
\r
252 } else if (!childNodes.equals(other.childNodes)) {
\r
255 if (groupings == null) {
\r
256 if (other.groupings != null) {
\r
259 } else if (!groupings.equals(other.groupings)) {
\r
262 if (uses == null) {
\r
263 if (other.uses != null) {
\r
266 } else if (!uses.equals(other.uses)) {
\r
269 if (description == null) {
\r
270 if (other.description != null) {
\r
273 } else if (!description.equals(other.description)) {
\r
276 if (reference == null) {
\r
277 if (other.reference != null) {
\r
280 } else if (!reference.equals(other.reference)) {
\r
283 if (status == null) {
\r
284 if (other.status != null) {
\r
287 } else if (!status.equals(other.status)) {
\r
294 public String toString() {
\r
295 StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
\r
297 sb.append("targetPath="+ targetPath);
\r
298 sb.append(", childNodes="+ childNodes.values());
\r
299 sb.append(", groupings="+ groupings);
\r
300 sb.append(", uses="+ uses);
\r
302 return sb.toString();
\r