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;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
23 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
24 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
25 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
26 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
28 public final class ContainerSchemaNodeBuilder extends AbstractDocumentedDataNodeContainerBuilder implements
29 AugmentationTargetBuilder, DataSchemaNodeBuilder {
30 private ContainerSchemaNodeImpl instance;
31 private boolean presence;
33 private SchemaPath path;
34 // DataSchemaNode args
35 private boolean augmenting;
36 private boolean addedByUses;
37 private boolean configuration;
38 private ContainerSchemaNode originalNode;
39 private ContainerSchemaNodeBuilder originalBuilder;
40 private final ConstraintsBuilder constraints;
41 // AugmentationTarget args
42 private final List<AugmentationSchema> augmentations = new ArrayList<>();
43 private final List<AugmentationSchemaBuilder> augmentationBuilders = new ArrayList<>();
45 public ContainerSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
46 super(moduleName, line, qname);
47 this.path = Preconditions.checkNotNull(path, "Schema Path must not be null");
48 this.constraints = new ConstraintsBuilderImpl(moduleName, line);
51 // constructor for uses
52 public ContainerSchemaNodeBuilder(final String moduleName, final int line, final QName qname,
53 final SchemaPath path, final ContainerSchemaNode base) {
54 super(moduleName, line, qname, path, base);
55 this.path = Preconditions.checkNotNull(path, "Schema Path must not be null");
57 constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
59 augmenting = base.isAugmenting();
60 addedByUses = base.isAddedByUses();
62 configuration = base.isConfiguration();
63 presence = base.isPresenceContainer();
65 augmentations.addAll(base.getAvailableAugmentations());
70 protected String getStatementName() {
75 public ContainerSchemaNode build() {
76 if (instance != null) {
81 instance = new ContainerSchemaNodeImpl(this);
83 instance.augmenting = augmenting;
84 instance.addedByUses = addedByUses;
85 instance.configuration = configuration;
86 instance.constraints = constraints.build();
87 instance.presence = presence;
90 if (originalNode == null && originalBuilder != null) {
91 originalNode = originalBuilder.build();
93 instance.original = originalNode;
96 for (AugmentationSchemaBuilder builder : augmentationBuilders) {
97 augmentations.add(builder.build());
99 instance.augmentations = ImmutableSet.copyOf(augmentations);
102 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
103 unknownNodes.add(b.build());
105 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
110 public List<AugmentationSchemaBuilder> getAugmentationBuilders() {
111 return augmentationBuilders;
115 public void addAugmentation(final AugmentationSchemaBuilder augment) {
116 augmentationBuilders.add(augment);
120 public SchemaPath getPath() {
125 public void setPath(final SchemaPath path) {
130 public boolean isAugmenting() {
135 public void setAugmenting(final boolean augmenting) {
136 this.augmenting = augmenting;
140 public boolean isAddedByUses() {
145 public void setAddedByUses(final boolean addedByUses) {
146 this.addedByUses = addedByUses;
150 public ContainerSchemaNodeBuilder getOriginal() {
151 return originalBuilder;
155 public void setOriginal(final SchemaNodeBuilder builder) {
156 Preconditions.checkArgument(builder instanceof ContainerSchemaNodeBuilder, "Original of container cannot be "
158 this.originalBuilder = (ContainerSchemaNodeBuilder) builder;
162 public boolean isConfiguration() {
163 return configuration;
167 public void setConfiguration(final boolean configuration) {
168 this.configuration = configuration;
172 public ConstraintsBuilder getConstraints() {
176 public boolean isPresence() {
180 public void setPresence(final boolean presence) {
181 this.presence = presence;
185 public int hashCode() {
186 final int prime = 31;
188 result = prime * result + Objects.hashCode(path);
193 public boolean equals(final Object obj) {
200 if (getClass() != obj.getClass()) {
203 ContainerSchemaNodeBuilder other = (ContainerSchemaNodeBuilder) obj;
205 if (other.path != null) {
208 } else if (!path.equals(other.path)) {
211 if (getParent() == null) {
212 if (other.getParent() != null) {
215 } else if (!getParent().equals(other.getParent())) {
222 public String toString() {
223 return "container " + qname.getLocalName();