blob: aff53c4c02880d62b5d228d4e04440b295b5726b [file] [log] [blame]
Vinod Kumar S38046502016-03-23 15:30:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S38046502016-03-23 15:30:27 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.yangutils.datamodel.utils;
17
18import org.onosproject.yangutils.datamodel.YangAugment;
19import org.onosproject.yangutils.datamodel.YangCase;
20import org.onosproject.yangutils.datamodel.YangChoice;
21import org.onosproject.yangutils.datamodel.YangContainer;
22import org.onosproject.yangutils.datamodel.YangGrouping;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053023import org.onosproject.yangutils.datamodel.YangInput;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053024import org.onosproject.yangutils.datamodel.YangLeaf;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053025import org.onosproject.yangutils.datamodel.YangLeafList;
Vinod Kumar S38046502016-03-23 15:30:27 +053026import org.onosproject.yangutils.datamodel.YangList;
27import org.onosproject.yangutils.datamodel.YangModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053028import org.onosproject.yangutils.datamodel.YangNotification;
29import org.onosproject.yangutils.datamodel.YangOutput;
30import org.onosproject.yangutils.datamodel.YangRpc;
Vinod Kumar S38046502016-03-23 15:30:27 +053031import org.onosproject.yangutils.datamodel.YangSubModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053032import org.onosproject.yangutils.datamodel.YangType;
Vinod Kumar S38046502016-03-23 15:30:27 +053033import org.onosproject.yangutils.datamodel.YangTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053034import org.onosproject.yangutils.datamodel.YangUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053035import org.onosproject.yangutils.datamodel.YangUses;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053036import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053037import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
38import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
39import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
40import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
Bharat saraswald72411a2016-04-19 01:00:16 +053041import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
Vinod Kumar S38046502016-03-23 15:30:27 +053042import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053043import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053044import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053045import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
Vinod Kumar S38046502016-03-23 15:30:27 +053046import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
47import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053048import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
49import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
50import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
Vinod Kumar S38046502016-03-23 15:30:27 +053051import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053052import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
Vinod Kumar S38046502016-03-23 15:30:27 +053053import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053054import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053055import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
56
57/**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053058 * Represents factory to create data model objects based on the target file type.
Vinod Kumar S38046502016-03-23 15:30:27 +053059 */
60public final class YangDataModelFactory {
61
62 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053063 * Creates a YANG data model factory object.
Vinod Kumar S38046502016-03-23 15:30:27 +053064 */
65 private YangDataModelFactory() {
66 }
67
68 /**
69 * Based on the target language generate the inherited data model node.
70 *
71 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053072 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053073 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053074 */
75 public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
76 switch (targetLanguage) {
77 case JAVA_GENERATION: {
78 return new YangJavaModule();
79 }
80 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053081 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053082 }
83 }
84 }
85
86 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053088 *
89 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053090 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053091 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053092 */
93 public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
94 switch (targetLanguage) {
95 case JAVA_GENERATION: {
96 return new YangJavaAugment();
97 }
98 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053099 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530100 }
101 }
102 }
103
104 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530105 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530106 *
107 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530108 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530109 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530110 */
111 public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
112 switch (targetLanguage) {
113 case JAVA_GENERATION: {
114 return new YangJavaCase();
115 }
116 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530117 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530118 }
119 }
120 }
121
122 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530123 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530124 *
125 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530126 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530127 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530128 */
129 public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
130 switch (targetLanguage) {
131 case JAVA_GENERATION: {
132 return new YangJavaChoice();
133 }
134 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530135 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530136 }
137 }
138 }
139
140 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530141 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530142 *
143 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530144 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530145 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530146 */
147 public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
148 switch (targetLanguage) {
149 case JAVA_GENERATION: {
150 return new YangJavaContainer();
151 }
152 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530153 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530154 }
155 }
156 }
157
158 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530159 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530160 *
161 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530162 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530163 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530164 */
165 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
166 switch (targetLanguage) {
167 case JAVA_GENERATION: {
168 return new YangJavaGrouping();
169 }
170 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530171 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530172 }
173 }
174 }
175
176 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530177 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530178 *
179 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530180 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530181 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530182 */
183 public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
184 switch (targetLanguage) {
185 case JAVA_GENERATION: {
186 return new YangJavaList();
187 }
188 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530189 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530190 }
191 }
192 }
193
194 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530195 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530196 *
197 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530198 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530199 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530200 */
201 public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
202 switch (targetLanguage) {
203 case JAVA_GENERATION: {
204 return new YangJavaSubModule();
205 }
206 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530207 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530208 }
209 }
210 }
211
212 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530213 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530214 *
215 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530216 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530217 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530218 */
219 public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
220 switch (targetLanguage) {
221 case JAVA_GENERATION: {
222 return new YangJavaTypeDef();
223 }
224 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530225 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530226 }
227 }
228 }
229
230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530232 *
233 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530234 * generated
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530235 * @return the corresponding inherited node based on the target language
236 */
237 public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
238 switch (targetLanguage) {
239 case JAVA_GENERATION: {
240 return new YangJavaUnion();
241 }
242 default: {
243 throw new TranslatorException("Only YANG to Java is supported.");
244 }
245 }
246 }
247
248 /**
249 * Returns based on the target language generate the inherited data model node.
250 *
251 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530252 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530253 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530254 */
255 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
256 switch (targetLanguage) {
257 case JAVA_GENERATION: {
258 return new YangJavaUses();
259 }
260 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530261 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530262 }
263 }
264 }
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530265
266 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530267 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530268 *
269 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530270 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530271 * @return the corresponding inherited node based on the target language
272 */
273 public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
274 switch (targetLanguage) {
275 case JAVA_GENERATION: {
276 return new YangJavaNotification();
277 }
278 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530279 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530280 }
281 }
282 }
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530283
284 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530285 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530286 *
287 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530288 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530289 * @return the corresponding inherited node based on the target language
290 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530291 public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
292 switch (targetLanguage) {
293 case JAVA_GENERATION: {
294 return new YangJavaLeaf();
295 }
296 default: {
297 throw new RuntimeException("Only YANG to Java is supported.");
298 }
299 }
300 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530301
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530302 /**
303 * Returns based on the target language generate the inherited data model node.
304 *
305 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530306 * generated
307 * @return the corresponding inherited node based on the target language
308 */
309 public static YangLeafList getYangLeafList(GeneratedLanguage targetLanguage) {
310 switch (targetLanguage) {
311 case JAVA_GENERATION: {
312 return new YangJavaLeafList();
313 }
314 default: {
315 throw new RuntimeException("Only YANG to Java is supported.");
316 }
317 }
318 }
319
320 /**
321 * Returns based on the target language generate the inherited data model node.
322 *
323 * @param targetLanguage target language in which YANG mapping needs to be
324 * generated
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530325 * @return the corresponding inherited node based on the target language
326 */
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530327 public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
328 switch (targetLanguage) {
329 case JAVA_GENERATION: {
330 return new YangJavaRpc();
331 }
332 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530333 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530334 }
335 }
336 }
337
338 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530339 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530340 *
341 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530342 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530343 * @return the corresponding inherited node based on the target language
344 */
345 public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
346 switch (targetLanguage) {
347 case JAVA_GENERATION: {
348 return new YangJavaInput();
349 }
350 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530351 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530352 }
353 }
354 }
355
356 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530357 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530358 *
359 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530360 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530361 * @return the corresponding inherited node based on the target language
362 */
363 public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
364 switch (targetLanguage) {
365 case JAVA_GENERATION: {
366 return new YangJavaOutput();
367 }
368 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530369 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530370 }
371 }
372 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530373
374 /**
375 * Returns based on the target language generate the inherited data model node.
376 *
377 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530378 * generated
Bharat saraswald72411a2016-04-19 01:00:16 +0530379 * @return the corresponding inherited node based on the target language
380 */
381 public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) {
382 switch (targetLanguage) {
383 case JAVA_GENERATION: {
384 return new YangJavaEnumeration();
385 }
386 default: {
387 throw new TranslatorException("Only YANG to Java is supported.");
388 }
389 }
390 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530391 /**
392 * Returns based on the target language generate the inherited data model node.
393 *
394 * @param targetLanguage target language in which YANG mapping needs to be
395 * generated
396 * @return the corresponding inherited node based on the target language
397 */
398 public static YangType getYangType(GeneratedLanguage targetLanguage) {
399 switch (targetLanguage) {
400 case JAVA_GENERATION: {
401 return new YangJavaType();
402 }
403 default: {
404 throw new RuntimeException("Only YANG to Java is supported.");
405 }
406 }
407 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530408}