Merge "Refactor frontend JS"
[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 implements SchemaNodeBuilder,
26         DataSchemaNodeBuilder {
27
28     private final LeafListSchemaNodeImpl instance;
29     private final QName qname;
30     private final ConstraintsBuilder constraints = new ConstraintsBuilder();
31     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
32
33     LeafListSchemaNodeBuilder(QName qname) {
34         this.qname = qname;
35         instance = new LeafListSchemaNodeImpl(qname);
36     }
37
38     @Override
39     public LeafListSchemaNode build() {
40         instance.setConstraints(constraints.build());
41
42         if(type == null) {
43             instance.setType(typedef.build());
44         } else {
45             instance.setType(type);
46         }
47
48         // UNKNOWN NODES
49         final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
50         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
51             unknownNodes.add(b.build());
52         }
53         instance.setUnknownSchemaNodes(unknownNodes);
54
55         return instance;
56     }
57
58     @Override
59     public QName getQName() {
60         return qname;
61     }
62
63     @Override
64     public void setPath(SchemaPath path) {
65         instance.setPath(path);
66     }
67
68     @Override
69     public void setDescription(String description) {
70         instance.setDescription(description);
71     }
72
73     @Override
74     public void setReference(String reference) {
75         instance.setReference(reference);
76     }
77
78     @Override
79     public void setStatus(Status status) {
80         if(status != null) {
81             instance.setStatus(status);
82         }
83     }
84
85     @Override
86     public void setAugmenting(boolean augmenting) {
87         instance.setAugmenting(augmenting);
88     }
89
90     @Override
91     public void setConfiguration(boolean configuration) {
92         instance.setConfiguration(configuration);
93     }
94
95     @Override
96     public ConstraintsBuilder getConstraintsBuilder() {
97         return constraints;
98     }
99
100     public void setUserOrdered(boolean userOrdered) {
101         instance.setUserOrdered(userOrdered);
102     }
103
104     @Override
105     public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
106         addedUnknownNodes.add(unknownSchemaNodeBuilder);
107     }
108
109     private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
110         private final QName qname;
111         private SchemaPath path;
112         private String description;
113         private String reference;
114         private Status status = Status.CURRENT;
115         private boolean augmenting;
116         private boolean configuration;
117         private ConstraintDefinition constraintsDef;
118         private TypeDefinition<?> type;
119         private boolean userOrdered;
120         private List<UnknownSchemaNode> unknownNodes = Collections
121                 .emptyList();
122
123         private LeafListSchemaNodeImpl(QName qname) {
124             this.qname = qname;
125         }
126
127         @Override
128         public QName getQName() {
129             return qname;
130         }
131
132         @Override
133         public SchemaPath getPath() {
134             return path;
135         }
136
137         private void setPath(SchemaPath path) {
138             this.path = path;
139         }
140
141         @Override
142         public String getDescription() {
143             return description;
144         }
145
146         private void setDescription(String description) {
147             this.description = description;
148         }
149
150         @Override
151         public String getReference() {
152             return reference;
153         }
154
155         private void setReference(String reference) {
156             this.reference = reference;
157         }
158
159         @Override
160         public Status getStatus() {
161             return status;
162         }
163
164         private void setStatus(Status status) {
165             this.status = status;
166         }
167
168         @Override
169         public boolean isAugmenting() {
170             return augmenting;
171         }
172
173         private void setAugmenting(boolean augmenting) {
174             this.augmenting = augmenting;
175         }
176
177         @Override
178         public boolean isConfiguration() {
179             return configuration;
180         }
181
182         private void setConfiguration(boolean configuration) {
183             this.configuration = configuration;
184         }
185
186         @Override
187         public ConstraintDefinition getConstraints() {
188             return constraintsDef;
189         }
190
191         private void setConstraints(ConstraintDefinition constraintsDef) {
192             this.constraintsDef = constraintsDef;
193         }
194
195         @Override
196         public TypeDefinition<?> getType() {
197             return type;
198         }
199
200         public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
201             this.type = type;
202         }
203
204         @Override
205         public boolean isUserOrdered() {
206             return userOrdered;
207         }
208
209         private void setUserOrdered(boolean userOrdered) {
210             this.userOrdered = userOrdered;
211         }
212
213         @Override
214         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
215             return unknownNodes;
216         }
217
218         private void setUnknownSchemaNodes(
219                 List<UnknownSchemaNode> unknownNodes) {
220             if (unknownNodes != null) {
221                 this.unknownNodes = unknownNodes;
222             }
223         }
224
225         @Override
226         public int hashCode() {
227             final int prime = 31;
228             int result = 1;
229             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
230             result = prime * result + ((path == null) ? 0 : path.hashCode());
231             return result;
232         }
233
234         @Override
235         public boolean equals(Object obj) {
236             if (this == obj) {
237                 return true;
238             }
239             if (obj == null) {
240                 return false;
241             }
242             if (getClass() != obj.getClass()) {
243                 return false;
244             }
245             LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
246             if (qname == null) {
247                 if (other.qname != null) {
248                     return false;
249                 }
250             } else if (!qname.equals(other.qname)) {
251                 return false;
252             }
253             if (path == null) {
254                 if (other.path != null) {
255                     return false;
256                 }
257             } else if (!path.equals(other.path)) {
258                 return false;
259             }
260             return true;
261         }
262
263         @Override
264         public String toString() {
265             StringBuilder sb = new StringBuilder(
266                     LeafListSchemaNodeImpl.class.getSimpleName());
267             sb.append("[");
268             sb.append("qname=" + qname);
269             sb.append(", path=" + path);
270             sb.append(", description=" + description);
271             sb.append(", reference=" + reference);
272             sb.append(", status=" + status);
273             sb.append(", augmenting=" + augmenting);
274             sb.append(", configuration=" + configuration);
275             sb.append(", constraints=" + constraintsDef);
276             sb.append(", type=" + type);
277             sb.append(", userOrdered=" + userOrdered);
278             sb.append("]");
279             return sb.toString();
280         }
281     }
282
283 }