blob: 110bd1169fe3a90b4213bf4b648ede30ff7079fd [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 Sd4deb062016-04-15 18:08:57 +053023import org.onosproject.yangutils.datamodel.YangLeaf;
Vinod Kumar S38046502016-03-23 15:30:27 +053024import org.onosproject.yangutils.datamodel.YangList;
25import org.onosproject.yangutils.datamodel.YangModule;
26import org.onosproject.yangutils.datamodel.YangSubModule;
27import org.onosproject.yangutils.datamodel.YangTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053028import org.onosproject.yangutils.datamodel.YangUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053029import org.onosproject.yangutils.datamodel.YangUses;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053030import org.onosproject.yangutils.datamodel.YangNotification;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053031import org.onosproject.yangutils.datamodel.YangRpc;
32import org.onosproject.yangutils.datamodel.YangInput;
33import org.onosproject.yangutils.datamodel.YangOutput;
Vinod Kumar S38046502016-03-23 15:30:27 +053034import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
35import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
36import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
37import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
38import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053039import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
Vinod Kumar S38046502016-03-23 15:30:27 +053040import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
41import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
42import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
43import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053044import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
Vinod Kumar S38046502016-03-23 15:30:27 +053045import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053046import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053047import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
48import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
49import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053050import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053051
52/**
Bharat saraswald9822e92016-04-05 15:13:44 +053053 *Represents factory to create data model objects based on the target file type.
Vinod Kumar S38046502016-03-23 15:30:27 +053054 */
55public final class YangDataModelFactory {
56
57 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +053058 * Creates a YANG data model factory object.
Vinod Kumar S38046502016-03-23 15:30:27 +053059 */
60 private YangDataModelFactory() {
61 }
62
63 /**
64 * Based on the target language generate the inherited data model node.
65 *
66 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +053067 * generated
68 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053069 */
70 public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
71 switch (targetLanguage) {
72 case JAVA_GENERATION: {
73 return new YangJavaModule();
74 }
75 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053076 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053077 }
78 }
79 }
80
81 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053082 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053083 *
84 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +053085 * generated
86 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053087 */
88 public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
89 switch (targetLanguage) {
90 case JAVA_GENERATION: {
91 return new YangJavaAugment();
92 }
93 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053094 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053095 }
96 }
97 }
98
99 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530100 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530101 *
102 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530103 * generated
104 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530105 */
106 public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
107 switch (targetLanguage) {
108 case JAVA_GENERATION: {
109 return new YangJavaCase();
110 }
111 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530112 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530113 }
114 }
115 }
116
117 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530118 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530119 *
120 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530121 * generated
122 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530123 */
124 public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
125 switch (targetLanguage) {
126 case JAVA_GENERATION: {
127 return new YangJavaChoice();
128 }
129 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530130 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530131 }
132 }
133 }
134
135 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530137 *
138 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530139 * generated
140 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530141 */
142 public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
143 switch (targetLanguage) {
144 case JAVA_GENERATION: {
145 return new YangJavaContainer();
146 }
147 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530148 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530149 }
150 }
151 }
152
153 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530154 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530155 *
156 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530157 * generated
158 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530159 */
160 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
161 switch (targetLanguage) {
162 case JAVA_GENERATION: {
163 return new YangJavaGrouping();
164 }
165 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530166 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530167 }
168 }
169 }
170
171 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530172 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530173 *
174 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530175 * generated
176 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530177 */
178 public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
179 switch (targetLanguage) {
180 case JAVA_GENERATION: {
181 return new YangJavaList();
182 }
183 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530184 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530185 }
186 }
187 }
188
189 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530190 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530191 *
192 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530193 * generated
194 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530195 */
196 public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
197 switch (targetLanguage) {
198 case JAVA_GENERATION: {
199 return new YangJavaSubModule();
200 }
201 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530202 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530203 }
204 }
205 }
206
207 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530208 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530209 *
210 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530211 * generated
212 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530213 */
214 public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
215 switch (targetLanguage) {
216 case JAVA_GENERATION: {
217 return new YangJavaTypeDef();
218 }
219 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530220 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530221 }
222 }
223 }
224
225 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530226 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530227 *
228 * @param targetLanguage target language in which YANG mapping needs to be
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530229 * generated
230 * @return the corresponding inherited node based on the target language
231 */
232 public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
233 switch (targetLanguage) {
234 case JAVA_GENERATION: {
235 return new YangJavaUnion();
236 }
237 default: {
238 throw new TranslatorException("Only YANG to Java is supported.");
239 }
240 }
241 }
242
243 /**
244 * Returns based on the target language generate the inherited data model node.
245 *
246 * @param targetLanguage target language in which YANG mapping needs to be
247 * generated
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530248 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530249 */
250 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
251 switch (targetLanguage) {
252 case JAVA_GENERATION: {
253 return new YangJavaUses();
254 }
255 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530256 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530257 }
258 }
259 }
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530260
261 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530262 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530263 *
264 * @param targetLanguage target language in which YANG mapping needs to be
265 * generated
266 * @return the corresponding inherited node based on the target language
267 */
268 public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
269 switch (targetLanguage) {
270 case JAVA_GENERATION: {
271 return new YangJavaNotification();
272 }
273 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530274 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530275 }
276 }
277 }
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530278
279 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530280 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530281 *
282 * @param targetLanguage target language in which YANG mapping needs to be
283 * generated
284 * @return the corresponding inherited node based on the target language
285 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530286 public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
287 switch (targetLanguage) {
288 case JAVA_GENERATION: {
289 return new YangJavaLeaf();
290 }
291 default: {
292 throw new RuntimeException("Only YANG to Java is supported.");
293 }
294 }
295 }
296 /**
297 * Returns based on the target language generate the inherited data model node.
298 *
299 * @param targetLanguage target language in which YANG mapping needs to be
300 * generated
301 * @return the corresponding inherited node based on the target language
302 */
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530303 public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
304 switch (targetLanguage) {
305 case JAVA_GENERATION: {
306 return new YangJavaRpc();
307 }
308 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530309 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530310 }
311 }
312 }
313
314 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530315 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530316 *
317 * @param targetLanguage target language in which YANG mapping needs to be
318 * generated
319 * @return the corresponding inherited node based on the target language
320 */
321 public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
322 switch (targetLanguage) {
323 case JAVA_GENERATION: {
324 return new YangJavaInput();
325 }
326 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530327 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530328 }
329 }
330 }
331
332 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530333 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530334 *
335 * @param targetLanguage target language in which YANG mapping needs to be
336 * generated
337 * @return the corresponding inherited node based on the target language
338 */
339 public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
340 switch (targetLanguage) {
341 case JAVA_GENERATION: {
342 return new YangJavaOutput();
343 }
344 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530345 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530346 }
347 }
348 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530349}