Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / model / parser / builder / ListSchemaNodeBuilder.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.controller.model.parser.builder;\r
9 \r
10 import java.util.HashMap;\r
11 import java.util.HashSet;\r
12 import java.util.List;\r
13 import java.util.Map;\r
14 import java.util.Set;\r
15 \r
16 import org.opendaylight.controller.model.parser.api.AbstractChildNodeBuilder;\r
17 import org.opendaylight.controller.model.parser.api.AugmentationTargetBuilder;\r
18 import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder;\r
19 import org.opendaylight.controller.model.parser.api.GroupingBuilder;\r
20 import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder;\r
21 import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder;\r
22 import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder;\r
23 import org.opendaylight.controller.model.parser.api.UsesNodeBuilder;\r
24 import org.opendaylight.controller.yang.common.QName;\r
25 import org.opendaylight.controller.yang.model.api.AugmentationSchema;\r
26 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;\r
27 import org.opendaylight.controller.yang.model.api.DataSchemaNode;\r
28 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;\r
29 import org.opendaylight.controller.yang.model.api.GroupingDefinition;\r
30 import org.opendaylight.controller.yang.model.api.ListSchemaNode;\r
31 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
32 import org.opendaylight.controller.yang.model.api.Status;\r
33 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
34 import org.opendaylight.controller.yang.model.api.UsesNode;\r
35 \r
36 \r
37 public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder, TypeDefinitionAwareBuilder {\r
38 \r
39                 private final ListSchemaNodeImpl instance;\r
40 \r
41                 private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();\r
42                 private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();\r
43                 private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();\r
44 \r
45                 ListSchemaNodeBuilder(QName qname) {\r
46                         super(qname);\r
47                         instance = new ListSchemaNodeImpl(qname);\r
48                 }\r
49 \r
50                 @Override\r
51                 public ListSchemaNode build() {\r
52                         // CHILD NODES\r
53                         Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();\r
54                         for(DataSchemaNodeBuilder node : childNodes) {\r
55                                 childs.put(node.getQName(), node.build());\r
56                         }\r
57                         instance.setChildNodes(childs);\r
58 \r
59                         // TYPEDEFS\r
60                         Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();\r
61                         for (TypeDefinitionBuilder entry : addedTypedefs) {\r
62                                 typedefs.add(entry.build());\r
63                         }\r
64                         instance.setTypeDefinitions(typedefs);\r
65 \r
66                         // USES\r
67                         Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();\r
68                         for(UsesNodeBuilder builder : usesNodes) {\r
69                                 usesNodeDefinitions.add(builder.build());\r
70                         }\r
71                         instance.setUses(usesNodeDefinitions);\r
72 \r
73                         // GROUPINGS\r
74                         Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();\r
75                         for (GroupingBuilder builder : groupings) {\r
76                                 groupingDefinitions.add(builder.build());\r
77                         }\r
78                         instance.setGroupings(groupingDefinitions);\r
79 \r
80                         instance.setAvailableAugmentations(augmentations);\r
81 \r
82                         return instance;\r
83                 }\r
84 \r
85 \r
86                 @Override\r
87                 public void addTypedef(TypeDefinitionBuilder type) {\r
88                         addedTypedefs.add(type);\r
89                 }\r
90 \r
91                 @Override\r
92                 public void setPath(SchemaPath path) {\r
93                         instance.setPath(path);\r
94                 }\r
95 \r
96                 @Override\r
97                 public void setDescription(String description) {\r
98                         instance.setDescription(description);\r
99                 }\r
100 \r
101                 @Override\r
102                 public void setReference(String reference) {\r
103                         instance.setReference(reference);\r
104                 }\r
105 \r
106                 @Override\r
107                 public void setStatus(Status status) {\r
108                         instance.setStatus(status);\r
109                 }\r
110 \r
111                 @Override\r
112                 public void addUsesNode(UsesNodeBuilder usesBuilder) {\r
113                         usesNodes.add(usesBuilder);\r
114                 }\r
115 \r
116                 @Override\r
117                 public void addAugmentation(AugmentationSchema augmentationSchema) {\r
118                         augmentations.add(augmentationSchema);\r
119                 }\r
120 \r
121                 public void setKeyDefinition(List<QName> keyDefinition) {\r
122                         instance.setKeyDefinition(keyDefinition);\r
123                 }\r
124                 public void setAugmenting(boolean augmenting) {\r
125                         instance.setAugmenting(augmenting);\r
126                 }\r
127                 public void setConfiguration(boolean configuration) {\r
128                         instance.setConfiguration(configuration);\r
129                 }\r
130                 public void setConstraints(ConstraintDefinition constraints) {\r
131                         instance.setConstraints(constraints);\r
132                 }\r
133                 public void setUserOrdered(boolean userOrdered) {\r
134                         instance.setUserOrdered(userOrdered);\r
135                 }\r
136 \r
137 \r
138                 private class ListSchemaNodeImpl implements ListSchemaNode {\r
139                         private final QName qname;\r
140                         private SchemaPath path;\r
141                         private String description;\r
142                         private String reference;\r
143                         private Status status = Status.CURRENT;\r
144 \r
145                         private List<QName> keyDefinition;\r
146 \r
147                         private boolean augmenting;\r
148                         private boolean configuration;\r
149                         private ConstraintDefinition constraints;\r
150 \r
151                         private Set<AugmentationSchema> augmentations;\r
152 \r
153                         private Map<QName, DataSchemaNode> childNodes;\r
154                         private Set<TypeDefinition<?>> typeDefinitions;\r
155                         private Set<GroupingDefinition> groupings;\r
156                         private Set<UsesNode> uses;\r
157 \r
158                         private boolean userOrdered;\r
159 \r
160                         private ListSchemaNodeImpl(QName qname) {\r
161                                 this.qname = qname;\r
162                         }\r
163 \r
164 \r
165                         @Override\r
166                         public QName getQName() {\r
167                                 return qname;\r
168                         }\r
169 \r
170                         @Override\r
171                         public SchemaPath getPath() {\r
172                                 return path;\r
173                         }\r
174                         private void setPath(SchemaPath path) {\r
175                                 this.path = path;\r
176                         }\r
177 \r
178                         @Override\r
179                         public String getDescription() {\r
180                                 return description;\r
181                         }\r
182                         private void setDescription(String description) {\r
183                                 this.description = description;\r
184                         }\r
185 \r
186                         @Override\r
187                         public String getReference() {\r
188                                 return reference;\r
189                         }\r
190                         private void setReference(String reference) {\r
191                                 this.reference = reference;\r
192                         }\r
193 \r
194                         @Override\r
195                         public Status getStatus() {\r
196                                 return status;\r
197                         }\r
198                         private void setStatus(Status status) {\r
199                                 this.status = status;\r
200                         }\r
201 \r
202                         @Override\r
203                         public List<QName> getKeyDefinition() {\r
204                                 return keyDefinition;\r
205                         }\r
206                         private void setKeyDefinition(List<QName> keyDefinition) {\r
207                                 this.keyDefinition = keyDefinition;\r
208                         }\r
209 \r
210                         @Override\r
211                         public boolean isAugmenting() {\r
212                                 return augmenting;\r
213                         }\r
214                         private void setAugmenting(boolean augmenting) {\r
215                                 this.augmenting = augmenting;\r
216                         }\r
217 \r
218                         @Override\r
219                         public boolean isConfiguration() {\r
220                                 return configuration;\r
221                         }\r
222                         private void setConfiguration(boolean configuration) {\r
223                                 this.configuration = configuration;\r
224                         }\r
225 \r
226                         @Override\r
227                         public ConstraintDefinition getConstraints() {\r
228                                 return constraints;\r
229                         }\r
230                         private void setConstraints(ConstraintDefinition constraints) {\r
231                                 this.constraints = constraints;\r
232                         }\r
233 \r
234                         @Override\r
235                         public Set<AugmentationSchema> getAvailableAugmentations() {\r
236                                 return augmentations;\r
237                         }\r
238                         private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {\r
239                                 this.augmentations = augmentations;\r
240                         }\r
241 \r
242                         @Override\r
243                         public Set<DataSchemaNode> getChildNodes() {\r
244                                 return new HashSet<DataSchemaNode>(childNodes.values());\r
245                         }\r
246                         void setChildNodes(Map<QName, DataSchemaNode> childNodes) {\r
247                                 this.childNodes = childNodes;\r
248                         }\r
249 \r
250                         @Override\r
251                         public Set<GroupingDefinition> getGroupings() {\r
252                                 return groupings;\r
253                         }\r
254                         private void setGroupings(Set<GroupingDefinition> groupings) {\r
255                                 this.groupings = groupings;\r
256                         }\r
257 \r
258                         @Override\r
259                         public Set<TypeDefinition<?>> getTypeDefinitions() {\r
260                                 return typeDefinitions;\r
261                         }\r
262                         private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {\r
263                                 this.typeDefinitions = typeDefinitions;\r
264                         }\r
265 \r
266                         @Override\r
267                         public Set<UsesNode> getUses() {\r
268                                 return uses;\r
269                         }\r
270                         private void setUses(Set<UsesNode> uses) {\r
271                                 this.uses = uses;\r
272                         }\r
273 \r
274                         @Override\r
275                         public DataSchemaNode getDataChildByName(QName name) {\r
276                                 return childNodes.get(name);\r
277                         }\r
278 \r
279                         @Override\r
280                         public DataSchemaNode getDataChildByName(String name) {\r
281                                 DataSchemaNode result = null;\r
282                                 for(Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {\r
283                                         if(entry.getKey().getLocalName().equals(name)) {\r
284                                                 result = entry.getValue();\r
285                                                 break;\r
286                                         }\r
287                                 }\r
288                                 return result;\r
289                         }\r
290 \r
291                         @Override\r
292                         public boolean isUserOrdered() {\r
293                                 return userOrdered;\r
294                         }\r
295                         private void setUserOrdered(boolean userOrdered) {\r
296                                 this.userOrdered = userOrdered;\r
297                         }\r
298 \r
299                         @Override\r
300                         public List<ExtensionDefinition> getExtensionSchemaNodes() {\r
301                                 // TODO Auto-generated method stub\r
302                                 return null;\r
303                         }\r
304 \r
305                         @Override\r
306                 public int hashCode() {\r
307                     final int prime = 31;\r
308                     int result = 1;\r
309                     result = prime * result + ((qname == null) ? 0 : qname.hashCode());\r
310                     result = prime * result + ((path == null) ? 0 : path.hashCode());\r
311                     result = prime * result + ((description == null) ? 0 : description.hashCode());\r
312                     result = prime * result + ((reference == null) ? 0 : reference.hashCode());\r
313                     result = prime * result + ((status == null) ? 0 : status.hashCode());\r
314                     result = prime * result + ((keyDefinition == null) ? 0 : keyDefinition.hashCode());\r
315                     result = prime * result + (augmenting ? 1231 : 1237);\r
316                     result = prime * result + (configuration ? 1231 : 1237);\r
317                     result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());\r
318                     result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
319                     result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());\r
320                     result = prime * result + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode());\r
321                     result = prime * result + ((groupings == null) ? 0 : groupings.hashCode());\r
322                     result = prime * result + ((uses == null) ? 0 : uses.hashCode());\r
323                     result = prime * result + (userOrdered ? 1231 : 1237);\r
324                     return result;\r
325                 }\r
326 \r
327 \r
328                         @Override\r
329                 public boolean equals(Object obj) {\r
330                     if (this == obj) {\r
331                         return true;\r
332                     }\r
333                     if (obj == null) {\r
334                         return false;\r
335                     }\r
336                     if (getClass() != obj.getClass()) {\r
337                         return false;\r
338                     }\r
339                     ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj;\r
340                     if (qname == null) {\r
341                         if (other.qname != null) {\r
342                             return false;\r
343                         }\r
344                     } else if (!qname.equals(other.qname)) {\r
345                         return false;\r
346                     }\r
347                     if (path == null) {\r
348                         if (other.path != null) {\r
349                             return false;\r
350                         }\r
351                     } else if (!path.equals(other.path)) {\r
352                         return false;\r
353                     }\r
354                     if (description == null) {\r
355                         if (other.description != null) {\r
356                             return false;\r
357                         }\r
358                     } else if (!description.equals(other.description)) {\r
359                         return false;\r
360                     }\r
361                     if (reference == null) {\r
362                         if (other.reference != null) {\r
363                             return false;\r
364                         }\r
365                     } else if (!reference.equals(other.reference)) {\r
366                         return false;\r
367                     }\r
368                     if (status == null) {\r
369                         if (other.status != null) {\r
370                             return false;\r
371                         }\r
372                     } else if (!status.equals(other.status)) {\r
373                         return false;\r
374                     }\r
375                     if (keyDefinition == null) {\r
376                         if (other.keyDefinition != null) {\r
377                             return false;\r
378                         }\r
379                     } else if (!keyDefinition.equals(other.keyDefinition)) {\r
380                         return false;\r
381                     }\r
382                     if(augmenting != other.augmenting) {\r
383                         return false;\r
384                     }\r
385                     if(configuration != other.configuration) {\r
386                         return false;\r
387                     }\r
388                     if (constraints == null) {\r
389                         if (other.constraints != null) {\r
390                             return false;\r
391                         }\r
392                     } else if (!constraints.equals(other.constraints)) {\r
393                         return false;\r
394                     }\r
395                     if (augmentations == null) {\r
396                         if (other.augmentations != null) {\r
397                             return false;\r
398                         }\r
399                     } else if (!augmentations.equals(other.augmentations)) {\r
400                         return false;\r
401                     }\r
402                     if (childNodes == null) {\r
403                         if (other.childNodes != null) {\r
404                             return false;\r
405                         }\r
406                     } else if (!childNodes.equals(other.childNodes)) {\r
407                         return false;\r
408                     }\r
409                     if (typeDefinitions == null) {\r
410                         if (other.typeDefinitions != null) {\r
411                             return false;\r
412                         }\r
413                     } else if (!typeDefinitions.equals(other.typeDefinitions)) {\r
414                         return false;\r
415                     }\r
416                     if (groupings == null) {\r
417                         if (other.groupings != null) {\r
418                             return false;\r
419                         }\r
420                     } else if (!groupings.equals(other.groupings)) {\r
421                         return false;\r
422                     }\r
423                     if (uses == null) {\r
424                         if (other.uses != null) {\r
425                             return false;\r
426                         }\r
427                     } else if (!uses.equals(other.uses)) {\r
428                         return false;\r
429                     }\r
430                         if(userOrdered != other.userOrdered) {\r
431                         return false;\r
432                     }\r
433                     return true;\r
434                 }\r
435 \r
436 \r
437 \r
438 \r
439                         @Override\r
440                         public String toString() {\r
441                                 StringBuilder sb = new StringBuilder(ListSchemaNodeImpl.class.getSimpleName());\r
442                                 sb.append("[");\r
443                                 sb.append("qname="+ qname);\r
444                                 sb.append(", path="+ path);\r
445                                 sb.append(", description="+ description);\r
446                                 sb.append(", reference="+ reference);\r
447                                 sb.append(", status="+ status);\r
448                                 sb.append(", keyDefinition="+ keyDefinition);\r
449                                 sb.append(", augmenting="+ augmenting);\r
450                                 sb.append(", configuration="+ configuration);\r
451                                 sb.append(", constraints="+ constraints);\r
452                                 sb.append(", augmentations="+ augmentations);\r
453                                 sb.append(", childNodes="+ childNodes.values());\r
454                                 sb.append(", typedefinitions="+ typeDefinitions);\r
455                                 sb.append(", groupings="+ groupings);\r
456                                 sb.append(", uses="+ uses);\r
457                                 sb.append(", userOrdered="+ userOrdered);\r
458                                 sb.append("]");\r
459                                 return sb.toString();\r
460                         }\r
461                 }\r
462 \r
463         }