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.ExtensionDefinition;
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.model.api.YangNode;
19 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;
20 import org.opendaylight.yangtools.yang.parser.util.Comparators;
22 public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
23 private boolean isBuilt;
24 private final UnknownSchemaNodeImpl instance;
25 private boolean addedByUses;
26 private QName nodeType;
27 private String nodeParameter;
29 private ExtensionDefinition extensionDefinition;
30 private ExtensionBuilder extensionBuilder;
32 public UnknownSchemaNodeBuilder(final String moduleName, final int line, final QName qname) {
33 super(moduleName, line, qname);
34 instance = new UnknownSchemaNodeImpl(qname);
38 public int hashCode() {
41 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
42 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
43 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
44 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
49 public boolean equals(Object obj) {
56 if (getClass() != obj.getClass()) {
59 UnknownSchemaNodeBuilder other = (UnknownSchemaNodeBuilder) obj;
61 if (other.qname != null) {
64 } else if (!qname.equals(other.qname)) {
67 if (schemaPath == null) {
68 if (other.schemaPath != null) {
71 } else if (!schemaPath.equals(other.schemaPath)) {
74 if (nodeType == null) {
75 if (other.nodeType != null) {
78 } else if (!nodeType.equals(other.nodeType)) {
81 if (nodeParameter == null) {
82 if (other.nodeParameter != null) {
85 } else if (!nodeParameter.equals(other.nodeParameter)) {
92 public UnknownSchemaNode build(YangNode parent) {
94 instance.setPath(schemaPath);
95 instance.setNodeType(nodeType);
96 instance.setNodeParameter(nodeParameter);
97 instance.setDescription(description);
98 instance.setReference(reference);
99 instance.setStatus(status);
100 instance.setAddedByUses(addedByUses);
103 if (extensionDefinition != null) {
104 instance.setExtensionDefinition(extensionDefinition);
106 if (extensionBuilder != null) {
107 instance.setExtensionDefinition(extensionBuilder.build(null));
112 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
113 unknownNodes.add(b.build(null));
115 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
116 instance.setUnknownSchemaNodes(unknownNodes);
124 public void setQName(QName qname) {
128 public boolean isAddedByUses() {
132 public void setAddedByUses(final boolean addedByUses) {
133 this.addedByUses = addedByUses;
136 public QName getNodeType() {
140 public void setNodeType(final QName nodeType) {
141 this.nodeType = nodeType;
144 public String getNodeParameter() {
145 return nodeParameter;
148 public void setNodeParameter(final String nodeParameter) {
149 this.nodeParameter = nodeParameter;
152 public ExtensionDefinition getExtensionDefinition() {
153 return extensionDefinition;
156 public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
157 this.extensionDefinition = extensionDefinition;
160 public ExtensionBuilder getExtensionBuilder() {
161 return extensionBuilder;
164 public void setExtensionBuilder(final ExtensionBuilder extension) {
165 this.extensionBuilder = extension;
169 public String toString() {
170 StringBuilder sb = new StringBuilder();
171 sb.append(nodeType.getPrefix());
173 sb.append(nodeType.getLocalName());
175 sb.append(nodeParameter);
176 return sb.toString();
179 private final class UnknownSchemaNodeImpl implements UnknownSchemaNode {
180 private final QName qname;
181 private SchemaPath path;
182 private ExtensionDefinition extension;
183 private String description;
184 private String reference;
185 private Status status = Status.CURRENT;
186 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
187 private QName nodeType;
188 private String nodeParameter;
189 private boolean addedByUses;
191 private UnknownSchemaNodeImpl(final QName qname) {
196 public QName getQName() {
201 public SchemaPath getPath() {
205 private void setPath(final SchemaPath path) {
210 public ExtensionDefinition getExtensionDefinition() {
214 private void setExtensionDefinition(final ExtensionDefinition extension) {
215 this.extension = extension;
219 public String getDescription() {
223 private void setDescription(final String description) {
224 this.description = description;
228 public String getReference() {
232 private void setReference(final String reference) {
233 this.reference = reference;
237 public Status getStatus() {
241 private void setStatus(final Status status) {
242 if (status != null) {
243 this.status = status;
248 public boolean isAddedByUses() {
252 private void setAddedByUses(final boolean addedByUses) {
253 this.addedByUses = addedByUses;
257 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
261 private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
262 if (unknownNodes != null) {
263 this.unknownNodes = unknownNodes;
268 public QName getNodeType() {
272 private void setNodeType(final QName nodeType) {
273 this.nodeType = nodeType;
277 public String getNodeParameter() {
278 return nodeParameter;
281 private void setNodeParameter(final String nodeParameter) {
282 this.nodeParameter = nodeParameter;
286 public String toString() {
287 StringBuilder sb = new StringBuilder();
288 sb.append(nodeType.getPrefix());
290 sb.append(nodeType.getLocalName());
292 sb.append(nodeParameter);
293 return sb.toString();
297 public int hashCode() {
298 final int prime = 31;
300 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
301 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
302 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
303 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
308 public boolean equals(Object obj) {
315 if (getClass() != obj.getClass()) {
318 UnknownSchemaNodeImpl other = (UnknownSchemaNodeImpl) 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)) {
333 if (nodeType == null) {
334 if (other.nodeType != null) {
337 } else if (!nodeType.equals(other.nodeType)) {
340 if (nodeParameter == null) {
341 if (other.nodeParameter != null) {
344 } else if (!nodeParameter.equals(other.nodeParameter)) {