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;
24 * @deprecated Pre-Beryllium implementation, scheduled for removal.
27 public final class UnknownSchemaNodeBuilderImpl extends AbstractBuilder implements UnknownSchemaNodeBuilder {
28 private final QName qname;
29 private SchemaPath schemaPath;
30 private String description;
31 private String reference;
32 private Status status = Status.CURRENT;
33 private boolean addedByUses;
35 private UnknownSchemaNodeImpl instance;
36 private QName nodeType;
37 private String nodeParameter;
39 private ExtensionDefinition extensionDefinition;
40 private ExtensionBuilder extensionBuilder;
42 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path) {
43 super(moduleName, line);
45 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
48 public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path, final UnknownSchemaNode base) {
49 super(moduleName, line);
50 this.qname = base.getQName();
51 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
53 this.nodeType = base.getNodeType();
54 this.nodeParameter = base.getNodeParameter();
55 this.description = base.getDescription();
56 this.reference = base.getReference();
57 this.status = base.getStatus();
58 this.addedByUses = base.isAddedByUses();
59 this.extensionDefinition = base.getExtensionDefinition();
60 this.unknownNodes.addAll(base.getUnknownSchemaNodes());
64 public QName getQName() {
69 public SchemaPath getPath() {
74 public void setPath(final SchemaPath schemaPath) {
75 this.schemaPath = schemaPath;
79 public int hashCode() {
82 result = prime * result + Objects.hashCode(qname);
83 result = prime * result + Objects.hashCode(schemaPath);
84 result = prime * result + Objects.hashCode(nodeType);
85 result = prime * result + Objects.hashCode(nodeParameter);
90 public boolean equals(final Object obj) {
97 if (getClass() != obj.getClass()) {
100 UnknownSchemaNodeBuilderImpl other = (UnknownSchemaNodeBuilderImpl) obj;
102 if (other.qname != null) {
105 } else if (!qname.equals(other.qname)) {
108 if (schemaPath == null) {
109 if (other.schemaPath != null) {
112 } else if (!schemaPath.equals(other.schemaPath)) {
115 if (nodeType == null) {
116 if (other.nodeType != null) {
119 } else if (!nodeType.equals(other.nodeType)) {
122 if (nodeParameter == null) {
123 if (other.nodeParameter != null) {
126 } else if (!nodeParameter.equals(other.nodeParameter)) {
133 public UnknownSchemaNode build() {
134 if (instance != null) {
138 instance = new UnknownSchemaNodeImpl(qname, schemaPath);
140 instance.setNodeType(nodeType);
141 instance.setNodeParameter(nodeParameter);
143 instance.description = description;
144 instance.reference = reference;
145 instance.status = status;
146 instance.addedByUses = addedByUses;
149 if (extensionDefinition != null) {
150 instance.setExtensionDefinition(extensionDefinition);
152 if (extensionBuilder != null) {
153 instance.setExtensionDefinition(extensionBuilder.build());
158 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
159 unknownNodes.add(b.build());
161 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
162 instance.setUnknownSchemaNodes(unknownNodes);
168 public String getDescription() {
173 public void setDescription(final String description) {
174 this.description = description;
178 public String getReference() {
183 public void setReference(final String reference) {
184 this.reference = reference;
188 public Status getStatus() {
193 public void setStatus(final Status status) {
194 if (status != null) {
195 this.status = status;
200 public boolean isAddedByUses() {
205 public void setAddedByUses(final boolean addedByUses) {
206 this.addedByUses = addedByUses;
210 public QName getNodeType() {
215 public void setNodeType(final QName nodeType) {
216 this.nodeType = nodeType;
220 public String getNodeParameter() {
221 return nodeParameter;
225 public void setNodeParameter(final String nodeParameter) {
226 this.nodeParameter = nodeParameter;
230 public ExtensionDefinition getExtensionDefinition() {
231 return extensionDefinition;
235 public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
236 this.extensionDefinition = extensionDefinition;
240 public ExtensionBuilder getExtensionBuilder() {
241 return extensionBuilder;
245 public void setExtensionBuilder(final ExtensionBuilder extension) {
246 this.extensionBuilder = extension;
250 public String toString() {
251 return String.valueOf(nodeType.getNamespace()) +
253 nodeType.getLocalName() +