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.yangtools.yang.parser.builder.impl;
10 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
14 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
20 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractTypeAwareBuilder;
24 import com.google.common.base.Preconditions;
25 import com.google.common.collect.ImmutableList;
27 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
28 private LeafListSchemaNodeImpl instance;
29 private boolean userOrdered;
31 private SchemaPath schemaPath;
32 private String description;
33 private String reference;
34 private Status status = Status.CURRENT;
35 // DataSchemaNode args
36 private boolean augmenting;
37 private boolean addedByUses;
38 private boolean configuration;
39 private final ConstraintsBuilder constraints;
41 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
42 super(moduleName, line, qname);
43 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
44 constraints = new ConstraintsBuilderImpl(moduleName, line);
47 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
48 final LeafListSchemaNode base) {
49 super(moduleName, line, qname);
50 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
51 constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
53 description = base.getDescription();
54 reference = base.getReference();
55 status = base.getStatus();
56 augmenting = base.isAugmenting();
57 addedByUses = base.isAddedByUses();
58 configuration = base.isConfiguration();
59 this.type = base.getType();
60 userOrdered = base.isUserOrdered();
61 unknownNodes.addAll(base.getUnknownSchemaNodes());
65 public LeafListSchemaNode build() {
66 if (instance != null) {
70 instance = new LeafListSchemaNodeImpl(qname, schemaPath);
72 instance.description = description;
73 instance.reference = reference;
74 instance.status = status;
75 instance.augmenting = augmenting;
76 instance.addedByUses = addedByUses;
77 instance.configuration = configuration;
78 instance.constraintsDef = constraints.toInstance();
79 instance.userOrdered = userOrdered;
82 instance.type = typedef.build();
88 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
89 unknownNodes.add(b.build());
91 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
97 public SchemaPath getPath() {
102 public void setPath(final SchemaPath path) {
103 this.schemaPath = path;
107 public String getDescription() {
112 public void setDescription(final String description) {
113 this.description = description;
117 public String getReference() {
122 public void setReference(final String reference) {
123 this.reference = reference;
127 public Status getStatus() {
132 public void setStatus(final Status status) {
133 this.status = Preconditions.checkNotNull(status, "status cannot be null");
137 public boolean isAugmenting() {
142 public void setAugmenting(final boolean augmenting) {
143 this.augmenting = augmenting;
147 public boolean isAddedByUses() {
152 public void setAddedByUses(final boolean addedByUses) {
153 this.addedByUses = addedByUses;
157 public boolean isConfiguration() {
158 return configuration;
162 public void setConfiguration(final boolean configuration) {
163 this.configuration = configuration;
167 public ConstraintsBuilder getConstraints() {
171 public boolean isUserOrdered() {
175 public void setUserOrdered(final boolean userOrdered) {
176 this.userOrdered = userOrdered;
180 public int hashCode() {
181 final int prime = 31;
183 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
188 public boolean equals(final Object obj) {
195 if (getClass() != obj.getClass()) {
198 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
199 if (schemaPath == null) {
200 if (other.schemaPath != null) {
203 } else if (!schemaPath.equals(other.schemaPath)) {
206 if (getParent() == null) {
207 if (other.getParent() != null) {
210 } else if (!getParent().equals(other.getParent())) {
217 public String toString() {
218 return "leaf-list " + qname.getLocalName();
221 private static final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
222 private final QName qname;
223 private final SchemaPath path;
224 private String description;
225 private String reference;
226 private Status status;
227 private boolean augmenting;
228 private boolean addedByUses;
229 private boolean configuration;
230 private ConstraintDefinition constraintsDef;
231 private TypeDefinition<?> type;
232 private boolean userOrdered;
233 private ImmutableList<UnknownSchemaNode> unknownNodes;
235 private LeafListSchemaNodeImpl(final QName qname, final SchemaPath path) {
241 public QName getQName() {
246 public SchemaPath getPath() {
251 public String getDescription() {
256 public String getReference() {
261 public Status getStatus() {
266 public boolean isAugmenting() {
271 public boolean isAddedByUses() {
276 public boolean isConfiguration() {
277 return configuration;
281 public ConstraintDefinition getConstraints() {
282 return constraintsDef;
286 public TypeDefinition<?> getType() {
291 public boolean isUserOrdered() {
296 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
301 public int hashCode() {
302 final int prime = 31;
304 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
305 result = prime * result + ((path == null) ? 0 : path.hashCode());
310 public boolean equals(final Object obj) {
317 if (getClass() != obj.getClass()) {
320 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
322 if (other.qname != null) {
325 } else if (!qname.equals(other.qname)) {
329 if (other.path != null) {
332 } else if (!path.equals(other.path)) {
339 public String toString() {
340 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
344 return sb.toString();