2 * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
13 import org.opendaylight.yangtools.yang.model.api.Status;
14 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Builder of {@link TypeDefinitions} for use in typedef statements.
21 * @param <T> Resulting {@link TypeDefinition}
23 public abstract class DerivedTypeBuilder<T extends TypeDefinition<T>> extends TypeBuilder<T> {
24 private static final Logger LOG = LoggerFactory.getLogger(DecimalTypeBuilder.class);
25 private Object defaultValue;
26 private String description;
27 private String reference;
28 private Status status = Status.CURRENT;
31 DerivedTypeBuilder(final T baseType, final SchemaPath path) {
32 super(Preconditions.checkNotNull(baseType), path);
34 Preconditions.checkArgument(baseType instanceof AbstractBaseType
35 || baseType instanceof AbstractDerivedType || baseType instanceof AbstractRestrictedType,
36 "Derived type can be built only from a base, derived, or restricted type, not %s", baseType);
38 // http://tools.ietf.org/html/rfc6020#section-7.3.4
39 defaultValue = baseType.getDefaultValue();
41 // In similar vein, it makes sense to propagate units
42 units = baseType.getUnits();
45 public void setDefaultValue(@Nonnull final Object defaultValue) {
46 this.defaultValue = Preconditions.checkNotNull(defaultValue);
49 public final void setDescription(@Nonnull final String description) {
50 this.description = Preconditions.checkNotNull(description);
53 public final void setReference(@Nonnull final String reference) {
54 this.reference = Preconditions.checkNotNull(reference);
57 public final void setStatus(@Nonnull final Status status) {
58 this.status = Preconditions.checkNotNull(status);
61 public final void setUnits(final String units) {
62 Preconditions.checkNotNull(units);
63 if (getBaseType().getUnits() != null && !units.equals(getBaseType().getUnits())) {
64 LOG.warn("Type {} uverrides 'units' of type {} to \"{}\"", getPath(), getBaseType(), units);
70 final Object getDefaultValue() {
74 final String getDescription() {
78 final String getReference() {
82 final Status getStatus() {
86 final String getUnits() {