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.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.TypeDefinition;
18 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
19 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
20 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
21 import org.opendaylight.controller.yang.model.parser.builder.api.AbstractTypeAwareBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
23 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
24 import org.opendaylight.controller.yang.model.util.UnionType;
27 * Builder for YANG union type. User can add type to this union as
28 * TypeDefinition object (resolved type) or in form of TypeDefinitionBuilder.
29 * When build is called, types in builder form will be built and add to resolved
32 public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
33 TypeDefinitionBuilder, Builder {
34 private final List<TypeDefinition<?>> types;
35 private final List<TypeDefinitionBuilder> typedefs;
36 private final UnionType instance;
38 public UnionTypeBuilder() {
39 types = new ArrayList<TypeDefinition<?>>();
40 typedefs = new ArrayList<TypeDefinitionBuilder>();
41 instance = new UnionType(types);
44 public List<TypeDefinition<?>> getTypes() {
49 public TypeDefinition<?> getType() {
53 public List<TypeDefinitionBuilder> getTypedefs() {
54 return Collections.unmodifiableList(typedefs);
58 public TypeDefinitionBuilder getTypedef() {
63 public void setType(final TypeDefinition<?> type) {
68 public void setType(final TypeDefinitionBuilder tdb) {
73 public UnionType build() {
74 for (TypeDefinitionBuilder tdb : typedefs) {
75 types.add(tdb.build());
81 public void setPath(final SchemaPath schemaPath) {
82 throw new IllegalStateException("Can not set path to "
83 + UnionTypeBuilder.class.getSimpleName());
87 public void setDescription(final String description) {
88 throw new IllegalStateException("Can not set description to "
89 + UnionTypeBuilder.class.getSimpleName());
93 public void setReference(final String reference) {
94 throw new IllegalStateException("Can not set reference to "
95 + UnionTypeBuilder.class.getSimpleName());
99 public void setStatus(final Status status) {
100 throw new IllegalStateException("Can not set status to "
101 + UnionTypeBuilder.class.getSimpleName());
105 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
106 throw new IllegalStateException("Can not add unknown node to "
107 + UnionTypeBuilder.class.getSimpleName());
111 public QName getQName() {
116 public SchemaPath getPath() {
121 public String getDescription() {
126 public String getReference() {
131 public Status getStatus() {
136 public List<RangeConstraint> getRanges() {
137 return Collections.emptyList();
141 public void setRanges(List<RangeConstraint> ranges) {
142 throw new IllegalStateException("Can not set ranges to "
143 + UnionTypeBuilder.class.getSimpleName());
147 public List<LengthConstraint> getLengths() {
148 return Collections.emptyList();
152 public void setLengths(List<LengthConstraint> lengths) {
153 throw new IllegalStateException("Can not set lengths to "
154 + UnionTypeBuilder.class.getSimpleName());
158 public List<PatternConstraint> getPatterns() {
159 return Collections.emptyList();
163 public void setPatterns(List<PatternConstraint> patterns) {
164 throw new IllegalStateException("Can not set patterns to "
165 + UnionTypeBuilder.class.getSimpleName());
169 public Integer getFractionDigits() {
174 public void setFractionDigits(Integer fractionDigits) {
175 throw new IllegalStateException("Can not set fraction digits to "
176 + UnionTypeBuilder.class.getSimpleName());
180 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
181 return Collections.emptyList();
185 public Object getDefaultValue() {
190 public void setDefaultValue(Object defaultValue) {
191 throw new IllegalStateException("Can not set default value to "
192 + UnionTypeBuilder.class.getSimpleName());
196 public String getUnits() {
201 public void setUnits(String units) {
202 throw new IllegalStateException("Can not set units to "
203 + UnionTypeBuilder.class.getSimpleName());
207 public String toString() {
208 final StringBuilder result = new StringBuilder(
209 UnionTypeBuilder.class.getSimpleName() + "[");
210 result.append(", types=" + types);
211 result.append(", typedefs=" + typedefs);
213 return result.toString();