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 int line;
37 private final List<TypeDefinition<?>> types;
38 private final List<TypeDefinitionBuilder> typedefs;
39 private final UnionType instance;
41 private final List<String> actualPath;
42 private final URI namespace;
43 private final Date revision;
45 public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
46 final Date revision, final int line) {
48 types = new ArrayList<TypeDefinition<?>>();
49 typedefs = new ArrayList<TypeDefinitionBuilder>();
50 instance = new UnionType(actualPath, namespace, revision, types);
52 this.actualPath = actualPath;
53 this.namespace = namespace;
54 this.revision = revision;
58 public int getLine() {
62 public List<TypeDefinition<?>> getTypes() {
67 public TypeDefinition<?> getType() {
71 public List<TypeDefinitionBuilder> getTypedefs() {
72 return Collections.unmodifiableList(typedefs);
76 public TypeDefinitionBuilder getTypedef() {
81 public void setType(final TypeDefinition<?> type) {
86 public void setType(final TypeDefinitionBuilder tdb) {
91 public UnionType build() {
92 for (TypeDefinitionBuilder tdb : typedefs) {
93 types.add(tdb.build());
99 public void setPath(final SchemaPath schemaPath) {
100 throw new IllegalStateException("Can not set path to "
101 + UnionTypeBuilder.class.getSimpleName());
105 public void setDescription(final String description) {
106 throw new IllegalStateException("Can not set description to "
107 + UnionTypeBuilder.class.getSimpleName());
111 public void setReference(final String reference) {
112 throw new IllegalStateException("Can not set reference to "
113 + UnionTypeBuilder.class.getSimpleName());
117 public void setStatus(final Status status) {
118 throw new IllegalStateException("Can not set status to "
119 + UnionTypeBuilder.class.getSimpleName());
123 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
124 throw new IllegalStateException("Can not add unknown node to "
125 + UnionTypeBuilder.class.getSimpleName());
129 public QName getQName() {
134 public SchemaPath getPath() {
139 public String getDescription() {
144 public String getReference() {
149 public Status getStatus() {
154 public List<RangeConstraint> getRanges() {
155 return Collections.emptyList();
159 public void setRanges(List<RangeConstraint> ranges) {
160 throw new IllegalStateException("Can not set ranges to "
161 + UnionTypeBuilder.class.getSimpleName());
165 public List<LengthConstraint> getLengths() {
166 return Collections.emptyList();
170 public void setLengths(List<LengthConstraint> lengths) {
171 throw new IllegalStateException("Can not set lengths to "
172 + UnionTypeBuilder.class.getSimpleName());
176 public List<PatternConstraint> getPatterns() {
177 return Collections.emptyList();
181 public void setPatterns(List<PatternConstraint> patterns) {
182 throw new IllegalStateException("Can not set patterns to "
183 + UnionTypeBuilder.class.getSimpleName());
187 public Integer getFractionDigits() {
192 public void setFractionDigits(Integer fractionDigits) {
193 throw new IllegalStateException("Can not set fraction digits to "
194 + UnionTypeBuilder.class.getSimpleName());
198 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
199 return Collections.emptyList();
203 public Object getDefaultValue() {
208 public void setDefaultValue(Object defaultValue) {
209 throw new IllegalStateException("Can not set default value to "
210 + UnionTypeBuilder.class.getSimpleName());
214 public String getUnits() {
219 public void setUnits(String units) {
220 throw new IllegalStateException("Can not set units to "
221 + UnionTypeBuilder.class.getSimpleName());
224 public List<String> getActualPath() {
228 public URI getNamespace() {
232 public Date getRevision() {
237 public String toString() {
238 final StringBuilder result = new StringBuilder(
239 UnionTypeBuilder.class.getSimpleName() + "[");
240 result.append(", types=" + types);
241 result.append(", typedefs=" + typedefs);
243 return result.toString();