Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.yangutils.datamodel.utils; |
| 17 | |
| 18 | import org.onosproject.yangutils.datamodel.YangAugment; |
| 19 | import org.onosproject.yangutils.datamodel.YangCase; |
| 20 | import org.onosproject.yangutils.datamodel.YangChoice; |
| 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 22 | import org.onosproject.yangutils.datamodel.YangGrouping; |
| 23 | import org.onosproject.yangutils.datamodel.YangList; |
| 24 | import org.onosproject.yangutils.datamodel.YangModule; |
| 25 | import org.onosproject.yangutils.datamodel.YangSubModule; |
| 26 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 27 | import org.onosproject.yangutils.datamodel.YangUses; |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangNotification; |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangRpc; |
| 30 | import org.onosproject.yangutils.datamodel.YangInput; |
| 31 | import org.onosproject.yangutils.datamodel.YangOutput; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; |
| 33 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase; |
| 34 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; |
| 35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer; |
| 36 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; |
| 37 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList; |
| 38 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
| 39 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; |
| 40 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; |
| 41 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses; |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 42 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 43 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc; |
| 44 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; |
| 45 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 46 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Factory to create data model objects based on the target file type. |
| 50 | */ |
| 51 | public final class YangDataModelFactory { |
| 52 | |
| 53 | /** |
| 54 | * Utility class, hence private to prevent creating objects. |
| 55 | */ |
| 56 | private YangDataModelFactory() { |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Based on the target language generate the inherited data model node. |
| 61 | * |
| 62 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 63 | * generated |
| 64 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 65 | */ |
| 66 | public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) { |
| 67 | switch (targetLanguage) { |
| 68 | case JAVA_GENERATION: { |
| 69 | return new YangJavaModule(); |
| 70 | } |
| 71 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 72 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Based on the target language generate the inherited data model node. |
| 79 | * |
| 80 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 81 | * generated |
| 82 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 83 | */ |
| 84 | public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) { |
| 85 | switch (targetLanguage) { |
| 86 | case JAVA_GENERATION: { |
| 87 | return new YangJavaAugment(); |
| 88 | } |
| 89 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 90 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Based on the target language generate the inherited data model node. |
| 97 | * |
| 98 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 99 | * generated |
| 100 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 101 | */ |
| 102 | public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) { |
| 103 | switch (targetLanguage) { |
| 104 | case JAVA_GENERATION: { |
| 105 | return new YangJavaCase(); |
| 106 | } |
| 107 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 108 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Based on the target language generate the inherited data model node. |
| 115 | * |
| 116 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 117 | * generated |
| 118 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 119 | */ |
| 120 | public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) { |
| 121 | switch (targetLanguage) { |
| 122 | case JAVA_GENERATION: { |
| 123 | return new YangJavaChoice(); |
| 124 | } |
| 125 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 126 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Based on the target language generate the inherited data model node. |
| 133 | * |
| 134 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 135 | * generated |
| 136 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 137 | */ |
| 138 | public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) { |
| 139 | switch (targetLanguage) { |
| 140 | case JAVA_GENERATION: { |
| 141 | return new YangJavaContainer(); |
| 142 | } |
| 143 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 144 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Based on the target language generate the inherited data model node. |
| 151 | * |
| 152 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 153 | * generated |
| 154 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 155 | */ |
| 156 | public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) { |
| 157 | switch (targetLanguage) { |
| 158 | case JAVA_GENERATION: { |
| 159 | return new YangJavaGrouping(); |
| 160 | } |
| 161 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 162 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Based on the target language generate the inherited data model node. |
| 169 | * |
| 170 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 171 | * generated |
| 172 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 173 | */ |
| 174 | public static YangList getYangListNode(GeneratedLanguage targetLanguage) { |
| 175 | switch (targetLanguage) { |
| 176 | case JAVA_GENERATION: { |
| 177 | return new YangJavaList(); |
| 178 | } |
| 179 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 180 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Based on the target language generate the inherited data model node. |
| 187 | * |
| 188 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 189 | * generated |
| 190 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 191 | */ |
| 192 | public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) { |
| 193 | switch (targetLanguage) { |
| 194 | case JAVA_GENERATION: { |
| 195 | return new YangJavaSubModule(); |
| 196 | } |
| 197 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 198 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Based on the target language generate the inherited data model node. |
| 205 | * |
| 206 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 207 | * generated |
| 208 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 209 | */ |
| 210 | public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) { |
| 211 | switch (targetLanguage) { |
| 212 | case JAVA_GENERATION: { |
| 213 | return new YangJavaTypeDef(); |
| 214 | } |
| 215 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 216 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Based on the target language generate the inherited data model node. |
| 223 | * |
| 224 | * @param targetLanguage target language in which YANG mapping needs to be |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 225 | * generated |
| 226 | * @return the corresponding inherited node based on the target language |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 227 | */ |
| 228 | public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) { |
| 229 | switch (targetLanguage) { |
| 230 | case JAVA_GENERATION: { |
| 231 | return new YangJavaUses(); |
| 232 | } |
| 233 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 234 | throw new TranslatorException("Only YANG to Java is supported."); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Based on the target language generate the inherited data model node. |
| 241 | * |
| 242 | * @param targetLanguage target language in which YANG mapping needs to be |
| 243 | * generated |
| 244 | * @return the corresponding inherited node based on the target language |
| 245 | */ |
| 246 | public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) { |
| 247 | switch (targetLanguage) { |
| 248 | case JAVA_GENERATION: { |
| 249 | return new YangJavaNotification(); |
| 250 | } |
| 251 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 252 | throw new TranslatorException("Only YANG to Java is supported."); |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | } |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * Based on the target language generate the inherited data model node. |
| 259 | * |
| 260 | * @param targetLanguage target language in which YANG mapping needs to be |
| 261 | * generated |
| 262 | * @return the corresponding inherited node based on the target language |
| 263 | */ |
| 264 | public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) { |
| 265 | switch (targetLanguage) { |
| 266 | case JAVA_GENERATION: { |
| 267 | return new YangJavaRpc(); |
| 268 | } |
| 269 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 270 | throw new TranslatorException("Only YANG to Java is supported."); |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Based on the target language generate the inherited data model node. |
| 277 | * |
| 278 | * @param targetLanguage target language in which YANG mapping needs to be |
| 279 | * generated |
| 280 | * @return the corresponding inherited node based on the target language |
| 281 | */ |
| 282 | public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) { |
| 283 | switch (targetLanguage) { |
| 284 | case JAVA_GENERATION: { |
| 285 | return new YangJavaInput(); |
| 286 | } |
| 287 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 288 | throw new TranslatorException("Only YANG to Java is supported."); |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Based on the target language generate the inherited data model node. |
| 295 | * |
| 296 | * @param targetLanguage target language in which YANG mapping needs to be |
| 297 | * generated |
| 298 | * @return the corresponding inherited node based on the target language |
| 299 | */ |
| 300 | public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) { |
| 301 | switch (targetLanguage) { |
| 302 | case JAVA_GENERATION: { |
| 303 | return new YangJavaOutput(); |
| 304 | } |
| 305 | default: { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 306 | throw new TranslatorException("Only YANG to Java is supported."); |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 310 | } |