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.Collections;
11 import java.util.List;
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;
24 public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
25 SchemaNodeBuilder, TypeAwareBuilder {
27 private final QName qname;
28 private final LeafSchemaNodeImpl instance;
29 private final ConstraintsBuilder constraintsBuilder;
30 private TypeDefinition<?> type;
32 LeafSchemaNodeBuilder(QName qname) {
34 instance = new LeafSchemaNodeImpl(qname);
35 constraintsBuilder = new ConstraintsBuilder();
39 public LeafSchemaNode build() {
40 instance.setConstraints(constraintsBuilder.build());
45 public QName getQName() {
50 public void setPath(SchemaPath path) {
51 instance.setPath(path);
55 public void setDescription(String description) {
56 instance.setDescription(description);
60 public void setReference(String reference) {
61 instance.setReference(reference);
65 public void setStatus(Status status) {
67 instance.setStatus(status);
72 public void setAugmenting(boolean augmenting) {
73 instance.setAugmenting(augmenting);
77 public void setConfiguration(boolean configuration) {
78 instance.setConfiguration(configuration);
82 public ConstraintsBuilder getConstraintsBuilder() {
83 return constraintsBuilder;
87 public TypeDefinition<?> getType() {
92 public void setType(TypeDefinition<?> type) {
94 instance.setType(type);
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();
109 private LeafSchemaNodeImpl(QName qname) {
114 public QName getQName() {
119 public SchemaPath getPath() {
123 private void setPath(SchemaPath path) {
128 public String getDescription() {
132 private void setDescription(String description) {
133 this.description = description;
137 public String getReference() {
141 private void setReference(String reference) {
142 this.reference = reference;
146 public Status getStatus() {
150 private void setStatus(Status status) {
151 if (status != null) {
152 this.status = status;
157 public boolean isAugmenting() {
161 private void setAugmenting(boolean augmenting) {
162 this.augmenting = augmenting;
166 public boolean isConfiguration() {
167 return configuration;
170 private void setConfiguration(boolean configuration) {
171 this.configuration = configuration;
175 public ConstraintDefinition getConstraints() {
179 private void setConstraints(ConstraintDefinition constraints) {
180 this.constraints = constraints;
184 public TypeDefinition<?> getType() {
188 private void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
193 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
194 return unknownSchemaNodes;
198 public int hashCode() {
199 final int prime = 31;
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());
218 public boolean equals(Object obj) {
225 if (getClass() != obj.getClass()) {
228 LeafSchemaNodeImpl other = (LeafSchemaNodeImpl) obj;
230 if (other.qname != null) {
233 } else if (!qname.equals(other.qname)) {
237 if (other.path != null) {
240 } else if (!path.equals(other.path)) {
243 if (description == null) {
244 if (other.description != null) {
247 } else if (!description.equals(other.description)) {
250 if (reference == null) {
251 if (other.reference != null) {
254 } else if (!reference.equals(other.reference)) {
257 if (status == null) {
258 if (other.status != null) {
261 } else if (!status.equals(other.status)) {
264 if (augmenting != other.augmenting) {
267 if (configuration != other.configuration) {
270 if (constraints == null) {
271 if (other.constraints != null) {
274 } else if (!constraints.equals(other.constraints)) {
278 if (other.type != null) {
281 } else if (!type.equals(other.type)) {
288 public String toString() {
289 StringBuilder sb = new StringBuilder(
290 LeafSchemaNodeImpl.class.getSimpleName());
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);
303 return sb.toString();