Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
| 21 | import java.util.LinkedList; |
| 22 | import java.util.List; |
| 23 | import java.util.SortedSet; |
| 24 | import java.util.TreeSet; |
| 25 | |
| 26 | import org.onosproject.yangutils.datamodel.YangType; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.translator.CachedFileHandle; |
| 29 | import org.onosproject.yangutils.translator.GeneratedFileType; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.utils.UtilConstants; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Maintain the information about the java file to be generated. |
| 37 | */ |
| 38 | public class CachedJavaFileHandle implements CachedFileHandle { |
| 39 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 40 | private static final int MAX_CACHABLE_ATTR = 64; |
| 41 | private static final String JAVA_FILE_EXTENSION = ".java"; |
| 42 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
| 43 | |
| 44 | /** |
| 45 | * The type(s) of java source file(s) to be generated when the cached file |
| 46 | * handle is closed. |
| 47 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 48 | private int genFileTypes; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 49 | |
| 50 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 51 | * Name of the object in YANG file. |
| 52 | */ |
| 53 | private String yangName; |
| 54 | |
| 55 | /** |
| 56 | * Sorted set of import info, to be used to maintain the set of classes to |
| 57 | * be imported in the generated class. |
| 58 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 59 | private SortedSet<ImportInfo> importSet; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Cached list of attribute info. |
| 63 | */ |
| 64 | private List<AttributeInfo> attributeList; |
| 65 | |
| 66 | /** |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 67 | * File generation directory path. |
| 68 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 69 | private String relativeFilePath; |
| 70 | |
| 71 | /** |
| 72 | * Typedef Info. |
| 73 | */ |
| 74 | private YangTypeDef typedefInfo; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 75 | |
| 76 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 77 | * Prevent invoking default constructor. |
| 78 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 79 | public CachedJavaFileHandle() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 80 | setCachedAttributeList(new LinkedList<AttributeInfo>()); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Create a cached file handle which takes care of adding attributes to the |
| 85 | * generated java file. |
| 86 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 87 | * @param pcg package in which class/interface need to be generated |
| 88 | * @param yangName name of the attribute in YANG file |
| 89 | * @param types the types of files that needs to be generated |
| 90 | * @throws IOException file IO exception |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 91 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 92 | public CachedJavaFileHandle(String pcg, String yangName, int types) throws IOException { |
| 93 | setCachedAttributeList(new LinkedList<AttributeInfo>()); |
| 94 | setImportSet(new TreeSet<ImportInfo>()); |
| 95 | setRelativeFilePath(pcg.replace(".", "/")); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 96 | setGeneratedFileTypes(types); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 97 | setYangName(yangName); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the types of files being generated corresponding to the YANG |
| 102 | * definition. |
| 103 | * |
| 104 | * @return the types of files being generated corresponding to the YANG |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 105 | * definition |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 106 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 107 | public int getGeneratedFileTypes() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 108 | return genFileTypes; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Set the types of files being generated corresponding to the YANG |
| 113 | * definition. |
| 114 | * |
| 115 | * @param fileTypes the types of files being generated corresponding to the |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 116 | * YANG definition |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 117 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 118 | public void setGeneratedFileTypes(int fileTypes) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 119 | genFileTypes = fileTypes; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get the corresponding name defined in YANG. |
| 124 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 125 | * @return the corresponding name defined in YANG |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 126 | */ |
| 127 | public String getYangName() { |
| 128 | return yangName; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Set the corresponding name defined in YANG. |
| 133 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 134 | * @param yangName the corresponding name defined in YANG |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 135 | */ |
| 136 | public void setYangName(String yangName) { |
| 137 | this.yangName = yangName; |
| 138 | } |
| 139 | |
| 140 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 141 | * Get the set containing the imported class/interface info. |
| 142 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 143 | * @return the set containing the imported class/interface info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 144 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 145 | public SortedSet<ImportInfo> getImportSet() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 146 | return importSet; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Assign the set containing the imported class/interface info. |
| 151 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 152 | * @param importSet the set containing the imported class/interface info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 153 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 154 | private void setImportSet(SortedSet<ImportInfo> importSet) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 155 | this.importSet = importSet; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Add an imported class/interface info is it is not already part of the |
| 160 | * set. If already part of the set, return false, else add to set and return |
| 161 | * true. |
| 162 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 163 | * @param importInfo class/interface info being imported |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 164 | * @return status of new addition of class/interface to the import set |
| 165 | */ |
| 166 | public boolean addImportInfo(ImportInfo importInfo) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 167 | return getImportSet().add(importInfo); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Get the list of cached attribute list. |
| 172 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 173 | * @return the set containing the imported class/interface info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 174 | */ |
| 175 | public List<AttributeInfo> getCachedAttributeList() { |
| 176 | return attributeList; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Set the cached attribute list. |
| 181 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 182 | * @param attrList attribute list |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 183 | */ |
| 184 | private void setCachedAttributeList(List<AttributeInfo> attrList) { |
| 185 | attributeList = attrList; |
| 186 | } |
| 187 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 188 | /** |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 189 | * Set the package relative path. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 190 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 191 | * @param path package relative path |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 192 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 193 | @Override |
| 194 | public void setRelativeFilePath(String path) { |
| 195 | relativeFilePath = path; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 196 | } |
| 197 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 198 | /** |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 199 | * Get the package relative path. |
| 200 | * |
| 201 | * @return package relative path |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 202 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 203 | @Override |
| 204 | public String getRelativeFilePath() { |
| 205 | return relativeFilePath; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Flush the cached attribute list to the corresponding temporary file. |
| 210 | */ |
| 211 | private void flushCacheAttrToTempFile() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 212 | |
| 213 | for (AttributeInfo attr : getCachedAttributeList()) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 214 | JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), getYangName()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* |
| 218 | * clear the contents from the cached attribute list. |
| 219 | */ |
| 220 | getCachedAttributeList().clear(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Add a new attribute to the file(s). |
| 225 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 226 | * @param attrType data type of the added attribute |
| 227 | * @param name name of the attribute |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 228 | * @param isListAttr if the current added attribute needs to be maintained |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 229 | * in a list |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 230 | */ |
| 231 | @Override |
| 232 | public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 233 | /* YANG name is mapped to java name */ |
| 234 | name = JavaIdentifierSyntax.getCamelCase(name); |
| 235 | |
| 236 | ImportInfo importInfo = new ImportInfo(); |
| 237 | boolean isImport = false; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 238 | |
| 239 | AttributeInfo newAttr = new AttributeInfo(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 240 | if (attrType != null) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 241 | newAttr.setAttributeType(attrType); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 242 | String importStr = AttributesJavaDataType.getJavaImportClass(attrType, isListAttr); |
| 243 | if (importStr != null) { |
| 244 | importInfo.setClassInfo(importStr); |
| 245 | importStr = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr); |
| 246 | importInfo.setPkgInfo(importStr); |
| 247 | isImport = true; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 248 | } else { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 249 | importStr = AttributesJavaDataType.getJavaDataType(attrType); |
| 250 | if (importStr == null) { |
| 251 | throw new RuntimeException("not supported data type"); |
| 252 | //TODO: need to change to translator exception. |
| 253 | } |
| 254 | importInfo.setClassInfo(importStr); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 255 | } |
| 256 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 257 | } else { |
| 258 | importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name)); |
| 259 | |
| 260 | importInfo.setPkgInfo(getRelativeFilePath().replace('/', '.') |
| 261 | + "." + getYangName()); |
| 262 | isImport = true; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 263 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 264 | |
| 265 | newAttr.setQualifiedName(false); |
| 266 | if (isImport) { |
| 267 | boolean isNewImport = addImportInfo(importInfo); |
| 268 | if (!isNewImport) { |
| 269 | newAttr.setQualifiedName(true); |
| 270 | } |
| 271 | } |
| 272 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 273 | newAttr.setAttributeName(name); |
| 274 | newAttr.setListAttr(isListAttr); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 275 | newAttr.setImportInfo(importInfo); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 276 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 277 | if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) { |
| 278 | flushCacheAttrToTempFile(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 279 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 280 | getCachedAttributeList().add(newAttr); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Flushes the cached contents to the target file, frees used resources. |
| 285 | */ |
| 286 | @Override |
| 287 | public void close() throws IOException { |
| 288 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 289 | flushCacheAttrToTempFile(); |
| 290 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 291 | String className = getYangName(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 292 | className = JavaIdentifierSyntax.getCaptialCase(className); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 293 | String path = getRelativeFilePath(); |
| 294 | int fileType = getGeneratedFileTypes(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 295 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 296 | /* |
| 297 | * TODO: add the file header using |
| 298 | * JavaCodeSnippetGen.getFileHeaderComment |
| 299 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 300 | |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 301 | List<String> imports = new LinkedList<>(); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 302 | String importString; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 303 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 304 | for (ImportInfo importInfo : getImportSet()) { |
| 305 | importString = ""; |
| 306 | if (importInfo.getPkgInfo() != null) { |
| 307 | importString = importString + importInfo.getPkgInfo() + "."; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 308 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 309 | importString = importString + importInfo.getClassInfo(); |
| 310 | imports.add(importString); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 311 | } |
| 312 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 313 | /** |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 314 | * Start generation of files. |
| 315 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 316 | if ((fileType & GeneratedFileType.INTERFACE_MASK) != 0 |
| 317 | || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 318 | |
| 319 | /** |
| 320 | * Create interface file. |
| 321 | */ |
| 322 | String interfaceFileName = className; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 323 | File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 324 | interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 325 | getCachedAttributeList(), path.replace('/', '.')); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 326 | |
| 327 | /** |
| 328 | * Create temp builder interface file. |
| 329 | */ |
| 330 | String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 331 | File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName, |
| 332 | TEMP_FILE_EXTENSION); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 333 | builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 334 | path.replace('/', '.'), getCachedAttributeList()); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Append builder interface file to interface file and close it. |
| 338 | */ |
| 339 | JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile); |
| 340 | JavaFileGenerator.insert(interfaceFile, |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 341 | JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE_MASK, interfaceFileName)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 342 | |
| 343 | /** |
| 344 | * Remove temp files. |
| 345 | */ |
| 346 | JavaFileGenerator.clean(builderInterfaceFile); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 347 | } |
| 348 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 349 | if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0 |
| 350 | || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 351 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 352 | /** |
| 353 | * Create builder class file. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 354 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 355 | String builderFileName = className + UtilConstants.BUILDER; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 356 | File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION); |
| 357 | builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, |
| 358 | path.replace('/', '.'), getCachedAttributeList()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 359 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 360 | /** |
| 361 | * Create temp impl class file. |
| 362 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 363 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 364 | String implFileName = className + UtilConstants.IMPL; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 365 | File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION); |
| 366 | implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, |
| 367 | path.replace('/', '.'), getCachedAttributeList()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 368 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 369 | /** |
| 370 | * Append impl class to builder class and close it. |
| 371 | */ |
| 372 | JavaFileGenerator.appendFileContents(implTempFile, builderFile); |
| 373 | JavaFileGenerator.insert(builderFile, |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 374 | JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS_MASK, builderFileName)); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 375 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 376 | /** |
| 377 | * Remove temp files. |
| 378 | */ |
| 379 | JavaFileGenerator.clean(implTempFile); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 380 | } |
| 381 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 382 | |
| 383 | public YangTypeDef getTypedefInfo() { |
| 384 | return typedefInfo; |
| 385 | } |
| 386 | |
| 387 | public void setTypedefInfo(YangTypeDef typedefInfo) { |
| 388 | this.typedefInfo = typedefInfo; |
| 389 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 390 | } |