blob: 03d82d11dfcce69f3fee4f8e22ee8ae7aa32f0e9 [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;
28import org.onosproject.yangutils.datamodel.YangUses;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053029import org.onosproject.yangutils.datamodel.YangNotification;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053030import org.onosproject.yangutils.datamodel.YangRpc;
31import org.onosproject.yangutils.datamodel.YangInput;
32import org.onosproject.yangutils.datamodel.YangOutput;
Vinod Kumar S38046502016-03-23 15:30:27 +053033import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
34import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
35import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
36import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
37import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053038import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
Vinod Kumar S38046502016-03-23 15:30:27 +053039import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
40import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
41import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
42import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
43import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053044import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053045import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
46import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
47import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053048import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053049
50/**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 *Represents factory to create data model objects based on the target file type.
Vinod Kumar S38046502016-03-23 15:30:27 +053052 */
53public final class YangDataModelFactory {
54
55 /**
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053056 * Utility class, hence private to prevent creating objects.
Vinod Kumar S38046502016-03-23 15:30:27 +053057 */
58 private YangDataModelFactory() {
59 }
60
61 /**
62 * Based on the target language generate the inherited data model node.
63 *
64 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +053065 * generated
66 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053067 */
68 public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
69 switch (targetLanguage) {
70 case JAVA_GENERATION: {
71 return new YangJavaModule();
72 }
73 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053074 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053075 }
76 }
77 }
78
79 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053080 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053081 *
82 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +053083 * generated
84 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +053085 */
86 public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
87 switch (targetLanguage) {
88 case JAVA_GENERATION: {
89 return new YangJavaAugment();
90 }
91 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053092 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +053093 }
94 }
95 }
96
97 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053098 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +053099 *
100 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530101 * generated
102 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530103 */
104 public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
105 switch (targetLanguage) {
106 case JAVA_GENERATION: {
107 return new YangJavaCase();
108 }
109 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530110 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530111 }
112 }
113 }
114
115 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530116 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530117 *
118 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530119 * generated
120 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530121 */
122 public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
123 switch (targetLanguage) {
124 case JAVA_GENERATION: {
125 return new YangJavaChoice();
126 }
127 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530128 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530129 }
130 }
131 }
132
133 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530134 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530135 *
136 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530137 * generated
138 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530139 */
140 public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
141 switch (targetLanguage) {
142 case JAVA_GENERATION: {
143 return new YangJavaContainer();
144 }
145 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530146 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530147 }
148 }
149 }
150
151 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530152 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530153 *
154 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530155 * generated
156 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530157 */
158 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
159 switch (targetLanguage) {
160 case JAVA_GENERATION: {
161 return new YangJavaGrouping();
162 }
163 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530164 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530165 }
166 }
167 }
168
169 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530170 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530171 *
172 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530173 * generated
174 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530175 */
176 public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
177 switch (targetLanguage) {
178 case JAVA_GENERATION: {
179 return new YangJavaList();
180 }
181 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530182 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530183 }
184 }
185 }
186
187 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530188 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530189 *
190 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530191 * generated
192 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530193 */
194 public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
195 switch (targetLanguage) {
196 case JAVA_GENERATION: {
197 return new YangJavaSubModule();
198 }
199 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530200 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530201 }
202 }
203 }
204
205 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530206 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530207 *
208 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530209 * generated
210 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530211 */
212 public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
213 switch (targetLanguage) {
214 case JAVA_GENERATION: {
215 return new YangJavaTypeDef();
216 }
217 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530218 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530219 }
220 }
221 }
222
223 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530224 * Returns based on the target language generate the inherited data model node.
Vinod Kumar S38046502016-03-23 15:30:27 +0530225 *
226 * @param targetLanguage target language in which YANG mapping needs to be
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530227 * generated
228 * @return the corresponding inherited node based on the target language
Vinod Kumar S38046502016-03-23 15:30:27 +0530229 */
230 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
231 switch (targetLanguage) {
232 case JAVA_GENERATION: {
233 return new YangJavaUses();
234 }
235 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530236 throw new TranslatorException("Only YANG to Java is supported.");
Vinod Kumar S38046502016-03-23 15:30:27 +0530237 }
238 }
239 }
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530240
241 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530242 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530243 *
244 * @param targetLanguage target language in which YANG mapping needs to be
245 * generated
246 * @return the corresponding inherited node based on the target language
247 */
248 public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
249 switch (targetLanguage) {
250 case JAVA_GENERATION: {
251 return new YangJavaNotification();
252 }
253 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530254 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530255 }
256 }
257 }
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530258
259 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530260 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530261 *
262 * @param targetLanguage target language in which YANG mapping needs to be
263 * generated
264 * @return the corresponding inherited node based on the target language
265 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530266 public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
267 switch (targetLanguage) {
268 case JAVA_GENERATION: {
269 return new YangJavaLeaf();
270 }
271 default: {
272 throw new RuntimeException("Only YANG to Java is supported.");
273 }
274 }
275 }
276 /**
277 * Returns based on the target language generate the inherited data model node.
278 *
279 * @param targetLanguage target language in which YANG mapping needs to be
280 * generated
281 * @return the corresponding inherited node based on the target language
282 */
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530283 public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
284 switch (targetLanguage) {
285 case JAVA_GENERATION: {
286 return new YangJavaRpc();
287 }
288 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530289 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530290 }
291 }
292 }
293
294 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530295 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530296 *
297 * @param targetLanguage target language in which YANG mapping needs to be
298 * generated
299 * @return the corresponding inherited node based on the target language
300 */
301 public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
302 switch (targetLanguage) {
303 case JAVA_GENERATION: {
304 return new YangJavaInput();
305 }
306 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530307 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530308 }
309 }
310 }
311
312 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530313 * Returns based on the target language generate the inherited data model node.
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530314 *
315 * @param targetLanguage target language in which YANG mapping needs to be
316 * generated
317 * @return the corresponding inherited node based on the target language
318 */
319 public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
320 switch (targetLanguage) {
321 case JAVA_GENERATION: {
322 return new YangJavaOutput();
323 }
324 default: {
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530325 throw new TranslatorException("Only YANG to Java is supported.");
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530326 }
327 }
328 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530329}