Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +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 | |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
| 21 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
| 22 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; |
| 23 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 24 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 25 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 36 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
| 39 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; |
| 43 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; |
| 46 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; |
| 50 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 53 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
| 54 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 55 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 56 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 58 | import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT; |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 60 | |
| 61 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 62 | * Represents generator for class definition of generated files. |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 63 | */ |
| 64 | public final class ClassDefinitionGenerator { |
| 65 | |
| 66 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 67 | * Creates an instance of class definition generator. |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 68 | */ |
| 69 | private ClassDefinitionGenerator() { |
| 70 | } |
| 71 | |
| 72 | /** |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 73 | * Based on the file type and the YANG name of the file, generate the class |
| 74 | * / interface definition start. |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 75 | * |
| 76 | * @param genFileTypes generated file type |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 77 | * @param yangName class name |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 78 | * @return class definition |
| 79 | */ |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 80 | public static String generateClassDefinition(int genFileTypes, String yangName) { |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 81 | |
| 82 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 83 | * Based on the file type and the YANG name of the file, generate the |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 84 | * class / interface definition start. |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 85 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 86 | switch (genFileTypes) { |
| 87 | case BUILDER_CLASS_MASK: |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 88 | return getBuilderClassDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 89 | case IMPL_CLASS_MASK: |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 90 | return getImplClassDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 91 | case BUILDER_INTERFACE_MASK: |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 92 | return getBuilderInterfaceDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 93 | case GENERATE_TYPEDEF_CLASS: |
| 94 | case GENERATE_UNION_CLASS: |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 95 | return getTypeClassDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 96 | case GENERATE_ENUM_CLASS: |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 97 | return getEnumClassDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 98 | default: |
| 99 | return null; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 100 | } |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Based on the file type and the YANG name of the file, generate the class |
| 105 | * / interface definition start. |
| 106 | * |
| 107 | * @param genFileTypes generated file type |
| 108 | * @param yangName class name |
| 109 | * @param curNode current YANG node |
| 110 | * @return class definition |
| 111 | */ |
| 112 | public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) { |
| 113 | |
| 114 | /** |
| 115 | * Based on the file type and the YANG name of the file, generate the |
| 116 | * class / interface definition start. |
| 117 | */ |
| 118 | switch (genFileTypes) { |
| 119 | case INTERFACE_MASK: |
| 120 | return getInterfaceDefinition(yangName, curNode); |
| 121 | case GENERATE_SERVICE_AND_MANAGER: |
| 122 | return getRpcInterfaceDefinition(yangName, curNode); |
| 123 | case GENERATE_EVENT_CLASS: |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 124 | String eventName = yangName + SUBJECT; |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 125 | return getEventDefinition(yangName, eventName); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 126 | case GENERATE_EVENT_LISTENER_INTERFACE: |
| 127 | return getEventListenerDefinition(yangName); |
| 128 | case GENERATE_EVENT_SUBJECT_CLASS: |
| 129 | return getClassDefinition(yangName); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 130 | default: |
| 131 | return null; |
| 132 | } |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 136 | * Returns enum file class definition. |
| 137 | * |
| 138 | * @param yangName class name |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 139 | * @return enum file class definition |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 140 | */ |
| 141 | private static String getEnumClassDefinition(String yangName) { |
| 142 | return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 143 | } |
| 144 | |
| 145 | /** |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 146 | * Returns interface file class definition. |
| 147 | * |
| 148 | * @param yangName file name |
| 149 | * @return definition |
| 150 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 151 | private static String getInterfaceDefinition(String yangName, YangNode curNode) { |
| 152 | JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 153 | .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder(); |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 154 | |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 155 | if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) { |
| 156 | String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; |
| 157 | for (JavaQualifiedTypeInfo info : holder.getExtendsList()) { |
| 158 | if (!holder.getExtendedClassStore().get(info)) { |
| 159 | def = def + info.getClassInfo() + COMMA + SPACE; |
| 160 | } else { |
| 161 | def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | def = trimAtLast(def, COMMA); |
| 166 | |
| 167 | return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 168 | } |
| 169 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Returns builder interface file class definition. |
| 174 | * |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 175 | * @param yangName java class name, corresponding to which the builder class |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 176 | * is being generated |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 177 | * @return definition |
| 178 | */ |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 179 | private static String getBuilderInterfaceDefinition(String yangName) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 180 | return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Returns builder file class definition. |
| 185 | * |
| 186 | * @param yangName file name |
| 187 | * @return definition |
| 188 | */ |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 189 | private static String getBuilderClassDefinition(String yangName) { |
| 190 | return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD |
| 191 | + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns impl file class definition. |
| 196 | * |
| 197 | * @param yangName file name |
| 198 | * @return definition |
| 199 | */ |
| 200 | private static String getImplClassDefinition(String yangName) { |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 201 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE |
| 202 | + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Returns impl file class definition. |
| 207 | * |
| 208 | * @param yangName file name |
| 209 | * @return definition |
| 210 | */ |
| 211 | private static String getClassDefinition(String yangName) { |
| 212 | return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 213 | } |
| 214 | |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 215 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 216 | * Returns type file class definition. |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 217 | * |
| 218 | * @param yangName file name |
| 219 | * @return definition |
| 220 | */ |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 221 | private static String getTypeClassDefinition(String yangName) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 222 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 223 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 224 | |
| 225 | /** |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 226 | * Returns RPC file interface definition. |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 227 | * |
| 228 | * @param yangName file name |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 229 | * @param curNode current YANG node |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 230 | * @return definition |
| 231 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 232 | private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) { |
| 233 | JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 234 | .getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder(); |
| 235 | if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) { |
| 236 | curNode = curNode.getChild(); |
| 237 | while (curNode != null) { |
| 238 | if (curNode instanceof YangJavaNotification) { |
| 239 | return getRpcInterfaceDefinitionWhenItExtends(yangName, holder); |
| 240 | } |
| 241 | curNode = curNode.getNextSibling(); |
| 242 | } |
| 243 | } |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 244 | if (yangName.contains(SERVICE)) { |
| 245 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 246 | } |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 247 | return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName |
| 248 | + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 249 | } |
| 250 | |
| 251 | /* Provides class definition when RPC interface needs to extends any event.*/ |
| 252 | private static String getRpcInterfaceDefinitionWhenItExtends(String yangName, |
| 253 | JavaExtendsListHolder holder) { |
| 254 | |
| 255 | if (yangName.contains(SERVICE)) { |
| 256 | String[] strArray = yangName.split(SERVICE); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 257 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 258 | + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA |
| 259 | + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE |
| 260 | + OPEN_CURLY_BRACKET + NEW_LINE; |
| 261 | } |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 262 | return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 263 | + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame^] | 264 | + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 265 | + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET |
| 266 | + NEW_LINE; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 267 | } |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * Returns event class definition. |
| 271 | * |
| 272 | * @param javaName file name |
| 273 | * @return definition |
| 274 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 275 | private static String getEventDefinition(String javaName, String eventName) { |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 276 | String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<" |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 277 | + javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 278 | |
| 279 | return classDef; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Returns event listener interface definition. |
| 284 | * |
| 285 | * @param javaName file name |
| 286 | * @return definition |
| 287 | */ |
| 288 | private static String getEventListenerDefinition(String javaName) { |
| 289 | String intfDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<" |
| 290 | + javaName; |
| 291 | if (intfDef.length() < 8) { |
| 292 | throw new RuntimeException("Event listener interface name is error"); |
| 293 | } |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 294 | intfDef = intfDef.substring(0, intfDef.length() - 8); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 295 | intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 296 | |
| 297 | return intfDef; |
| 298 | } |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 299 | } |