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.AnyXmlSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
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.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
21 import com.google.common.collect.ImmutableList;
23 public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder {
24 private AnyXmlSchemaNodeImpl instance;
26 private boolean augmenting;
27 private boolean addedByUses;
28 private boolean configuration;
30 private final ConstraintsBuilder constraints;
32 public AnyXmlBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
33 super(moduleName, line, qname);
34 this.schemaPath = path;
35 constraints = new ConstraintsBuilder(moduleName, line);
38 public AnyXmlBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
39 final AnyXmlSchemaNode base) {
40 super(moduleName, line, qname);
41 this.schemaPath = path;
42 constraints = new ConstraintsBuilder(moduleName, line, base.getConstraints());
44 description = base.getDescription();
45 reference = base.getReference();
46 status = base.getStatus();
47 augmenting = base.isAugmenting();
48 addedByUses = base.isAddedByUses();
49 configuration = base.isConfiguration();
50 unknownNodes.addAll(base.getUnknownSchemaNodes());
54 public AnyXmlSchemaNode build() {
55 if (instance != null) {
59 instance = new AnyXmlSchemaNodeImpl(qname, schemaPath);
61 instance.description = description;
62 instance.reference = reference;
63 instance.status = status;
64 instance.augmenting = augmenting;
65 instance.addedByUses = addedByUses;
66 instance.configuration = configuration;
68 instance.constraintsDef = constraints.build();
71 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
72 unknownNodes.add(b.build());
74 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
80 public ConstraintsBuilder getConstraints() {
85 public boolean isAugmenting() {
90 public void setAugmenting(final boolean augmenting) {
91 this.augmenting = augmenting;
95 public boolean isAddedByUses() {
100 public void setAddedByUses(final boolean addedByUses) {
101 this.addedByUses = addedByUses;
105 public boolean isConfiguration() {
106 return configuration;
110 public void setConfiguration(final boolean configuration) {
111 this.configuration = configuration;
115 public int hashCode() {
116 final int prime = 31;
118 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
123 public boolean equals(Object obj) {
130 if (getClass() != obj.getClass()) {
133 AnyXmlBuilder other = (AnyXmlBuilder) obj;
134 if (schemaPath == null) {
135 if (other.schemaPath != null) {
138 } else if (!schemaPath.equals(other.schemaPath)) {
141 if (parentBuilder == null) {
142 if (other.parentBuilder != null) {
145 } else if (!parentBuilder.equals(other.parentBuilder)) {
152 public String toString() {
153 return "anyxml " + qname.getLocalName();
156 private static final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
157 private final QName qname;
158 private final SchemaPath path;
159 private String description;
160 private String reference;
161 private Status status;
162 private boolean configuration;
163 private ConstraintDefinition constraintsDef;
164 private boolean augmenting;
165 private boolean addedByUses;
166 private ImmutableList<UnknownSchemaNode> unknownNodes;
168 private AnyXmlSchemaNodeImpl(final QName qname, final SchemaPath path) {
174 public QName getQName() {
179 public SchemaPath getPath() {
184 public String getDescription() {
189 public String getReference() {
194 public Status getStatus() {
199 public boolean isAugmenting() {
204 public boolean isAddedByUses() {
209 public boolean isConfiguration() {
210 return configuration;
214 public ConstraintDefinition getConstraints() {
215 return constraintsDef;
219 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
224 public int hashCode() {
225 final int prime = 31;
227 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
228 result = prime * result + ((path == null) ? 0 : path.hashCode());
233 public boolean equals(Object obj) {
240 if (getClass() != obj.getClass()) {
243 AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj;
245 if (other.qname != null) {
248 } else if (!qname.equals(other.qname)) {
252 if (other.path != null) {
255 } else if (!path.equals(other.path)) {
262 public String toString() {
263 StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
265 sb.append("qname=" + qname);
266 sb.append(", path=" + path);
268 return sb.toString();