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) {
68 instance.setQName(qname);
72 public ConstraintsBuilder getConstraints() {
76 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
77 return addedUnknownNodes;
81 public boolean isAugmenting() {
86 public void setAugmenting(final boolean augmenting) {
87 this.augmenting = augmenting;
91 public boolean isAddedByUses() {
96 public void setAddedByUses(final boolean addedByUses) {
97 this.addedByUses = addedByUses;
101 public Boolean isConfiguration() {
102 return configuration;
106 public void setConfiguration(final Boolean configuration) {
107 this.configuration = configuration;
111 public int hashCode() {
112 final int prime = 31;
114 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
119 public boolean equals(Object obj) {
126 if (getClass() != obj.getClass()) {
129 AnyXmlBuilder other = (AnyXmlBuilder) obj;
130 if (schemaPath == null) {
131 if (other.schemaPath != null) {
134 } else if (!schemaPath.equals(other.schemaPath)) {
137 if (parentBuilder == null) {
138 if (other.parentBuilder != null) {
141 } else if (!parentBuilder.equals(other.parentBuilder)) {
148 public String toString() {
149 return "anyxml " + qname.getLocalName();
152 private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
154 private SchemaPath path;
155 private YangNode parent;
156 private String description;
157 private String reference;
158 private Status status = Status.CURRENT;
159 private boolean configuration;
160 private ConstraintDefinition constraintsDef;
161 private boolean augmenting;
162 private boolean addedByUses;
163 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
165 private AnyXmlSchemaNodeImpl(final QName qname) {
170 public QName getQName() {
174 private void setQName(QName qname) {
179 public SchemaPath getPath() {
183 private void setPath(final SchemaPath path) {
188 public YangNode getParent() {
192 private void setParent(YangNode parent) {
193 this.parent = parent;
197 public String getDescription() {
201 private void setDescription(String description) {
202 this.description = description;
206 public String getReference() {
210 private void setReference(String reference) {
211 this.reference = reference;
215 public Status getStatus() {
219 private void setStatus(Status status) {
220 if (status != null) {
221 this.status = status;
226 public boolean isAugmenting() {
230 private void setAugmenting(boolean augmenting) {
231 this.augmenting = augmenting;
235 public boolean isAddedByUses() {
239 private void setAddedByUses(boolean addedByUses) {
240 this.addedByUses = addedByUses;
244 public boolean isConfiguration() {
245 return configuration;
248 private void setConfiguration(boolean configuration) {
249 this.configuration = configuration;
253 public ConstraintDefinition getConstraints() {
254 return constraintsDef;
257 private void setConstraints(ConstraintDefinition constraintsDef) {
258 this.constraintsDef = constraintsDef;
262 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
266 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
267 if (unknownNodes != null) {
268 this.unknownNodes = unknownNodes;
273 public int hashCode() {
274 final int prime = 31;
276 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
277 result = prime * result + ((path == null) ? 0 : path.hashCode());
282 public boolean equals(Object obj) {
289 if (getClass() != obj.getClass()) {
292 AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj;
294 if (other.qname != null) {
297 } else if (!qname.equals(other.qname)) {
301 if (other.path != null) {
304 } else if (!path.equals(other.path)) {
311 public String toString() {
312 StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
314 sb.append("qname=" + qname);
315 sb.append(", path=" + path);
317 return sb.toString();