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.DataSchemaNodeBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
23 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
25 public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
26 TypeAwareBuilder, DataSchemaNodeBuilder {
28 private final LeafListSchemaNodeImpl instance;
29 private final QName qname;
30 private final ConstraintsBuilder constraintsBuilder = new ConstraintsBuilder();
31 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
32 private TypeDefinition<?> type;
34 LeafListSchemaNodeBuilder(QName qname) {
36 instance = new LeafListSchemaNodeImpl(qname);
40 public LeafListSchemaNode build() {
41 instance.setConstraints(constraintsBuilder.build());
46 public QName getQName() {
51 public void setPath(SchemaPath path) {
52 instance.setPath(path);
56 public void setDescription(String description) {
57 instance.setDescription(description);
61 public void setReference(String reference) {
62 instance.setReference(reference);
66 public void setStatus(Status status) {
68 instance.setStatus(status);
73 public TypeDefinition<?> getType() {
78 public void setType(TypeDefinition<?> type) {
80 instance.setType(type);
84 public void setAugmenting(boolean augmenting) {
85 instance.setAugmenting(augmenting);
89 public void setConfiguration(boolean configuration) {
90 instance.setConfiguration(configuration);
94 public ConstraintsBuilder getConstraintsBuilder() {
95 return constraintsBuilder;
98 public void setUserOrdered(boolean userOrdered) {
99 instance.setUserOrdered(userOrdered);
103 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
104 addedUnknownNodes.add(unknownSchemaNodeBuilder);
107 private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
108 private final QName qname;
109 private SchemaPath path;
110 private String description;
111 private String reference;
112 private Status status = Status.CURRENT;
113 private boolean augmenting;
114 private boolean configuration;
115 private ConstraintDefinition constraints;
116 private TypeDefinition<?> type;
117 private boolean userOrdered;
118 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
120 private LeafListSchemaNodeImpl(QName qname) {
125 public QName getQName() {
130 public SchemaPath getPath() {
134 private void setPath(SchemaPath path) {
139 public String getDescription() {
143 private void setDescription(String description) {
144 this.description = description;
148 public String getReference() {
152 private void setReference(String reference) {
153 this.reference = reference;
157 public Status getStatus() {
161 private void setStatus(Status status) {
162 this.status = status;
166 public boolean isAugmenting() {
170 private void setAugmenting(boolean augmenting) {
171 this.augmenting = augmenting;
175 public boolean isConfiguration() {
176 return configuration;
179 private void setConfiguration(boolean configuration) {
180 this.configuration = configuration;
184 public ConstraintDefinition getConstraints() {
188 private void setConstraints(ConstraintDefinition constraints) {
189 this.constraints = constraints;
193 public TypeDefinition<?> getType() {
197 public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
202 public boolean isUserOrdered() {
206 private void setUserOrdered(boolean userOrdered) {
207 this.userOrdered = userOrdered;
211 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
212 return unknownSchemaNodes;
215 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
216 if(unknownSchemaNodes != null) {
217 this.unknownSchemaNodes = unknownSchemaNodes;
222 public int hashCode() {
223 final int prime = 31;
225 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
226 result = prime * result + ((path == null) ? 0 : path.hashCode());
231 public boolean equals(Object obj) {
238 if (getClass() != obj.getClass()) {
241 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
243 if (other.qname != null) {
246 } else if (!qname.equals(other.qname)) {
250 if (other.path != null) {
253 } else if (!path.equals(other.path)) {
260 public String toString() {
261 StringBuilder sb = new StringBuilder(
262 LeafListSchemaNodeImpl.class.getSimpleName());
264 sb.append("qname=" + qname);
265 sb.append(", path=" + path);
266 sb.append(", description=" + description);
267 sb.append(", reference=" + reference);
268 sb.append(", status=" + status);
269 sb.append(", augmenting=" + augmenting);
270 sb.append(", configuration=" + configuration);
271 sb.append(", constraints=" + constraints);
272 sb.append(", type=" + type);
273 sb.append(", userOrdered=" + userOrdered);
275 return sb.toString();