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.ArrayList;
11 import java.util.Collections;
12 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.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() {
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());
112 if (unknownNodes == null) {
113 unknownNodes = new ArrayList<UnknownSchemaNode>();
114 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
115 unknownNodes.add(b.build());
117 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
119 instance.setUnknownSchemaNodes(unknownNodes);
127 public void setQName(QName qname) {
131 public boolean isAddedByUses() {
135 public void setAddedByUses(final boolean addedByUses) {
136 this.addedByUses = addedByUses;
139 public QName getNodeType() {
143 public void setNodeType(final QName nodeType) {
144 this.nodeType = nodeType;
147 public String getNodeParameter() {
148 return nodeParameter;
151 public void setNodeParameter(final String nodeParameter) {
152 this.nodeParameter = nodeParameter;
155 public ExtensionDefinition getExtensionDefinition() {
156 return extensionDefinition;
159 public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
160 this.extensionDefinition = extensionDefinition;
163 public ExtensionBuilder getExtensionBuilder() {
164 return extensionBuilder;
167 public void setExtensionBuilder(final ExtensionBuilder extension) {
168 this.extensionBuilder = extension;
172 public String toString() {
173 StringBuilder sb = new StringBuilder();
174 sb.append(nodeType.getPrefix());
176 sb.append(nodeType.getLocalName());
178 sb.append(nodeParameter);
179 return sb.toString();
182 private final class UnknownSchemaNodeImpl implements UnknownSchemaNode {
183 private final QName qname;
184 private SchemaPath path;
185 private ExtensionDefinition extension;
186 private String description;
187 private String reference;
188 private Status status = Status.CURRENT;
189 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
190 private QName nodeType;
191 private String nodeParameter;
192 private boolean addedByUses;
194 private UnknownSchemaNodeImpl(final QName qname) {
199 public QName getQName() {
204 public SchemaPath getPath() {
208 private void setPath(final SchemaPath path) {
213 public ExtensionDefinition getExtensionDefinition() {
217 private void setExtensionDefinition(final ExtensionDefinition extension) {
218 this.extension = extension;
222 public String getDescription() {
226 private void setDescription(final String description) {
227 this.description = description;
231 public String getReference() {
235 private void setReference(final String reference) {
236 this.reference = reference;
240 public Status getStatus() {
244 private void setStatus(final Status status) {
245 if (status != null) {
246 this.status = status;
251 public boolean isAddedByUses() {
255 private void setAddedByUses(final boolean addedByUses) {
256 this.addedByUses = addedByUses;
260 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
264 private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
265 if (unknownNodes != null) {
266 this.unknownNodes = unknownNodes;
271 public QName getNodeType() {
275 private void setNodeType(final QName nodeType) {
276 this.nodeType = nodeType;
280 public String getNodeParameter() {
281 return nodeParameter;
284 private void setNodeParameter(final String nodeParameter) {
285 this.nodeParameter = nodeParameter;
289 public String toString() {
290 StringBuilder sb = new StringBuilder();
291 sb.append(nodeType.getPrefix());
293 sb.append(nodeType.getLocalName());
295 sb.append(nodeParameter);
296 return sb.toString();
300 public int hashCode() {
301 final int prime = 31;
303 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
304 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
305 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
306 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
311 public boolean equals(Object obj) {
318 if (getClass() != obj.getClass()) {
321 UnknownSchemaNodeImpl other = (UnknownSchemaNodeImpl) obj;
323 if (other.qname != null) {
326 } else if (!qname.equals(other.qname)) {
330 if (other.path != null) {
333 } else if (!path.equals(other.path)) {
336 if (nodeType == null) {
337 if (other.nodeType != null) {
340 } else if (!nodeType.equals(other.nodeType)) {
343 if (nodeParameter == null) {
344 if (other.nodeParameter != null) {
347 } else if (!nodeParameter.equals(other.nodeParameter)) {