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 com.google.common.collect.ImmutableSet;
14 import java.util.ArrayList;
15 import java.util.List;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
24 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
25 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
26 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
27 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
28 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
29 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
30 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
32 public final class ListSchemaNodeBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DataSchemaNodeBuilder,
33 AugmentationTargetBuilder {
34 private ListSchemaNodeImpl instance;
35 private boolean userOrdered;
36 private List<String> keys;
37 private List<QName> keyDefinition;
39 private SchemaPath schemaPath;
40 // DataSchemaNode args
41 private boolean augmenting;
42 private boolean addedByUses;
43 private boolean configuration;
44 private final ConstraintsBuilder constraints;
45 // AugmentationTarget args
46 private final List<AugmentationSchema> augmentations = new ArrayList<>();
47 private final List<AugmentationSchemaBuilder> augmentationBuilders = new ArrayList<>();
49 public ListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
50 super(moduleName, line, qname);
51 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
52 constraints = new ConstraintsBuilderImpl(moduleName, line);
55 public ListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
56 final ListSchemaNode base) {
57 super(moduleName, line, qname,path,base);
58 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
59 constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
61 keyDefinition = ImmutableList.copyOf(base.getKeyDefinition());
62 userOrdered = base.isUserOrdered();
64 augmenting = base.isAugmenting();
65 addedByUses = base.isAddedByUses();
66 configuration = base.isConfiguration();
68 addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path,
70 augmentations.addAll(base.getAvailableAugmentations());
74 public ListSchemaNode build() {
75 if (instance != null) {
79 instance = new ListSchemaNodeImpl(qname, schemaPath,this);
81 instance.augmenting = augmenting;
82 instance.addedByUses = addedByUses;
83 instance.configuration = configuration;
84 instance.constraints = constraints.toInstance();
85 instance.userOrdered = userOrdered;
89 instance.keyDefinition = ImmutableList.of();
91 keyDefinition = new ArrayList<>();
92 for (String key : keys) {
93 keyDefinition.add(instance.getDataChildByName(key).getQName());
95 instance.keyDefinition = ImmutableList.copyOf(keyDefinition);
99 for (AugmentationSchemaBuilder builder : augmentationBuilders) {
100 augmentations.add(builder.build());
102 instance.augmentations = ImmutableSet.copyOf(augmentations);
105 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
106 unknownNodes.add(b.build());
108 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
114 protected String getStatementName() {
119 public SchemaPath getPath() {
124 public void setPath(final SchemaPath path) {
125 this.schemaPath = path;
129 public void addAugmentation(final AugmentationSchemaBuilder augment) {
130 augmentationBuilders.add(augment);
133 public List<AugmentationSchemaBuilder> getAugmentationBuilders() {
134 return augmentationBuilders;
137 public List<String> getKeys() {
141 public void setKeys(final List<String> keys) {
146 public boolean isAugmenting() {
151 public void setAugmenting(final boolean augmenting) {
152 this.augmenting = augmenting;
156 public boolean isAddedByUses() {
161 public void setAddedByUses(final boolean addedByUses) {
162 this.addedByUses = addedByUses;
166 public boolean isConfiguration() {
167 return configuration;
171 public void setConfiguration(final boolean configuration) {
172 this.configuration = configuration;
176 public ConstraintsBuilder getConstraints() {
180 public boolean isUserOrdered() {
184 public void setUserOrdered(final boolean userOrdered) {
185 this.userOrdered = userOrdered;
189 public int hashCode() {
190 final int prime = 31;
192 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
197 public boolean equals(final Object obj) {
204 if (getClass() != obj.getClass()) {
207 ListSchemaNodeBuilder other = (ListSchemaNodeBuilder) obj;
208 if (schemaPath == null) {
209 if (other.schemaPath != null) {
212 } else if (!schemaPath.equals(other.schemaPath)) {
215 if (getParent() == null) {
216 if (other.getParent() != null) {
219 } else if (!getParent().equals(other.getParent())) {
226 public String toString() {
227 return "list " + qname.getLocalName();
230 private static final class ListSchemaNodeImpl extends AbstractDocumentedDataNodeContainer implements ListSchemaNode {
231 private final QName qname;
232 private final SchemaPath path;
233 private ImmutableList<QName> keyDefinition;
234 private boolean augmenting;
235 private boolean addedByUses;
236 private boolean configuration;
237 private ConstraintDefinition constraints;
238 private ImmutableSet<AugmentationSchema> augmentations;
239 private ImmutableList<UnknownSchemaNode> unknownNodes;
240 private boolean userOrdered;
242 private ListSchemaNodeImpl(final QName qname, final SchemaPath path, final ListSchemaNodeBuilder builder) {
249 public QName getQName() {
254 public SchemaPath getPath() {
259 public List<QName> getKeyDefinition() {
260 return keyDefinition;
264 public boolean isAugmenting() {
269 public boolean isAddedByUses() {
274 public boolean isConfiguration() {
275 return configuration;
279 public ConstraintDefinition getConstraints() {
284 public Set<AugmentationSchema> getAvailableAugmentations() {
285 return augmentations;
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 final ListSchemaNodeImpl other = (ListSchemaNodeImpl) 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 return "list " + qname.getLocalName();