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.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
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.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.YangNode;
20 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
22 import org.opendaylight.yangtools.yang.parser.util.Comparators;
24 public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder {
25 private boolean built;
26 private final AnyXmlSchemaNodeImpl instance;
27 private final ConstraintsBuilder constraints;
29 private Boolean configuration;
30 private boolean augmenting;
31 private boolean addedByUses;
33 public AnyXmlBuilder(final String moduleName, final int line, final QName qname, final SchemaPath schemaPath) {
34 super(moduleName, line, qname);
35 this.schemaPath = schemaPath;
36 instance = new AnyXmlSchemaNodeImpl(qname);
37 constraints = new ConstraintsBuilder(moduleName, line);
41 public AnyXmlSchemaNode build(YangNode parent) {
43 instance.setParent(parent);
44 instance.setPath(schemaPath);
45 instance.setConstraints(constraints.build());
46 instance.setDescription(description);
47 instance.setReference(reference);
48 instance.setStatus(status);
49 instance.setConfiguration(configuration);
50 instance.setAugmenting(augmenting);
51 instance.setAddedByUses(addedByUses);
54 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
55 unknownNodes.add(b.build(instance));
57 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
58 instance.setUnknownSchemaNodes(unknownNodes);
66 public void setQName(QName qname) {
71 public ConstraintsBuilder getConstraints() {
75 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
76 return addedUnknownNodes;
80 public boolean isAugmenting() {
85 public void setAugmenting(final boolean augmenting) {
86 this.augmenting = augmenting;
90 public boolean isAddedByUses() {
95 public void setAddedByUses(final boolean addedByUses) {
96 this.addedByUses = addedByUses;
100 public Boolean isConfiguration() {
101 return configuration;
105 public void setConfiguration(final Boolean configuration) {
106 this.configuration = configuration;
110 public int hashCode() {
111 final int prime = 31;
113 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
118 public boolean equals(Object obj) {
125 if (getClass() != obj.getClass()) {
128 AnyXmlBuilder other = (AnyXmlBuilder) obj;
129 if (schemaPath == null) {
130 if (other.schemaPath != null) {
133 } else if (!schemaPath.equals(other.schemaPath)) {
136 if (parentBuilder == null) {
137 if (other.parentBuilder != null) {
140 } else if (!parentBuilder.equals(other.parentBuilder)) {
147 public String toString() {
148 return "anyxml " + qname.getLocalName();
151 private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
152 private final QName qname;
153 private SchemaPath path;
154 private YangNode parent;
155 private String description;
156 private String reference;
157 private Status status = Status.CURRENT;
158 private boolean configuration;
159 private ConstraintDefinition constraintsDef;
160 private boolean augmenting;
161 private boolean addedByUses;
162 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
164 private AnyXmlSchemaNodeImpl(final QName qname) {
169 public QName getQName() {
174 public SchemaPath getPath() {
178 private void setPath(final SchemaPath path) {
183 public YangNode getParent() {
187 private void setParent(YangNode parent) {
188 this.parent = parent;
192 public String getDescription() {
196 private void setDescription(String description) {
197 this.description = description;
201 public String getReference() {
205 private void setReference(String reference) {
206 this.reference = reference;
210 public Status getStatus() {
214 private void setStatus(Status status) {
215 if (status != null) {
216 this.status = status;
221 public boolean isAugmenting() {
225 private void setAugmenting(boolean augmenting) {
226 this.augmenting = augmenting;
230 public boolean isAddedByUses() {
234 private void setAddedByUses(boolean addedByUses) {
235 this.addedByUses = addedByUses;
239 public boolean isConfiguration() {
240 return configuration;
243 private void setConfiguration(boolean configuration) {
244 this.configuration = configuration;
248 public ConstraintDefinition getConstraints() {
249 return constraintsDef;
252 private void setConstraints(ConstraintDefinition constraintsDef) {
253 this.constraintsDef = constraintsDef;
257 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
261 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
262 if (unknownNodes != null) {
263 this.unknownNodes = unknownNodes;
268 public int hashCode() {
269 final int prime = 31;
271 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
272 result = prime * result + ((path == null) ? 0 : path.hashCode());
277 public boolean equals(Object obj) {
284 if (getClass() != obj.getClass()) {
287 AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj;
289 if (other.qname != null) {
292 } else if (!qname.equals(other.qname)) {
296 if (other.path != null) {
299 } else if (!path.equals(other.path)) {
306 public String toString() {
307 StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
309 sb.append("qname=" + qname);
310 sb.append(", path=" + path);
312 return sb.toString();