Remove 'model' from package names in yang-model-parser-impl.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / builder / impl / UnionTypeBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang.parser.builder.impl;
9
10 import java.net.URI;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
15
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.util.UnionType;
24 import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
25 import org.opendaylight.controller.yang.parser.builder.api.Builder;
26 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
27
28 /**
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
32  * types.
33  */
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;
40
41     private final List<String> actualPath;
42     private final URI namespace;
43     private final Date revision;
44
45     public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
46             final Date revision, final int line) {
47         this.line = line;
48         types = new ArrayList<TypeDefinition<?>>();
49         typedefs = new ArrayList<TypeDefinitionBuilder>();
50         instance = new UnionType(actualPath, namespace, revision, types);
51
52         this.actualPath = actualPath;
53         this.namespace = namespace;
54         this.revision = revision;
55     }
56
57     @Override
58     public int getLine() {
59         return line;
60     }
61
62     public List<TypeDefinition<?>> getTypes() {
63         return types;
64     }
65
66     @Override
67     public TypeDefinition<?> getType() {
68         return null;
69     }
70
71     public List<TypeDefinitionBuilder> getTypedefs() {
72         return Collections.unmodifiableList(typedefs);
73     }
74
75     @Override
76     public TypeDefinitionBuilder getTypedef() {
77         return null;
78     }
79
80     @Override
81     public void setType(final TypeDefinition<?> type) {
82         types.add(type);
83     }
84
85     @Override
86     public void setType(final TypeDefinitionBuilder tdb) {
87         typedefs.add(tdb);
88     }
89
90     @Override
91     public UnionType build() {
92         for (TypeDefinitionBuilder tdb : typedefs) {
93             types.add(tdb.build());
94         }
95         return instance;
96     }
97
98     @Override
99     public void setPath(final SchemaPath schemaPath) {
100         throw new IllegalStateException("Can not set path to "
101                 + UnionTypeBuilder.class.getSimpleName());
102     }
103
104     @Override
105     public void setDescription(final String description) {
106         throw new IllegalStateException("Can not set description to "
107                 + UnionTypeBuilder.class.getSimpleName());
108     }
109
110     @Override
111     public void setReference(final String reference) {
112         throw new IllegalStateException("Can not set reference to "
113                 + UnionTypeBuilder.class.getSimpleName());
114     }
115
116     @Override
117     public void setStatus(final Status status) {
118         throw new IllegalStateException("Can not set status to "
119                 + UnionTypeBuilder.class.getSimpleName());
120     }
121
122     @Override
123     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
124         throw new IllegalStateException("Can not add unknown node to "
125                 + UnionTypeBuilder.class.getSimpleName());
126     }
127
128     @Override
129     public QName getQName() {
130         return null;
131     }
132
133     @Override
134     public SchemaPath getPath() {
135         return null;
136     }
137
138     @Override
139     public String getDescription() {
140         return null;
141     }
142
143     @Override
144     public String getReference() {
145         return null;
146     }
147
148     @Override
149     public Status getStatus() {
150         return null;
151     }
152
153     @Override
154     public List<RangeConstraint> getRanges() {
155         return Collections.emptyList();
156     }
157
158     @Override
159     public void setRanges(List<RangeConstraint> ranges) {
160         throw new IllegalStateException("Can not set ranges to "
161                 + UnionTypeBuilder.class.getSimpleName());
162     }
163
164     @Override
165     public List<LengthConstraint> getLengths() {
166         return Collections.emptyList();
167     }
168
169     @Override
170     public void setLengths(List<LengthConstraint> lengths) {
171         throw new IllegalStateException("Can not set lengths to "
172                 + UnionTypeBuilder.class.getSimpleName());
173     }
174
175     @Override
176     public List<PatternConstraint> getPatterns() {
177         return Collections.emptyList();
178     }
179
180     @Override
181     public void setPatterns(List<PatternConstraint> patterns) {
182         throw new IllegalStateException("Can not set patterns to "
183                 + UnionTypeBuilder.class.getSimpleName());
184     }
185
186     @Override
187     public Integer getFractionDigits() {
188         return null;
189     }
190
191     @Override
192     public void setFractionDigits(Integer fractionDigits) {
193         throw new IllegalStateException("Can not set fraction digits to "
194                 + UnionTypeBuilder.class.getSimpleName());
195     }
196
197     @Override
198     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
199         return Collections.emptyList();
200     }
201
202     @Override
203     public Object getDefaultValue() {
204         return null;
205     }
206
207     @Override
208     public void setDefaultValue(Object defaultValue) {
209         throw new IllegalStateException("Can not set default value to "
210                 + UnionTypeBuilder.class.getSimpleName());
211     }
212
213     @Override
214     public String getUnits() {
215         return null;
216     }
217
218     @Override
219     public void setUnits(String units) {
220         throw new IllegalStateException("Can not set units to "
221                 + UnionTypeBuilder.class.getSimpleName());
222     }
223
224     public List<String> getActualPath() {
225         return actualPath;
226     }
227
228     public URI getNamespace() {
229         return namespace;
230     }
231
232     public Date getRevision() {
233         return revision;
234     }
235
236     @Override
237     public String toString() {
238         final StringBuilder result = new StringBuilder(
239                 UnionTypeBuilder.class.getSimpleName() + "[");
240         result.append(", types=" + types);
241         result.append(", typedefs=" + typedefs);
242         result.append("]");
243         return result.toString();
244     }
245
246 }