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