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;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
16 import org.opendaylight.controller.yang.common.QName;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.TypeDefinition;
20 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
21 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
22 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
23 import org.opendaylight.controller.yang.model.parser.builder.api.AbstractTypeAwareBuilder;
24 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
25 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
26 import org.opendaylight.controller.yang.model.util.UnionType;
29 * Builder for YANG union type. User can add type to this union as
30 * TypeDefinition object (resolved type) or in form of TypeDefinitionBuilder.
31 * When build is called, types in builder form will be built and add to resolved
34 public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
35 TypeDefinitionBuilder, Builder {
36 private final List<TypeDefinition<?>> types;
37 private final List<TypeDefinitionBuilder> typedefs;
38 private final UnionType instance;
40 private final List<String> actualPath;
41 private final URI namespace;
42 private final Date revision;
44 public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
45 final Date revision) {
46 types = new ArrayList<TypeDefinition<?>>();
47 typedefs = new ArrayList<TypeDefinitionBuilder>();
48 instance = new UnionType(actualPath, namespace, revision, types);
50 this.actualPath = actualPath;
51 this.namespace = namespace;
52 this.revision = revision;
55 public List<TypeDefinition<?>> getTypes() {
60 public TypeDefinition<?> getType() {
64 public List<TypeDefinitionBuilder> getTypedefs() {
65 return Collections.unmodifiableList(typedefs);
69 public TypeDefinitionBuilder getTypedef() {
74 public void setType(final TypeDefinition<?> type) {
79 public void setType(final TypeDefinitionBuilder tdb) {
84 public UnionType build() {
85 for (TypeDefinitionBuilder tdb : typedefs) {
86 types.add(tdb.build());
92 public void setPath(final SchemaPath schemaPath) {
93 throw new IllegalStateException("Can not set path to "
94 + UnionTypeBuilder.class.getSimpleName());
98 public void setDescription(final String description) {
99 throw new IllegalStateException("Can not set description to "
100 + UnionTypeBuilder.class.getSimpleName());
104 public void setReference(final String reference) {
105 throw new IllegalStateException("Can not set reference to "
106 + UnionTypeBuilder.class.getSimpleName());
110 public void setStatus(final Status status) {
111 throw new IllegalStateException("Can not set status to "
112 + UnionTypeBuilder.class.getSimpleName());
116 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
117 throw new IllegalStateException("Can not add unknown node to "
118 + UnionTypeBuilder.class.getSimpleName());
122 public QName getQName() {
127 public SchemaPath getPath() {
132 public String getDescription() {
137 public String getReference() {
142 public Status getStatus() {
147 public List<RangeConstraint> getRanges() {
148 return Collections.emptyList();
152 public void setRanges(List<RangeConstraint> ranges) {
153 throw new IllegalStateException("Can not set ranges to "
154 + UnionTypeBuilder.class.getSimpleName());
158 public List<LengthConstraint> getLengths() {
159 return Collections.emptyList();
163 public void setLengths(List<LengthConstraint> lengths) {
164 throw new IllegalStateException("Can not set lengths to "
165 + UnionTypeBuilder.class.getSimpleName());
169 public List<PatternConstraint> getPatterns() {
170 return Collections.emptyList();
174 public void setPatterns(List<PatternConstraint> patterns) {
175 throw new IllegalStateException("Can not set patterns to "
176 + UnionTypeBuilder.class.getSimpleName());
180 public Integer getFractionDigits() {
185 public void setFractionDigits(Integer fractionDigits) {
186 throw new IllegalStateException("Can not set fraction digits to "
187 + UnionTypeBuilder.class.getSimpleName());
191 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
192 return Collections.emptyList();
196 public Object getDefaultValue() {
201 public void setDefaultValue(Object defaultValue) {
202 throw new IllegalStateException("Can not set default value to "
203 + UnionTypeBuilder.class.getSimpleName());
207 public String getUnits() {
212 public void setUnits(String units) {
213 throw new IllegalStateException("Can not set units to "
214 + UnionTypeBuilder.class.getSimpleName());
217 public List<String> getActualPath() {
221 public URI getNamespace() {
225 public Date getRevision() {
230 public String toString() {
231 final StringBuilder result = new StringBuilder(
232 UnionTypeBuilder.class.getSimpleName() + "[");
233 result.append(", types=" + types);
234 result.append(", typedefs=" + typedefs);
236 return result.toString();