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.model.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.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;
25 public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder
26 implements SchemaNodeBuilder, DataSchemaNodeBuilder {
27 private final LeafListSchemaNodeImpl instance;
28 private final QName qname;
29 private final ConstraintsBuilder constraints = new ConstraintsBuilder();
30 private SchemaPath schemaPath;
31 private String description;
32 private String reference;
33 private Status status = Status.CURRENT;
34 private boolean augmenting;
35 private boolean configuration;
36 private boolean userOrdered;
38 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
40 public LeafListSchemaNodeBuilder(final QName qname) {
42 instance = new LeafListSchemaNodeImpl(qname);
46 public LeafListSchemaNode build() {
47 instance.setConstraints(constraints.build());
48 instance.setPath(schemaPath);
49 instance.setDescription(description);
50 instance.setReference(reference);
51 instance.setStatus(status);
52 instance.setAugmenting(augmenting);
53 instance.setConfiguration(configuration);
54 instance.setUserOrdered(userOrdered);
57 instance.setType(typedef.build());
59 instance.setType(type);
63 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
64 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
65 unknownNodes.add(b.build());
67 instance.setUnknownSchemaNodes(unknownNodes);
73 public QName getQName() {
77 public SchemaPath getPath() {
82 public void setPath(final SchemaPath schemaPath) {
83 this.schemaPath = schemaPath;
86 public String getDescription() {
91 public void setDescription(final String description) {
92 this.description = description;
95 public String getReference() {
100 public void setReference(String reference) {
101 this.reference = reference;
104 public Status getStatus() {
109 public void setStatus(Status status) {
111 this.status = status;
115 public boolean isAugmenting() {
120 public void setAugmenting(boolean augmenting) {
121 this.augmenting = augmenting;
124 public boolean isConfiguration() {
125 return configuration;
129 public void setConfiguration(boolean configuration) {
130 this.configuration = configuration;
134 public ConstraintsBuilder getConstraints() {
138 public boolean isUserOrdered() {
142 public void setUserOrdered(final boolean userOrdered) {
143 this.userOrdered = userOrdered;
146 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
147 return addedUnknownNodes;
151 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
152 addedUnknownNodes.add(unknownNode);
155 private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
156 private final QName qname;
157 private SchemaPath path;
158 private String description;
159 private String reference;
160 private Status status = Status.CURRENT;
161 private boolean augmenting;
162 private boolean configuration;
163 private ConstraintDefinition constraintsDef;
164 private TypeDefinition<?> type;
165 private boolean userOrdered;
166 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
168 private LeafListSchemaNodeImpl(final QName qname) {
173 public QName getQName() {
178 public SchemaPath getPath() {
182 private void setPath(final SchemaPath path) {
187 public String getDescription() {
191 private void setDescription(String description) {
192 this.description = description;
196 public String getReference() {
200 private void setReference(String reference) {
201 this.reference = reference;
205 public Status getStatus() {
209 private void setStatus(Status status) {
210 this.status = status;
214 public boolean isAugmenting() {
218 private void setAugmenting(boolean augmenting) {
219 this.augmenting = augmenting;
223 public boolean isConfiguration() {
224 return configuration;
227 private void setConfiguration(boolean configuration) {
228 this.configuration = configuration;
232 public ConstraintDefinition getConstraints() {
233 return constraintsDef;
236 private void setConstraints(ConstraintDefinition constraintsDef) {
237 this.constraintsDef = constraintsDef;
241 public TypeDefinition<?> getType() {
245 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
250 public boolean isUserOrdered() {
254 private void setUserOrdered(boolean userOrdered) {
255 this.userOrdered = userOrdered;
259 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
263 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
264 if (unknownNodes != null) {
265 this.unknownNodes = unknownNodes;
270 public int hashCode() {
271 final int prime = 31;
273 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
274 result = prime * result + ((path == null) ? 0 : path.hashCode());
279 public boolean equals(Object obj) {
286 if (getClass() != obj.getClass()) {
289 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
291 if (other.qname != null) {
294 } else if (!qname.equals(other.qname)) {
298 if (other.path != null) {
301 } else if (!path.equals(other.path)) {
308 public String toString() {
309 StringBuilder sb = new StringBuilder(
310 LeafListSchemaNodeImpl.class.getSimpleName());
312 sb.append("qname=" + qname);
313 sb.append(", path=" + path);
314 sb.append(", augmenting=" + augmenting);
315 sb.append(", configuration=" + configuration);
316 sb.append(", constraints=" + constraintsDef);
317 sb.append(", type=" + type);
318 sb.append(", userOrdered=" + userOrdered);
320 return sb.toString();