5ea82c214477665f9d761dedcafee84bd229e857
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / LeafListSchemaNodeBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang.model.parser.builder.impl;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
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.model.parser.builder.api.AbstractTypeAwareBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
23 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
24
25 public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder
26         implements SchemaNodeBuilder, DataSchemaNodeBuilder {
27     private final LeafListSchemaNodeImpl instance;
28     private final int line;
29     // SchemaNode args
30     private final QName qname;
31     private SchemaPath schemaPath;
32     private String description;
33     private String reference;
34     private Status status = Status.CURRENT;
35     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
36     // DataSchemaNode args
37     private boolean augmenting;
38     private boolean configuration;
39     private final ConstraintsBuilder constraints;
40     // LeafListSchemaNode args
41     private boolean userOrdered;
42
43     public LeafListSchemaNodeBuilder(final QName qname, final int line) {
44         this.qname = qname;
45         this.line = line;
46         instance = new LeafListSchemaNodeImpl(qname);
47         constraints = new ConstraintsBuilder(line);
48     }
49
50     @Override
51     public LeafListSchemaNode build() {
52         instance.setConstraints(constraints.build());
53         instance.setPath(schemaPath);
54         instance.setDescription(description);
55         instance.setReference(reference);
56         instance.setStatus(status);
57         instance.setAugmenting(augmenting);
58         instance.setConfiguration(configuration);
59         instance.setUserOrdered(userOrdered);
60
61         if (type == null) {
62             instance.setType(typedef.build());
63         } else {
64             instance.setType(type);
65         }
66
67         // UNKNOWN NODES
68         final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
69         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
70             unknownNodes.add(b.build());
71         }
72         instance.setUnknownSchemaNodes(unknownNodes);
73
74         return instance;
75     }
76
77     @Override
78     public int getLine() {
79         return line;
80     }
81
82     @Override
83     public QName getQName() {
84         return qname;
85     }
86
87     public SchemaPath getPath() {
88         return schemaPath;
89     }
90
91     @Override
92     public void setPath(final SchemaPath schemaPath) {
93         this.schemaPath = schemaPath;
94     }
95
96     public String getDescription() {
97         return description;
98     }
99
100     @Override
101     public void setDescription(final String description) {
102         this.description = description;
103     }
104
105     public String getReference() {
106         return reference;
107     }
108
109     @Override
110     public void setReference(String reference) {
111         this.reference = reference;
112     }
113
114     public Status getStatus() {
115         return status;
116     }
117
118     @Override
119     public void setStatus(Status status) {
120         if (status != null) {
121             this.status = status;
122         }
123     }
124
125     public boolean isAugmenting() {
126         return augmenting;
127     }
128
129     @Override
130     public void setAugmenting(boolean augmenting) {
131         this.augmenting = augmenting;
132     }
133
134     public boolean isConfiguration() {
135         return configuration;
136     }
137
138     @Override
139     public void setConfiguration(boolean configuration) {
140         this.configuration = configuration;
141     }
142
143     @Override
144     public ConstraintsBuilder getConstraints() {
145         return constraints;
146     }
147
148     public boolean isUserOrdered() {
149         return userOrdered;
150     }
151
152     public void setUserOrdered(final boolean userOrdered) {
153         this.userOrdered = userOrdered;
154     }
155
156     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
157         return addedUnknownNodes;
158     }
159
160     @Override
161     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
162         addedUnknownNodes.add(unknownNode);
163     }
164
165     private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
166         private final QName qname;
167         private SchemaPath path;
168         private String description;
169         private String reference;
170         private Status status = Status.CURRENT;
171         private boolean augmenting;
172         private boolean configuration;
173         private ConstraintDefinition constraintsDef;
174         private TypeDefinition<?> type;
175         private boolean userOrdered;
176         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
177
178         private LeafListSchemaNodeImpl(final QName qname) {
179             this.qname = qname;
180         }
181
182         @Override
183         public QName getQName() {
184             return qname;
185         }
186
187         @Override
188         public SchemaPath getPath() {
189             return path;
190         }
191
192         private void setPath(final SchemaPath path) {
193             this.path = path;
194         }
195
196         @Override
197         public String getDescription() {
198             return description;
199         }
200
201         private void setDescription(String description) {
202             this.description = description;
203         }
204
205         @Override
206         public String getReference() {
207             return reference;
208         }
209
210         private void setReference(String reference) {
211             this.reference = reference;
212         }
213
214         @Override
215         public Status getStatus() {
216             return status;
217         }
218
219         private void setStatus(Status status) {
220             this.status = status;
221         }
222
223         @Override
224         public boolean isAugmenting() {
225             return augmenting;
226         }
227
228         private void setAugmenting(boolean augmenting) {
229             this.augmenting = augmenting;
230         }
231
232         @Override
233         public boolean isConfiguration() {
234             return configuration;
235         }
236
237         private void setConfiguration(boolean configuration) {
238             this.configuration = configuration;
239         }
240
241         @Override
242         public ConstraintDefinition getConstraints() {
243             return constraintsDef;
244         }
245
246         private void setConstraints(ConstraintDefinition constraintsDef) {
247             this.constraintsDef = constraintsDef;
248         }
249
250         @Override
251         public TypeDefinition<?> getType() {
252             return type;
253         }
254
255         public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
256             this.type = type;
257         }
258
259         @Override
260         public boolean isUserOrdered() {
261             return userOrdered;
262         }
263
264         private void setUserOrdered(boolean userOrdered) {
265             this.userOrdered = userOrdered;
266         }
267
268         @Override
269         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
270             return unknownNodes;
271         }
272
273         private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
274             if (unknownNodes != null) {
275                 this.unknownNodes = unknownNodes;
276             }
277         }
278
279         @Override
280         public int hashCode() {
281             final int prime = 31;
282             int result = 1;
283             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
284             result = prime * result + ((path == null) ? 0 : path.hashCode());
285             return result;
286         }
287
288         @Override
289         public boolean equals(Object obj) {
290             if (this == obj) {
291                 return true;
292             }
293             if (obj == null) {
294                 return false;
295             }
296             if (getClass() != obj.getClass()) {
297                 return false;
298             }
299             LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
300             if (qname == null) {
301                 if (other.qname != null) {
302                     return false;
303                 }
304             } else if (!qname.equals(other.qname)) {
305                 return false;
306             }
307             if (path == null) {
308                 if (other.path != null) {
309                     return false;
310                 }
311             } else if (!path.equals(other.path)) {
312                 return false;
313             }
314             return true;
315         }
316
317         @Override
318         public String toString() {
319             StringBuilder sb = new StringBuilder(
320                     LeafListSchemaNodeImpl.class.getSimpleName());
321             sb.append("[");
322             sb.append("qname=" + qname);
323             sb.append(", path=" + path);
324             sb.append(", augmenting=" + augmenting);
325             sb.append(", configuration=" + configuration);
326             sb.append(", constraints=" + constraintsDef);
327             sb.append(", type=" + type);
328             sb.append(", userOrdered=" + userOrdered);
329             sb.append("]");
330             return sb.toString();
331         }
332     }
333
334 }