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