Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +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 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 22 | import java.util.List; |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 23 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangCase; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangChoice; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangModule; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangSubModule; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 38 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 40 | import org.onosproject.yangutils.translator.tojava |
| 41 | .JavaQualifiedTypeInfoTranslator; |
| 42 | import org.onosproject.yangutils.translator.tojava |
| 43 | .TempJavaCodeFragmentFilesContainer; |
| 44 | import org.onosproject.yangutils.translator.tojava |
| 45 | .TempJavaEnumerationFragmentFiles; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 46 | import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 47 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 48 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 49 | import org.onosproject.yangutils.utils.io.YangPluginConfig; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 50 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 51 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype |
| 52 | .YangDataTypes.BINARY; |
| 53 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype |
| 54 | .YangDataTypes.BITS; |
| 55 | import static org.onosproject.yangutils.translator.tojava |
| 56 | .GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 57 | import static org.onosproject.yangutils.translator.tojava |
| 58 | .GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
| 59 | import static org.onosproject.yangutils.translator.tojava |
| 60 | .GeneratedJavaFileType.DEFAULT_CLASS_MASK; |
| 61 | import static org.onosproject.yangutils.translator.tojava |
| 62 | .GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
| 63 | import static org.onosproject.yangutils.translator.tojava |
| 64 | .GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 65 | import static org.onosproject.yangutils.translator.tojava |
| 66 | .GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
| 67 | import static org.onosproject.yangutils.translator.tojava |
| 68 | .GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
| 69 | import static org.onosproject.yangutils.translator.tojava |
| 70 | .GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 71 | import static org.onosproject.yangutils.translator.tojava |
| 72 | .GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
| 73 | import static org.onosproject.yangutils.translator.tojava |
| 74 | .GeneratedJavaFileType.GENERATE_UNION_CLASS; |
| 75 | import static org.onosproject.yangutils.translator.tojava |
| 76 | .GeneratedJavaFileType.INTERFACE_MASK; |
| 77 | import static org.onosproject.yangutils.translator.tojava |
| 78 | .GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK; |
| 79 | import static org.onosproject.yangutils.translator.tojava |
| 80 | .GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK; |
| 81 | import static org.onosproject.yangutils.translator.tojava |
| 82 | .GeneratedTempFileType.ATTRIBUTES_MASK; |
| 83 | import static org.onosproject.yangutils.translator.tojava |
| 84 | .GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
| 85 | import static org.onosproject.yangutils.translator.tojava |
| 86 | .GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
| 87 | import static org.onosproject.yangutils.translator.tojava |
| 88 | .GeneratedTempFileType.ENUM_IMPL_MASK; |
| 89 | import static org.onosproject.yangutils.translator.tojava |
| 90 | .GeneratedTempFileType.EQUALS_IMPL_MASK; |
| 91 | import static org.onosproject.yangutils.translator.tojava |
| 92 | .GeneratedTempFileType.EVENT_ENUM_MASK; |
| 93 | import static org.onosproject.yangutils.translator.tojava |
| 94 | .GeneratedTempFileType.EVENT_METHOD_MASK; |
| 95 | import static org.onosproject.yangutils.translator.tojava |
| 96 | .GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 97 | import static org.onosproject.yangutils.translator.tojava |
| 98 | .GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 99 | import static org.onosproject.yangutils.translator.tojava |
| 100 | .GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
| 101 | import static org.onosproject.yangutils.translator.tojava |
| 102 | .GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
| 103 | import static org.onosproject.yangutils.translator.tojava |
| 104 | .GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 105 | import static org.onosproject.yangutils.translator.tojava |
| 106 | .GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 107 | import static org.onosproject.yangutils.translator.tojava |
| 108 | .GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
| 109 | import static org.onosproject.yangutils.translator.tojava |
| 110 | .GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK; |
| 111 | import static org.onosproject.yangutils.translator.tojava |
| 112 | .GeneratedTempFileType.OF_STRING_IMPL_MASK; |
| 113 | import static org.onosproject.yangutils.translator.tojava |
| 114 | .GeneratedTempFileType.RPC_INTERFACE_MASK; |
| 115 | import static org.onosproject.yangutils.translator.tojava |
| 116 | .GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 117 | import static org.onosproject.yangutils.translator.tojava |
| 118 | .GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 119 | import static org.onosproject.yangutils.translator.tojava |
| 120 | .GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 121 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo |
| 122 | .getAttributeInfoForTheData; |
| 123 | import static org.onosproject.yangutils.translator.tojava |
| 124 | .JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode; |
| 125 | import static org.onosproject.yangutils.translator.tojava |
| 126 | .TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; |
| 127 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils |
| 128 | .getQualifierInfoForCasesParent; |
| 129 | import static org.onosproject.yangutils.translator.tojava.utils |
| 130 | .JavaCodeSnippetGen.addAugmentationAttribute; |
| 131 | import static org.onosproject.yangutils.translator.tojava.utils |
| 132 | .JavaCodeSnippetGen.getEnumsValueAttribute; |
| 133 | import static org.onosproject.yangutils.translator.tojava.utils |
| 134 | .JavaCodeSnippetGen.getEventEnumTypeStart; |
| 135 | import static org.onosproject.yangutils.translator.tojava.utils |
| 136 | .JavaCodeSnippetGen.getOperationAttributeForConstructor; |
| 137 | import static org.onosproject.yangutils.translator.tojava.utils |
| 138 | .JavaCodeSnippetGen.getOperationAttributes; |
| 139 | import static org.onosproject.yangutils.translator.tojava.utils |
| 140 | .JavaCodeSnippetGen.getOperationTypeAttr; |
| 141 | import static org.onosproject.yangutils.translator.tojava.utils |
| 142 | .JavaCodeSnippetGen.getOperationTypeEnum; |
| 143 | import static org.onosproject.yangutils.translator.tojava.utils |
| 144 | .JavaCodeSnippetGen.getOperationTypeForConstructor; |
| 145 | import static org.onosproject.yangutils.translator.tojava.utils |
| 146 | .JavaFileGeneratorUtils.getDataFromTempFileHandle; |
| 147 | import static org.onosproject.yangutils.translator.tojava.utils |
| 148 | .JavaFileGeneratorUtils.initiateJavaFileGeneration; |
| 149 | import static org.onosproject.yangutils.translator.tojava.utils |
| 150 | .MethodsGenerator.builderMethod; |
| 151 | import static org.onosproject.yangutils.translator.tojava.utils |
| 152 | .MethodsGenerator.getAddAugmentInfoMethodImpl; |
| 153 | import static org.onosproject.yangutils.translator.tojava.utils |
| 154 | .MethodsGenerator.getAddAugmentInfoMethodInterface; |
| 155 | import static org.onosproject.yangutils.translator.tojava.utils |
| 156 | .MethodsGenerator.getAugmentsDataMethodForService; |
| 157 | import static org.onosproject.yangutils.translator.tojava.utils |
| 158 | .MethodsGenerator.getConstructorStart; |
| 159 | import static org.onosproject.yangutils.translator.tojava.utils |
| 160 | .MethodsGenerator.getEnumsConstructor; |
| 161 | import static org.onosproject.yangutils.translator.tojava.utils |
| 162 | .MethodsGenerator.getEnumsOfMethod; |
| 163 | import static org.onosproject.yangutils.translator.tojava.utils |
| 164 | .MethodsGenerator.getEqualsMethodClose; |
| 165 | import static org.onosproject.yangutils.translator.tojava.utils |
| 166 | .MethodsGenerator.getEqualsMethodOpen; |
| 167 | import static org.onosproject.yangutils.translator.tojava.utils |
| 168 | .MethodsGenerator.getFromStringMethodClose; |
| 169 | import static org.onosproject.yangutils.translator.tojava.utils |
| 170 | .MethodsGenerator.getFromStringMethodSignature; |
| 171 | import static org.onosproject.yangutils.translator.tojava.utils |
| 172 | .MethodsGenerator.getGetter; |
| 173 | import static org.onosproject.yangutils.translator.tojava.utils |
| 174 | .MethodsGenerator.getGetterForOperationType; |
| 175 | import static org.onosproject.yangutils.translator.tojava.utils |
| 176 | .MethodsGenerator.getGettersForValueAndSelectLeaf; |
| 177 | import static org.onosproject.yangutils.translator.tojava.utils |
| 178 | .MethodsGenerator.getHashCodeMethodClose; |
| 179 | import static org.onosproject.yangutils.translator.tojava.utils |
| 180 | .MethodsGenerator.getHashCodeMethodOpen; |
| 181 | import static org.onosproject.yangutils.translator.tojava.utils |
| 182 | .MethodsGenerator.getInterfaceLeafIdEnumMethods; |
| 183 | import static org.onosproject.yangutils.translator.tojava.utils |
| 184 | .MethodsGenerator.getInterfaceLeafIdEnumSignature; |
| 185 | import static org.onosproject.yangutils.translator.tojava.utils |
| 186 | .MethodsGenerator.getOmitNullValueString; |
| 187 | import static org.onosproject.yangutils.translator.tojava.utils |
| 188 | .MethodsGenerator.getOperationAttributesGetters; |
| 189 | import static org.onosproject.yangutils.translator.tojava.utils |
| 190 | .MethodsGenerator.getOverRideString; |
| 191 | import static org.onosproject.yangutils.translator.tojava.utils |
| 192 | .MethodsGenerator.getRangeValidatorMethodForUnion; |
| 193 | import static org.onosproject.yangutils.translator.tojava.utils |
| 194 | .MethodsGenerator.getSetterForOperationType; |
| 195 | import static org.onosproject.yangutils.translator.tojava.utils |
| 196 | .MethodsGenerator.getSetterForSelectLeaf; |
| 197 | import static org.onosproject.yangutils.translator.tojava.utils |
| 198 | .MethodsGenerator.getToStringMethodClose; |
| 199 | import static org.onosproject.yangutils.translator.tojava.utils |
| 200 | .MethodsGenerator.getToStringMethodOpen; |
| 201 | import static org.onosproject.yangutils.translator.tojava.utils |
| 202 | .MethodsGenerator.getYangAugmentInfoImpl; |
| 203 | import static org.onosproject.yangutils.translator.tojava.utils |
| 204 | .MethodsGenerator.getYangAugmentInfoInterface; |
| 205 | import static org.onosproject.yangutils.translator.tojava.utils |
| 206 | .MethodsGenerator.getYangAugmentInfoMapImpl; |
| 207 | import static org.onosproject.yangutils.translator.tojava.utils |
| 208 | .MethodsGenerator.getYangAugmentInfoMapInterface; |
| 209 | import static org.onosproject.yangutils.translator.tojava.utils |
| 210 | .MethodsGenerator.isLeafValueSetInterface; |
| 211 | import static org.onosproject.yangutils.translator.tojava.utils |
| 212 | .MethodsGenerator.isSelectLeafSetInterface; |
| 213 | import static org.onosproject.yangutils.translator.tojava.utils |
| 214 | .MethodsGenerator.processSubtreeFilteringInterface; |
| 215 | import static org.onosproject.yangutils.translator.tojava.utils |
| 216 | .MethodsGenerator.setSelectLeafSetInterface; |
| 217 | import static org.onosproject.yangutils.translator.tojava.utils |
| 218 | .SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering; |
| 219 | import static org.onosproject.yangutils.translator.tojava.utils |
| 220 | .SubtreeFilteringMethodsGenerator.getProcessChildNodeSubtreeFiltering; |
| 221 | import static org.onosproject.yangutils.translator.tojava.utils |
| 222 | .SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering; |
| 223 | import static org.onosproject.yangutils.translator.tojava.utils |
| 224 | .SubtreeFilteringMethodsGenerator.getProcessLeafSubtreeFiltering; |
| 225 | import static org.onosproject.yangutils.translator.tojava.utils |
| 226 | .SubtreeFilteringMethodsGenerator.getProcessSubTreeFilteringEnd; |
| 227 | import static org.onosproject.yangutils.translator.tojava.utils |
| 228 | .SubtreeFilteringMethodsGenerator.getProcessSubtreeFilteringStart; |
| 229 | import static org.onosproject.yangutils.translator.tojava.utils |
| 230 | .SubtreeFilteringMethodsGenerator.getProcessSubtreeFunctionBody; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 231 | import static org.onosproject.yangutils.utils.UtilConstants.BASE64; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 232 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 233 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 234 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 235 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 236 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 237 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 238 | import static org.onosproject.yangutils.utils.UtilConstants |
| 239 | .EIGHT_SPACE_INDENTATION; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 240 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 241 | import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 242 | import static org.onosproject.yangutils.utils.UtilConstants |
| 243 | .EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 244 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 245 | import static org.onosproject.yangutils.utils.UtilConstants |
| 246 | .EVENT_SUBJECT_NAME_SUFFIX; |
| 247 | import static org.onosproject.yangutils.utils.UtilConstants |
| 248 | .FOUR_SPACE_INDENTATION; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 249 | import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 250 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 251 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 252 | import static org.onosproject.yangutils.utils.UtilConstants |
| 253 | .JAVA_UTIL_IMPORT_BASE64_CLASS; |
| 254 | import static org.onosproject.yangutils.utils.UtilConstants |
| 255 | .JAVA_UTIL_OBJECTS_IMPORT_PKG; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 256 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 257 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 258 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 259 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 260 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 261 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 262 | import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 263 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 264 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 265 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 266 | import static org.onosproject.yangutils.utils.UtilConstants |
| 267 | .SERVICE_METHOD_STRING; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 268 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 269 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 270 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 271 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType |
| 272 | .GETTER_METHOD; |
| 273 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType |
| 274 | .TYPE_CONSTRUCTOR; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 275 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 276 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils |
| 277 | .getCapitalCase; |
| 278 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils |
| 279 | .insertDataIntoJavaFile; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 280 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.replaceLast; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 281 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 282 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils |
| 283 | .validateLineLength; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 284 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 285 | import static java.util.Collections.sort; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 286 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 287 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 288 | * Representation of java file generator. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 289 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 290 | public final class JavaFileGenerator { |
| 291 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 292 | private JavaFileGenerator() { |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Returns generated interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 297 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 298 | * @param file file |
| 299 | * @param imports imports for the file |
| 300 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 301 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 302 | * @return interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 303 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 304 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 305 | public static File generateInterfaceFile(File file, List<String> imports, |
| 306 | YangNode curNode, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 307 | boolean isAttrPresent) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 308 | throws IOException { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 309 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 310 | JavaFileInfoTranslator javaFileInfo = |
| 311 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 312 | |
| 313 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 314 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 315 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 316 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 317 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 318 | path = javaFileInfo.getBaseCodeGenPath() + |
| 319 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 320 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 321 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 322 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 323 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 324 | boolean isLeavesPresent; |
| 325 | YangLeavesHolder leavesHolder; |
| 326 | if (curNode instanceof YangLeavesHolder) { |
| 327 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 328 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 329 | !leavesHolder.getListOfLeaf().isEmpty() |
| 330 | || leavesHolder.getListOfLeafList() != null && |
| 331 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 332 | } else { |
| 333 | isLeavesPresent = false; |
| 334 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 335 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 336 | initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, |
| 337 | className); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 338 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 339 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 340 | // Add getter methods to interface file. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 341 | try { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 342 | //Leaf identifier enum. |
| 343 | if (isLeavesPresent) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 344 | insertDataIntoJavaFile(file, NEW_LINE + |
| 345 | getInterfaceLeafIdEnumSignature(className) + |
| 346 | NEW_LINE + |
| 347 | trimAtLast(replaceLast(getDataFromTempFileHandle( |
| 348 | LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK, |
| 349 | ((TempJavaCodeFragmentFilesContainer) |
| 350 | curNode) |
| 351 | .getTempJavaCodeFragmentFiles() |
| 352 | .getBeanTempFiles(), path), |
| 353 | COMMA, SEMI_COLAN), |
| 354 | NEW_LINE) + |
| 355 | NEW_LINE + NEW_LINE + |
| 356 | getInterfaceLeafIdEnumMethods()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 357 | } |
| 358 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 359 | //Getter methods. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 360 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 361 | GETTER_FOR_INTERFACE_MASK, |
| 362 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 363 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 364 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 365 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 366 | throw new IOException( |
| 367 | "No data found in temporary java code fragment files " + |
| 368 | "for " + |
| 369 | className |
| 370 | + " while interface file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 371 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 372 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 373 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 374 | if (curNode instanceof YangAugmentableNode && |
| 375 | !(curNode instanceof YangChoice)) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 376 | methods.add(getYangAugmentInfoInterface()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 377 | methods.add(getYangAugmentInfoMapInterface( |
| 378 | javaFileInfo.getPluginConfig())); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 379 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 380 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 381 | if (curNode instanceof YangCase) { |
| 382 | YangNode caseParent = curNode.getParent(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 383 | JavaQualifiedTypeInfo qualifiedTypeInfo = |
| 384 | getQualifierInfoForCasesParent(caseParent, |
| 385 | javaFileInfo |
| 386 | .getPluginConfig()); |
| 387 | methods.add(NEW_LINE + processSubtreeFilteringInterface |
| 388 | (qualifiedTypeInfo.getClassInfo())); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 389 | } else { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 390 | methods.add(NEW_LINE + processSubtreeFilteringInterface(className)); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 391 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 392 | |
| 393 | if (isLeavesPresent) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 394 | methods.add(NEW_LINE + isLeafValueSetInterface()); |
| 395 | methods.add(NEW_LINE + isSelectLeafSetInterface()); |
| 396 | } |
| 397 | for (String method : methods) { |
| 398 | insertDataIntoJavaFile(file, method); |
| 399 | } |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 400 | return file; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 401 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 405 | * Returns generated builder interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 406 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 407 | * @param file file |
| 408 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 409 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 410 | * @return builder interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 411 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 412 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 413 | public static File generateBuilderInterfaceFile(File file, YangNode curNode, |
| 414 | boolean isAttrPresent) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 415 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 416 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 417 | JavaFileInfoTranslator javaFileInfo = |
| 418 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 419 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 420 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 421 | boolean isLeavesPresent; |
| 422 | YangLeavesHolder leavesHolder; |
| 423 | if (curNode instanceof YangLeavesHolder) { |
| 424 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 425 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 426 | !leavesHolder.getListOfLeaf().isEmpty() |
| 427 | || leavesHolder.getListOfLeafList() != null && |
| 428 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 429 | } else { |
| 430 | isLeavesPresent = false; |
| 431 | } |
| 432 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 433 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 434 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 435 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 436 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 437 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 438 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 439 | path = javaFileInfo.getBaseCodeGenPath() + |
| 440 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 441 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 442 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 443 | initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, |
| 444 | className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 445 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 446 | if (isAttrPresent) { |
| 447 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 448 | |
| 449 | //Getter methods. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 450 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle( |
| 451 | GETTER_FOR_INTERFACE_MASK, |
| 452 | ((TempJavaCodeFragmentFilesContainer) |
| 453 | curNode) |
| 454 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 455 | .getBeanTempFiles(), path)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 456 | |
| 457 | //Setter methods. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 458 | methods.add(NEW_LINE); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 459 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle( |
| 460 | SETTER_FOR_INTERFACE_MASK, |
| 461 | ((TempJavaCodeFragmentFilesContainer) |
| 462 | curNode) |
| 463 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 464 | .getBeanTempFiles(), path)); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 465 | |
| 466 | //Add to list method. |
| 467 | methods.add(NEW_LINE); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 468 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 469 | ADD_TO_LIST_INTERFACE_MASK, |
| 470 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 471 | .getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 472 | .getBeanTempFiles(), path)); |
| 473 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 474 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 475 | throw new IOException( |
| 476 | "No data found in temporary java code fragment files " + |
| 477 | "for " + |
| 478 | className |
| 479 | + " while builder interface file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 480 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 481 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 482 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 483 | if (curNode instanceof YangAugmentableNode && |
| 484 | !(curNode instanceof YangChoice)) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 485 | methods.add(getAddAugmentInfoMethodInterface()); |
| 486 | methods.add(getYangAugmentInfoInterface()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 487 | methods.add(getYangAugmentInfoMapInterface( |
| 488 | javaFileInfo.getPluginConfig())); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 489 | } |
| 490 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 491 | if (isLeavesPresent) { |
| 492 | methods.add(NEW_LINE + setSelectLeafSetInterface(className)); |
| 493 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 494 | //Add build method to builder interface file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 495 | methods.add( |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 496 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 497 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 498 | .addBuildMethodForInterface(pluginConfig)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 499 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 500 | |
| 501 | //Add getters and setters in builder interface. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 502 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 503 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 504 | } |
| 505 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 506 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 507 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Returns generated builder class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 512 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 513 | * @param file file |
| 514 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 515 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 516 | * @return builder class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 517 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 518 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 519 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 520 | public static File generateBuilderClassFile(File file, YangNode curNode, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 521 | boolean isAttrPresent) |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 522 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 523 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 524 | JavaFileInfoTranslator javaFileInfo = |
| 525 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 526 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 527 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 528 | boolean isLeavesPresent; |
| 529 | YangLeavesHolder leavesHolder; |
| 530 | if (curNode instanceof YangLeavesHolder) { |
| 531 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 532 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 533 | !leavesHolder.getListOfLeaf().isEmpty() |
| 534 | || leavesHolder.getListOfLeafList() != null && |
| 535 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 536 | } else { |
| 537 | isLeavesPresent = false; |
| 538 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 539 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 540 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
| 541 | boolean isRootNode = false; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 542 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 543 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 544 | isRootNode = true; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 545 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 546 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 547 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 548 | path = javaFileInfo.getBaseCodeGenPath() + |
| 549 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 550 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 551 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 552 | initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, |
| 553 | className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 554 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 555 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 556 | if (curNode instanceof YangAugmentableNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 557 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 558 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 559 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 560 | |
| 561 | //Add attribute strings. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 562 | try { |
| 563 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 564 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 565 | getDataFromTempFileHandle( |
| 566 | ATTRIBUTES_MASK, |
| 567 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 568 | .getTempJavaCodeFragmentFiles() |
| 569 | .getBeanTempFiles(), |
| 570 | path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 571 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 572 | throw new IOException( |
| 573 | "No data found in temporary java code fragment files " + |
| 574 | "for " + className + |
| 575 | " while builder class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 576 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 577 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 578 | insertDataIntoJavaFile(file, getOperationTypeAttr()); |
| 579 | if (isLeavesPresent) { |
| 580 | insertDataIntoJavaFile(file, getOperationAttributes()); |
| 581 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 582 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 583 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 584 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 585 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 586 | .getTempJavaCodeFragmentFiles() |
| 587 | .getBeanTempFiles(), |
| 588 | path)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 589 | // Setter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 590 | methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 591 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 592 | .getTempJavaCodeFragmentFiles() |
| 593 | .getBeanTempFiles(), |
| 594 | path)); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 595 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 596 | //Add to list impl method. |
| 597 | methods.add(getDataFromTempFileHandle(ADD_TO_LIST_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 598 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 599 | .getTempJavaCodeFragmentFiles() |
| 600 | .getBeanTempFiles(), |
| 601 | path)); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 602 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 603 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 604 | |
| 605 | methods.add(getGetterForOperationType()); |
| 606 | methods.add(getSetterForOperationType(className)); |
| 607 | //Add operation attribute methods. |
| 608 | if (isLeavesPresent) { |
| 609 | methods.add(getOperationAttributesGetters() + NEW_LINE); |
| 610 | methods.add(getSetterForSelectLeaf(className, isRootNode)); |
| 611 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 612 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 613 | throw new IOException( |
| 614 | "No data found in temporary java code fragment files " + |
| 615 | "for " + className + |
| 616 | " while builder class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 617 | } |
| 618 | } else { |
| 619 | insertDataIntoJavaFile(file, NEW_LINE); |
| 620 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 621 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 622 | if (curNode instanceof YangAugmentableNode) { |
| 623 | methods.add(getAddAugmentInfoMethodImpl()); |
| 624 | methods.add(getYangAugmentInfoImpl()); |
| 625 | methods.add(getYangAugmentInfoMapImpl()); |
| 626 | } |
| 627 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 628 | // Add default constructor and build method impl. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 629 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 630 | .getTempJavaCodeFragmentFiles() |
| 631 | .addBuildMethodImpl(curNode)); |
| 632 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 633 | .getTempJavaCodeFragmentFiles() |
| 634 | .addDefaultConstructor(PUBLIC, BUILDER, |
| 635 | pluginConfig, curNode)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 636 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 637 | |
| 638 | //Add methods in builder class. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 639 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 640 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 641 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 642 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 643 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 644 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 648 | * Returns generated default class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 649 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 650 | * @param file file |
| 651 | * @param curNode current YANG node |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 652 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 653 | * @param imports list of imports |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 654 | * @return impl class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 655 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 656 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 657 | public static File generateDefaultClassFile(File file, YangNode curNode, |
| 658 | boolean isAttrPresent, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 659 | List<String> imports) |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 660 | throws IOException { |
| 661 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 662 | JavaFileInfoTranslator javaFileInfo = |
| 663 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 664 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 665 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 666 | boolean isLeavesPresent; |
| 667 | YangLeavesHolder leavesHolder; |
| 668 | if (curNode instanceof YangLeavesHolder) { |
| 669 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 670 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 671 | !leavesHolder.getListOfLeaf().isEmpty() || |
| 672 | leavesHolder.getListOfLeafList() != null && |
| 673 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 674 | } else { |
| 675 | isLeavesPresent = false; |
| 676 | } |
| 677 | |
| 678 | boolean isRootNode = false; |
| 679 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 680 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 681 | String opParamClassName = className; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 682 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 683 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 684 | opParamClassName = className + OP_PARAM; |
| 685 | isRootNode = true; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 686 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 687 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 688 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 689 | path = javaFileInfo.getBaseCodeGenPath() + |
| 690 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 691 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 692 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 693 | initiateJavaFileGeneration(file, DEFAULT_CLASS_MASK, imports, curNode, |
| 694 | className); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 695 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 696 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 697 | if (curNode instanceof YangAugmentableNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 698 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 699 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 700 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 701 | |
| 702 | //Add attribute strings. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 703 | try { |
| 704 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 705 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 706 | getDataFromTempFileHandle( |
| 707 | ATTRIBUTES_MASK, |
| 708 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 709 | .getTempJavaCodeFragmentFiles() |
| 710 | .getBeanTempFiles(), |
| 711 | path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 712 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 713 | throw new IOException( |
| 714 | "No data found in temporary java code fragment files " + |
| 715 | "for " + className + |
| 716 | " while impl class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 717 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 718 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 719 | //Add operation attributes |
| 720 | insertDataIntoJavaFile(file, getOperationTypeEnum()); |
| 721 | insertDataIntoJavaFile(file, getOperationTypeAttr()); |
| 722 | if (isLeavesPresent) { |
| 723 | insertDataIntoJavaFile(file, getOperationAttributes()); |
| 724 | } |
| 725 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 726 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 727 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 728 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 729 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 730 | .getTempJavaCodeFragmentFiles() |
| 731 | .getBeanTempFiles(), |
| 732 | path)); |
| 733 | |
| 734 | methods.add(getGetterForOperationType()); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 735 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 736 | // Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 737 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 738 | getDataFromTempFileHandle( |
| 739 | HASH_CODE_IMPL_MASK, |
| 740 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 741 | .getTempJavaCodeFragmentFiles() |
| 742 | .getBeanTempFiles(), |
| 743 | path) |
| 744 | .replace( |
| 745 | NEW_LINE, |
| 746 | EMPTY_STRING))); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 747 | |
| 748 | //Equals method. |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 749 | if (isRootNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 750 | methods.add(getEqualsMethodClose( |
| 751 | getEqualsMethodOpen(opParamClassName) + |
| 752 | getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 753 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 754 | .getTempJavaCodeFragmentFiles() |
| 755 | .getBeanTempFiles(), |
| 756 | path))); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 757 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 758 | methods.add(getEqualsMethodClose(getEqualsMethodOpen( |
| 759 | getCapitalCase(DEFAULT) + className) + |
| 760 | getDataFromTempFileHandle( |
| 761 | EQUALS_IMPL_MASK, |
| 762 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 763 | .getTempJavaCodeFragmentFiles() |
| 764 | .getBeanTempFiles(), |
| 765 | path))); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 766 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 767 | // To string method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 768 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle( |
| 769 | TO_STRING_IMPL_MASK, |
| 770 | ((TempJavaCodeFragmentFilesContainer) |
| 771 | curNode) |
| 772 | .getTempJavaCodeFragmentFiles() |
| 773 | .getBeanTempFiles(), path) + |
| 774 | getToStringMethodClose()); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 775 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 776 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 777 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 778 | throw new IOException( |
| 779 | "No data found in temporary java code fragment files " + |
| 780 | "for " + className + |
| 781 | " while impl class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 782 | } |
| 783 | } else { |
| 784 | insertDataIntoJavaFile(file, NEW_LINE); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 785 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 786 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 787 | if (curNode instanceof YangAugmentableNode) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 788 | methods.add(getYangAugmentInfoImpl()); |
| 789 | methods.add(getYangAugmentInfoMapImpl()); |
| 790 | } |
| 791 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 792 | //Constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 793 | String constructor = |
| 794 | getConstructorStart(className, pluginConfig, isRootNode); |
| 795 | constructor = constructor + |
| 796 | getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, |
| 797 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 798 | .getTempJavaCodeFragmentFiles() |
| 799 | .getBeanTempFiles(), |
| 800 | path); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 801 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 802 | if (isAttrPresent) { |
| 803 | constructor = constructor + getOperationTypeForConstructor(); |
| 804 | } |
| 805 | if (isLeavesPresent) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 806 | constructor = |
| 807 | constructor + getOperationAttributeForConstructor(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 808 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 809 | methods.add( |
| 810 | constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + |
| 811 | NEW_LINE); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 812 | |
| 813 | // add is filter content match. |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 814 | String augmentableSubTreeFiltering = ""; |
| 815 | if (curNode instanceof YangAugmentableNode) { |
| 816 | augmentableSubTreeFiltering = getAugmentableSubTreeFiltering(); |
| 817 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 818 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 819 | methods.add(getProcessSubtreeFilteringStart(curNode, pluginConfig) |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 820 | + getProcessSubtreeFunctionBody(curNode) |
| 821 | + augmentableSubTreeFiltering |
| 822 | + getProcessSubTreeFilteringEnd()); |
| 823 | |
| 824 | if (curNode instanceof YangLeavesHolder) { |
| 825 | if (((YangLeavesHolder) curNode).getListOfLeaf() != null |
| 826 | && !((YangLeavesHolder) curNode).getListOfLeaf() |
| 827 | .isEmpty()) { |
| 828 | methods.add(getProcessLeafSubtreeFiltering(curNode, |
| 829 | pluginConfig, |
| 830 | path)); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
| 835 | if (curNode instanceof YangLeavesHolder) { |
| 836 | if (((YangLeavesHolder) curNode).getListOfLeafList() != null |
| 837 | && !((YangLeavesHolder) curNode).getListOfLeafList() |
| 838 | .isEmpty()) { |
| 839 | methods.add(getProcessLeafListSubtreeFiltering(curNode, |
| 840 | pluginConfig, |
| 841 | path)); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | if (curNode.getChild() != null) { |
| 846 | methods.add(getProcessChildNodeSubtreeFiltering(curNode, |
| 847 | pluginConfig, |
| 848 | path)); |
| 849 | } |
| 850 | |
| 851 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 852 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 853 | throw new IOException( |
| 854 | "No data found in temporary java code fragment files for " + |
| 855 | className + " while impl class file generation"); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 856 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 857 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 858 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 859 | .getTempJavaCodeFragmentFiles() |
| 860 | .addDefaultConstructor(PROTECTED, DEFAULT, |
| 861 | pluginConfig, curNode)); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 862 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 863 | methods.add(builderMethod(className) + NEW_LINE); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 864 | if (isLeavesPresent) { |
| 865 | methods.add(getOperationAttributesGetters()); |
| 866 | methods.add(getGettersForValueAndSelectLeaf()); |
| 867 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 868 | // Add methods in impl class. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 869 | for (String method : methods) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 870 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 871 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 872 | |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 873 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 877 | * Generates class file for type def. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 878 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 879 | * @param file generated file |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 880 | * @param curNode current YANG node |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 881 | * @param imports imports for file |
| 882 | * @return type def class file |
| 883 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 884 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 885 | public static File generateTypeDefClassFile(File file, YangNode curNode, |
| 886 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 887 | throws IOException { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 888 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 889 | JavaFileInfoTranslator javaFileInfo = |
| 890 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 891 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 892 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 893 | // import |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 894 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 895 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 896 | javaFileInfo.getPackageFilePath(); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 897 | YangTypeDef typeDef = (YangTypeDef) curNode; |
| 898 | List<YangType<?>> types = typeDef.getTypeList(); |
| 899 | YangType type = types.get(0); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 900 | YangDataTypes yangDataTypes = type.getDataType(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 901 | if (type.getDataType().equals(BINARY)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 902 | imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + |
| 903 | JAVA_UTIL_IMPORT_BASE64_CLASS); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 904 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 905 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 906 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, |
| 907 | imports, path, pluginConfig); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 908 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 909 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 910 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 911 | |
| 912 | //Add attribute strings. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 913 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 914 | insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION + |
| 915 | getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 916 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 917 | .getTempJavaCodeFragmentFiles() |
| 918 | .getTypeTempFiles(), |
| 919 | path)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 920 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 921 | throw new IOException( |
| 922 | "No data found in temporary java code fragment files for " + |
| 923 | className + " while type def class file " + |
| 924 | "generation"); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 925 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 926 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 927 | |
| 928 | //Default constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 929 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 930 | .getTempJavaCodeFragmentFiles() |
| 931 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, |
| 932 | pluginConfig, curNode)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 933 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 934 | try { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 935 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 936 | //Type constructor. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 937 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 938 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 939 | .getTempJavaCodeFragmentFiles() |
| 940 | .getTypeTempFiles(), |
| 941 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 942 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 943 | |
| 944 | //Of method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 945 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 946 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 947 | .getTempJavaCodeFragmentFiles() |
| 948 | .getTypeTempFiles(), |
| 949 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 950 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 951 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 952 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 953 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 954 | .getTempJavaCodeFragmentFiles() |
| 955 | .getTypeTempFiles(), |
| 956 | path)); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 957 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 958 | // Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 959 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 960 | getDataFromTempFileHandle( |
| 961 | HASH_CODE_IMPL_MASK, |
| 962 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 963 | .getTempJavaCodeFragmentFiles() |
| 964 | .getTypeTempFiles(), |
| 965 | path) |
| 966 | .replace( |
| 967 | NEW_LINE, |
| 968 | EMPTY_STRING))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 969 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 970 | |
| 971 | //Equals method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 972 | methods.add(getEqualsMethodClose( |
| 973 | getEqualsMethodOpen(className + EMPTY_STRING) |
| 974 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 975 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 976 | .getTempJavaCodeFragmentFiles() |
| 977 | .getTypeTempFiles(), |
| 978 | path))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 979 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 980 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 981 | //To string method. |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 982 | if (type.getDataType().equals(BINARY)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 983 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = |
| 984 | getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase( |
| 985 | "binary")); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 986 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 987 | JavaAttributeInfo attr = |
| 988 | getAttributeInfoForTheData(qualifiedTypeInfo, "binary", |
| 989 | null, false, false); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 990 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 991 | String bitsToStringMethod = |
| 992 | getOverRideString() + FOUR_SPACE_INDENTATION + |
| 993 | PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO + |
| 994 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 995 | CLOSE_PARENTHESIS + SPACE + |
| 996 | OPEN_CURLY_BRACKET + NEW_LINE + |
| 997 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + |
| 998 | BASE64 + PERIOD + GET_ENCODER + |
| 999 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + |
| 1000 | PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + |
| 1001 | attributeName + CLOSE_PARENTHESIS + |
| 1002 | SEMI_COLAN + NEW_LINE + |
| 1003 | FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + |
| 1004 | NEW_LINE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1005 | methods.add(bitsToStringMethod); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1006 | } else if (type.getDataType().equals(BITS)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1007 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = |
| 1008 | getQualifiedTypeInfoOfCurNode(curNode, |
| 1009 | getCapitalCase( |
| 1010 | "bits")); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1011 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1012 | JavaAttributeInfo attr = |
| 1013 | getAttributeInfoForTheData(qualifiedTypeInfo, "bits", |
| 1014 | null, false, false); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1015 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1016 | String bitsToStringMethod = |
| 1017 | getOverRideString() + FOUR_SPACE_INDENTATION + |
| 1018 | PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO + |
| 1019 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 1020 | CLOSE_PARENTHESIS + SPACE + |
| 1021 | OPEN_CURLY_BRACKET + NEW_LINE + |
| 1022 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + |
| 1023 | attributeName + PERIOD + TO + |
| 1024 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 1025 | CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + |
| 1026 | FOUR_SPACE_INDENTATION + |
| 1027 | CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1028 | methods.add(bitsToStringMethod); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 1029 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1030 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle( |
| 1031 | TO_STRING_IMPL_MASK, |
| 1032 | ((TempJavaCodeFragmentFilesContainer) |
| 1033 | curNode) |
| 1034 | .getTempJavaCodeFragmentFiles() |
| 1035 | .getTypeTempFiles(), path) + |
| 1036 | getToStringMethodClose()); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 1037 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1038 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1039 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
| 1040 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1041 | //From string method. |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1042 | if ((type.getDataType().equals(YangDataTypes.DERIVED)) |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1043 | && (((YangDerivedInfo) type.getDataTypeExtendedInfo()) |
| 1044 | .getEffectiveBuiltInType() |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1045 | .equals(YangDataTypes.IDENTITYREF))) { |
| 1046 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 1047 | } |
| 1048 | |
| 1049 | if (type.getDataType().equals(YangDataTypes.IDENTITYREF)) { |
| 1050 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 1051 | } |
| 1052 | |
| 1053 | if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1054 | methods.add( |
| 1055 | getFromStringMethodSignature(className, pluginConfig) + |
| 1056 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 1057 | javaGenInfo |
| 1058 | .getTempJavaCodeFragmentFiles() |
| 1059 | .getTypeTempFiles(), |
| 1060 | path) + |
| 1061 | getFromStringMethodClose()); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1062 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1063 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1064 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1065 | throw new IOException( |
| 1066 | "No data found in temporary java code fragment files for " + |
| 1067 | className + " while type def class file " + |
| 1068 | "generation"); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1069 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1070 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1071 | for (String method : methods) { |
| 1072 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1073 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1074 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1075 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1076 | return validateLineLength(file); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1077 | } |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1078 | |
| 1079 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1080 | * Generates class file for union type. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1081 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1082 | * @param file generated file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1083 | * @param curNode current YANG node |
| 1084 | * @param imports imports for file |
| 1085 | * @return type def class file |
| 1086 | * @throws IOException when fails to generate class file |
| 1087 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1088 | public static File generateUnionClassFile(File file, YangNode curNode, |
| 1089 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1090 | throws IOException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1091 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1092 | JavaFileInfoTranslator javaFileInfo = |
| 1093 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1094 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1095 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1096 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1097 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1098 | javaFileInfo.getPackageFilePath(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1099 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1100 | TempJavaTypeFragmentFiles tempJavaTypeFragmentFiles = |
| 1101 | ((JavaCodeGeneratorInfo) curNode) |
| 1102 | .getTempJavaCodeFragmentFiles().getTypeTempFiles(); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1103 | |
| 1104 | boolean isIntConflict = false; |
| 1105 | boolean isLongConflict = false; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1106 | boolean isShortConflict = false; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1107 | JavaAttributeInfo intAttr = tempJavaTypeFragmentFiles.getIntAttribute(); |
| 1108 | if (intAttr == null) { |
| 1109 | intAttr = tempJavaTypeFragmentFiles.getUIntAttribute(); |
| 1110 | } |
| 1111 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1112 | JavaAttributeInfo longAttr = |
| 1113 | tempJavaTypeFragmentFiles.getLongAttribute(); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1114 | if (longAttr == null) { |
| 1115 | longAttr = tempJavaTypeFragmentFiles.getULongAttribute(); |
| 1116 | } |
| 1117 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1118 | JavaAttributeInfo shortAttr = |
| 1119 | tempJavaTypeFragmentFiles.getShortAttribute(); |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1120 | if (shortAttr == null) { |
| 1121 | shortAttr = tempJavaTypeFragmentFiles.getUInt8Attribute(); |
| 1122 | } |
| 1123 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1124 | if (intAttr != null) { |
| 1125 | isIntConflict = intAttr.isIntConflict(); |
| 1126 | } |
| 1127 | if (longAttr != null) { |
| 1128 | isLongConflict = longAttr.isLongConflict(); |
| 1129 | } |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1130 | if (shortAttr != null) { |
| 1131 | isShortConflict = shortAttr.isShortConflict(); |
| 1132 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1133 | if (isLongConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1134 | imports.add(tempJavaTypeFragmentFiles.getJavaImportData() |
| 1135 | .getBigIntegerImport()); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1136 | sort(imports); |
| 1137 | } |
| 1138 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1139 | initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, |
| 1140 | imports, path, pluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1141 | |
| 1142 | List<String> methods = new ArrayList<>(); |
| 1143 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1144 | |
| 1145 | // Add attribute strings. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1146 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1147 | if (isIntConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1148 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1149 | .addStaticAttributeIntRange(PRIVATE, |
| 1150 | tempJavaTypeFragmentFiles |
| 1151 | .getIntIndex() < |
| 1152 | tempJavaTypeFragmentFiles |
| 1153 | .getUIntIndex())); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | if (isLongConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1157 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1158 | .addStaticAttributeLongRange(PRIVATE, |
| 1159 | tempJavaTypeFragmentFiles |
| 1160 | .getLongIndex() < |
| 1161 | tempJavaTypeFragmentFiles |
| 1162 | .getULongIndex())); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1163 | } |
| 1164 | |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1165 | if (isShortConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1166 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1167 | .addStaticAttributeShortRange(PRIVATE, |
| 1168 | tempJavaTypeFragmentFiles |
| 1169 | .getShortIndex() < |
| 1170 | tempJavaTypeFragmentFiles |
| 1171 | .getUInt8Index())); |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1172 | } |
| 1173 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1174 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1175 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 1176 | getDataFromTempFileHandle( |
| 1177 | ATTRIBUTES_MASK, |
| 1178 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1179 | .getTempJavaCodeFragmentFiles() |
| 1180 | .getTypeTempFiles(), |
| 1181 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1182 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1183 | throw new IOException( |
| 1184 | "No data found in temporary java code fragment files for " + |
| 1185 | className + " while union class file generation"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1186 | } |
| 1187 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1188 | |
| 1189 | //Default constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1190 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 1191 | .getTempJavaCodeFragmentFiles() |
| 1192 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, |
| 1193 | pluginConfig, curNode)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1194 | |
| 1195 | try { |
| 1196 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1197 | |
| 1198 | //Type constructor. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1199 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1200 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1201 | .getTempJavaCodeFragmentFiles() |
| 1202 | .getTypeTempFiles(), |
| 1203 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1204 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1205 | |
| 1206 | // Of string method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1207 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1208 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1209 | .getTempJavaCodeFragmentFiles() |
| 1210 | .getTypeTempFiles(), |
| 1211 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1212 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1213 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1214 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1215 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1216 | .getTempJavaCodeFragmentFiles() |
| 1217 | .getTypeTempFiles(), |
| 1218 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1219 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1220 | |
| 1221 | //Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1222 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1223 | getDataFromTempFileHandle( |
| 1224 | HASH_CODE_IMPL_MASK, |
| 1225 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1226 | .getTempJavaCodeFragmentFiles() |
| 1227 | .getTypeTempFiles(), |
| 1228 | path).replace( |
| 1229 | NEW_LINE, |
| 1230 | EMPTY_STRING))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1231 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1232 | //Equals method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1233 | methods.add(getEqualsMethodClose( |
| 1234 | getEqualsMethodOpen(className + EMPTY_STRING) |
| 1235 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 1236 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1237 | .getTempJavaCodeFragmentFiles() |
| 1238 | .getTypeTempFiles(), |
| 1239 | path))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1240 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1241 | |
| 1242 | //To string method. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1243 | methods.add(getToStringMethodOpen() + getOmitNullValueString() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1244 | getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 1245 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1246 | .getTempJavaCodeFragmentFiles() |
| 1247 | .getTypeTempFiles(), |
| 1248 | path) + |
| 1249 | getToStringMethodClose()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1250 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1251 | |
| 1252 | //From string method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1253 | methods.add(getFromStringMethodSignature(className, pluginConfig) + |
| 1254 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 1255 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1256 | .getTempJavaCodeFragmentFiles() |
| 1257 | .getTypeTempFiles(), |
| 1258 | path) + |
| 1259 | getFromStringMethodClose()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1260 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1261 | if (isIntConflict) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1262 | methods.add(getRangeValidatorMethodForUnion(INT)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1263 | } |
| 1264 | if (isLongConflict) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1265 | methods.add(getRangeValidatorMethodForUnion(BIG_INTEGER)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1266 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1267 | if (isShortConflict && !isIntConflict) { |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1268 | methods.add(getRangeValidatorMethodForUnion(INT)); |
| 1269 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1270 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1271 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1272 | throw new IOException( |
| 1273 | "No data found in temporary java code fragment files for " + |
| 1274 | className + " while union class file generation"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | for (String method : methods) { |
| 1278 | insertDataIntoJavaFile(file, method); |
| 1279 | } |
| 1280 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1281 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1282 | return validateLineLength(file); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1283 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1284 | |
| 1285 | /** |
| 1286 | * Generates class file for type enum. |
| 1287 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1288 | * @param file generated file |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1289 | * @param curNode current YANG node |
| 1290 | * @return class file for type enum |
| 1291 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1292 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1293 | public static File generateEnumClassFile(File file, YangNode curNode) |
| 1294 | throws IOException { |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1295 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1296 | JavaFileInfoTranslator javaFileInfo = |
| 1297 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1298 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1299 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1300 | String className = javaFileInfo.getJavaName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1301 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1302 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1303 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1304 | initiateJavaFileGeneration(file, getCapitalCase(className), |
| 1305 | GENERATE_ENUM_CLASS, null, path, |
| 1306 | pluginConfig); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1307 | |
| 1308 | //Add attribute strings. |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1309 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1310 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1311 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1312 | trimAtLast(trimAtLast( |
| 1313 | getDataFromTempFileHandle( |
| 1314 | ENUM_IMPL_MASK, javaGenInfo |
| 1315 | .getTempJavaCodeFragmentFiles() |
| 1316 | .getEnumerationTempFiles(), |
| 1317 | path), COMMA), |
| 1318 | NEW_LINE) + SEMI_COLAN + |
| 1319 | NEW_LINE); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1320 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1321 | throw new IOException( |
| 1322 | "No data found in temporary java code fragment files for " + |
| 1323 | getCapitalCase(className) + " while enum class " + |
| 1324 | "file generation"); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1325 | } |
| 1326 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1327 | |
| 1328 | // Add an attribute to get the enum's values. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1329 | insertDataIntoJavaFile(file, getEnumsValueAttribute( |
| 1330 | getCapitalCase(className))); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1331 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1332 | // Add a constructor for enum. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1333 | insertDataIntoJavaFile(file, |
| 1334 | getJavaDoc(TYPE_CONSTRUCTOR, className, false, |
| 1335 | pluginConfig, null) |
| 1336 | + getEnumsConstructor( |
| 1337 | getCapitalCase(className)) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1338 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1339 | TempJavaEnumerationFragmentFiles enumFragFiles = |
| 1340 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1341 | .getTempJavaCodeFragmentFiles() |
| 1342 | .getEnumerationTempFiles(); |
| 1343 | insertDataIntoJavaFile(file, |
| 1344 | getEnumsOfMethod(className, enumFragFiles |
| 1345 | .getJavaAttributeForEnum( |
| 1346 | pluginConfig), |
| 1347 | enumFragFiles |
| 1348 | .getEnumSetJavaMap(), |
| 1349 | enumFragFiles |
| 1350 | .getEnumStringList(), |
| 1351 | pluginConfig) + NEW_LINE); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1352 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1353 | // Add a getter method for enum. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1354 | insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, |
| 1355 | pluginConfig, null) + |
| 1356 | getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1357 | |
| 1358 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1359 | insertDataIntoJavaFile(file, getFromStringMethodSignature( |
| 1360 | getCapitalCase(className), pluginConfig) + |
| 1361 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 1362 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1363 | .getTempJavaCodeFragmentFiles() |
| 1364 | .getEnumerationTempFiles(), |
| 1365 | path) + |
| 1366 | getFromStringMethodClose()); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1367 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1368 | throw new IOException( |
| 1369 | "No data found in temporary java code fragment files for " + |
| 1370 | getCapitalCase(className) + |
| 1371 | " while enum class file generation"); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1372 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1373 | |
| 1374 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1375 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1376 | return validateLineLength(file); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1377 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1378 | |
| 1379 | /** |
| 1380 | * Generates interface file for rpc. |
| 1381 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1382 | * @param file generated file |
| 1383 | * @param curNode current YANG node |
| 1384 | * @param imports imports for file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1385 | * @return rpc class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1386 | * @throws IOException when fails to generate class file |
| 1387 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1388 | public static File generateServiceInterfaceFile(File file, YangNode curNode, |
| 1389 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1390 | throws IOException { |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1391 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1392 | JavaFileInfoTranslator javaFileInfo = |
| 1393 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1394 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1395 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = |
| 1396 | ((JavaCodeGeneratorInfo) curNode) |
| 1397 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
| 1398 | String className = getCapitalCase(javaFileInfo.getJavaName()) + |
| 1399 | SERVICE_METHOD_STRING; |
| 1400 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1401 | javaFileInfo.getPackageFilePath(); |
| 1402 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, |
| 1403 | curNode, className); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1404 | |
| 1405 | List<String> methods = new ArrayList<>(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1406 | JavaAttributeInfo rootAttribute = |
| 1407 | getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 1408 | tempJavaServiceFragmentFiles); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1409 | |
| 1410 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1411 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1412 | methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE); |
| 1413 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1414 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles() |
| 1415 | .getServiceTempFiles() != null) { |
| 1416 | JavaCodeGeneratorInfo javaGenInfo = |
| 1417 | (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1418 | |
| 1419 | // Rpc methods |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1420 | methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1421 | javaGenInfo |
| 1422 | .getTempJavaCodeFragmentFiles() |
| 1423 | .getServiceTempFiles(), |
| 1424 | path)); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1425 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1426 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1427 | throw new IOException( |
| 1428 | "No data found in temporary java code fragment files for " + |
| 1429 | className + " while rpc class file generation"); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | for (String method : methods) { |
| 1433 | insertDataIntoJavaFile(file, method); |
| 1434 | } |
| 1435 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1436 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1437 | return validateLineLength(file); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1438 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1439 | |
| 1440 | /** |
| 1441 | * Generates event file. |
| 1442 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1443 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1444 | * @param curNode current YANG node |
| 1445 | * @param imports imports for file |
| 1446 | * @throws IOException when fails to generate class file |
| 1447 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1448 | public static void generateEventFile(File file, YangNode curNode, |
| 1449 | List<String> imports) |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1450 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1451 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1452 | String className = getCapitalCase( |
| 1453 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1454 | .getJavaName()) |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1455 | + EVENT_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1456 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1457 | TempJavaEventFragmentFiles tempFiles = |
| 1458 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1459 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1460 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1461 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1462 | .getBaseCodeGenPath() |
| 1463 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1464 | .getPackageFilePath(); |
| 1465 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, |
| 1466 | className); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1467 | try { |
| 1468 | insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1469 | trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, |
| 1470 | tempFiles, path), |
| 1471 | COMMA) + FOUR_SPACE_INDENTATION + |
| 1472 | CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1473 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1474 | insertDataIntoJavaFile(file, |
| 1475 | getDataFromTempFileHandle(EVENT_METHOD_MASK, |
| 1476 | tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1477 | |
| 1478 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1479 | throw new IOException( |
| 1480 | "No data found in temporary java code fragment files for " + |
| 1481 | className + " while event class file generation"); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1485 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Generates event listener file. |
| 1490 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1491 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1492 | * @param curNode current YANG node |
| 1493 | * @param imports imports for file |
| 1494 | * @throws IOException when fails to generate class file |
| 1495 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1496 | public static void generateEventListenerFile(File file, YangNode curNode, |
| 1497 | List<String> imports) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1498 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1499 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1500 | String className = getCapitalCase( |
| 1501 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1502 | .getJavaName()) + EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1503 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1504 | initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, |
| 1505 | imports, curNode, className); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1506 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1507 | validateLineLength(file); |
| 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * Generates event subject's file. |
| 1512 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1513 | * @param file file handle |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1514 | * @param curNode current YANG node |
| 1515 | * @throws IOException when fails to do IO exceptions |
| 1516 | */ |
| 1517 | public static void generateEventSubjectFile(File file, YangNode curNode) |
| 1518 | throws IOException { |
| 1519 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1520 | String className = getCapitalCase( |
| 1521 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1522 | .getJavaName()) + EVENT_SUBJECT_NAME_SUFFIX; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1523 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1524 | initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, |
| 1525 | curNode, className); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1526 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1527 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1528 | .getBaseCodeGenPath() |
| 1529 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1530 | .getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1531 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1532 | TempJavaEventFragmentFiles tempFiles = |
| 1533 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1534 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1535 | |
| 1536 | insertDataIntoJavaFile(file, NEW_LINE); |
| 1537 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1538 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1539 | EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1540 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1541 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1542 | EVENT_SUBJECT_GETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1543 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1544 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1545 | EVENT_SUBJECT_SETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1546 | |
| 1547 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame^] | 1548 | throw new IOException( |
| 1549 | "No data found in temporary java code fragment files for " + |
| 1550 | className + " while event class file generation"); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1554 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1555 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1556 | } |