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 java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
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.parser.builder.api.ExtensionBuilder;
20 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
24 public final class UnknownSchemaNodeBuilderImpl extends AbstractBuilder implements UnknownSchemaNodeBuilder {
26 private SchemaPath schemaPath;
27 private String description;
28 private String reference;
29 private Status status = Status.CURRENT;
30 private boolean addedByUses;
32 private UnknownSchemaNodeImpl instance;
33 private QName nodeType;
34 private String nodeParameter;
36 private ExtensionDefinition extensionDefinition;
37 private ExtensionBuilder extensionBuilder;
39 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path) {
40 super(moduleName, line);
42 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
45 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path, final UnknownSchemaNode base) {
46 super(moduleName, line);
47 this.qname = base.getQName();
48 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
50 this.nodeType = base.getNodeType();
51 this.nodeParameter = base.getNodeParameter();
52 this.description = base.getDescription();
53 this.reference = base.getReference();
54 this.status = base.getStatus();
55 this.addedByUses = base.isAddedByUses();
56 this.extensionDefinition = base.getExtensionDefinition();
57 this.unknownNodes.addAll(base.getUnknownSchemaNodes());
61 public QName getQName() {
66 public SchemaPath getPath() {
71 public void setPath(SchemaPath schemaPath) {
72 this.schemaPath = schemaPath;
76 public int hashCode() {
79 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
80 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
81 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
82 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
87 public boolean equals(final Object obj) {
94 if (getClass() != obj.getClass()) {
97 UnknownSchemaNodeBuilderImpl other = (UnknownSchemaNodeBuilderImpl) obj;
99 if (other.qname != null) {
102 } else if (!qname.equals(other.qname)) {
105 if (schemaPath == null) {
106 if (other.schemaPath != null) {
109 } else if (!schemaPath.equals(other.schemaPath)) {
112 if (nodeType == null) {
113 if (other.nodeType != null) {
116 } else if (!nodeType.equals(other.nodeType)) {
119 if (nodeParameter == null) {
120 if (other.nodeParameter != null) {
123 } else if (!nodeParameter.equals(other.nodeParameter)) {
130 public UnknownSchemaNode build() {
131 if (instance != null) {
135 instance = new UnknownSchemaNodeImpl(qname, schemaPath);
137 instance.setNodeType(nodeType);
138 instance.setNodeParameter(nodeParameter);
140 instance.description = description;
141 instance.reference = reference;
142 instance.status = status;
143 instance.addedByUses = addedByUses;
146 if (extensionDefinition != null) {
147 instance.setExtensionDefinition(extensionDefinition);
149 if (extensionBuilder != null) {
150 instance.setExtensionDefinition(extensionBuilder.build());
155 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
156 unknownNodes.add(b.build());
158 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
159 instance.setUnknownSchemaNodes(unknownNodes);
165 public String getDescription() {
170 public void setDescription(final String description) {
171 this.description = description;
175 public String getReference() {
180 public void setReference(final String reference) {
181 this.reference = reference;
185 public Status getStatus() {
190 public void setStatus(final Status status) {
191 if (status != null) {
192 this.status = status;
197 public boolean isAddedByUses() {
202 public void setAddedByUses(final boolean addedByUses) {
203 this.addedByUses = addedByUses;
207 public QName getNodeType() {
212 public void setNodeType(final QName nodeType) {
213 this.nodeType = nodeType;
217 public String getNodeParameter() {
218 return nodeParameter;
222 public void setNodeParameter(final String nodeParameter) {
223 this.nodeParameter = nodeParameter;
227 public ExtensionDefinition getExtensionDefinition() {
228 return extensionDefinition;
232 public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
233 this.extensionDefinition = extensionDefinition;
237 public ExtensionBuilder getExtensionBuilder() {
238 return extensionBuilder;
242 public void setExtensionBuilder(final ExtensionBuilder extension) {
243 this.extensionBuilder = extension;
247 public String toString() {
248 StringBuilder sb = new StringBuilder();
249 sb.append(nodeType.getNamespace());
251 sb.append(nodeType.getLocalName());
253 sb.append(nodeParameter);
254 return sb.toString();
257 private static final class UnknownSchemaNodeImpl implements UnknownSchemaNode {
258 private final QName qname;
259 private final SchemaPath path;
260 private ExtensionDefinition extension;
261 private String description;
262 private String reference;
263 private Status status = Status.CURRENT;
264 private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
265 private QName nodeType;
266 private String nodeParameter;
267 private boolean addedByUses;
269 private UnknownSchemaNodeImpl(final QName qname, final SchemaPath path) {
275 public QName getQName() {
280 public SchemaPath getPath() {
285 public ExtensionDefinition getExtensionDefinition() {
289 private void setExtensionDefinition(final ExtensionDefinition extension) {
290 this.extension = extension;
294 public String getDescription() {
299 public String getReference() {
304 public Status getStatus() {
309 public boolean isAddedByUses() {
314 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
318 private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
319 if (unknownNodes != null) {
320 this.unknownNodes.addAll(unknownNodes);
325 public QName getNodeType() {
329 private void setNodeType(final QName nodeType) {
330 this.nodeType = nodeType;
334 public String getNodeParameter() {
335 return nodeParameter;
338 private void setNodeParameter(final String nodeParameter) {
339 this.nodeParameter = nodeParameter;
343 public String toString() {
344 StringBuilder sb = new StringBuilder();
345 sb.append(nodeType.getNamespace());
347 sb.append(nodeType.getLocalName());
349 sb.append(nodeParameter);
350 return sb.toString();
354 public int hashCode() {
355 final int prime = 31;
357 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
358 result = prime * result + ((path == null) ? 0 : path.hashCode());
359 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
360 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
365 public boolean equals(final Object obj) {
372 if (getClass() != obj.getClass()) {
375 UnknownSchemaNodeImpl other = (UnknownSchemaNodeImpl) obj;
377 if (other.qname != null) {
380 } else if (!qname.equals(other.qname)) {
384 if (other.path != null) {
387 } else if (!path.equals(other.path)) {
390 if (nodeType == null) {
391 if (other.nodeType != null) {
394 } else if (!nodeType.equals(other.nodeType)) {
397 if (nodeParameter == null) {
398 if (other.nodeParameter != null) {
401 } else if (!nodeParameter.equals(other.nodeParameter)) {