blob: 9ba4068c354a3c9f4ca0372f0c98599ac8a9ecb3 [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 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053016package org.onosproject.yangutils.translator.tojava;
Vinod Kumar S38046502016-03-23 15:30:27 +053017
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;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053023import org.onosproject.yangutils.datamodel.YangIdentity;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053024import org.onosproject.yangutils.datamodel.YangInput;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053025import org.onosproject.yangutils.datamodel.YangLeaf;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053026import org.onosproject.yangutils.datamodel.YangLeafList;
Vinod Kumar S38046502016-03-23 15:30:27 +053027import org.onosproject.yangutils.datamodel.YangList;
28import org.onosproject.yangutils.datamodel.YangModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053029import org.onosproject.yangutils.datamodel.YangNotification;
30import org.onosproject.yangutils.datamodel.YangOutput;
31import org.onosproject.yangutils.datamodel.YangRpc;
Vinod Kumar S38046502016-03-23 15:30:27 +053032import org.onosproject.yangutils.datamodel.YangSubModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053033import org.onosproject.yangutils.datamodel.YangType;
Vinod Kumar S38046502016-03-23 15:30:27 +053034import org.onosproject.yangutils.datamodel.YangTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053035import org.onosproject.yangutils.datamodel.YangUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053036import org.onosproject.yangutils.datamodel.YangUses;
Bharat saraswal96dfef02016-06-16 00:29:12 +053037import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053038import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053039import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
40import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
41import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
42import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
Bharat saraswald72411a2016-04-19 01:00:16 +053043import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
Vinod Kumar S38046502016-03-23 15:30:27 +053044import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053045import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053046import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053047import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053048import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
Vinod Kumar S38046502016-03-23 15:30:27 +053049import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
50import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053051import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
52import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
53import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
Vinod Kumar S38046502016-03-23 15:30:27 +053054import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053055import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
Vinod Kumar S38046502016-03-23 15:30:27 +053056import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053057import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053058import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
59
60/**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053061 * Represents factory to create data model objects based on the target file type.
Vinod Kumar S38046502016-03-23 15:30:27 +053062 */
63public final class YangDataModelFactory {
64
65 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053066 * Creates a YANG data model factory object.
Vinod Kumar S38046502016-03-23 15:30:27 +053067 */
68 private YangDataModelFactory() {
69 }
70
71 /**
72 * Based on the target language generate the inherited data model node.
73 *
74 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053075 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053076 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053077 */
78 public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
79 switch (targetLanguage) {
80 case JAVA_GENERATION: {
81 return new YangJavaModule();
82 }
83 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053084 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053085 }
86 }
87 }
88
89 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053090 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053091 *
92 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053093 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053094 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053095 */
96 public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
97 switch (targetLanguage) {
98 case JAVA_GENERATION: {
99 return new YangJavaAugment();
100 }
101 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530102 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530103 }
104 }
105 }
106
107 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530108 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530109 *
110 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530111 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530112 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530113 */
114 public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
115 switch (targetLanguage) {
116 case JAVA_GENERATION: {
117 return new YangJavaCase();
118 }
119 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530120 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530121 }
122 }
123 }
124
125 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530126 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530127 *
128 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530129 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530130 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530131 */
132 public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
133 switch (targetLanguage) {
134 case JAVA_GENERATION: {
135 return new YangJavaChoice();
136 }
137 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530138 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530139 }
140 }
141 }
142
143 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530144 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530145 *
146 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530147 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530148 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530149 */
150 public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
151 switch (targetLanguage) {
152 case JAVA_GENERATION: {
153 return new YangJavaContainer();
154 }
155 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530156 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530157 }
158 }
159 }
160
161 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530162 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530163 *
164 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530165 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530166 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530167 */
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530168 public static YangIdentity getYangIdentityNode(GeneratedLanguage targetLanguage) {
169 switch (targetLanguage) {
170 case JAVA_GENERATION: {
171 return new YangJavaIdentity();
172 }
173 default: {
174 throw new TranslatorException("Only YANG to Java is supported.");
175 }
176 }
177 }
178
179 /**
180 * Returns based on the target language generate the inherited data model node.
181 *
182 * @param targetLanguage target language in which YANG mapping needs to be
183 * generated
184 * @return the corresponding inherited node based on the target language
185 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530186 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
187 switch (targetLanguage) {
188 case JAVA_GENERATION: {
189 return new YangJavaGrouping();
190 }
191 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530192 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530193 }
194 }
195 }
196
197 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530198 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530199 *
200 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530201 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530202 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530203 */
204 public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
205 switch (targetLanguage) {
206 case JAVA_GENERATION: {
207 return new YangJavaList();
208 }
209 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530210 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530211 }
212 }
213 }
214
215 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530216 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530217 *
218 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530219 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530220 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530221 */
222 public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
223 switch (targetLanguage) {
224 case JAVA_GENERATION: {
225 return new YangJavaSubModule();
226 }
227 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530228 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530229 }
230 }
231 }
232
233 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530234 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530235 *
236 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530237 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530238 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530239 */
240 public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
241 switch (targetLanguage) {
242 case JAVA_GENERATION: {
243 return new YangJavaTypeDef();
244 }
245 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530246 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530247 }
248 }
249 }
250
251 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530252 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530253 *
254 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530255 * generated
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530256 * @return the corresponding inherited node based on the target language
257 */
258 public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
259 switch (targetLanguage) {
260 case JAVA_GENERATION: {
261 return new YangJavaUnion();
262 }
263 default: {
264 throw new TranslatorException("Only YANG to Java is supported.");
265 }
266 }
267 }
268
269 /**
270 * Returns based on the target language generate the inherited data model node.
271 *
272 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530273 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530274 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530275 */
276 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
277 switch (targetLanguage) {
278 case JAVA_GENERATION: {
279 return new YangJavaUses();
280 }
281 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530282 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530283 }
284 }
285 }
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530286
287 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530288 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530289 *
290 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530291 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530292 * @return the corresponding inherited node based on the target language
293 */
294 public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
295 switch (targetLanguage) {
296 case JAVA_GENERATION: {
297 return new YangJavaNotification();
298 }
299 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530300 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530301 }
302 }
303 }
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530304
305 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530306 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530307 *
308 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530309 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530310 * @return the corresponding inherited node based on the target language
311 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530312 public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
313 switch (targetLanguage) {
314 case JAVA_GENERATION: {
315 return new YangJavaLeaf();
316 }
317 default: {
318 throw new RuntimeException("Only YANG to Java is supported.");
319 }
320 }
321 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530322
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530323 /**
324 * Returns based on the target language generate the inherited data model node.
325 *
326 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530327 * generated
328 * @return the corresponding inherited node based on the target language
329 */
330 public static YangLeafList getYangLeafList(GeneratedLanguage targetLanguage) {
331 switch (targetLanguage) {
332 case JAVA_GENERATION: {
333 return new YangJavaLeafList();
334 }
335 default: {
336 throw new RuntimeException("Only YANG to Java is supported.");
337 }
338 }
339 }
340
341 /**
342 * Returns based on the target language generate the inherited data model node.
343 *
344 * @param targetLanguage target language in which YANG mapping needs to be
345 * generated
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530346 * @return the corresponding inherited node based on the target language
347 */
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530348 public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
349 switch (targetLanguage) {
350 case JAVA_GENERATION: {
351 return new YangJavaRpc();
352 }
353 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530354 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530355 }
356 }
357 }
358
359 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530360 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530361 *
362 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530363 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530364 * @return the corresponding inherited node based on the target language
365 */
366 public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
367 switch (targetLanguage) {
368 case JAVA_GENERATION: {
369 return new YangJavaInput();
370 }
371 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530372 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530373 }
374 }
375 }
376
377 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530378 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530379 *
380 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530381 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530382 * @return the corresponding inherited node based on the target language
383 */
384 public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
385 switch (targetLanguage) {
386 case JAVA_GENERATION: {
387 return new YangJavaOutput();
388 }
389 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530390 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530391 }
392 }
393 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530394
395 /**
396 * Returns based on the target language generate the inherited data model node.
397 *
398 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530399 * generated
Bharat saraswald72411a2016-04-19 01:00:16 +0530400 * @return the corresponding inherited node based on the target language
401 */
402 public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) {
403 switch (targetLanguage) {
404 case JAVA_GENERATION: {
405 return new YangJavaEnumeration();
406 }
407 default: {
408 throw new TranslatorException("Only YANG to Java is supported.");
409 }
410 }
411 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530412 /**
413 * Returns based on the target language generate the inherited data model node.
414 *
415 * @param targetLanguage target language in which YANG mapping needs to be
416 * generated
417 * @return the corresponding inherited node based on the target language
418 */
419 public static YangType getYangType(GeneratedLanguage targetLanguage) {
420 switch (targetLanguage) {
421 case JAVA_GENERATION: {
422 return new YangJavaType();
423 }
424 default: {
425 throw new RuntimeException("Only YANG to Java is supported.");
426 }
427 }
428 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530429}