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.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
15 import org.opendaylight.controller.yang.model.api.Status;
16 import org.opendaylight.controller.yang.model.api.TypeDefinition;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
19 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
20 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
21 import org.opendaylight.controller.yang.model.util.UnknownType;
22 import org.opendaylight.controller.yang.model.util.YangTypesConverter;
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;
35 private Object defaultValue;
37 TypedefBuilder(QName qname) {
42 public TypeDefinition<? extends TypeDefinition<?>> build() {
43 final TypeDefinition<?> type = YangTypesConverter
44 .javaTypeForBaseYangType(qname);
48 if (baseType != null) {
50 TypeDefinitionImpl instance = new TypeDefinitionImpl(qname);
51 instance.setDescription(description);
52 instance.setReference(reference);
53 instance.setStatus(status);
54 instance.setPath(schemaPath);
55 instance.setBaseType(baseType);
56 instance.setUnits(units);
57 instance.setDefaultValue(defaultValue);
61 final UnknownType.Builder unknownBuilder = new UnknownType.Builder(
62 qname, description, reference);
63 unknownBuilder.status(status);
64 return unknownBuilder.build();
70 public QName getQName() {
75 public void setPath(final SchemaPath schemaPath) {
76 this.schemaPath = schemaPath;
80 public void setDescription(final String description) {
81 this.description = description;
85 public void setReference(final String reference) {
86 this.reference = reference;
90 public void setStatus(final Status status) {
97 public void setUnits(String units) {
102 public void setDefaultValue(Object defaultValue) {
103 this.defaultValue = defaultValue;
107 public TypeDefinition<?> getType() {
112 public void setType(TypeDefinition<?> baseType) {
113 this.baseType = baseType;
117 public TypeDefinition<?> getBaseType() {
122 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
126 private static class TypeDefinitionImpl<T extends TypeDefinition<T>>
127 implements TypeDefinition<T> {
129 private final QName qname;
130 private SchemaPath path;
131 private String description;
132 private String reference;
133 private Status status = Status.CURRENT;
134 private Object defaultValue;
136 private String units;
137 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
139 private TypeDefinitionImpl(QName qname) {
144 public QName getQName() {
149 public SchemaPath getPath() {
153 private void setPath(SchemaPath path) {
158 public String getDescription() {
162 private void setDescription(String description) {
163 this.description = description;
167 public String getReference() {
171 private void setReference(String reference) {
172 this.reference = reference;
176 public Status getStatus() {
180 private void setStatus(Status status) {
181 this.status = status;
185 public T getBaseType() {
189 private void setBaseType(T type) {
190 this.baseType = type;
194 public String getUnits() {
198 private void setUnits(String units) {
203 public Object getDefaultValue() {
207 private void setDefaultValue(Object defaultValue) {
208 this.defaultValue = defaultValue;
212 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
213 return unknownSchemaNodes;
217 public int hashCode() {
218 final int prime = 31;
220 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
221 result = prime * result + ((path == null) ? 0 : path.hashCode());
222 result = prime * result
223 + ((description == null) ? 0 : description.hashCode());
224 result = prime * result
225 + ((reference == null) ? 0 : reference.hashCode());
226 result = prime * result
227 + ((status == null) ? 0 : status.hashCode());
228 result = prime * result
229 + ((baseType == null) ? 0 : baseType.hashCode());
230 result = prime * result + ((units == null) ? 0 : units.hashCode());
235 public boolean equals(Object obj) {
242 if (getClass() != obj.getClass()) {
245 TypeDefinitionImpl other = (TypeDefinitionImpl) obj;
247 if (other.qname != null) {
250 } else if (!qname.equals(other.qname)) {
254 if (other.path != null) {
257 } else if (!path.equals(other.path)) {
260 if (description == null) {
261 if (other.description != null) {
264 } else if (!description.equals(other.description)) {
267 if (reference == null) {
268 if (other.reference != null) {
271 } else if (!reference.equals(other.reference)) {
274 if (status == null) {
275 if (other.status != null) {
278 } else if (!status.equals(other.status)) {
281 if (baseType == null) {
282 if (other.baseType != null) {
285 } else if (!baseType.equals(other.baseType)) {
289 if (other.units != null) {
292 } else if (!units.equals(other.units)) {
299 public String toString() {
300 final StringBuilder sb = new StringBuilder(
301 TypeDefinitionImpl.class.getSimpleName());
303 sb.append("qname=" + qname);
304 sb.append(", path=" + path);
305 sb.append(", description=" + description);
306 sb.append(", reference=" + reference);
307 sb.append(", status=" + status);
308 sb.append(", baseType=" + baseType + "]");
309 return sb.toString();