2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.parser.builder.impl;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
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.parser.builder.api.AbstractTypeAwareBuilder;
22 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
23 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
25 public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder
26 implements SchemaNodeBuilder, DataSchemaNodeBuilder {
27 private boolean built;
28 private final LeafListSchemaNodeImpl instance;
29 private final int line;
31 private final QName qname;
32 private SchemaPath schemaPath;
33 private String description;
34 private String reference;
35 private Status status = Status.CURRENT;
36 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
37 // DataSchemaNode args
38 private boolean augmenting;
39 private boolean configuration;
40 private final ConstraintsBuilder constraints;
41 // LeafListSchemaNode args
42 private boolean userOrdered;
44 public LeafListSchemaNodeBuilder(final QName qname, final int line) {
47 instance = new LeafListSchemaNodeImpl(qname);
48 constraints = new ConstraintsBuilder(line);
52 public LeafListSchemaNode build() {
54 instance.setConstraints(constraints.build());
55 instance.setPath(schemaPath);
56 instance.setDescription(description);
57 instance.setReference(reference);
58 instance.setStatus(status);
59 instance.setAugmenting(augmenting);
60 instance.setConfiguration(configuration);
61 instance.setUserOrdered(userOrdered);
64 instance.setType(typedef.build());
66 instance.setType(type);
70 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
71 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
72 unknownNodes.add(b.build());
74 instance.setUnknownSchemaNodes(unknownNodes);
82 public int getLine() {
87 public QName getQName() {
91 public SchemaPath getPath() {
96 public void setPath(final SchemaPath schemaPath) {
97 this.schemaPath = schemaPath;
100 public String getDescription() {
105 public void setDescription(final String description) {
106 this.description = description;
109 public String getReference() {
114 public void setReference(String reference) {
115 this.reference = reference;
118 public Status getStatus() {
123 public void setStatus(Status status) {
124 if (status != null) {
125 this.status = status;
129 public boolean isAugmenting() {
134 public void setAugmenting(boolean augmenting) {
135 this.augmenting = augmenting;
138 public boolean isConfiguration() {
139 return configuration;
143 public void setConfiguration(boolean configuration) {
144 this.configuration = configuration;
148 public ConstraintsBuilder getConstraints() {
152 public boolean isUserOrdered() {
156 public void setUserOrdered(final boolean userOrdered) {
157 this.userOrdered = userOrdered;
160 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
161 return addedUnknownNodes;
165 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
166 addedUnknownNodes.add(unknownNode);
169 private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
170 private final QName qname;
171 private SchemaPath path;
172 private String description;
173 private String reference;
174 private Status status = Status.CURRENT;
175 private boolean augmenting;
176 private boolean configuration;
177 private ConstraintDefinition constraintsDef;
178 private TypeDefinition<?> type;
179 private boolean userOrdered;
180 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
182 private LeafListSchemaNodeImpl(final QName qname) {
187 public QName getQName() {
192 public SchemaPath getPath() {
196 private void setPath(final SchemaPath path) {
201 public String getDescription() {
205 private void setDescription(String description) {
206 this.description = description;
210 public String getReference() {
214 private void setReference(String reference) {
215 this.reference = reference;
219 public Status getStatus() {
223 private void setStatus(Status status) {
224 this.status = status;
228 public boolean isAugmenting() {
232 private void setAugmenting(boolean augmenting) {
233 this.augmenting = augmenting;
237 public boolean isConfiguration() {
238 return configuration;
241 private void setConfiguration(boolean configuration) {
242 this.configuration = configuration;
246 public ConstraintDefinition getConstraints() {
247 return constraintsDef;
250 private void setConstraints(ConstraintDefinition constraintsDef) {
251 this.constraintsDef = constraintsDef;
255 public TypeDefinition<?> getType() {
259 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
264 public boolean isUserOrdered() {
268 private void setUserOrdered(boolean userOrdered) {
269 this.userOrdered = userOrdered;
273 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
277 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
278 if (unknownNodes != null) {
279 this.unknownNodes = unknownNodes;
284 public int hashCode() {
285 final int prime = 31;
287 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
288 result = prime * result + ((path == null) ? 0 : path.hashCode());
293 public boolean equals(Object obj) {
300 if (getClass() != obj.getClass()) {
303 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
305 if (other.qname != null) {
308 } else if (!qname.equals(other.qname)) {
312 if (other.path != null) {
315 } else if (!path.equals(other.path)) {
322 public String toString() {
323 StringBuilder sb = new StringBuilder(
324 LeafListSchemaNodeImpl.class.getSimpleName());
326 sb.append("qname=" + qname);
327 sb.append(", path=" + path);
328 sb.append(", augmenting=" + augmenting);
329 sb.append(", configuration=" + configuration);
330 sb.append(", constraints=" + constraintsDef);
331 sb.append(", type=" + type);
332 sb.append(", userOrdered=" + userOrdered);
334 return sb.toString();