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; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 23 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangAugment; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 27 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 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; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 32 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 38 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 40 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 41 | import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 42 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 43 | import org.onosproject.yangutils.translator.tojava.YangJavaModelUtils; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 44 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 45 | |
| 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK; |
| 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 63 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; |
| 65 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; |
| 66 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 67 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 68 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 70 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 71 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 72 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 77 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 78 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
| 80 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; |
| 82 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 83 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart; |
| 85 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 86 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 87 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod; |
| 88 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; |
| 90 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 91 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoMapImpl; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager; |
| 93 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 94 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBaseClassMethodImpl; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 98 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
| 99 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; |
| 101 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 102 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 104 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 105 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
| 106 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 107 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilterContentMatch; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 109 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart; |
| 110 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter; |
| 111 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypegetter; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
| 113 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 114 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeaf; |
| 115 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeafList; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 116 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 117 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafListgetter; |
| 118 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafgetter; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 119 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
| 120 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 121 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter; |
| 122 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 123 | import static org.onosproject.yangutils.utils.UtilConstants.BASE64; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 124 | import static org.onosproject.yangutils.utils.UtilConstants.BITSET; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 125 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 126 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 127 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 128 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 129 | import static org.onosproject.yangutils.utils.UtilConstants.CREATE; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 130 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 131 | import static org.onosproject.yangutils.utils.UtilConstants.DELETE; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 132 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 133 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 134 | import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING; |
| 135 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
| 136 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 137 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; |
| 138 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 139 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 140 | import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF; |
| 141 | import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 142 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 143 | import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 144 | import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF; |
| 145 | import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 146 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 147 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 148 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS; |
| 149 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 150 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 151 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 152 | import static org.onosproject.yangutils.utils.UtilConstants.MERGE; |
| 153 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 154 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 155 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 156 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 157 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 158 | import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM; |
| 159 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 160 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 161 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 162 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
| 163 | import static org.onosproject.yangutils.utils.UtilConstants.REMOVE; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 164 | import static org.onosproject.yangutils.utils.UtilConstants.REPLACE; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 165 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 166 | import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF; |
| 167 | import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST; |
| 168 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 169 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; |
| 170 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 171 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 172 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 173 | import static org.onosproject.yangutils.utils.UtilConstants.SUPER; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 174 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 175 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 176 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 177 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 178 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 179 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 180 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 181 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 182 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 183 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 184 | * Representation of java file generator. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 185 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 186 | public final class JavaFileGenerator { |
| 187 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 188 | private JavaFileGenerator() { |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns generated interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 193 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 194 | * @param file file |
| 195 | * @param imports imports for the file |
| 196 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 197 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 198 | * @return interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 199 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 200 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 201 | public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 202 | boolean isAttrPresent) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 203 | throws IOException { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 204 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 205 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 206 | |
| 207 | String path; |
| 208 | if (curNode instanceof YangModule) { |
| 209 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 210 | } else { |
| 211 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 212 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 213 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 214 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 215 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 216 | initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 217 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 218 | if (isAttrPresent) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 219 | /** |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 220 | * Add getter methods to interface file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 221 | */ |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 222 | try { |
| 223 | /** |
| 224 | * Getter methods. |
| 225 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 226 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, |
| 227 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 228 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 229 | } catch (IOException e) { |
| 230 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 231 | + " while interface file generation"); |
| 232 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 233 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 234 | return validateLineLength(file); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 238 | * Returns generated builder interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 239 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 240 | * @param file file |
| 241 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 242 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 243 | * @return builder interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 244 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 245 | */ |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 246 | public static File generateBuilderInterfaceFile(File file, YangNode curNode, boolean isAttrPresent) |
| 247 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 248 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 249 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 250 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 251 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 252 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 253 | String path; |
| 254 | if (curNode instanceof YangModule) { |
| 255 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 256 | } else { |
| 257 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 258 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 259 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 260 | initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 261 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 262 | if (isAttrPresent) { |
| 263 | try { |
| 264 | /** |
| 265 | * Getter methods. |
| 266 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 267 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, |
| 268 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 269 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 270 | /** |
| 271 | * Setter methods. |
| 272 | */ |
| 273 | methods.add(NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 274 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, |
| 275 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 276 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 277 | } catch (IOException e) { |
| 278 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 279 | + " while builder interface file generation"); |
| 280 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 281 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 282 | /** |
| 283 | * Add build method to builder interface file. |
| 284 | */ |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 285 | methods.add( |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 286 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 287 | .addBuildMethodForInterface(pluginConfig)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * Add getters and setters in builder interface. |
| 291 | */ |
| 292 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 293 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 294 | } |
| 295 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 296 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 297 | return validateLineLength(file); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Returns generated builder class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 302 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 303 | * @param file file |
| 304 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 305 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 306 | * @return builder class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 307 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 308 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 309 | public static File generateBuilderClassFile(File file, YangNode curNode, |
| 310 | boolean isAttrPresent) throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 311 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 312 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 313 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 314 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 315 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 316 | |
| 317 | String path; |
| 318 | if (curNode instanceof YangModule) { |
| 319 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 320 | } else { |
| 321 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 322 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 323 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 324 | initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 325 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 326 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 327 | if (isAttrPresent) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 328 | /** |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 329 | * Add attribute strings. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 330 | */ |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 331 | try { |
| 332 | insertDataIntoJavaFile(file, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 333 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 334 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 335 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 336 | } catch (IOException e) { |
| 337 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 338 | + " while builder class file generation"); |
| 339 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 340 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 341 | try { |
| 342 | /** |
| 343 | * Getter methods. |
| 344 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 345 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
| 346 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 347 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 348 | /** |
| 349 | * Setter methods. |
| 350 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 351 | methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, |
| 352 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 353 | .getBeanTempFiles(), path)); |
| 354 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 355 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 356 | } catch (IOException e) { |
| 357 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 358 | + " while builder class file generation"); |
| 359 | } |
| 360 | } else { |
| 361 | insertDataIntoJavaFile(file, NEW_LINE); |
| 362 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 363 | /** |
| 364 | * Add default constructor and build method impl. |
| 365 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 366 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 367 | .addBuildMethodImpl()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 368 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 369 | .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 370 | |
| 371 | /** |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 372 | * Add methods in builder class. |
| 373 | */ |
| 374 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 375 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 376 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 377 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 378 | return validateLineLength(file); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 382 | * Returns generated op param builder class file for current node. |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 383 | * |
| 384 | * @param file file handle |
| 385 | * @param curNode current YANG node |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 386 | * @param isAttrPresent if any attribute is present or not |
| 387 | * @return builder class file |
| 388 | * @throws IOException when fails to write in file |
| 389 | */ |
| 390 | public static File generateOpParamBuilderClassFile(File file, YangNode curNode, |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 391 | boolean isAttrPresent) throws IOException { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 392 | |
| 393 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 394 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
| 395 | |
| 396 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
| 397 | |
| 398 | initiateJavaFileGeneration(file, OPERATION_BUILDER_CLASS_MASK, null, curNode, className); |
| 399 | List<String> methods = new ArrayList<>(); |
| 400 | |
| 401 | if (isAttrPresent) { |
| 402 | /** |
| 403 | * Add attribute strings. |
| 404 | */ |
| 405 | try { |
| 406 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 407 | OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE); |
| 408 | |
| 409 | } catch (IOException e) { |
| 410 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 411 | + " while impl class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | try { |
| 415 | if (curNode instanceof YangLeavesHolder) { |
| 416 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 417 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 418 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 419 | |
| 420 | if (leaves != null && !leaves.isEmpty()) { |
| 421 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 422 | BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE + |
| 423 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
| 424 | + NEW_LINE); |
| 425 | |
| 426 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 427 | BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE + |
| 428 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 429 | + SEMI_COLAN + NEW_LINE); |
| 430 | } |
| 431 | |
| 432 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 433 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 434 | BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 435 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 436 | + SEMI_COLAN + NEW_LINE); |
| 437 | |
| 438 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 439 | BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 440 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 441 | + SEMI_COLAN + NEW_LINE); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | } catch (IOException e) { |
| 446 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 447 | + " while impl class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | try { |
| 451 | /** |
| 452 | * Setter methods. |
| 453 | */ |
| 454 | methods.add(getSetterForLeaf(className, curNode, pluginConfig)); |
| 455 | methods.add(getSetterForLeafList(className, curNode, pluginConfig)); |
| 456 | |
| 457 | if (curNode instanceof YangLeavesHolder) { |
| 458 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 459 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 460 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 461 | |
| 462 | if (leaves != null && !leaves.isEmpty()) { |
| 463 | methods.add(getToStringLeafgetter()); |
| 464 | methods.add(getToStringSelectLeafgetter()); |
| 465 | } |
| 466 | |
| 467 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 468 | methods.add(getToStringLeafListgetter()); |
| 469 | methods.add(getToStringSelectLeafListgetter()); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | methods.add(getOperationTypegetter()); |
| 474 | methods.add(getOperationTypeSetter()); |
| 475 | insertDataIntoJavaFile(file, NEW_LINE); |
| 476 | } catch (IOException e) { |
| 477 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 478 | + " while builder class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 479 | } |
| 480 | } else { |
| 481 | insertDataIntoJavaFile(file, NEW_LINE); |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Add methods in builder class. |
| 486 | */ |
| 487 | for (String method : methods) { |
| 488 | insertDataIntoJavaFile(file, method); |
| 489 | } |
| 490 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
| 491 | return validateLineLength(file); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 496 | * Returns generated manager class file for current node. |
| 497 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 498 | * @param file file |
| 499 | * @param imports imports for the file |
| 500 | * @param curNode current YANG node |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 501 | * @return builder class file |
| 502 | * @throws IOException when fails to write in file |
| 503 | */ |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 504 | public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 505 | throws IOException { |
| 506 | |
| 507 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 508 | |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 509 | String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 510 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 511 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 512 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 513 | |
| 514 | List<String> methods = new ArrayList<>(); |
| 515 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 516 | insertDataIntoJavaFile(file, LOGGER_STATEMENT); |
| 517 | methods.add(addActivateMethod()); |
| 518 | methods.add(addDeActivateMethod()); |
| 519 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 520 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 521 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 522 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 523 | JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 524 | tempJavaServiceFragmentFiles); |
| 525 | try { |
| 526 | /** |
| 527 | * Getter methods. |
| 528 | */ |
| 529 | methods.add(getOverRideString() + |
| 530 | getGetterForClass(rootAttribute, GENERATE_SERVICE_AND_MANAGER) + NEW_LINE); |
| 531 | /** |
| 532 | * Setter methods. |
| 533 | */ |
| 534 | methods.add(getOverRideString() + |
| 535 | getSetterForClass(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER) |
| 536 | + NEW_LINE); |
| 537 | |
| 538 | methods.add(getAugmentsDataMethodForManager(curNode) + NEW_LINE); |
| 539 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 540 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 541 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
| 542 | /** |
| 543 | * Rpc methods |
| 544 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 545 | methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 546 | javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 547 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 548 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 549 | |
| 550 | } catch (IOException e) { |
| 551 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 552 | + " while manager class file generation"); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Add methods in builder class. |
| 557 | */ |
| 558 | for (String method : methods) { |
| 559 | insertDataIntoJavaFile(file, method); |
| 560 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 561 | return validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 565 | * Returns generated impl class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 566 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 567 | * @param file file |
| 568 | * @param curNode current YANG node |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 569 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 570 | * @param imports list of imports |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 571 | * @return impl class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 572 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 573 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 574 | public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent, List<String> imports) |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 575 | throws IOException { |
| 576 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 577 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 578 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 579 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 580 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 581 | String path; |
| 582 | if (curNode instanceof YangModule) { |
| 583 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 584 | } else { |
| 585 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 586 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 587 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 588 | initiateJavaFileGeneration(file, IMPL_CLASS_MASK, imports, curNode, className); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 589 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 590 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 591 | if (curNode instanceof YangAugmentableNode) { |
| 592 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
| 593 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 594 | if (isAttrPresent) { |
| 595 | /** |
| 596 | * Add attribute strings. |
| 597 | */ |
| 598 | try { |
| 599 | insertDataIntoJavaFile(file, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 600 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 601 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 602 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 603 | } catch (IOException e) { |
| 604 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 605 | + " while impl class file generation"); |
| 606 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 607 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 608 | try { |
| 609 | /** |
| 610 | * Getter methods. |
| 611 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 612 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
| 613 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 614 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * Hash code method. |
| 618 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 619 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 620 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 621 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 622 | .getBeanTempFiles(), path).replace(NEW_LINE, EMPTY_STRING))); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 623 | /** |
| 624 | * Equals method. |
| 625 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 626 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(getCapitalCase(DEFAULT) + className) |
| 627 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 628 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 629 | .getBeanTempFiles(), path))); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 630 | /** |
| 631 | * To string method. |
| 632 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 633 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 634 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 635 | .getBeanTempFiles(), path) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 636 | + getToStringMethodClose()); |
| 637 | |
| 638 | } catch (IOException e) { |
| 639 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 640 | + " while impl class file generation"); |
| 641 | } |
| 642 | } else { |
| 643 | insertDataIntoJavaFile(file, NEW_LINE); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 644 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 645 | try { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 646 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 647 | /** |
| 648 | * Constructor. |
| 649 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 650 | String constructor = getConstructorStart(className, pluginConfig); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 651 | constructor = constructor + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, |
| 652 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 653 | .getBeanTempFiles(), path); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 654 | |
| 655 | methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 656 | } catch (IOException e) { |
| 657 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 658 | + " while impl class file generation"); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 659 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 660 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 661 | if (curNode instanceof YangAugmentableNode) { |
| 662 | methods.add(getAddAugmentInfoMethodImpl()); |
| 663 | methods.add(getAugmentInfoImpl()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 664 | methods.add(getAugmentInfoMapImpl(javaFileInfo.getPluginConfig())); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 665 | } |
| 666 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 667 | /** |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 668 | * Add methods in impl class. |
| 669 | */ |
| 670 | for (String method : methods) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 671 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 672 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 673 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 674 | return validateLineLength(file); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 678 | * Returns generated op param class file for current node. |
| 679 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 680 | * @param file file handle |
| 681 | * @param curNode current YANG node |
| 682 | * @param isAttrPresent if any attribute is present or not |
| 683 | * @param imports import list |
| 684 | * @return returns generated op param class file for current node |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 685 | * @throws IOException when fails to write in file |
| 686 | */ |
| 687 | public static File generateOpParamImplClassFile(File file, YangNode curNode, |
| 688 | boolean isAttrPresent, List<String> imports) |
| 689 | throws IOException { |
| 690 | |
| 691 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 692 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
| 693 | |
| 694 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 695 | |
| 696 | initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className); |
| 697 | |
| 698 | List<String> methods = new ArrayList<>(); |
| 699 | |
| 700 | if (isAttrPresent) { |
| 701 | /** |
| 702 | * Add attribute strings. |
| 703 | */ |
| 704 | try { |
| 705 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + |
| 706 | SPACE + ENUM + SPACE + OPERATION_ENUM + SPACE + OPEN_CURLY_BRACKET + |
| 707 | NEW_LINE + EIGHT_SPACE_INDENTATION + MERGE + |
| 708 | NEW_LINE + EIGHT_SPACE_INDENTATION + REPLACE + |
| 709 | NEW_LINE + EIGHT_SPACE_INDENTATION + CREATE + |
| 710 | NEW_LINE + EIGHT_SPACE_INDENTATION + DELETE + |
| 711 | NEW_LINE + EIGHT_SPACE_INDENTATION + REMOVE + |
| 712 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE); |
| 713 | |
| 714 | } catch (IOException e) { |
| 715 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 716 | + " while impl class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Add attribute strings. |
| 721 | */ |
| 722 | try { |
| 723 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 724 | OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE); |
| 725 | |
| 726 | } catch (IOException e) { |
| 727 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 728 | + " while impl class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | try { |
| 732 | if (curNode instanceof YangLeavesHolder) { |
| 733 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 734 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 735 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 736 | |
| 737 | if (leaves != null && !leaves.isEmpty()) { |
| 738 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 739 | BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE + |
| 740 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 741 | + SEMI_COLAN + NEW_LINE); |
| 742 | |
| 743 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 744 | BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE + |
| 745 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 746 | + SEMI_COLAN + NEW_LINE); |
| 747 | } |
| 748 | |
| 749 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 750 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 751 | BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 752 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 753 | + SEMI_COLAN + NEW_LINE); |
| 754 | |
| 755 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 756 | BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 757 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 758 | + SEMI_COLAN + NEW_LINE); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | } catch (IOException e) { |
| 763 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 764 | + " while impl class file generation"); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | if (curNode instanceof YangLeavesHolder) { |
| 768 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 769 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 770 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 771 | |
| 772 | if (leaves != null && !leaves.isEmpty()) { |
| 773 | methods.add(getToStringLeafgetter()); |
| 774 | methods.add(getToStringSelectLeafgetter()); |
| 775 | } |
| 776 | |
| 777 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 778 | methods.add(getToStringLeafListgetter()); |
| 779 | methods.add(getToStringSelectLeafListgetter()); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | methods.add(getOperationTypegetter()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 784 | methods.add(getIsFilterContentMatch(className, curNode, pluginConfig)); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 785 | |
| 786 | } else { |
| 787 | insertDataIntoJavaFile(file, NEW_LINE); |
| 788 | } |
| 789 | String constructor = getOpParamConstructorStart(className, pluginConfig); |
| 790 | |
| 791 | constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS |
| 792 | + BUILDER.toLowerCase() + OBJECT |
| 793 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 794 | |
| 795 | if (curNode instanceof YangLeavesHolder) { |
| 796 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 797 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 798 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 799 | String filterLeaf = ""; |
| 800 | String filterLeafList = ""; |
| 801 | |
| 802 | if (leaves != null && !leaves.isEmpty()) { |
| 803 | filterLeaf = EIGHT_SPACE_INDENTATION + FILTER_LEAF + SPACE + EQUAL + SPACE |
| 804 | + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF + OPEN_PARENTHESIS |
| 805 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 806 | } |
| 807 | |
| 808 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 809 | filterLeafList = EIGHT_SPACE_INDENTATION + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE |
| 810 | + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS |
| 811 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 812 | } |
| 813 | |
| 814 | constructor = constructor + filterLeaf + filterLeafList; |
| 815 | } |
| 816 | |
| 817 | methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); |
| 818 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 819 | if (curNode instanceof YangAugment) { |
| 820 | String clsName = getCapitalCase(DEFAULT) + |
| 821 | getCapitalCase(YangJavaModelUtils.getAugmentClassName((YangAugment) curNode, pluginConfig)); |
| 822 | methods.add(getBaseClassMethodImpl(clsName)); |
| 823 | } |
| 824 | |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 825 | /** |
| 826 | * Add methods in impl class. |
| 827 | */ |
| 828 | for (String method : methods) { |
| 829 | insertDataIntoJavaFile(file, method); |
| 830 | } |
| 831 | |
| 832 | |
| 833 | return validateLineLength(file); |
| 834 | } |
| 835 | |
| 836 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 837 | * Generates class file for type def. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 838 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 839 | * @param file generated file |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 840 | * @param curNode current YANG node |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 841 | * @param imports imports for file |
| 842 | * @return type def class file |
| 843 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 844 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 845 | public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports) |
| 846 | throws IOException { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 847 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 848 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 849 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 850 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 851 | // import |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 852 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 853 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 854 | YangTypeDef typeDef = (YangTypeDef) curNode; |
| 855 | List<YangType<?>> types = typeDef.getTypeList(); |
| 856 | YangType type = types.get(0); |
| 857 | if (type.getDataType().equals(YangDataTypes.BINARY)) { |
| 858 | imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_IMPORT_BASE64_CLASS); |
| 859 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 860 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 861 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 862 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 863 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 864 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 865 | /** |
| 866 | * Add attribute strings. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 867 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 868 | try { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 869 | insertDataIntoJavaFile(file, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 870 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 871 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 872 | .getTypeTempFiles(), path)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 873 | } catch (IOException e) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 874 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 875 | + " while type def class file generation"); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 876 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 877 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 878 | /** |
| 879 | * Default constructor. |
| 880 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 881 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 882 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 883 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 884 | try { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 885 | |
| 886 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 887 | * Type constructor. |
| 888 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 889 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 890 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 891 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 892 | |
| 893 | /** |
| 894 | * Of method. |
| 895 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 896 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 897 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 898 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 899 | |
| 900 | /** |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 901 | * Getter method. |
| 902 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 903 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 904 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 905 | path)); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 906 | |
| 907 | /** |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 908 | * Hash code method. |
| 909 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 910 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 911 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 912 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 913 | .getTypeTempFiles(), path) |
| 914 | .replace(NEW_LINE, EMPTY_STRING))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 915 | |
| 916 | /** |
| 917 | * Equals method. |
| 918 | */ |
| 919 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 920 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 921 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 922 | .getTypeTempFiles(), path))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 923 | |
| 924 | /** |
| 925 | * To string method. |
| 926 | */ |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 927 | if (type.getDataType().equals(YangDataTypes.BINARY)) { |
| 928 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 929 | getCapitalCase("binary")); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 930 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 931 | JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "binary", null, false, |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 932 | false); |
| 933 | String attributeName = attr.getAttributeName(); |
| 934 | String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC |
| 935 | + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 936 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 937 | + RETURN + SPACE + BASE64 + PERIOD + GET_ENCODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 938 | + PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + attributeName + CLOSE_PARENTHESIS |
| 939 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 940 | methods.add(bitsToStringMethod); |
| 941 | } else if (type.getDataType().equals(YangDataTypes.BITS)) { |
| 942 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 943 | getCapitalCase("bits")); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 944 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 945 | JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "bits", null, false, false); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 946 | String attributeName = attr.getAttributeName(); |
| 947 | String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC |
| 948 | + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 949 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 950 | + RETURN + SPACE + attributeName + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 951 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 952 | + NEW_LINE; |
| 953 | methods.add(bitsToStringMethod); |
| 954 | } else { |
| 955 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 956 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 957 | path) + getToStringMethodClose()); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 958 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 959 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 960 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 961 | /** |
| 962 | * From string method. |
| 963 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 964 | methods.add(getFromStringMethodSignature(className, pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 965 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 966 | .getTypeTempFiles(), path) |
| 967 | + getFromStringMethodClose()); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 968 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 969 | } catch (IOException e) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 970 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 971 | + " while type def class file generation"); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 972 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 973 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 974 | for (String method : methods) { |
| 975 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 976 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 977 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 978 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 979 | return validateLineLength(file); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 980 | } |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 981 | |
| 982 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 983 | * Generates class file for union type. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 984 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 985 | * @param file generated file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 986 | * @param curNode current YANG node |
| 987 | * @param imports imports for file |
| 988 | * @return type def class file |
| 989 | * @throws IOException when fails to generate class file |
| 990 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 991 | public static File generateUnionClassFile(File file, YangNode curNode, List<String> imports) |
| 992 | throws IOException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 993 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 994 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 995 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 996 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 997 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 998 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 999 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1000 | initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path, pluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1001 | |
| 1002 | List<String> methods = new ArrayList<>(); |
| 1003 | |
| 1004 | /** |
| 1005 | * Add attribute strings. |
| 1006 | */ |
| 1007 | try { |
| 1008 | insertDataIntoJavaFile(file, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1009 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 1010 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1011 | .getTypeTempFiles(), path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1012 | } catch (IOException e) { |
| 1013 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1014 | + " while union class file generation"); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Default constructor. |
| 1019 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1020 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1021 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1022 | |
| 1023 | try { |
| 1024 | |
| 1025 | /** |
| 1026 | * Type constructor. |
| 1027 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1028 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1029 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1030 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1031 | |
| 1032 | /** |
| 1033 | * Of string method. |
| 1034 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1035 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1036 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1037 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1038 | |
| 1039 | /** |
| 1040 | * Getter method. |
| 1041 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1042 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1043 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1044 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1045 | |
| 1046 | /** |
| 1047 | * Hash code method. |
| 1048 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1049 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1050 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 1051 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1052 | .getTypeTempFiles(), path) |
| 1053 | .replace(NEW_LINE, EMPTY_STRING))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1054 | |
| 1055 | /** |
| 1056 | * Equals method. |
| 1057 | */ |
| 1058 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1059 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1060 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1061 | .getTypeTempFiles(), path))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1062 | |
| 1063 | /** |
| 1064 | * To string method. |
| 1065 | */ |
| 1066 | methods.add(getToStringMethodOpen() + getOmitNullValueString() + |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1067 | getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 1068 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1069 | .getTypeTempFiles(), path) |
| 1070 | + getToStringMethodClose()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1071 | |
| 1072 | /** |
| 1073 | * From string method. |
| 1074 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1075 | methods.add(getFromStringMethodSignature(className, pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1076 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1077 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1078 | .getTypeTempFiles(), path) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1079 | + getFromStringMethodClose()); |
| 1080 | |
| 1081 | } catch (IOException e) { |
| 1082 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1083 | + " while union class file generation"); |
| 1084 | } |
| 1085 | |
| 1086 | for (String method : methods) { |
| 1087 | insertDataIntoJavaFile(file, method); |
| 1088 | } |
| 1089 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1090 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1091 | return validateLineLength(file); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1092 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1093 | |
| 1094 | /** |
| 1095 | * Generates class file for type enum. |
| 1096 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1097 | * @param file generated file |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1098 | * @param curNode current YANG node |
| 1099 | * @return class file for type enum |
| 1100 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1101 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1102 | public static File generateEnumClassFile(File file, YangNode curNode) |
| 1103 | throws IOException { |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1104 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1105 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1106 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1107 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1108 | String className = javaFileInfo.getJavaName(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1109 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 1110 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1111 | initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path, pluginConfig); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1112 | /** |
| 1113 | * Add attribute strings. |
| 1114 | */ |
| 1115 | try { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1116 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1117 | insertDataIntoJavaFile(file, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1118 | trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, javaGeninfo |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1119 | .getTempJavaCodeFragmentFiles().getEnumerationTempFiles(), path), COMMA), NEW_LINE) |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1120 | + SEMI_COLAN + NEW_LINE); |
| 1121 | } catch (IOException e) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1122 | throw new IOException("No data found in temporary java code fragment files for " + getCapitalCase(className) |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1123 | + " while enum class file generation"); |
| 1124 | } |
| 1125 | |
| 1126 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1127 | * Add an |
| 1128 | * attribute to get the enum's values. |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1129 | */ |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1130 | insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className))); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1131 | |
| 1132 | /** |
| 1133 | * Add a constructor for enum. |
| 1134 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1135 | insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig) |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1136 | + getEnumsConstructor(getCapitalCase(className)) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1137 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1138 | TempJavaEnumerationFragmentFiles enumFragFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1139 | .getTempJavaCodeFragmentFiles() |
| 1140 | .getEnumerationTempFiles(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1141 | insertDataIntoJavaFile(file, getEnumsOfMethod(className, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1142 | enumFragFiles.getJavaAttributeForEnum(pluginConfig), |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1143 | enumFragFiles.getEnumSetJavaMap(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1144 | enumFragFiles.getEnumStringList(), pluginConfig) |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1145 | + NEW_LINE); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1146 | |
| 1147 | /** |
| 1148 | * Add a getter method for enum. |
| 1149 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1150 | insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig) |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1151 | + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1152 | |
| 1153 | try { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1154 | insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig) |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1155 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1156 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1157 | .getEnumerationTempFiles(), path) |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1158 | + getFromStringMethodClose()); |
| 1159 | } catch (IOException e) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1160 | throw new IOException("No data found in temporary java code fragment files for " + |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1161 | getCapitalCase(className) + " while enum class file generation"); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1162 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1163 | |
| 1164 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1165 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1166 | return validateLineLength(file); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1167 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1168 | |
| 1169 | /** |
| 1170 | * Generates interface file for rpc. |
| 1171 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1172 | * @param file generated file |
| 1173 | * @param curNode current YANG node |
| 1174 | * @param imports imports for file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1175 | * @return rpc class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1176 | * @throws IOException when fails to generate class file |
| 1177 | */ |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1178 | public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1179 | throws IOException { |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1180 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1181 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1182 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1183 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1184 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1185 | String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1186 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1187 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1188 | |
| 1189 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1190 | JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 1191 | tempJavaServiceFragmentFiles); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1192 | |
| 1193 | try { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1194 | /** |
| 1195 | * Getter methods. |
| 1196 | */ |
| 1197 | methods.add(getGetterString(rootAttribute, GENERATE_SERVICE_AND_MANAGER, |
| 1198 | javaFileInfo.getPluginConfig()) + NEW_LINE); |
| 1199 | /** |
| 1200 | * Setter methods. |
| 1201 | */ |
| 1202 | methods.add(getSetterString(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER, |
| 1203 | javaFileInfo.getPluginConfig()) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1204 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1205 | methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE); |
| 1206 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1207 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { |
| 1208 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
| 1209 | /** |
| 1210 | * Rpc methods |
| 1211 | */ |
| 1212 | methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1213 | javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1214 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1215 | } catch (IOException e) { |
| 1216 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1217 | + " while rpc class file generation"); |
| 1218 | } |
| 1219 | |
| 1220 | for (String method : methods) { |
| 1221 | insertDataIntoJavaFile(file, method); |
| 1222 | } |
| 1223 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1224 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1225 | return validateLineLength(file); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1226 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1227 | |
| 1228 | /** |
| 1229 | * Generates event file. |
| 1230 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1231 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1232 | * @param curNode current YANG node |
| 1233 | * @param imports imports for file |
| 1234 | * @throws IOException when fails to generate class file |
| 1235 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1236 | public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1237 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1238 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1239 | + EVENT_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1240 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 1241 | TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1242 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1243 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1244 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath() |
| 1245 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1246 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); |
| 1247 | try { |
| 1248 | insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() + |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1249 | trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles, path), COMMA) |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1250 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1251 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1252 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1253 | |
| 1254 | } catch (IOException e) { |
| 1255 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1256 | + " while event class file generation"); |
| 1257 | } |
| 1258 | |
| 1259 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1260 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Generates event listener file. |
| 1265 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1266 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1267 | * @param curNode current YANG node |
| 1268 | * @param imports imports for file |
| 1269 | * @throws IOException when fails to generate class file |
| 1270 | */ |
| 1271 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) |
| 1272 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1273 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1274 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1275 | + EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1276 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1277 | initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1278 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1279 | validateLineLength(file); |
| 1280 | } |
| 1281 | |
| 1282 | /** |
| 1283 | * Generates event subject's file. |
| 1284 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1285 | * @param file file handle |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1286 | * @param curNode current YANG node |
| 1287 | * @throws IOException when fails to do IO exceptions |
| 1288 | */ |
| 1289 | public static void generateEventSubjectFile(File file, YangNode curNode) |
| 1290 | throws IOException { |
| 1291 | |
| 1292 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1293 | + EVENT_SUBJECT_NAME_SUFFIX; |
| 1294 | |
| 1295 | initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className); |
| 1296 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1297 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath() |
| 1298 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 1299 | |
| 1300 | TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1301 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1302 | |
| 1303 | insertDataIntoJavaFile(file, NEW_LINE); |
| 1304 | try { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1305 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1306 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1307 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1308 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1309 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1310 | |
| 1311 | } catch (IOException e) { |
| 1312 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1313 | + " while event class file generation"); |
| 1314 | } |
| 1315 | |
| 1316 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1317 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1318 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1319 | } |