blob: 4d68fe201e41324053706c182d69bcc606446b75 [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;
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;
Bharat saraswal96dfef02016-06-16 00:29:12 +053036import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053037import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053038import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
39import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
40import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
41import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
Bharat saraswald72411a2016-04-19 01:00:16 +053042import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
Vinod Kumar S38046502016-03-23 15:30:27 +053043import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053044import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053045import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053046import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
Vinod Kumar S38046502016-03-23 15:30:27 +053047import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
48import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053049import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
50import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
51import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
Vinod Kumar S38046502016-03-23 15:30:27 +053052import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053053import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
Vinod Kumar S38046502016-03-23 15:30:27 +053054import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053055import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053056import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
57
58/**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053059 * Represents factory to create data model objects based on the target file type.
Vinod Kumar S38046502016-03-23 15:30:27 +053060 */
61public final class YangDataModelFactory {
62
63 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053064 * Creates a YANG data model factory object.
Vinod Kumar S38046502016-03-23 15:30:27 +053065 */
66 private YangDataModelFactory() {
67 }
68
69 /**
70 * Based on the target language generate the inherited data model node.
71 *
72 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053073 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053074 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053075 */
76 public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
77 switch (targetLanguage) {
78 case JAVA_GENERATION: {
79 return new YangJavaModule();
80 }
81 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053082 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053083 }
84 }
85 }
86
87 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053088 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053089 *
90 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053091 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +053092 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053093 */
94 public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
95 switch (targetLanguage) {
96 case JAVA_GENERATION: {
97 return new YangJavaAugment();
98 }
99 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530100 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530101 }
102 }
103 }
104
105 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530106 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530107 *
108 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530109 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530110 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530111 */
112 public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
113 switch (targetLanguage) {
114 case JAVA_GENERATION: {
115 return new YangJavaCase();
116 }
117 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530118 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530119 }
120 }
121 }
122
123 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530124 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530125 *
126 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530127 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530128 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530129 */
130 public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
131 switch (targetLanguage) {
132 case JAVA_GENERATION: {
133 return new YangJavaChoice();
134 }
135 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530136 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530137 }
138 }
139 }
140
141 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530142 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530143 *
144 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530145 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530146 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530147 */
148 public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
149 switch (targetLanguage) {
150 case JAVA_GENERATION: {
151 return new YangJavaContainer();
152 }
153 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530154 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530155 }
156 }
157 }
158
159 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530160 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530161 *
162 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530163 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530164 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530165 */
166 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
167 switch (targetLanguage) {
168 case JAVA_GENERATION: {
169 return new YangJavaGrouping();
170 }
171 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530172 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530173 }
174 }
175 }
176
177 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530178 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530179 *
180 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530181 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530182 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530183 */
184 public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
185 switch (targetLanguage) {
186 case JAVA_GENERATION: {
187 return new YangJavaList();
188 }
189 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530190 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530191 }
192 }
193 }
194
195 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530196 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530197 *
198 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530199 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530200 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530201 */
202 public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
203 switch (targetLanguage) {
204 case JAVA_GENERATION: {
205 return new YangJavaSubModule();
206 }
207 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530208 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530209 }
210 }
211 }
212
213 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530214 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530215 *
216 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530217 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530218 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530219 */
220 public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
221 switch (targetLanguage) {
222 case JAVA_GENERATION: {
223 return new YangJavaTypeDef();
224 }
225 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530226 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530227 }
228 }
229 }
230
231 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530232 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530233 *
234 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530235 * generated
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530236 * @return the corresponding inherited node based on the target language
237 */
238 public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
239 switch (targetLanguage) {
240 case JAVA_GENERATION: {
241 return new YangJavaUnion();
242 }
243 default: {
244 throw new TranslatorException("Only YANG to Java is supported.");
245 }
246 }
247 }
248
249 /**
250 * Returns based on the target language generate the inherited data model node.
251 *
252 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530253 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530254 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530255 */
256 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
257 switch (targetLanguage) {
258 case JAVA_GENERATION: {
259 return new YangJavaUses();
260 }
261 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530262 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530263 }
264 }
265 }
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530266
267 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530268 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530269 *
270 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530271 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530272 * @return the corresponding inherited node based on the target language
273 */
274 public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
275 switch (targetLanguage) {
276 case JAVA_GENERATION: {
277 return new YangJavaNotification();
278 }
279 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530280 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530281 }
282 }
283 }
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530284
285 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530286 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530287 *
288 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530289 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530290 * @return the corresponding inherited node based on the target language
291 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530292 public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
293 switch (targetLanguage) {
294 case JAVA_GENERATION: {
295 return new YangJavaLeaf();
296 }
297 default: {
298 throw new RuntimeException("Only YANG to Java is supported.");
299 }
300 }
301 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530302
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530303 /**
304 * Returns based on the target language generate the inherited data model node.
305 *
306 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530307 * generated
308 * @return the corresponding inherited node based on the target language
309 */
310 public static YangLeafList getYangLeafList(GeneratedLanguage targetLanguage) {
311 switch (targetLanguage) {
312 case JAVA_GENERATION: {
313 return new YangJavaLeafList();
314 }
315 default: {
316 throw new RuntimeException("Only YANG to Java is supported.");
317 }
318 }
319 }
320
321 /**
322 * Returns based on the target language generate the inherited data model node.
323 *
324 * @param targetLanguage target language in which YANG mapping needs to be
325 * generated
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530326 * @return the corresponding inherited node based on the target language
327 */
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530328 public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
329 switch (targetLanguage) {
330 case JAVA_GENERATION: {
331 return new YangJavaRpc();
332 }
333 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530334 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530335 }
336 }
337 }
338
339 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530340 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530341 *
342 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530343 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530344 * @return the corresponding inherited node based on the target language
345 */
346 public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
347 switch (targetLanguage) {
348 case JAVA_GENERATION: {
349 return new YangJavaInput();
350 }
351 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530352 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530353 }
354 }
355 }
356
357 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530358 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530359 *
360 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530361 * generated
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530362 * @return the corresponding inherited node based on the target language
363 */
364 public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
365 switch (targetLanguage) {
366 case JAVA_GENERATION: {
367 return new YangJavaOutput();
368 }
369 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530370 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530371 }
372 }
373 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530374
375 /**
376 * Returns based on the target language generate the inherited data model node.
377 *
378 * @param targetLanguage target language in which YANG mapping needs to be
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530379 * generated
Bharat saraswald72411a2016-04-19 01:00:16 +0530380 * @return the corresponding inherited node based on the target language
381 */
382 public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) {
383 switch (targetLanguage) {
384 case JAVA_GENERATION: {
385 return new YangJavaEnumeration();
386 }
387 default: {
388 throw new TranslatorException("Only YANG to Java is supported.");
389 }
390 }
391 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530392 /**
393 * Returns based on the target language generate the inherited data model node.
394 *
395 * @param targetLanguage target language in which YANG mapping needs to be
396 * generated
397 * @return the corresponding inherited node based on the target language
398 */
399 public static YangType getYangType(GeneratedLanguage targetLanguage) {
400 switch (targetLanguage) {
401 case JAVA_GENERATION: {
402 return new YangJavaType();
403 }
404 default: {
405 throw new RuntimeException("Only YANG to Java is supported.");
406 }
407 }
408 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530409}