Bharat saraswal
Committed by Gerrit Code Review

[ONOS-3908] Implemetation of YANG container translator.

Change-Id: I9ffcfc4b370edb801dfc90c5394cef787c77641d
Showing 23 changed files with 431 additions and 147 deletions
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 23 import org.onosproject.yangutils.parser.ParsableDataType;
24 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 25
25 /*- 26 /*-
26 * Reference RFC 6020. 27 * Reference RFC 6020.
...@@ -342,4 +343,16 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo ...@@ -342,4 +343,16 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
342 // TODO Auto-generated method stub 343 // TODO Auto-generated method stub
343 344
344 } 345 }
346 +
347 + @Override
348 + public CachedFileHandle getFileHandle() {
349 + // TODO Auto-generated method stub
350 + return null;
351 + }
352 +
353 + @Override
354 + public void setFileHandle(CachedFileHandle fileHandle) {
355 + // TODO Auto-generated method stub
356 +
357 + }
345 } 358 }
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 23 import org.onosproject.yangutils.parser.ParsableDataType;
24 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 25
25 /*- 26 /*-
26 * Reference RFC 6020. 27 * Reference RFC 6020.
...@@ -336,4 +337,16 @@ public class YangCase extends YangNode implements YangLeavesHolder, YangCommonIn ...@@ -336,4 +337,16 @@ public class YangCase extends YangNode implements YangLeavesHolder, YangCommonIn
336 // TODO Auto-generated method stub 337 // TODO Auto-generated method stub
337 338
338 } 339 }
340 +
341 + @Override
342 + public CachedFileHandle getFileHandle() {
343 + // TODO Auto-generated method stub
344 + return null;
345 + }
346 +
347 + @Override
348 + public void setFileHandle(CachedFileHandle fileHandle) {
349 + // TODO Auto-generated method stub
350 +
351 + }
339 } 352 }
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 23 import org.onosproject.yangutils.parser.ParsableDataType;
24 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 25
25 /*- 26 /*-
26 * Reference RFC 6020. 27 * Reference RFC 6020.
...@@ -252,6 +253,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -252,6 +253,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
252 * 253 *
253 * @return the description. 254 * @return the description.
254 */ 255 */
256 + @Override
255 public String getDescription() { 257 public String getDescription() {
256 return description; 258 return description;
257 } 259 }
...@@ -261,6 +263,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -261,6 +263,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
261 * 263 *
262 * @param description set the description. 264 * @param description set the description.
263 */ 265 */
266 + @Override
264 public void setDescription(String description) { 267 public void setDescription(String description) {
265 this.description = description; 268 this.description = description;
266 } 269 }
...@@ -270,6 +273,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -270,6 +273,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
270 * 273 *
271 * @return the reference. 274 * @return the reference.
272 */ 275 */
276 + @Override
273 public String getReference() { 277 public String getReference() {
274 return reference; 278 return reference;
275 } 279 }
...@@ -279,6 +283,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -279,6 +283,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
279 * 283 *
280 * @param reference the reference to set. 284 * @param reference the reference to set.
281 */ 285 */
286 + @Override
282 public void setReference(String reference) { 287 public void setReference(String reference) {
283 this.reference = reference; 288 this.reference = reference;
284 } 289 }
...@@ -288,6 +293,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -288,6 +293,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
288 * 293 *
289 * @return the status. 294 * @return the status.
290 */ 295 */
296 + @Override
291 public YangStatusType getStatus() { 297 public YangStatusType getStatus() {
292 return status; 298 return status;
293 } 299 }
...@@ -297,6 +303,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -297,6 +303,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
297 * 303 *
298 * @param status the status to set. 304 * @param status the status to set.
299 */ 305 */
306 + @Override
300 public void setStatus(YangStatusType status) { 307 public void setStatus(YangStatusType status) {
301 this.status = status; 308 this.status = status;
302 } 309 }
...@@ -306,6 +313,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -306,6 +313,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
306 * 313 *
307 * @return returns CHOICE_DATA 314 * @return returns CHOICE_DATA
308 */ 315 */
316 + @Override
309 public ParsableDataType getParsableDataType() { 317 public ParsableDataType getParsableDataType() {
310 return ParsableDataType.CHOICE_DATA; 318 return ParsableDataType.CHOICE_DATA;
311 } 319 }
...@@ -315,6 +323,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -315,6 +323,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
315 * 323 *
316 * @throws DataModelException a violation of data model rules. 324 * @throws DataModelException a violation of data model rules.
317 */ 325 */
326 + @Override
318 public void validateDataOnEntry() throws DataModelException { 327 public void validateDataOnEntry() throws DataModelException {
319 // TODO auto-generated method stub, to be implemented by parser 328 // TODO auto-generated method stub, to be implemented by parser
320 } 329 }
...@@ -324,6 +333,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -324,6 +333,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
324 * 333 *
325 * @throws DataModelException a violation of data model rules. 334 * @throws DataModelException a violation of data model rules.
326 */ 335 */
336 + @Override
327 public void validateDataOnExit() throws DataModelException { 337 public void validateDataOnExit() throws DataModelException {
328 // TODO auto-generated method stub, to be implemented by parser 338 // TODO auto-generated method stub, to be implemented by parser
329 } 339 }
...@@ -349,6 +359,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -349,6 +359,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
349 /* (non-Javadoc) 359 /* (non-Javadoc)
350 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 360 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
351 */ 361 */
362 + @Override
352 public void generateJavaCodeEntry() { 363 public void generateJavaCodeEntry() {
353 // TODO Auto-generated method stub 364 // TODO Auto-generated method stub
354 365
...@@ -357,8 +368,21 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable { ...@@ -357,8 +368,21 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
357 /* (non-Javadoc) 368 /* (non-Javadoc)
358 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 369 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
359 */ 370 */
371 + @Override
360 public void generateJavaCodeExit() { 372 public void generateJavaCodeExit() {
361 // TODO Auto-generated method stub 373 // TODO Auto-generated method stub
362 374
363 } 375 }
376 +
377 + @Override
378 + public CachedFileHandle getFileHandle() {
379 + // TODO Auto-generated method stub
380 + return null;
381 + }
382 +
383 + @Override
384 + public void setFileHandle(CachedFileHandle fileHandle) {
385 + // TODO Auto-generated method stub
386 +
387 + }
364 } 388 }
......
...@@ -133,7 +133,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -133,7 +133,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
133 private YangStatusType status; 133 private YangStatusType status;
134 134
135 /** 135 /**
136 - * package of the generated java code. 136 + * Package of the generated java code.
137 */ 137 */
138 private String pkg; 138 private String pkg;
139 139
...@@ -332,6 +332,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -332,6 +332,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
332 * 332 *
333 * @return the fileHandle 333 * @return the fileHandle
334 */ 334 */
335 + @Override
335 public CachedFileHandle getFileHandle() { 336 public CachedFileHandle getFileHandle() {
336 return fileHandle; 337 return fileHandle;
337 } 338 }
...@@ -341,6 +342,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -341,6 +342,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
341 * 342 *
342 * @param handle the fileHandle to set 343 * @param handle the fileHandle to set
343 */ 344 */
345 + @Override
344 public void setFileHandle(CachedFileHandle handle) { 346 public void setFileHandle(CachedFileHandle handle) {
345 fileHandle = handle; 347 fileHandle = handle;
346 } 348 }
...@@ -395,11 +397,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -395,11 +397,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
395 pkg = pcg; 397 pkg = pcg;
396 } 398 }
397 399
398 - /**
399 - * Generate the java code corresponding to YANG container.
400 - *
401 - * @throws IOException when fails to generate the source files.
402 - */
403 @Override 400 @Override
404 public void generateJavaCodeEntry() throws IOException { 401 public void generateJavaCodeEntry() throws IOException {
405 YangNode parent = getParent(); 402 YangNode parent = getParent();
...@@ -414,14 +411,33 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -414,14 +411,33 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
414 throw new IOException("Failed to create the source files."); 411 throw new IOException("Failed to create the source files.");
415 } 412 }
416 setFileHandle(handle); 413 setFileHandle(handle);
417 - addLavesAttributes(); 414 + addAttributeInParent();
415 + }
416 +
417 + /**
418 + * Adds current node attribute to parent file.
419 + *
420 + * @param pkg java file package path
421 + */
422 + private void addAttributeInParent() {
423 + if (getParent() != null) {
424 + getParent().getFileHandle().setChildsPackage(getPackage());
425 + getParent().getFileHandle().addAttributeInfo(null, getName(), false);
426 + }
427 + }
428 +
429 + @Override
430 + public void generateJavaCodeExit() throws IOException {
431 + addLeavesAttributes();
418 addLeafListAttributes(); 432 addLeafListAttributes();
433 + getFileHandle().close();
434 + return;
419 } 435 }
420 436
421 /** 437 /**
422 * Adds leaf attributes in generated files. 438 * Adds leaf attributes in generated files.
423 */ 439 */
424 - private void addLavesAttributes() { 440 + private void addLeavesAttributes() {
425 441
426 List<YangLeaf<?>> leaves = getListOfLeaf(); 442 List<YangLeaf<?>> leaves = getListOfLeaf();
427 if (leaves != null) { 443 if (leaves != null) {
...@@ -442,17 +458,5 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -442,17 +458,5 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
442 } 458 }
443 } 459 }
444 return; 460 return;
445 -
446 - }
447 -
448 - /**
449 - * Free resources used to generate code.
450 - *
451 - * @throws IOException when fails to generate source files.
452 - */
453 - @Override
454 - public void generateJavaCodeExit() throws IOException {
455 - getFileHandle().close();
456 - return;
457 } 461 }
458 } 462 }
......
...@@ -22,6 +22,7 @@ import java.util.Set; ...@@ -22,6 +22,7 @@ import java.util.Set;
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.ParsableDataType; 24 import org.onosproject.yangutils.parser.ParsableDataType;
25 +import org.onosproject.yangutils.translator.CachedFileHandle;
25 26
26 /* 27 /*
27 * The enumeration built-in type represents values from a set of 28 * The enumeration built-in type represents values from a set of
...@@ -79,6 +80,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -79,6 +80,7 @@ public class YangEnumeration extends YangNode implements Parsable {
79 * 80 *
80 * @return returns ENUMERATION_DATA 81 * @return returns ENUMERATION_DATA
81 */ 82 */
83 + @Override
82 public ParsableDataType getParsableDataType() { 84 public ParsableDataType getParsableDataType() {
83 return ParsableDataType.ENUMERATION_DATA; 85 return ParsableDataType.ENUMERATION_DATA;
84 } 86 }
...@@ -88,6 +90,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -88,6 +90,7 @@ public class YangEnumeration extends YangNode implements Parsable {
88 * 90 *
89 * @throws DataModelException a violation of data model rules. 91 * @throws DataModelException a violation of data model rules.
90 */ 92 */
93 + @Override
91 public void validateDataOnEntry() throws DataModelException { 94 public void validateDataOnEntry() throws DataModelException {
92 // TODO auto-generated method stub, to be implemented by parser 95 // TODO auto-generated method stub, to be implemented by parser
93 } 96 }
...@@ -97,6 +100,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -97,6 +100,7 @@ public class YangEnumeration extends YangNode implements Parsable {
97 * 100 *
98 * @throws DataModelException a violation of data model rules. 101 * @throws DataModelException a violation of data model rules.
99 */ 102 */
103 + @Override
100 public void validateDataOnExit() throws DataModelException { 104 public void validateDataOnExit() throws DataModelException {
101 // TODO auto-generated method stub, to be implemented by parser 105 // TODO auto-generated method stub, to be implemented by parser
102 } 106 }
...@@ -140,6 +144,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -140,6 +144,7 @@ public class YangEnumeration extends YangNode implements Parsable {
140 /* (non-Javadoc) 144 /* (non-Javadoc)
141 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 145 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
142 */ 146 */
147 + @Override
143 public void generateJavaCodeEntry() { 148 public void generateJavaCodeEntry() {
144 // TODO Auto-generated method stub 149 // TODO Auto-generated method stub
145 150
...@@ -148,8 +153,21 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -148,8 +153,21 @@ public class YangEnumeration extends YangNode implements Parsable {
148 /* (non-Javadoc) 153 /* (non-Javadoc)
149 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 154 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
150 */ 155 */
156 + @Override
151 public void generateJavaCodeExit() { 157 public void generateJavaCodeExit() {
152 // TODO Auto-generated method stub 158 // TODO Auto-generated method stub
153 159
154 } 160 }
161 +
162 + @Override
163 + public CachedFileHandle getFileHandle() {
164 + // TODO Auto-generated method stub
165 + return null;
166 + }
167 +
168 + @Override
169 + public void setFileHandle(CachedFileHandle fileHandle) {
170 + // TODO Auto-generated method stub
171 +
172 + }
155 } 173 }
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 23 import org.onosproject.yangutils.parser.ParsableDataType;
24 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 25
25 /*- 26 /*-
26 * Reference RFC 6020. 27 * Reference RFC 6020.
...@@ -321,4 +322,16 @@ public class YangGrouping extends YangNode implements YangLeavesHolder, YangComm ...@@ -321,4 +322,16 @@ public class YangGrouping extends YangNode implements YangLeavesHolder, YangComm
321 // TODO Auto-generated method stub 322 // TODO Auto-generated method stub
322 323
323 } 324 }
325 +
326 + @Override
327 + public CachedFileHandle getFileHandle() {
328 + // TODO Auto-generated method stub
329 + return null;
330 + }
331 +
332 + @Override
333 + public void setFileHandle(CachedFileHandle fileHandle) {
334 + // TODO Auto-generated method stub
335 +
336 + }
324 } 337 }
......
...@@ -22,6 +22,7 @@ import java.util.List; ...@@ -22,6 +22,7 @@ import java.util.List;
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.ParsableDataType; 24 import org.onosproject.yangutils.parser.ParsableDataType;
25 +import org.onosproject.yangutils.translator.CachedFileHandle;
25 26
26 /*- 27 /*-
27 * The "list" statement is used to define an interior data node in the 28 * The "list" statement is used to define an interior data node in the
...@@ -459,4 +460,16 @@ public class YangList extends YangNode implements YangLeavesHolder, YangCommonIn ...@@ -459,4 +460,16 @@ public class YangList extends YangNode implements YangLeavesHolder, YangCommonIn
459 // TODO Auto-generated method stub 460 // TODO Auto-generated method stub
460 461
461 } 462 }
463 +
464 + @Override
465 + public CachedFileHandle getFileHandle() {
466 + // TODO Auto-generated method stub
467 + return null;
468 + }
469 +
470 + @Override
471 + public void setFileHandle(CachedFileHandle fileHandle) {
472 + // TODO Auto-generated method stub
473 +
474 + }
462 } 475 }
......
...@@ -155,7 +155,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, ...@@ -155,7 +155,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
155 private byte version; 155 private byte version;
156 156
157 /** 157 /**
158 - * package of the generated java code. 158 + * Package of the generated java code.
159 */ 159 */
160 private String pkg; 160 private String pkg;
161 161
...@@ -493,6 +493,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, ...@@ -493,6 +493,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
493 * 493 *
494 * @return the fileHandle 494 * @return the fileHandle
495 */ 495 */
496 + @Override
496 public CachedFileHandle getFileHandle() { 497 public CachedFileHandle getFileHandle() {
497 return fileHandle; 498 return fileHandle;
498 } 499 }
...@@ -502,6 +503,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, ...@@ -502,6 +503,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
502 * 503 *
503 * @param handle the fileHandle to set 504 * @param handle the fileHandle to set
504 */ 505 */
506 + @Override
505 public void setFileHandle(CachedFileHandle handle) { 507 public void setFileHandle(CachedFileHandle handle) {
506 fileHandle = handle; 508 fileHandle = handle;
507 } 509 }
...@@ -555,14 +557,20 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, ...@@ -555,14 +557,20 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
555 throw new IOException("Failed to create the source files."); 557 throw new IOException("Failed to create the source files.");
556 } 558 }
557 setFileHandle(handle); 559 setFileHandle(handle);
558 - addLavesAttributes(); 560 + }
561 +
562 + @Override
563 + public void generateJavaCodeExit() throws IOException {
564 + addLeavesAttributes();
559 addLeafListAttributes(); 565 addLeafListAttributes();
566 + getFileHandle().close();
567 + return;
560 } 568 }
561 569
562 /** 570 /**
563 * Adds leaf attributes in generated files. 571 * Adds leaf attributes in generated files.
564 */ 572 */
565 - private void addLavesAttributes() { 573 + private void addLeavesAttributes() {
566 574
567 List<YangLeaf<?>> leaves = getListOfLeaf(); 575 List<YangLeaf<?>> leaves = getListOfLeaf();
568 if (leaves != null) { 576 if (leaves != null) {
...@@ -584,15 +592,4 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, ...@@ -584,15 +592,4 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
584 } 592 }
585 } 593 }
586 594
587 - /**
588 - * Free resources used to generate code.
589 - *
590 - * @throws IOException when fails to generate source files.
591 - */
592 - @Override
593 - public void generateJavaCodeExit() throws IOException {
594 - getFileHandle().close();
595 - return;
596 - }
597 -
598 } 595 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 +import org.onosproject.yangutils.translator.CachedFileHandle;
19 import org.onosproject.yangutils.translator.CodeGenerator; 20 import org.onosproject.yangutils.translator.CodeGenerator;
20 21
21 /** 22 /**
...@@ -253,4 +254,18 @@ public abstract class YangNode implements CodeGenerator { ...@@ -253,4 +254,18 @@ public abstract class YangNode implements CodeGenerator {
253 */ 254 */
254 public abstract void setPackage(String pkg); 255 public abstract void setPackage(String pkg);
255 256
257 + /**
258 + * Get the mapped java file handler.
259 + *
260 + * @return the file handle.
261 + */
262 + public abstract CachedFileHandle getFileHandle();
263 +
264 + /**
265 + * Set the mapped java file handle.
266 + *
267 + * @param fileHandle the file handle to set of current node.
268 + */
269 + public abstract void setFileHandle(CachedFileHandle fileHandle);
270 +
256 } 271 }
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 23 import org.onosproject.yangutils.parser.ParsableDataType;
24 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 25
25 /* 26 /*
26 * Reference RFC 6020. 27 * Reference RFC 6020.
...@@ -491,4 +492,16 @@ public class YangSubModule extends YangNode implements YangLeavesHolder, YangDes ...@@ -491,4 +492,16 @@ public class YangSubModule extends YangNode implements YangLeavesHolder, YangDes
491 // TODO Auto-generated method stub 492 // TODO Auto-generated method stub
492 493
493 } 494 }
495 +
496 + @Override
497 + public CachedFileHandle getFileHandle() {
498 + // TODO Auto-generated method stub
499 + return null;
500 + }
501 +
502 + @Override
503 + public void setFileHandle(CachedFileHandle fileHandle) {
504 + // TODO Auto-generated method stub
505 +
506 + }
494 } 507 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 19 import org.onosproject.yangutils.parser.Parsable;
20 import org.onosproject.yangutils.parser.ParsableDataType; 20 import org.onosproject.yangutils.parser.ParsableDataType;
21 +import org.onosproject.yangutils.translator.CachedFileHandle;
21 22
22 /*- 23 /*-
23 * Reference RFC 6020. 24 * Reference RFC 6020.
...@@ -138,6 +139,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -138,6 +139,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
138 * 139 *
139 * @return the description. 140 * @return the description.
140 */ 141 */
142 + @Override
141 public String getDescription() { 143 public String getDescription() {
142 return description; 144 return description;
143 } 145 }
...@@ -147,6 +149,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -147,6 +149,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
147 * 149 *
148 * @param description set the description. 150 * @param description set the description.
149 */ 151 */
152 + @Override
150 public void setDescription(String description) { 153 public void setDescription(String description) {
151 this.description = description; 154 this.description = description;
152 } 155 }
...@@ -156,6 +159,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -156,6 +159,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
156 * 159 *
157 * @return the reference. 160 * @return the reference.
158 */ 161 */
162 + @Override
159 public String getReference() { 163 public String getReference() {
160 return reference; 164 return reference;
161 } 165 }
...@@ -165,6 +169,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -165,6 +169,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
165 * 169 *
166 * @param reference the reference to set. 170 * @param reference the reference to set.
167 */ 171 */
172 + @Override
168 public void setReference(String reference) { 173 public void setReference(String reference) {
169 this.reference = reference; 174 this.reference = reference;
170 } 175 }
...@@ -174,6 +179,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -174,6 +179,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
174 * 179 *
175 * @return the status. 180 * @return the status.
176 */ 181 */
182 + @Override
177 public YangStatusType getStatus() { 183 public YangStatusType getStatus() {
178 return status; 184 return status;
179 } 185 }
...@@ -183,6 +189,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -183,6 +189,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
183 * 189 *
184 * @param status the status to set. 190 * @param status the status to set.
185 */ 191 */
192 + @Override
186 public void setStatus(YangStatusType status) { 193 public void setStatus(YangStatusType status) {
187 this.status = status; 194 this.status = status;
188 } 195 }
...@@ -230,6 +237,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -230,6 +237,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
230 * 237 *
231 * @return returns TYPEDEF_DATA 238 * @return returns TYPEDEF_DATA
232 */ 239 */
240 + @Override
233 public ParsableDataType getParsableDataType() { 241 public ParsableDataType getParsableDataType() {
234 return ParsableDataType.TYPEDEF_DATA; 242 return ParsableDataType.TYPEDEF_DATA;
235 } 243 }
...@@ -239,6 +247,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -239,6 +247,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
239 * 247 *
240 * @throws DataModelException a violation of data model rules. 248 * @throws DataModelException a violation of data model rules.
241 */ 249 */
250 + @Override
242 public void validateDataOnEntry() throws DataModelException { 251 public void validateDataOnEntry() throws DataModelException {
243 // TODO auto-generated method stub, to be implemented by parser 252 // TODO auto-generated method stub, to be implemented by parser
244 } 253 }
...@@ -248,6 +257,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -248,6 +257,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
248 * 257 *
249 * @throws DataModelException a violation of data model rules. 258 * @throws DataModelException a violation of data model rules.
250 */ 259 */
260 + @Override
251 public void validateDataOnExit() throws DataModelException { 261 public void validateDataOnExit() throws DataModelException {
252 // TODO auto-generated method stub, to be implemented by parser 262 // TODO auto-generated method stub, to be implemented by parser
253 } 263 }
...@@ -273,6 +283,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -273,6 +283,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
273 /* (non-Javadoc) 283 /* (non-Javadoc)
274 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 284 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
275 */ 285 */
286 + @Override
276 public void generateJavaCodeEntry() { 287 public void generateJavaCodeEntry() {
277 // TODO Auto-generated method stub 288 // TODO Auto-generated method stub
278 289
...@@ -281,6 +292,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -281,6 +292,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
281 /* (non-Javadoc) 292 /* (non-Javadoc)
282 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 293 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
283 */ 294 */
295 + @Override
284 public void generateJavaCodeExit() { 296 public void generateJavaCodeExit() {
285 // TODO Auto-generated method stub 297 // TODO Auto-generated method stub
286 298
...@@ -303,4 +315,16 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -303,4 +315,16 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
303 // TODO Auto-generated method stub 315 // TODO Auto-generated method stub
304 316
305 } 317 }
318 +
319 + @Override
320 + public CachedFileHandle getFileHandle() {
321 + // TODO Auto-generated method stub
322 + return null;
323 + }
324 +
325 + @Override
326 + public void setFileHandle(CachedFileHandle fileHandle) {
327 + // TODO Auto-generated method stub
328 +
329 + }
306 } 330 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 19 import org.onosproject.yangutils.parser.Parsable;
20 import org.onosproject.yangutils.parser.ParsableDataType; 20 import org.onosproject.yangutils.parser.ParsableDataType;
21 +import org.onosproject.yangutils.translator.CachedFileHandle;
21 22
22 /*- 23 /*-
23 * Reference RFC 6020. 24 * Reference RFC 6020.
...@@ -127,6 +128,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -127,6 +128,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
127 * 128 *
128 * @return the description. 129 * @return the description.
129 */ 130 */
131 + @Override
130 public String getDescription() { 132 public String getDescription() {
131 return description; 133 return description;
132 } 134 }
...@@ -136,6 +138,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -136,6 +138,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
136 * 138 *
137 * @param description set the description. 139 * @param description set the description.
138 */ 140 */
141 + @Override
139 public void setDescription(String description) { 142 public void setDescription(String description) {
140 this.description = description; 143 this.description = description;
141 } 144 }
...@@ -145,6 +148,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -145,6 +148,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
145 * 148 *
146 * @return the reference. 149 * @return the reference.
147 */ 150 */
151 + @Override
148 public String getReference() { 152 public String getReference() {
149 return reference; 153 return reference;
150 } 154 }
...@@ -154,6 +158,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -154,6 +158,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
154 * 158 *
155 * @param reference the reference to set. 159 * @param reference the reference to set.
156 */ 160 */
161 + @Override
157 public void setReference(String reference) { 162 public void setReference(String reference) {
158 this.reference = reference; 163 this.reference = reference;
159 } 164 }
...@@ -163,6 +168,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -163,6 +168,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
163 * 168 *
164 * @return the status. 169 * @return the status.
165 */ 170 */
171 + @Override
166 public YangStatusType getStatus() { 172 public YangStatusType getStatus() {
167 return status; 173 return status;
168 } 174 }
...@@ -172,6 +178,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -172,6 +178,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
172 * 178 *
173 * @param status the status to set. 179 * @param status the status to set.
174 */ 180 */
181 + @Override
175 public void setStatus(YangStatusType status) { 182 public void setStatus(YangStatusType status) {
176 this.status = status; 183 this.status = status;
177 } 184 }
...@@ -181,6 +188,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -181,6 +188,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
181 * 188 *
182 * @return returns USES_DATA. 189 * @return returns USES_DATA.
183 */ 190 */
191 + @Override
184 public ParsableDataType getParsableDataType() { 192 public ParsableDataType getParsableDataType() {
185 return ParsableDataType.USES_DATA; 193 return ParsableDataType.USES_DATA;
186 } 194 }
...@@ -190,6 +198,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -190,6 +198,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
190 * 198 *
191 * @throws DataModelException a violation of data model rules. 199 * @throws DataModelException a violation of data model rules.
192 */ 200 */
201 + @Override
193 public void validateDataOnEntry() throws DataModelException { 202 public void validateDataOnEntry() throws DataModelException {
194 // TODO auto-generated method stub, to be implemented by parser 203 // TODO auto-generated method stub, to be implemented by parser
195 } 204 }
...@@ -199,6 +208,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -199,6 +208,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
199 * 208 *
200 * @throws DataModelException a violation of data model rules. 209 * @throws DataModelException a violation of data model rules.
201 */ 210 */
211 + @Override
202 public void validateDataOnExit() throws DataModelException { 212 public void validateDataOnExit() throws DataModelException {
203 // TODO auto-generated method stub, to be implemented by parser 213 // TODO auto-generated method stub, to be implemented by parser
204 } 214 }
...@@ -224,6 +234,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -224,6 +234,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
224 /* (non-Javadoc) 234 /* (non-Javadoc)
225 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 235 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
226 */ 236 */
237 + @Override
227 public void generateJavaCodeEntry() { 238 public void generateJavaCodeEntry() {
228 // TODO Auto-generated method stub 239 // TODO Auto-generated method stub
229 240
...@@ -232,6 +243,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -232,6 +243,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
232 /* (non-Javadoc) 243 /* (non-Javadoc)
233 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 244 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
234 */ 245 */
246 + @Override
235 public void generateJavaCodeExit() { 247 public void generateJavaCodeExit() {
236 // TODO Auto-generated method stub 248 // TODO Auto-generated method stub
237 249
...@@ -254,4 +266,16 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -254,4 +266,16 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
254 // TODO Auto-generated method stub 266 // TODO Auto-generated method stub
255 267
256 } 268 }
269 +
270 + @Override
271 + public CachedFileHandle getFileHandle() {
272 + // TODO Auto-generated method stub
273 + return null;
274 + }
275 +
276 + @Override
277 + public void setFileHandle(CachedFileHandle fileHandle) {
278 + // TODO Auto-generated method stub
279 +
280 + }
257 } 281 }
......
...@@ -42,4 +42,11 @@ public interface CachedFileHandle { ...@@ -42,4 +42,11 @@ public interface CachedFileHandle {
42 * @throws IOException when failes to generated java files. 42 * @throws IOException when failes to generated java files.
43 */ 43 */
44 void close() throws IOException; 44 void close() throws IOException;
45 +
46 + /**
47 + * Sets child package path for import.
48 + *
49 + * @param pkg child's package path
50 + */
51 + void setChildsPackage(String pkg);
45 } 52 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 +import java.util.ArrayList;
21 import java.util.LinkedList; 22 import java.util.LinkedList;
22 import java.util.List; 23 import java.util.List;
23 import java.util.SortedSet; 24 import java.util.SortedSet;
...@@ -68,6 +69,11 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -68,6 +69,11 @@ public class CachedJavaFileHandle implements CachedFileHandle {
68 private String pkg; 69 private String pkg;
69 70
70 /** 71 /**
72 + * Java package in which the child class/interface needs to be generated.
73 + */
74 + private String childsPkg;
75 +
76 + /**
71 * Name of the object in YANG file. 77 * Name of the object in YANG file.
72 */ 78 */
73 private String yangName; 79 private String yangName;
...@@ -76,7 +82,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -76,7 +82,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
76 * Sorted set of import info, to be used to maintain the set of classes to 82 * Sorted set of import info, to be used to maintain the set of classes to
77 * be imported in the generated class. 83 * be imported in the generated class.
78 */ 84 */
79 - private SortedSet<ImportInfo> importSet; 85 + private SortedSet<String> importSet;
80 86
81 /** 87 /**
82 * Cached list of attribute info. 88 * Cached list of attribute info.
...@@ -171,11 +177,30 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -171,11 +177,30 @@ public class CachedJavaFileHandle implements CachedFileHandle {
171 } 177 }
172 178
173 /** 179 /**
180 + * Get the java package.
181 + *
182 + * @return the java package.
183 + */
184 + public String getChildsPackage() {
185 + return childsPkg;
186 + }
187 +
188 + /**
189 + * Set the java package.
190 + *
191 + * @param pcg the package to set
192 + */
193 + @Override
194 + public void setChildsPackage(String pcg) {
195 + childsPkg = pcg;
196 + }
197 +
198 + /**
174 * Get the set containing the imported class/interface info. 199 * Get the set containing the imported class/interface info.
175 * 200 *
176 * @return the set containing the imported class/interface info. 201 * @return the set containing the imported class/interface info.
177 */ 202 */
178 - public SortedSet<ImportInfo> getImportSet() { 203 + public SortedSet<String> getImportSet() {
179 return importSet; 204 return importSet;
180 } 205 }
181 206
...@@ -184,7 +209,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -184,7 +209,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
184 * 209 *
185 * @param importSet the set containing the imported class/interface info. 210 * @param importSet the set containing the imported class/interface info.
186 */ 211 */
187 - private void setImportSet(SortedSet<ImportInfo> importSet) { 212 + private void setImportSet(SortedSet<String> importSet) {
188 this.importSet = importSet; 213 this.importSet = importSet;
189 } 214 }
190 215
...@@ -203,9 +228,9 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -203,9 +228,9 @@ public class CachedJavaFileHandle implements CachedFileHandle {
203 * be used in the generated class. 228 * be used in the generated class.
204 */ 229 */
205 if (getImportSet() == null) { 230 if (getImportSet() == null) {
206 - setImportSet(new TreeSet<ImportInfo>()); 231 + setImportSet(new TreeSet<String>());
207 } 232 }
208 - return getImportSet().add(importInfo); 233 + return getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo));
209 } 234 }
210 235
211 /** 236 /**
...@@ -253,23 +278,42 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -253,23 +278,42 @@ public class CachedJavaFileHandle implements CachedFileHandle {
253 public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) { 278 public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) {
254 279
255 AttributeInfo newAttr = new AttributeInfo(); 280 AttributeInfo newAttr = new AttributeInfo();
281 + if (attrType != null) {
256 attrType.setDataTypeName(attrType.getDataTypeName().replace("\"", "")); 282 attrType.setDataTypeName(attrType.getDataTypeName().replace("\"", ""));
257 if (attrType.getDataTypeName().equals("string")) { 283 if (attrType.getDataTypeName().equals("string")) {
258 - attrType.setDataTypeName( 284 + attrType.setDataTypeName(JavaIdentifierSyntax.getCaptialCase(attrType.getDataTypeName()));
259 - attrType.getDataTypeName().substring(0, 1).toUpperCase() + attrType.getDataTypeName().substring(1));
260 } 285 }
261 newAttr.setAttributeType(attrType); 286 newAttr.setAttributeType(attrType);
287 + } else {
288 + ImportInfo importInfo = new ImportInfo();
289 + importInfo.setPkgInfo(getChildsPackage());
290 + importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name));
291 + if (getImportSet() != null) {
292 + getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo));
293 + } else {
294 + SortedSet<String> newImportInfo = new TreeSet<>();
295 + newImportInfo.add(JavaCodeSnippetGen.getImportText(importInfo));
296 + setImportSet(newImportInfo);
297 + }
298 +
299 + newAttr.setQualifiedName(getQualifiedFlag(JavaCodeSnippetGen.getImportText(importInfo)));
300 + }
262 newAttr.setAttributeName(name); 301 newAttr.setAttributeName(name);
263 newAttr.setListAttr(isListAttr); 302 newAttr.setListAttr(isListAttr);
264 303
265 - /* 304 + if (isListAttr) {
266 - * TODO: get the prefix and name of data type from attrType and 305 + String listImport = UtilConstants.COLLECTION_IMPORTS + UtilConstants.LIST + UtilConstants.SEMI_COLAN
267 - * initialize in importInfo. 306 + + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE;
268 - */ 307 + if (getImportSet() != null) {
308 + getImportSet().add(listImport);
309 + } else {
310 + SortedSet<String> newImportInfo = new TreeSet<>();
311 + newImportInfo.add(listImport);
312 + setImportSet(newImportInfo);
313 + }
269 314
270 - /** 315 + newAttr.setQualifiedName(getQualifiedFlag(listImport));
271 - * TODO: Handle QualifiedFlag for imports. 316 + }
272 - */
273 317
274 if (getCachedAttributeList() != null) { 318 if (getCachedAttributeList() != null) {
275 if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) { 319 if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) {
...@@ -281,7 +325,32 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -281,7 +325,32 @@ public class CachedJavaFileHandle implements CachedFileHandle {
281 newAttributeInfo.add(newAttr); 325 newAttributeInfo.add(newAttr);
282 setCachedAttributeList(newAttributeInfo); 326 setCachedAttributeList(newAttributeInfo);
283 } 327 }
284 - name = JavaIdentifierSyntax.getCamelCase(name); 328 + }
329 +
330 + /**
331 + * Check if the import set does not have a class info same as the new class
332 + * info, if so the new class info be added to the import set. Otherwise
333 + * check if the corresponding package info is same as the new package info,
334 + * if so no need to qualified access, otherwise, it needs qualified access.
335 + *
336 + * @param newImportInfo new import info to be check for qualified access or
337 + * not and updated in the import set accordingly.
338 + * @return if the new attribute needs to be accessed in a qualified manner.
339 + */
340 + private boolean getQualifiedFlag(String newImportInfo) {
341 + for (String curImportInfo : getImportSet()) {
342 + if (curImportInfo.equals(newImportInfo)) {
343 + /*
344 + * If import is already existing import with same package, we
345 + * don't need qualified access, otherwise it needs to be
346 + * qualified access.
347 + */
348 + return !curImportInfo.equals(newImportInfo);
349 + }
350 + }
351 +
352 + getImportSet().add(newImportInfo);
353 + return false;
285 } 354 }
286 355
287 /** 356 /**
...@@ -291,7 +360,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -291,7 +360,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
291 public void close() throws IOException { 360 public void close() throws IOException {
292 361
293 String className = getYangName(); 362 String className = getYangName();
294 - className = (className.substring(0, 1).toUpperCase() + className.substring(1)); 363 + className = JavaIdentifierSyntax.getCaptialCase(className);
295 String packagePath = getPackage(); 364 String packagePath = getPackage();
296 String filePath = UtilConstants.YANG_GEN_DIR + packagePath.replace(".", "/"); 365 String filePath = UtilConstants.YANG_GEN_DIR + packagePath.replace(".", "/");
297 GeneratedFileType fileType = getGeneratedFileTypes(); 366 GeneratedFileType fileType = getGeneratedFileTypes();
...@@ -322,60 +391,18 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -322,60 +391,18 @@ public class CachedJavaFileHandle implements CachedFileHandle {
322 String implFileName = className + UtilConstants.IMPL + TEMP_FILE_EXTENSION; 391 String implFileName = className + UtilConstants.IMPL + TEMP_FILE_EXTENSION;
323 File implTempFile = new File(filePath + File.separator + implFileName); 392 File implTempFile = new File(filePath + File.separator + implFileName);
324 393
325 - if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
326 -
327 - try {
328 - interfaceFile.createNewFile();
329 - appendContents(interfaceFile, className, GeneratedFileType.INTERFACE);
330 - } catch (IOException e) {
331 - throw new IOException("Failed to create interface file.");
332 - }
333 - }
334 -
335 - if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) {
336 -
337 - try {
338 - builderFile.createNewFile();
339 - appendContents(builderFile, className, GeneratedFileType.BUILDER_CLASS);
340 - } catch (IOException e) {
341 - throw new IOException("Failed to create builder class file.");
342 - }
343 - }
344 -
345 - if (fileType.equals(GeneratedFileType.IMPL) || fileType.equals(GeneratedFileType.ALL)) {
346 -
347 - try {
348 - implTempFile.createNewFile();
349 - appendContents(implTempFile, className, GeneratedFileType.IMPL);
350 - } catch (IOException e) {
351 - throw new IOException("Failed to create impl class file.");
352 - }
353 - }
354 -
355 - if (fileType.equals(GeneratedFileType.BUILDER_INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
356 -
357 - try {
358 - builderInterfaceFile.createNewFile();
359 - appendContents(builderInterfaceFile, className, GeneratedFileType.BUILDER_INTERFACE);
360 - } catch (IOException e) {
361 - throw new IOException("Failed to create builder interface class file.");
362 - }
363 - }
364 /* 394 /*
365 * TODO: add the file header using 395 * TODO: add the file header using
366 * JavaCodeSnippetGen.getFileHeaderComment 396 * JavaCodeSnippetGen.getFileHeaderComment
367 */ 397 */
368 - /*
369 - * TODO: get the import list using getImportText and add to the
370 - * generated java file using JavaCodeSnippetGen.getImportText
371 - */
372 398
373 List<String> attributes = new LinkedList<>(); 399 List<String> attributes = new LinkedList<>();
374 List<String> interfaceMethods = new LinkedList<>(); 400 List<String> interfaceMethods = new LinkedList<>();
375 List<String> builderInterfaceMethods = new LinkedList<>(); 401 List<String> builderInterfaceMethods = new LinkedList<>();
376 List<String> builderClassMethods = new LinkedList<>(); 402 List<String> builderClassMethods = new LinkedList<>();
377 List<String> implClassMethods = new LinkedList<>(); 403 List<String> implClassMethods = new LinkedList<>();
378 - //TODO: Handle imports for the attributes. 404 + List<String> imports = new LinkedList<>();
405 +
379 try { 406 try {
380 attributes = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.ATTRIBUTE); 407 attributes = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.ATTRIBUTE);
381 408
...@@ -391,7 +418,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -391,7 +418,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
391 implClassMethods = SerializedDataStore 418 implClassMethods = SerializedDataStore
392 .getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPL_METHODS); 419 .getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPL_METHODS);
393 420
394 - //TODO:imports = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPORT); 421 + imports = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPORT);
395 } catch (ClassNotFoundException | IOException e) { 422 } catch (ClassNotFoundException | IOException e) {
396 log.info("There is no attribute info of " + className + " YANG file in the serialized files."); 423 log.info("There is no attribute info of " + className + " YANG file in the serialized files.");
397 } 424 }
...@@ -399,6 +426,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -399,6 +426,14 @@ public class CachedJavaFileHandle implements CachedFileHandle {
399 if (getCachedAttributeList() != null) { 426 if (getCachedAttributeList() != null) {
400 MethodsGenerator.setAttrInfo(getCachedAttributeList()); 427 MethodsGenerator.setAttrInfo(getCachedAttributeList());
401 for (AttributeInfo attr : getCachedAttributeList()) { 428 for (AttributeInfo attr : getCachedAttributeList()) {
429 + if (attr.isListAttr()) {
430 + String listString = JavaCodeSnippetGen.getListAttribute(attr.getAttributeType().getDataTypeName());
431 + @SuppressWarnings("rawtypes")
432 + YangType<?> type = new YangType();
433 + type.setDataTypeName(listString);
434 + attr.setAttributeType(type);
435 + }
436 +
402 attributes.add(getAttributeString(attr)); 437 attributes.add(getAttributeString(attr));
403 438
404 interfaceMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE)); 439 interfaceMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE));
...@@ -409,6 +444,10 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -409,6 +444,10 @@ public class CachedJavaFileHandle implements CachedFileHandle {
409 .add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE)); 444 .add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE));
410 445
411 implClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL)); 446 implClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL));
447 +
448 + if (getImportSet() != null) {
449 + imports = new ArrayList<>(getImportSet());
450 + }
412 } 451 }
413 } 452 }
414 453
...@@ -422,6 +461,25 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -422,6 +461,25 @@ public class CachedJavaFileHandle implements CachedFileHandle {
422 implClassMethods.add(MethodsGenerator.getConstructorString(className)); 461 implClassMethods.add(MethodsGenerator.getConstructorString(className));
423 462
424 /** 463 /**
464 + * Start generation of files.
465 + */
466 + if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
467 + initiateFile(interfaceFile, className, GeneratedFileType.INTERFACE, imports);
468 + }
469 +
470 + if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) {
471 + initiateFile(builderFile, className, GeneratedFileType.BUILDER_CLASS, imports);
472 + }
473 +
474 + if (fileType.equals(GeneratedFileType.IMPL) || fileType.equals(GeneratedFileType.ALL)) {
475 + initiateFile(implTempFile, className, GeneratedFileType.IMPL, imports);
476 + }
477 +
478 + if (fileType.equals(GeneratedFileType.BUILDER_INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
479 + initiateFile(builderInterfaceFile, className, GeneratedFileType.BUILDER_INTERFACE, imports);
480 + }
481 +
482 + /**
425 * Add attributes to the file. 483 * Add attributes to the file.
426 */ 484 */
427 for (String attribute : attributes) { 485 for (String attribute : attributes) {
...@@ -483,6 +541,25 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -483,6 +541,25 @@ public class CachedJavaFileHandle implements CachedFileHandle {
483 } 541 }
484 542
485 /** 543 /**
544 + * Initiate generation of file based on generated file type.
545 + *
546 + * @param file generated file
547 + * @param className generated file class name
548 + * @param type generated file type
549 + * @param imports imports for the file
550 + * @throws IOException when fails to generate a file
551 + */
552 + private void initiateFile(File file, String className, GeneratedFileType type, List<String> imports)
553 + throws IOException {
554 + try {
555 + file.createNewFile();
556 + appendContents(file, className, type, imports);
557 + } catch (IOException e) {
558 + throw new IOException("Failed to create " + file.getName() + " class file.");
559 + }
560 + }
561 +
562 + /**
486 * Appends the temp files to main files. 563 * Appends the temp files to main files.
487 * 564 *
488 * @param appendFile temp file 565 * @param appendFile temp file
...@@ -584,7 +661,8 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -584,7 +661,8 @@ public class CachedJavaFileHandle implements CachedFileHandle {
584 * @param fileName generated file name 661 * @param fileName generated file name
585 * @param type generated file type 662 * @param type generated file type
586 */ 663 */
587 - private void appendContents(File file, String fileName, GeneratedFileType type) throws IOException { 664 + private void appendContents(File file, String fileName, GeneratedFileType type, List<String> importsList)
665 + throws IOException {
588 666
589 if (type.equals(GeneratedFileType.IMPL)) { 667 if (type.equals(GeneratedFileType.IMPL)) {
590 668
...@@ -599,12 +677,20 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -599,12 +677,20 @@ public class CachedJavaFileHandle implements CachedFileHandle {
599 if (type.equals(GeneratedFileType.INTERFACE)) { 677 if (type.equals(GeneratedFileType.INTERFACE)) {
600 insert(file, CopyrightHeader.getCopyrightHeader()); 678 insert(file, CopyrightHeader.getCopyrightHeader());
601 insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN 679 insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN
602 - + UtilConstants.NEW_LINE); 680 + + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE);
681 + for (String imports : importsList) {
682 + insert(file, imports);
683 + }
684 + insert(file, UtilConstants.NEW_LINE);
603 write(file, fileName, type, JavaDocType.INTERFACE); 685 write(file, fileName, type, JavaDocType.INTERFACE);
604 } else if (type.equals(GeneratedFileType.BUILDER_CLASS)) { 686 } else if (type.equals(GeneratedFileType.BUILDER_CLASS)) {
605 insert(file, CopyrightHeader.getCopyrightHeader()); 687 insert(file, CopyrightHeader.getCopyrightHeader());
606 insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN 688 insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN
607 - + UtilConstants.NEW_LINE); 689 + + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE);
690 + for (String imports : importsList) {
691 + insert(file, imports);
692 + }
693 + insert(file, UtilConstants.NEW_LINE);
608 write(file, fileName, type, JavaDocType.BUILDER_CLASS); 694 write(file, fileName, type, JavaDocType.BUILDER_CLASS);
609 } 695 }
610 } 696 }
......
...@@ -42,18 +42,19 @@ public final class JavaCodeGenerator { ...@@ -42,18 +42,19 @@ public final class JavaCodeGenerator {
42 TraversalType curTraversal = TraversalType.ROOT; 42 TraversalType curTraversal = TraversalType.ROOT;
43 43
44 while (!(curNode == null)) { 44 while (!(curNode == null)) {
45 - if (curTraversal != TraversalType.PARENT) { 45 + if (curTraversal != TraversalType.PARENT || curTraversal == TraversalType.SIBILING) {
46 curNode.generateJavaCodeEntry(); 46 curNode.generateJavaCodeEntry();
47 } 47 }
48 if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) { 48 if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) {
49 curTraversal = TraversalType.CHILD; 49 curTraversal = TraversalType.CHILD;
50 curNode = curNode.getChild(); 50 curNode = curNode.getChild();
51 - } else if (!(curNode.getNextSibling() == null)) { 51 + } else if (curTraversal == TraversalType.PARENT && !(curNode.getNextSibling() == null)) {
52 + curNode.generateJavaCodeExit();
52 curTraversal = TraversalType.SIBILING; 53 curTraversal = TraversalType.SIBILING;
53 curNode = curNode.getNextSibling(); 54 curNode = curNode.getNextSibling();
54 } else { 55 } else {
55 - curTraversal = TraversalType.PARENT;
56 curNode.generateJavaCodeExit(); 56 curNode.generateJavaCodeExit();
57 + curTraversal = TraversalType.PARENT;
57 curNode = curNode.getParent(); 58 curNode = curNode.getParent();
58 } 59 }
59 } 60 }
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 -import java.util.List;
20 -import java.util.SortedSet;
21 -
22 import org.onosproject.yangutils.datamodel.YangType; 19 import org.onosproject.yangutils.datamodel.YangType;
23 import org.onosproject.yangutils.translator.GeneratedFileType; 20 import org.onosproject.yangutils.translator.GeneratedFileType;
24 import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; 21 import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
...@@ -50,29 +47,15 @@ public final class JavaCodeSnippetGen { ...@@ -50,29 +47,15 @@ public final class JavaCodeSnippetGen {
50 } 47 }
51 48
52 /** 49 /**
53 - * reorder the import list based on the ONOS import rules.
54 - *
55 - * @param importInfo the set of classes/interfaces to be imported.
56 - * @return string of import info.
57 - */
58 - public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) {
59 - /* TODO: reorder the import list based on the ONOS import rules. */
60 - return null;
61 - }
62 -
63 - /**
64 * Get the textual java code information corresponding to the import list. 50 * Get the textual java code information corresponding to the import list.
65 * 51 *
66 - * @param importInfo sorted list of import info. 52 + * @param importInfo import info.
67 * @return the textual java code information corresponding to the import 53 * @return the textual java code information corresponding to the import
68 * list. 54 * list.
69 */ 55 */
70 - public static String getImportText(List<ImportInfo> importInfo) { 56 + public static String getImportText(ImportInfo importInfo) {
71 - /* 57 + return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo()
72 - * TODO: get the textual java code information corresponding to the 58 + + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE;
73 - * import list
74 - */
75 - return null;
76 } 59 }
77 60
78 /** 61 /**
...@@ -101,9 +84,23 @@ public final class JavaCodeSnippetGen { ...@@ -101,9 +84,23 @@ public final class JavaCodeSnippetGen {
101 */ 84 */
102 public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) { 85 public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) {
103 yangName = JavaIdentifierSyntax.getCamelCase(yangName); 86 yangName = JavaIdentifierSyntax.getCamelCase(yangName);
87 + if (type != null) {
104 return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName 88 return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName
105 + UtilConstants.SEMI_COLAN; 89 + UtilConstants.SEMI_COLAN;
106 } 90 }
91 + return UtilConstants.PRIVATE + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(yangName)
92 + + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN;
93 + }
94 +
95 + /**
96 + * Returns list attribute string.
97 + *
98 + * @param type attribute type
99 + * @return list attribute string
100 + */
101 + public static String getListAttribute(String type) {
102 + return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + type + UtilConstants.DIAMOND_CLOSE_BRACKET;
103 + }
107 104
108 /** 105 /**
109 * Based on the file type and method type(s) and the YANG name of the 106 * Based on the file type and method type(s) and the YANG name of the
......
...@@ -163,4 +163,14 @@ public final class JavaIdentifierSyntax { ...@@ -163,4 +163,14 @@ public final class JavaIdentifierSyntax {
163 } 163 }
164 return camelCase; 164 return camelCase;
165 } 165 }
166 +
167 + /**
168 + * Translate the YANG identifier name to java identifier with first letter in caps.
169 + *
170 + * @param yangIdentifier identifier in YANG file.
171 + * @return corresponding java identifier
172 + */
173 + public static String getCaptialCase(String yangIdentifier) {
174 + return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
175 + }
166 } 176 }
......
...@@ -112,6 +112,13 @@ public final class MethodsGenerator { ...@@ -112,6 +112,13 @@ public final class MethodsGenerator {
112 public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName, 112 public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName,
113 GeneratedMethodTypes methodTypes, YangType<?> returnType) { 113 GeneratedMethodTypes methodTypes, YangType<?> returnType) {
114 114
115 + if (returnType == null) {
116 + @SuppressWarnings("rawtypes")
117 + YangType<?> type = new YangType();
118 + type.setDataTypeName(yangName);
119 + returnType = type;
120 + }
121 +
115 if (genFileTypes.equals(GeneratedFileType.INTERFACE)) { 122 if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
116 123
117 /** 124 /**
...@@ -177,12 +184,10 @@ public final class MethodsGenerator { ...@@ -177,12 +184,10 @@ public final class MethodsGenerator {
177 184
178 String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE 185 String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
179 + UtilConstants.NEW_LINE; 186 + UtilConstants.NEW_LINE;
180 -
181 String getterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, 187 String getterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
182 attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType()); 188 attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType());
183 String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, 189 String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
184 attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType()); 190 attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType());
185 -
186 return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString 191 return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString
187 + UtilConstants.NEW_LINE; 192 + UtilConstants.NEW_LINE;
188 } 193 }
...@@ -299,7 +304,8 @@ public final class MethodsGenerator { ...@@ -299,7 +304,8 @@ public final class MethodsGenerator {
299 private static String getGetterForClass(String yangName, YangType<?> returnType) { 304 private static String getGetterForClass(String yangName, YangType<?> returnType) {
300 305
301 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE 306 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
302 - + returnType.getDataTypeName() + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + yangName 307 + + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName()) + UtilConstants.SPACE
308 + + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
303 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE 309 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
304 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION 310 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
305 + UtilConstants.RETURN + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN 311 + UtilConstants.RETURN + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
...@@ -316,13 +322,14 @@ public final class MethodsGenerator { ...@@ -316,13 +322,14 @@ public final class MethodsGenerator {
316 private static String getSetterForClass(String yangName, YangType<?> returnType) { 322 private static String getSetterForClass(String yangName, YangType<?> returnType) {
317 323
318 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + getBuilderClassName() 324 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + getBuilderClassName()
319 - + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS 325 + + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
320 - + returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS 326 + + UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
321 - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE 327 + + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
322 - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD + yangName 328 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
323 - + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN 329 + + UtilConstants.THIS + UtilConstants.PERIOD + yangName + UtilConstants.SPACE + UtilConstants.EQUAL
324 - + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN 330 + + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
325 - + UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE 331 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE
332 + + UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
326 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; 333 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
327 } 334 }
328 335
...@@ -335,9 +342,9 @@ public final class MethodsGenerator { ...@@ -335,9 +342,9 @@ public final class MethodsGenerator {
335 */ 342 */
336 private static String getGetterForInterface(String yangName, YangType<?> returnType) { 343 private static String getGetterForInterface(String yangName, YangType<?> returnType) {
337 returnType.setDataTypeName(returnType.getDataTypeName().replace("\"", "")); 344 returnType.setDataTypeName(returnType.getDataTypeName().replace("\"", ""));
338 - return UtilConstants.FOUR_SPACE_INDENTATION + returnType.getDataTypeName() + UtilConstants.SPACE 345 + return UtilConstants.FOUR_SPACE_INDENTATION + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
339 - + UtilConstants.GET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS 346 + + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
340 - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN; 347 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
341 } 348 }
342 349
343 /** 350 /**
...@@ -349,9 +356,9 @@ public final class MethodsGenerator { ...@@ -349,9 +356,9 @@ public final class MethodsGenerator {
349 */ 356 */
350 private static String getSetterForInterface(String yangName, YangType<?> returnType) { 357 private static String getSetterForInterface(String yangName, YangType<?> returnType) {
351 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.BUILDER + UtilConstants.SPACE 358 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.BUILDER + UtilConstants.SPACE
352 - + UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS 359 + + UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
353 - + returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS 360 + + UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
354 - + UtilConstants.SEMI_COLAN; 361 + + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
355 } 362 }
356 363
357 /** 364 /**
...@@ -387,7 +394,8 @@ public final class MethodsGenerator { ...@@ -387,7 +394,8 @@ public final class MethodsGenerator {
387 constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS 394 constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
388 + UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE 395 + UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
389 + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT 396 + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
390 - + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX + attribute.getAttributeName() 397 + + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
398 + + JavaIdentifierSyntax.getCaptialCase(attribute.getAttributeName())
391 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN 399 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
392 + UtilConstants.NEW_LINE; 400 + UtilConstants.NEW_LINE;
393 } 401 }
......
...@@ -129,7 +129,7 @@ public final class UtilConstants { ...@@ -129,7 +129,7 @@ public final class UtilConstants {
129 public static final String STATIC = "static"; 129 public static final String STATIC = "static";
130 public static final String FINAL = "final"; 130 public static final String FINAL = "final";
131 public static final String PACKAGE = "package"; 131 public static final String PACKAGE = "package";
132 - public static final String IMPORT = "import"; 132 + public static final String IMPORT = "import ";
133 public static final String NULL = "null"; 133 public static final String NULL = "null";
134 public static final String RETURN = "return"; 134 public static final String RETURN = "return";
135 public static final String NEW = "new"; 135 public static final String NEW = "new";
...@@ -144,6 +144,7 @@ public final class UtilConstants { ...@@ -144,6 +144,7 @@ public final class UtilConstants {
144 /** 144 /**
145 * For collections. 145 * For collections.
146 */ 146 */
147 + public static final String COLLECTION_IMPORTS = "import java.util.";
147 public static final String ABSTRACT_COLLECTION = "AbstractCollection"; 148 public static final String ABSTRACT_COLLECTION = "AbstractCollection";
148 149
149 public static final String LIST = "List"; 150 public static final String LIST = "List";
......
...@@ -62,8 +62,7 @@ public final class FileSystemUtil { ...@@ -62,8 +62,7 @@ public final class FileSystemUtil {
62 public static void createPackage(String pkg, String pkgInfo) throws IOException { 62 public static void createPackage(String pkg, String pkgInfo) throws IOException {
63 if (!doesPackageExist(new File(pkg))) { 63 if (!doesPackageExist(new File(pkg))) {
64 try { 64 try {
65 - File pack = YangIoUtils 65 + File pack = YangIoUtils.createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
66 - .createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
67 YangIoUtils.addPackageInfo(pack, pkgInfo, pkg); 66 YangIoUtils.addPackageInfo(pack, pkgInfo, pkg);
68 } catch (IOException e) { 67 } catch (IOException e) {
69 throw new IOException("failed to create package-info file"); 68 throw new IOException("failed to create package-info file");
......
...@@ -226,8 +226,8 @@ public final class JavaDocGen { ...@@ -226,8 +226,8 @@ public final class JavaDocGen {
226 */ 226 */
227 private static String generateForConstructors(String className) { 227 private static String generateForConstructors(String className) {
228 return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION 228 return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
229 - + UtilConstants.JAVA_DOC_SETTERS + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE 229 + + UtilConstants.JAVA_DOC_CONSTRUCTOR + className + UtilConstants.IMPL + UtilConstants.PERIOD
230 - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC 230 + + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
231 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM 231 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
232 + (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT 232 + (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT
233 + UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className 233 + UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className
......
...@@ -27,6 +27,7 @@ import java.io.ObjectInputStream; ...@@ -27,6 +27,7 @@ import java.io.ObjectInputStream;
27 import java.io.ObjectOutput; 27 import java.io.ObjectOutput;
28 import java.io.ObjectOutputStream; 28 import java.io.ObjectOutputStream;
29 import java.io.OutputStream; 29 import java.io.OutputStream;
30 +import java.util.ArrayList;
30 import java.util.List; 31 import java.util.List;
31 32
32 /** 33 /**
...@@ -165,7 +166,6 @@ public final class SerializedDataStore { ...@@ -165,7 +166,6 @@ public final class SerializedDataStore {
165 * @throws IOException when fails to read from the file. 166 * @throws IOException when fails to read from the file.
166 * @throws ClassNotFoundException when file is missing. 167 * @throws ClassNotFoundException when file is missing.
167 */ 168 */
168 - @SuppressWarnings("unchecked")
169 public static List<String> getSerializeData(SerializedDataStoreType type) 169 public static List<String> getSerializeData(SerializedDataStoreType type)
170 throws IOException, ClassNotFoundException { 170 throws IOException, ClassNotFoundException {
171 171
...@@ -191,10 +191,13 @@ public final class SerializedDataStore { ...@@ -191,10 +191,13 @@ public final class SerializedDataStore {
191 InputStream buffer = new BufferedInputStream(file); 191 InputStream buffer = new BufferedInputStream(file);
192 ObjectInput input = new ObjectInputStream(buffer); 192 ObjectInput input = new ObjectInputStream(buffer);
193 try { 193 try {
194 - List<String> recoveredData = (List<String>) input.readObject(); 194 + String data = (String) input.readObject();
195 + List<String> recoveredData = new ArrayList<>();
196 + recoveredData.add(data);
195 return recoveredData; 197 return recoveredData;
196 } finally { 198 } finally {
197 input.close(); 199 input.close();
200 + file.close();
198 } 201 }
199 } catch (ClassNotFoundException ex) { 202 } catch (ClassNotFoundException ex) {
200 throw new ClassNotFoundException("failed to fetch the serialized data file."); 203 throw new ClassNotFoundException("failed to fetch the serialized data file.");
......
...@@ -27,6 +27,7 @@ import org.apache.maven.project.MavenProject; ...@@ -27,6 +27,7 @@ import org.apache.maven.project.MavenProject;
27 import org.apache.maven.model.Resource; 27 import org.apache.maven.model.Resource;
28 28
29 import org.onosproject.yangutils.utils.UtilConstants; 29 import org.onosproject.yangutils.utils.UtilConstants;
30 +import org.apache.commons.io.FileUtils;
30 31
31 import static org.slf4j.LoggerFactory.getLogger; 32 import static org.slf4j.LoggerFactory.getLogger;
32 import org.slf4j.Logger; 33 import org.slf4j.Logger;
...@@ -102,10 +103,10 @@ public final class YangIoUtils { ...@@ -102,10 +103,10 @@ public final class YangIoUtils {
102 File currentFile = new File(file); 103 File currentFile = new File(file);
103 currentFile.delete(); 104 currentFile.delete();
104 } 105 }
106 + FileUtils.deleteDirectory(generatedDirectory);
105 } catch (IOException e) { 107 } catch (IOException e) {
106 log.info("Failed to delete the generated files in " + generatedDirectory + " directory"); 108 log.info("Failed to delete the generated files in " + generatedDirectory + " directory");
107 } 109 }
108 - generatedDirectory.delete();
109 } 110 }
110 } 111 }
111 112
......