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.DerivableSchemaNode;
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.SchemaNodeBuilder;
23 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
24 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractTypeAwareBuilder;
26 import com.google.common.base.Optional;
27 import com.google.common.base.Preconditions;
28 import com.google.common.collect.ImmutableList;
30 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
31 private LeafListSchemaNodeImpl instance;
32 private boolean userOrdered;
34 private SchemaPath schemaPath;
35 private String description;
36 private String reference;
37 private Status status = Status.CURRENT;
38 // DataSchemaNode args
39 private boolean augmenting;
40 private boolean addedByUses;
41 private LeafListSchemaNode originalNode;
42 private LeafListSchemaNodeBuilder originalBuilder;
43 private boolean configuration;
44 private final ConstraintsBuilder constraints;
46 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
47 super(moduleName, line, qname);
48 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
49 constraints = new ConstraintsBuilderImpl(moduleName, line);
52 public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
53 final LeafListSchemaNode base) {
54 super(moduleName, line, qname);
55 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
56 constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
58 description = base.getDescription();
59 reference = base.getReference();
60 status = base.getStatus();
61 augmenting = base.isAugmenting();
62 addedByUses = base.isAddedByUses();
64 configuration = base.isConfiguration();
65 this.type = base.getType();
66 userOrdered = base.isUserOrdered();
67 unknownNodes.addAll(base.getUnknownSchemaNodes());
71 public LeafListSchemaNode build() {
72 if (instance != null) {
76 instance = new LeafListSchemaNodeImpl(qname, schemaPath);
78 instance.description = description;
79 instance.reference = reference;
80 instance.status = status;
81 instance.augmenting = augmenting;
82 instance.addedByUses = addedByUses;
83 instance.configuration = configuration;
84 instance.constraintsDef = constraints.toInstance();
85 instance.userOrdered = userOrdered;
88 instance.type = typedef.build();
94 if (originalNode == null && originalBuilder != null) {
95 originalNode = originalBuilder.build();
97 instance.original = originalNode;
100 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
101 unknownNodes.add(b.build());
103 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
109 public SchemaPath getPath() {
114 public void setPath(final SchemaPath path) {
115 this.schemaPath = path;
119 public String getDescription() {
124 public void setDescription(final String description) {
125 this.description = description;
129 public String getReference() {
134 public void setReference(final String reference) {
135 this.reference = reference;
139 public Status getStatus() {
144 public void setStatus(final Status status) {
145 this.status = Preconditions.checkNotNull(status, "status cannot be null");
149 public boolean isAugmenting() {
154 public void setAugmenting(final boolean augmenting) {
155 this.augmenting = augmenting;
159 public boolean isAddedByUses() {
164 public void setAddedByUses(final boolean addedByUses) {
165 this.addedByUses = addedByUses;
169 public LeafListSchemaNodeBuilder getOriginal() {
170 return originalBuilder;
174 public void setOriginal(final SchemaNodeBuilder builder) {
175 Preconditions.checkArgument(builder instanceof LeafListSchemaNodeBuilder, "Original of leaf-list cannot be "
177 this.originalBuilder = (LeafListSchemaNodeBuilder) builder;
181 public boolean isConfiguration() {
182 return configuration;
186 public void setConfiguration(final boolean configuration) {
187 this.configuration = configuration;
191 public ConstraintsBuilder getConstraints() {
195 public boolean isUserOrdered() {
199 public void setUserOrdered(final boolean userOrdered) {
200 this.userOrdered = userOrdered;
204 public int hashCode() {
205 final int prime = 31;
207 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
212 public boolean equals(final Object obj) {
219 if (getClass() != obj.getClass()) {
222 LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
223 if (schemaPath == null) {
224 if (other.schemaPath != null) {
227 } else if (!schemaPath.equals(other.schemaPath)) {
230 if (getParent() == null) {
231 if (other.getParent() != null) {
234 } else if (!getParent().equals(other.getParent())) {
241 public String toString() {
242 return "leaf-list " + qname.getLocalName();
245 private static final class LeafListSchemaNodeImpl implements LeafListSchemaNode, DerivableSchemaNode {
246 private final QName qname;
247 private final SchemaPath path;
248 private String description;
249 private String reference;
250 private Status status;
251 private boolean augmenting;
252 private boolean addedByUses;
253 private LeafListSchemaNode original;
254 private boolean configuration;
255 private ConstraintDefinition constraintsDef;
256 private TypeDefinition<?> type;
257 private boolean userOrdered;
258 private ImmutableList<UnknownSchemaNode> unknownNodes;
260 private LeafListSchemaNodeImpl(final QName qname, final SchemaPath path) {
266 public QName getQName() {
271 public SchemaPath getPath() {
276 public String getDescription() {
281 public String getReference() {
286 public Status getStatus() {
291 public boolean isAugmenting() {
296 public boolean isAddedByUses() {
301 public Optional<LeafListSchemaNode> getOriginal() {
302 return Optional.fromNullable(original);
306 public boolean isConfiguration() {
307 return configuration;
311 public ConstraintDefinition getConstraints() {
312 return constraintsDef;
316 public TypeDefinition<?> getType() {
321 public boolean isUserOrdered() {
326 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
331 public int hashCode() {
332 final int prime = 31;
334 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
335 result = prime * result + ((path == null) ? 0 : path.hashCode());
340 public boolean equals(final Object obj) {
347 if (getClass() != obj.getClass()) {
350 LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
352 if (other.qname != null) {
355 } else if (!qname.equals(other.qname)) {
359 if (other.path != null) {
362 } else if (!path.equals(other.path)) {
369 public String toString() {
370 StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
374 return sb.toString();