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.controller.yang.model.parser.builder.impl;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.controller.model.util.UnknownType;
14 import org.opendaylight.controller.model.util.YangTypesConverter;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.TypeDefinition;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
21 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
24 public class TypedefBuilder implements TypeDefinitionBuilder,
25 SchemaNodeBuilder, TypeAwareBuilder {
27 private final QName qname;
28 private SchemaPath schemaPath;
29 private TypeDefinition<?> baseType;
31 private String description;
32 private String reference;
33 private Status status;
36 TypedefBuilder(QName qname) {
41 public TypeDefinition<? extends TypeDefinition<?>> build() {
42 final TypeDefinition<?> type = YangTypesConverter
43 .javaTypeForBaseYangType(qname);
47 if (baseType != null) {
49 TypeDefinitionImpl instance = new TypeDefinitionImpl(qname);
50 instance.setDescription(description);
51 instance.setReference(reference);
52 instance.setStatus(status);
53 instance.setPath(schemaPath);
54 instance.setBaseType(baseType);
55 instance.setUnits(units);
59 final UnknownType.Builder unknownBuilder = new UnknownType.Builder(
60 qname, description, reference);
61 unknownBuilder.status(status);
62 return unknownBuilder.build();
68 public QName getQName() {
73 public void setPath(final SchemaPath schemaPath) {
74 this.schemaPath = schemaPath;
78 public void setDescription(final String description) {
79 this.description = description;
83 public void setReference(final String reference) {
84 this.reference = reference;
88 public void setStatus(final Status status) {
95 public void setUnits(String units) {
100 public TypeDefinition<?> getType() {
105 public void setType(TypeDefinition<?> baseType) {
106 this.baseType = baseType;
110 public TypeDefinition<?> getBaseType() {
114 private static class TypeDefinitionImpl<T extends TypeDefinition<T>>
115 implements TypeDefinition<T> {
117 private final QName qname;
118 private SchemaPath path;
119 private String description;
120 private String reference;
121 private Status status = Status.CURRENT;
123 private String units;
124 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
126 private TypeDefinitionImpl(QName qname) {
131 public QName getQName() {
136 public SchemaPath getPath() {
140 private void setPath(SchemaPath path) {
145 public String getDescription() {
149 private void setDescription(String description) {
150 this.description = description;
154 public String getReference() {
158 private void setReference(String reference) {
159 this.reference = reference;
163 public Status getStatus() {
167 private void setStatus(Status status) {
168 this.status = status;
172 public T getBaseType() {
176 private void setBaseType(T type) {
177 this.baseType = type;
181 public String getUnits() {
185 private void setUnits(String units) {
190 public Object getDefaultValue() {
191 // TODO Auto-generated method stub
196 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
197 return unknownSchemaNodes;
201 public int hashCode() {
202 final int prime = 31;
204 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
205 result = prime * result + ((path == null) ? 0 : path.hashCode());
206 result = prime * result
207 + ((description == null) ? 0 : description.hashCode());
208 result = prime * result
209 + ((reference == null) ? 0 : reference.hashCode());
210 result = prime * result
211 + ((status == null) ? 0 : status.hashCode());
212 result = prime * result
213 + ((baseType == null) ? 0 : baseType.hashCode());
214 result = prime * result + ((units == null) ? 0 : units.hashCode());
219 public boolean equals(Object obj) {
226 if (getClass() != obj.getClass()) {
229 TypeDefinitionImpl other = (TypeDefinitionImpl) obj;
231 if (other.qname != null) {
234 } else if (!qname.equals(other.qname)) {
238 if (other.path != null) {
241 } else if (!path.equals(other.path)) {
244 if (description == null) {
245 if (other.description != null) {
248 } else if (!description.equals(other.description)) {
251 if (reference == null) {
252 if (other.reference != null) {
255 } else if (!reference.equals(other.reference)) {
258 if (status == null) {
259 if (other.status != null) {
262 } else if (!status.equals(other.status)) {
265 if (baseType == null) {
266 if (other.baseType != null) {
269 } else if (!baseType.equals(other.baseType)) {
273 if (other.units != null) {
276 } else if (!units.equals(other.units)) {
283 public String toString() {
284 final StringBuilder sb = new StringBuilder(
285 TypeDefinitionImpl.class.getSimpleName());
287 sb.append("qname=" + qname);
288 sb.append(", path=" + path);
289 sb.append(", description=" + description);
290 sb.append(", reference=" + reference);
291 sb.append(", status=" + status);
292 sb.append(", baseType=" + baseType + "]");
293 return sb.toString();