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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
15 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
23 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractTypeAwareBuilder;
25 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
26 private LeafListSchemaNodeImpl instance;
27 private boolean userOrdered;
29 private SchemaPath schemaPath;
30 private String description;
31 private String reference;
32 private Status status = Status.CURRENT;
33 // DataSchemaNode args
34 private boolean augmenting;
35 private boolean addedByUses;
36 private boolean configuration;
37 private final ConstraintsBuilder constraints;
39 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
40 super(moduleName, line, qname);
41 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
42 constraints = new ConstraintsBuilderImpl(moduleName, line);
45 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
46 final LeafListSchemaNode base) {
47 super(moduleName, line, qname);
48 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
49 constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
51 description = base.getDescription();
52 reference = base.getReference();
53 status = base.getStatus();
54 augmenting = base.isAugmenting();
55 addedByUses = base.isAddedByUses();
56 configuration = base.isConfiguration();
57 this.type = base.getType();
58 userOrdered = base.isUserOrdered();
59 unknownNodes.addAll(base.getUnknownSchemaNodes());
63 public LeafListSchemaNode build() {
64 if (instance != null) {
68 instance = new LeafListSchemaNodeImpl(qname, schemaPath);
70 instance.description = description;
71 instance.reference = reference;
72 instance.status = status;
73 instance.augmenting = augmenting;
74 instance.addedByUses = addedByUses;
75 instance.configuration = configuration;
76 instance.constraintsDef = constraints.toInstance();
77 instance.userOrdered = userOrdered;
80 instance.type = typedef.build();
86 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
87 unknownNodes.add(b.build());
89 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
95 public SchemaPath getPath() {
100 public void setPath(final SchemaPath path) {
101 this.schemaPath = path;
105 public String getDescription() {
110 public void setDescription(final String description) {
111 this.description = description;
115 public String getReference() {
120 public void setReference(final String reference) {
121 this.reference = reference;
125 public Status getStatus() {
130 public void setStatus(final Status status) {
131 this.status = Preconditions.checkNotNull(status, "status cannot be null");
135 public boolean isAugmenting() {
140 public void setAugmenting(final boolean augmenting) {
141 this.augmenting = augmenting;
145 public boolean isAddedByUses() {
150 public void setAddedByUses(final boolean addedByUses) {
151 this.addedByUses = addedByUses;
155 public boolean isConfiguration() {
156 return configuration;
160 public void setConfiguration(final boolean configuration) {
161 this.configuration = configuration;
165 public ConstraintsBuilder getConstraints() {
169 public boolean isUserOrdered() {
173 public void setUserOrdered(final boolean userOrdered) {
174 this.userOrdered = userOrdered;
178 public int hashCode() {
179 final int prime = 31;
181 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
186 public boolean equals(final Object obj) {
193 if (getClass() != obj.getClass()) {
196 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
197 if (schemaPath == null) {
198 if (other.schemaPath != null) {
201 } else if (!schemaPath.equals(other.schemaPath)) {
204 if (getParent() == null) {
205 if (other.getParent() != null) {
208 } else if (!getParent().equals(other.getParent())) {
215 public String toString() {
216 return "leaf-list " + qname.getLocalName();
219 private static final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
220 private final QName qname;
221 private final SchemaPath path;
222 private String description;
223 private String reference;
224 private Status status;
225 private boolean augmenting;
226 private boolean addedByUses;
227 private boolean configuration;
228 private ConstraintDefinition constraintsDef;
229 private TypeDefinition<?> type;
230 private boolean userOrdered;
231 private ImmutableList<UnknownSchemaNode> unknownNodes;
233 private LeafListSchemaNodeImpl(final QName qname, final SchemaPath path) {
239 public QName getQName() {
244 public SchemaPath getPath() {
249 public String getDescription() {
254 public String getReference() {
259 public Status getStatus() {
264 public boolean isAugmenting() {
269 public boolean isAddedByUses() {
274 public boolean isConfiguration() {
275 return configuration;
279 public ConstraintDefinition getConstraints() {
280 return constraintsDef;
284 public TypeDefinition<?> getType() {
289 public boolean isUserOrdered() {
294 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
299 public int hashCode() {
300 final int prime = 31;
302 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
303 result = prime * result + ((path == null) ? 0 : path.hashCode());
308 public boolean equals(final Object obj) {
315 if (getClass() != obj.getClass()) {
318 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
320 if (other.qname != null) {
323 } else if (!qname.equals(other.qname)) {
327 if (other.path != null) {
330 } else if (!path.equals(other.path)) {
337 public String toString() {
338 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
342 return sb.toString();