BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / UnknownSchemaNodeBuilderImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.builder.impl;
9
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;
22
23 /**
24  * @deprecated Pre-Beryllium implementation, scheduled for removal.
25  */
26 @Deprecated
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;
34
35     private UnknownSchemaNodeImpl instance;
36     private QName nodeType;
37     private String nodeParameter;
38
39     private ExtensionDefinition extensionDefinition;
40     private ExtensionBuilder extensionBuilder;
41
42     public UnknownSchemaNodeBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path) {
43         super(moduleName, line);
44         this.qname = qname;
45         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
46     }
47
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");
52
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());
61     }
62
63     @Override
64     public QName getQName() {
65         return qname;
66     }
67
68     @Override
69     public SchemaPath getPath() {
70         return schemaPath;
71     }
72
73     @Override
74     public void setPath(final SchemaPath schemaPath) {
75         this.schemaPath = schemaPath;
76     }
77
78     @Override
79     public int hashCode() {
80         final int prime = 31;
81         int result = 1;
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);
86         return result;
87     }
88
89     @Override
90     public boolean equals(final Object obj) {
91         if (this == obj) {
92             return true;
93         }
94         if (obj == null) {
95             return false;
96         }
97         if (getClass() != obj.getClass()) {
98             return false;
99         }
100         UnknownSchemaNodeBuilderImpl other = (UnknownSchemaNodeBuilderImpl) obj;
101         if (qname == null) {
102             if (other.qname != null) {
103                 return false;
104             }
105         } else if (!qname.equals(other.qname)) {
106             return false;
107         }
108         if (schemaPath == null) {
109             if (other.schemaPath != null) {
110                 return false;
111             }
112         } else if (!schemaPath.equals(other.schemaPath)) {
113             return false;
114         }
115         if (nodeType == null) {
116             if (other.nodeType != null) {
117                 return false;
118             }
119         } else if (!nodeType.equals(other.nodeType)) {
120             return false;
121         }
122         if (nodeParameter == null) {
123             if (other.nodeParameter != null) {
124                 return false;
125             }
126         } else if (!nodeParameter.equals(other.nodeParameter)) {
127             return false;
128         }
129         return true;
130     }
131
132     @Override
133     public UnknownSchemaNode build() {
134         if (instance != null) {
135             return instance;
136         }
137
138         instance = new UnknownSchemaNodeImpl(qname, schemaPath);
139
140         instance.setNodeType(nodeType);
141         instance.setNodeParameter(nodeParameter);
142
143         instance.description = description;
144         instance.reference = reference;
145         instance.status = status;
146         instance.addedByUses = addedByUses;
147
148         // EXTENSION
149         if (extensionDefinition != null) {
150             instance.setExtensionDefinition(extensionDefinition);
151         } else {
152             if (extensionBuilder != null) {
153                 instance.setExtensionDefinition(extensionBuilder.build());
154             }
155         }
156
157         // UNKNOWN NODES
158         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
159             unknownNodes.add(b.build());
160         }
161         Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
162         instance.setUnknownSchemaNodes(unknownNodes);
163
164         return instance;
165     }
166
167     @Override
168     public String getDescription() {
169         return description;
170     }
171
172     @Override
173     public void setDescription(final String description) {
174         this.description = description;
175     }
176
177     @Override
178     public String getReference() {
179         return reference;
180     }
181
182     @Override
183     public void setReference(final String reference) {
184         this.reference = reference;
185     }
186
187     @Override
188     public Status getStatus() {
189         return status;
190     }
191
192     @Override
193     public void setStatus(final Status status) {
194         if (status != null) {
195             this.status = status;
196         }
197     }
198
199     @Override
200     public boolean isAddedByUses() {
201         return addedByUses;
202     }
203
204     @Override
205     public void setAddedByUses(final boolean addedByUses) {
206         this.addedByUses = addedByUses;
207     }
208
209     @Override
210     public QName getNodeType() {
211         return nodeType;
212     }
213
214     @Override
215     public void setNodeType(final QName nodeType) {
216         this.nodeType = nodeType;
217     }
218
219     @Override
220     public String getNodeParameter() {
221         return nodeParameter;
222     }
223
224     @Override
225     public void setNodeParameter(final String nodeParameter) {
226         this.nodeParameter = nodeParameter;
227     }
228
229     @Override
230     public ExtensionDefinition getExtensionDefinition() {
231         return extensionDefinition;
232     }
233
234     @Override
235     public void setExtensionDefinition(final ExtensionDefinition extensionDefinition) {
236         this.extensionDefinition = extensionDefinition;
237     }
238
239     @Override
240     public ExtensionBuilder getExtensionBuilder() {
241         return extensionBuilder;
242     }
243
244     @Override
245     public void setExtensionBuilder(final ExtensionBuilder extension) {
246         this.extensionBuilder = extension;
247     }
248
249     @Override
250     public String toString() {
251         StringBuilder sb = new StringBuilder();
252         sb.append(nodeType.getNamespace());
253         sb.append(":");
254         sb.append(nodeType.getLocalName());
255         sb.append(" ");
256         sb.append(nodeParameter);
257         return sb.toString();
258     }
259
260 }