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.Collections;
12 import java.util.Objects;
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.parser.builder.api.ExtensionBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
20 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
23 public final class UnknownSchemaNodeBuilderImpl extends AbstractBuilder implements UnknownSchemaNodeBuilder {
25 private SchemaPath schemaPath;
26 private String description;
27 private String reference;
28 private Status status = Status.CURRENT;
29 private boolean addedByUses;
31 private UnknownSchemaNodeImpl instance;
32 private QName nodeType;
33 private String nodeParameter;
35 private ExtensionDefinition extensionDefinition;
36 private ExtensionBuilder extensionBuilder;
38 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path) {
39 super(moduleName, line);
41 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
44 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path, final UnknownSchemaNode base) {
45 super(moduleName, line);
46 this.qname = base.getQName();
47 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
49 this.nodeType = base.getNodeType();
50 this.nodeParameter = base.getNodeParameter();
51 this.description = base.getDescription();
52 this.reference = base.getReference();
53 this.status = base.getStatus();
54 this.addedByUses = base.isAddedByUses();
55 this.extensionDefinition = base.getExtensionDefinition();
56 this.unknownNodes.addAll(base.getUnknownSchemaNodes());
60 public QName getQName() {
65 public SchemaPath getPath() {
70 public void setPath(SchemaPath schemaPath) {
71 this.schemaPath = schemaPath;
75 public int hashCode() {
78 result = prime * result + Objects.hashCode(qname);
79 result = prime * result + Objects.hashCode(schemaPath);
80 result = prime * result + Objects.hashCode(nodeType);
81 result = prime * result + Objects.hashCode(nodeParameter);
86 public boolean equals(final Object obj) {
93 if (getClass() != obj.getClass()) {
96 UnknownSchemaNodeBuilderImpl other = (UnknownSchemaNodeBuilderImpl) obj;
98 if (other.qname != null) {
101 } else if (!qname.equals(other.qname)) {
104 if (schemaPath == null) {
105 if (other.schemaPath != null) {
108 } else if (!schemaPath.equals(other.schemaPath)) {
111 if (nodeType == null) {
112 if (other.nodeType != null) {
115 } else if (!nodeType.equals(other.nodeType)) {
118 if (nodeParameter == null) {
119 if (other.nodeParameter != null) {
122 } else if (!nodeParameter.equals(other.nodeParameter)) {
129 public UnknownSchemaNode build() {
130 if (instance != null) {
134 instance = new UnknownSchemaNodeImpl(qname, schemaPath);
136 instance.setNodeType(nodeType);
137 instance.setNodeParameter(nodeParameter);
139 instance.description = description;
140 instance.reference = reference;
141 instance.status = status;
142 instance.addedByUses = addedByUses;
145 if (extensionDefinition != null) {
146 instance.setExtensionDefinition(extensionDefinition);
148 if (extensionBuilder != null) {
149 instance.setExtensionDefinition(extensionBuilder.build());
154 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
155 unknownNodes.add(b.build());
157 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
158 instance.setUnknownSchemaNodes(unknownNodes);
164 public String getDescription() {
169 public void setDescription(final String description) {
170 this.description = description;
174 public String getReference() {
179 public void setReference(final String reference) {
180 this.reference = reference;
184 public Status getStatus() {
189 public void setStatus(final Status status) {
190 if (status != null) {
191 this.status = status;
196 public boolean isAddedByUses() {
201 public void setAddedByUses(final boolean addedByUses) {
202 this.addedByUses = addedByUses;
206 public QName getNodeType() {
211 public void setNodeType(final QName nodeType) {
212 this.nodeType = nodeType;
216 public String getNodeParameter() {
217 return nodeParameter;
221 public void setNodeParameter(final String nodeParameter) {
222 this.nodeParameter = nodeParameter;
226 public ExtensionDefinition getExtensionDefinition() {
227 return extensionDefinition;
231 public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
232 this.extensionDefinition = extensionDefinition;
236 public ExtensionBuilder getExtensionBuilder() {
237 return extensionBuilder;
241 public void setExtensionBuilder(final ExtensionBuilder extension) {
242 this.extensionBuilder = extension;
246 public String toString() {
247 StringBuilder sb = new StringBuilder();
248 sb.append(nodeType.getNamespace());
250 sb.append(nodeType.getLocalName());
252 sb.append(nodeParameter);
253 return sb.toString();