Vinod Kumar S
Committed by Gerrit Code Review

YANG Translator optimization

Change-Id: Ie6a6b9d371a4fc5fd973cf56d6f3c7b44a3146ba
Showing 70 changed files with 2989 additions and 1024 deletions
...@@ -21,7 +21,6 @@ import java.util.List; ...@@ -21,7 +21,6 @@ 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.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
24 -import org.onosproject.yangutils.translator.CachedFileHandle;
25 24
26 /*- 25 /*-
27 * Reference RFC 6020. 26 * Reference RFC 6020.
...@@ -77,7 +76,8 @@ import org.onosproject.yangutils.translator.CachedFileHandle; ...@@ -77,7 +76,8 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
77 /** 76 /**
78 * Data model node to maintain information defined in YANG augment. 77 * Data model node to maintain information defined in YANG augment.
79 */ 78 */
80 -public class YangAugment extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable { 79 +public class YangAugment extends YangNode
80 + implements YangLeavesHolder, YangCommonInfo, Parsable {
81 81
82 /** 82 /**
83 * Augment target node. 83 * Augment target node.
...@@ -110,11 +110,6 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo ...@@ -110,11 +110,6 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
110 private YangStatusType status; 110 private YangStatusType status;
111 111
112 /** 112 /**
113 - * Package of the generated java code.
114 - */
115 - private String pkg;
116 -
117 - /**
118 * Create a YANG augment node. 113 * Create a YANG augment node.
119 */ 114 */
120 public YangAugment() { 115 public YangAugment() {
...@@ -316,57 +311,4 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo ...@@ -316,57 +311,4 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
316 311
317 } 312 }
318 313
319 - /**
320 - * Get the mapped java package.
321 - *
322 - * @return the java package
323 - */
324 - @Override
325 - public String getPackage() {
326 - return pkg;
327 - }
328 -
329 - /**
330 - * Set the mapped java package.
331 - *
332 - * @param pakg the package to set
333 - */
334 - @Override
335 - public void setPackage(String pakg) {
336 - pkg = pakg;
337 -
338 - }
339 -
340 - /**
341 - * Prepare the information for java code generation corresponding to YANG
342 - * grouping info.
343 - *
344 - * @param codeGenDir code generation directory
345 - */
346 - @Override
347 - public void generateJavaCodeEntry(String codeGenDir) {
348 - // TODO Auto-generated method stub
349 -
350 - }
351 -
352 - /**
353 - * Create a java file using the YANG grouping info.
354 - */
355 - @Override
356 - public void generateJavaCodeExit() {
357 - // TODO Auto-generated method stub
358 -
359 - }
360 -
361 - @Override
362 - public CachedFileHandle getFileHandle() {
363 - // TODO Auto-generated method stub
364 - return null;
365 - }
366 -
367 - @Override
368 - public void setFileHandle(CachedFileHandle fileHandle) {
369 - // TODO Auto-generated method stub
370 -
371 - }
372 } 314 }
......
...@@ -15,15 +15,15 @@ ...@@ -15,15 +15,15 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.LinkedList;
19 +import java.util.List;
20 +
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
21 -import org.onosproject.yangutils.translator.CachedFileHandle;
22 import org.onosproject.yangutils.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
23 -import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
24 24
25 -import java.util.LinkedList; 25 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26 -import java.util.List; 26 +import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
27 27
28 /*- 28 /*-
29 * Reference RFC 6020. 29 * Reference RFC 6020.
...@@ -127,11 +127,6 @@ public class YangCase extends YangNode ...@@ -127,11 +127,6 @@ public class YangCase extends YangNode
127 private YangStatusType status; 127 private YangStatusType status;
128 128
129 /** 129 /**
130 - * Package of the generated java code.
131 - */
132 - private String pkg;
133 -
134 - /**
135 * Create a choice node. 130 * Create a choice node.
136 */ 131 */
137 public YangCase() { 132 public YangCase() {
...@@ -314,76 +309,23 @@ public class YangCase extends YangNode ...@@ -314,76 +309,23 @@ public class YangCase extends YangNode
314 // TODO auto-generated method stub, to be implemented by parser 309 // TODO auto-generated method stub, to be implemented by parser
315 } 310 }
316 311
317 - /**
318 - * Get the mapped java package.
319 - *
320 - * @return the java package
321 - */
322 - @Override
323 - public String getPackage() {
324 - return pkg;
325 - }
326 -
327 - /**
328 - * Set the mapped java package.
329 - *
330 - * @param pakg the package to set
331 - */
332 - @Override
333 - public void setPackage(String pakg) {
334 - pkg = pakg;
335 -
336 - }
337 -
338 - /**
339 - * Generate the code corresponding to YANG case info.
340 - *
341 - * @param codeGenDir code generation directory
342 - */
343 - @Override
344 - public void generateJavaCodeEntry(String codeGenDir) {
345 - // TODO Auto-generated method stub
346 -
347 - }
348 -
349 - /**
350 - * Free resource used for generating code and generate valid java files
351 - * corresponding to YANG case info.
352 - */
353 - @Override
354 - public void generateJavaCodeExit() {
355 - // TODO Auto-generated method stub
356 -
357 - }
358 -
359 - @Override
360 - public CachedFileHandle getFileHandle() {
361 - // TODO Auto-generated method stub
362 - return null;
363 - }
364 -
365 - @Override
366 - public void setFileHandle(CachedFileHandle fileHandle) {
367 - // TODO Auto-generated method stub
368 - }
369 -
370 @Override 312 @Override
371 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 313 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
372 - if ((this.getParent() == null) || (!(this.getParent() instanceof YangChoice))) { 314 + if (getParent() == null || !(getParent() instanceof YangChoice)) {
373 throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " + 315 throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
374 - this.getName()); 316 + getName());
375 } 317 }
376 // Traverse up in tree to ask parent choice start collision detection. 318 // Traverse up in tree to ask parent choice start collision detection.
377 - ((CollisionDetector) this.getParent()).detectCollidingChild(identifierName, dataType); 319 + ((CollisionDetector) getParent()).detectCollidingChild(identifierName, dataType);
378 } 320 }
379 321
380 @Override 322 @Override
381 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 323 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
382 324
383 if (dataType == CASE_DATA) { 325 if (dataType == CASE_DATA) {
384 - if (this.getName().equals(identifierName)) { 326 + if (getName().equals(identifierName)) {
385 throw new DataModelException("YANG File Error: Identifier collision detected in case \"" + 327 throw new DataModelException("YANG File Error: Identifier collision detected in case \"" +
386 - this.getName() + "\""); 328 + getName() + "\"");
387 } 329 }
388 return; 330 return;
389 } 331 }
......
...@@ -17,8 +17,8 @@ package org.onosproject.yangutils.datamodel; ...@@ -17,8 +17,8 @@ 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.parser.Parsable; 19 import org.onosproject.yangutils.parser.Parsable;
20 -import org.onosproject.yangutils.translator.CachedFileHandle;
21 import org.onosproject.yangutils.utils.YangConstructType; 20 import org.onosproject.yangutils.utils.YangConstructType;
21 +
22 import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA; 22 import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA;
23 23
24 /*- 24 /*-
...@@ -140,11 +140,21 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co ...@@ -140,11 +140,21 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co
140 super(YangNodeType.CHOICE_NODE); 140 super(YangNodeType.CHOICE_NODE);
141 } 141 }
142 142
143 + /**
144 + * Get the choice name.
145 + *
146 + * @return choice name
147 + */
143 @Override 148 @Override
144 public String getName() { 149 public String getName() {
145 return name; 150 return name;
146 } 151 }
147 152
153 + /**
154 + * Set the choice name.
155 + *
156 + * @param name choice name
157 + */
148 @Override 158 @Override
149 public void setName(String name) { 159 public void setName(String name) {
150 this.name = name; 160 this.name = name;
...@@ -295,46 +305,13 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co ...@@ -295,46 +305,13 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co
295 } 305 }
296 306
297 @Override 307 @Override
298 - public String getPackage() {
299 - // TODO Auto-generated method stub
300 - return null;
301 - }
302 -
303 - @Override
304 - public void setPackage(String pkg) {
305 - // TODO Auto-generated method stub
306 -
307 - }
308 -
309 - @Override
310 - public void generateJavaCodeEntry(String codeGenDir) {
311 - // TODO Auto-generated method stub
312 -
313 - }
314 -
315 - @Override
316 - public void generateJavaCodeExit() {
317 - // TODO Auto-generated method stub
318 -
319 - }
320 -
321 - @Override
322 - public CachedFileHandle getFileHandle() {
323 - // TODO Auto-generated method stub
324 - return null;
325 - }
326 -
327 - @Override
328 - public void setFileHandle(CachedFileHandle fileHandle) {
329 - // TODO Auto-generated method stub
330 -
331 - }
332 -
333 - @Override
334 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 308 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
335 309
336 - YangNode node = this.getChild(); 310 + if (this.getParent() instanceof YangCase && dataType != YangConstructType.CASE_DATA) {
337 - while ((node != null)) { 311 + ((CollisionDetector) getParent()).detectCollidingChild(identifierName, dataType);
312 + }
313 + YangNode node = getChild();
314 + while (node != null) {
338 if (node instanceof CollisionDetector) { 315 if (node instanceof CollisionDetector) {
339 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); 316 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
340 } 317 }
...@@ -346,15 +323,15 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co ...@@ -346,15 +323,15 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co
346 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 323 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
347 324
348 if (dataType == CHOICE_DATA) { 325 if (dataType == CHOICE_DATA) {
349 - if (this.getName().equals(identifierName)) { 326 + if (getName().equals(identifierName)) {
350 throw new DataModelException("YANG file error: Identifier collision detected in choice \"" + 327 throw new DataModelException("YANG file error: Identifier collision detected in choice \"" +
351 - this.getName() + "\""); 328 + getName() + "\"");
352 } 329 }
353 return; 330 return;
354 } 331 }
355 332
356 - YangNode node = this.getChild(); 333 + YangNode node = getChild();
357 - while ((node != null)) { 334 + while (node != null) {
358 if (node instanceof CollisionDetector) { 335 if (node instanceof CollisionDetector) {
359 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); 336 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
360 } 337 }
......
...@@ -16,20 +16,15 @@ ...@@ -16,20 +16,15 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20 -
21 -import java.io.IOException;
22 import java.util.LinkedList; 19 import java.util.LinkedList;
23 import java.util.List; 20 import java.util.List;
24 21
25 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
26 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
27 -import org.onosproject.yangutils.translator.CachedFileHandle;
28 -import org.onosproject.yangutils.translator.GeneratedFileType;
29 -import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
30 -import org.onosproject.yangutils.utils.UtilConstants;
31 import org.onosproject.yangutils.utils.YangConstructType; 24 import org.onosproject.yangutils.utils.YangConstructType;
32 -import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; 25 +
26 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
27 +
33 /*- 28 /*-
34 * Reference RFC 6020. 29 * Reference RFC 6020.
35 * 30 *
...@@ -136,16 +131,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -136,16 +131,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
136 private YangStatusType status = YangStatusType.CURRENT; 131 private YangStatusType status = YangStatusType.CURRENT;
137 132
138 /** 133 /**
139 - * Package of the generated java code.
140 - */
141 - private String pkg;
142 -
143 - /**
144 - * Cached Java File Handle.
145 - */
146 - private CachedFileHandle fileHandle;
147 -
148 - /**
149 * Create a container node. 134 * Create a container node.
150 */ 135 */
151 public YangContainer() { 136 public YangContainer() {
...@@ -335,26 +320,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -335,26 +320,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
335 } 320 }
336 321
337 /** 322 /**
338 - * Get the cached file handle.
339 - *
340 - * @return the fileHandle
341 - */
342 - @Override
343 - public CachedFileHandle getFileHandle() {
344 - return fileHandle;
345 - }
346 -
347 - /**
348 - * Set the cached file handle.
349 - *
350 - * @param handle the fileHandle to set
351 - */
352 - @Override
353 - public void setFileHandle(CachedFileHandle handle) {
354 - fileHandle = handle;
355 - }
356 -
357 - /**
358 * Returns the type of the data. 323 * Returns the type of the data.
359 * 324 *
360 * @return returns CONTAINER_DATA 325 * @return returns CONTAINER_DATA
...@@ -435,7 +400,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -435,7 +400,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
435 * If a node has "config" set to "false", no node underneath it can have 400 * If a node has "config" set to "false", no node underneath it can have
436 * "config" set to "true". 401 * "config" set to "true".
437 */ 402 */
438 - if ((!isConfig) && (leaves != null)) { 403 + if (!isConfig && leaves != null) {
439 for (YangLeaf leaf : leaves) { 404 for (YangLeaf leaf : leaves) {
440 if (leaf.isConfig()) { 405 if (leaf.isConfig()) {
441 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + 406 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
...@@ -444,7 +409,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -444,7 +409,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
444 } 409 }
445 } 410 }
446 411
447 - if ((!isConfig) && (leafLists != null)) { 412 + if (!isConfig && leafLists != null) {
448 for (YangLeafList leafList : leafLists) { 413 for (YangLeafList leafList : leafLists) {
449 if (leafList.isConfig()) { 414 if (leafList.isConfig()) {
450 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + 415 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
...@@ -454,98 +419,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -454,98 +419,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
454 } 419 }
455 } 420 }
456 421
457 - /**
458 - * Get the mapped java package.
459 - *
460 - * @return the java package
461 - */
462 - @Override
463 - public String getPackage() {
464 - return pkg;
465 - }
466 -
467 - /**
468 - * Set the mapped java package.
469 - *
470 - * @param pcg the package to set
471 - */
472 - @Override
473 - public void setPackage(String pcg) {
474 - pkg = pcg;
475 - }
476 -
477 - /**
478 - * Generate the java code corresponding to YANG container.
479 - *
480 - * @param codeGenDir code generation directory
481 - * @throws IOException when fails to generate the source files.
482 - */
483 - @Override
484 - public void generateJavaCodeEntry(String codeGenDir) throws IOException {
485 - YangNode parent = getParent();
486 - String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName());
487 -
488 - contPkg = JavaIdentifierSyntax.getCamelCase(contPkg).toLowerCase();
489 - setPackage(contPkg);
490 -
491 - CachedFileHandle handle = null;
492 - try {
493 - FileSystemUtil.createPackage(codeGenDir + getPackage(), parent.getName() + UtilConstants.CHILDREN);
494 - handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
495 - GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
496 - handle.setRelativeFilePath(getPackage().replace(".", "/"));
497 - handle.setCodeGenFilePath(codeGenDir);
498 - } catch (IOException e) {
499 - throw new IOException("Failed to create the source files.");
500 - }
501 - setFileHandle(handle);
502 -
503 - addLeavesAttributes();
504 - addLeafListAttributes();
505 - addAttributeInParent();
506 - }
507 -
508 - /**
509 - * Adds current node attribute to parent file.
510 - */
511 - private void addAttributeInParent() {
512 - if (getParent() != null) {
513 - getParent().getFileHandle().addAttributeInfo(null, getName(), false);
514 - }
515 - }
516 -
517 - @Override
518 - public void generateJavaCodeExit() throws IOException {
519 - getFileHandle().close();
520 - return;
521 - }
522 -
523 - /**
524 - * Adds leaf attributes in generated files.
525 - */
526 - private void addLeavesAttributes() {
527 -
528 - List<YangLeaf> leaves = getListOfLeaf();
529 - if (leaves != null) {
530 - for (YangLeaf leaf : leaves) {
531 - getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
532 - }
533 - }
534 - }
535 -
536 - /**
537 - * Adds leaf list's attributes in generated files.
538 - */
539 - private void addLeafListAttributes() {
540 - List<YangLeafList> leavesList = getListOfLeafList();
541 - if (leavesList != null) {
542 - for (YangLeafList leafList : leavesList) {
543 - getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
544 - }
545 - }
546 - return;
547 - }
548 -
549 @Override 422 @Override
550 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 423 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
551 // Asks helper to detect colliding child. 424 // Asks helper to detect colliding child.
...@@ -554,9 +427,9 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -554,9 +427,9 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
554 427
555 @Override 428 @Override
556 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 429 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
557 - if (this.getName().equals(identifierName)) { 430 + if (getName().equals(identifierName)) {
558 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \"" 431 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
559 - + this.getName() + "\""); 432 + + getName() + "\"");
560 } 433 }
561 } 434 }
562 } 435 }
......
...@@ -21,7 +21,6 @@ import java.util.List; ...@@ -21,7 +21,6 @@ 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.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
24 -import org.onosproject.yangutils.translator.CachedFileHandle;
25 24
26 /*- 25 /*-
27 * Reference RFC 6020. 26 * Reference RFC 6020.
...@@ -110,11 +109,6 @@ public class YangGrouping extends YangNode ...@@ -110,11 +109,6 @@ public class YangGrouping extends YangNode
110 private YangStatusType status; 109 private YangStatusType status;
111 110
112 /** 111 /**
113 - * Package of the generated java code.
114 - */
115 - private String pkg;
116 -
117 - /**
118 * Creates the grouping node. 112 * Creates the grouping node.
119 */ 113 */
120 public YangGrouping() { 114 public YangGrouping() {
...@@ -296,58 +290,4 @@ public class YangGrouping extends YangNode ...@@ -296,58 +290,4 @@ public class YangGrouping extends YangNode
296 public void validateDataOnExit() throws DataModelException { 290 public void validateDataOnExit() throws DataModelException {
297 // TODO auto-generated method stub, to be implemented by parser 291 // TODO auto-generated method stub, to be implemented by parser
298 } 292 }
299 -
300 - /**
301 - * Generate the code for YANG grouping.
302 - *
303 - * @param codeGenDir code generated directory.
304 - */
305 - @Override
306 - public void generateJavaCodeEntry(String codeGenDir) {
307 - // TODO Auto-generated method stub
308 -
309 - }
310 -
311 - /**
312 - * Free the resources used to generate java files corresponding to YANG
313 - * grouping info and generate valid java files.
314 - */
315 - @Override
316 - public void generateJavaCodeExit() {
317 - // TODO Auto-generated method stub
318 -
319 - }
320 -
321 - /**
322 - * Get the mapped java package.
323 - *
324 - * @return the java package
325 - */
326 - @Override
327 - public String getPackage() {
328 - return pkg;
329 - }
330 -
331 - /**
332 - * Set the mapped java package.
333 - *
334 - * @param pakg the package to set
335 - */
336 - @Override
337 - public void setPackage(String pakg) {
338 - pkg = pakg;
339 -
340 - }
341 -
342 - @Override
343 - public CachedFileHandle getFileHandle() {
344 - // TODO Auto-generated method stub
345 - return null;
346 - }
347 -
348 - @Override
349 - public void setFileHandle(CachedFileHandle fileHandle) {
350 - // TODO Auto-generated method stub
351 -
352 - }
353 } 293 }
......
...@@ -16,16 +16,16 @@ ...@@ -16,16 +16,16 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 +import java.util.LinkedList;
20 +import java.util.List;
21 +
19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
21 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
22 -import org.onosproject.yangutils.translator.CachedFileHandle;
23 import org.onosproject.yangutils.utils.YangConstructType; 24 import org.onosproject.yangutils.utils.YangConstructType;
24 25
25 -import java.util.LinkedList; 26 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26 -import java.util.List;
27 27
28 -/*- 28 +/*
29 * The "list" statement is used to define an interior data node in the 29 * The "list" statement is used to define an interior data node in the
30 * schema tree. A list node may exist in multiple instances in the data 30 * schema tree. A list node may exist in multiple instances in the data
31 * tree. Each such instance is known as a list entry. The "list" 31 * tree. Each such instance is known as a list entry. The "list"
...@@ -166,11 +166,6 @@ public class YangList extends YangNode ...@@ -166,11 +166,6 @@ public class YangList extends YangNode
166 private YangStatusType status = YangStatusType.CURRENT; 166 private YangStatusType status = YangStatusType.CURRENT;
167 167
168 /** 168 /**
169 - * Package of the generated java code.
170 - */
171 - private String pkg;
172 -
173 - /**
174 * Constructor. 169 * Constructor.
175 */ 170 */
176 public YangList() { 171 public YangList() {
...@@ -619,61 +614,6 @@ public class YangList extends YangNode ...@@ -619,61 +614,6 @@ public class YangList extends YangNode
619 } 614 }
620 } 615 }
621 616
622 - /**
623 - * Populate the cached handle with information about the list attributes to
624 - * generate java code.
625 - *
626 - * @param codeGenDir code generated directory
627 - */
628 - @Override
629 - public void generateJavaCodeEntry(String codeGenDir) {
630 - // TODO Auto-generated method stub
631 -
632 - }
633 -
634 - /**
635 - * Free the resources used to generate the java file corresponding to YANG
636 - * list info.
637 - */
638 - @Override
639 - public void generateJavaCodeExit() {
640 - // TODO Auto-generated method stub
641 -
642 - }
643 -
644 - /**
645 - * Get the mapped java package.
646 - *
647 - * @return the java package
648 - */
649 - @Override
650 - public String getPackage() {
651 - return pkg;
652 - }
653 -
654 - /**
655 - * Set the mapped java package.
656 - *
657 - * @param pakg the package to set
658 - */
659 - @Override
660 - public void setPackage(String pakg) {
661 - pkg = pakg;
662 -
663 - }
664 -
665 - @Override
666 - public CachedFileHandle getFileHandle() {
667 - // TODO Auto-generated method stub
668 - return null;
669 - }
670 -
671 - @Override
672 - public void setFileHandle(CachedFileHandle fileHandle) {
673 - // TODO Auto-generated method stub
674 -
675 - }
676 -
677 @Override 617 @Override
678 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 618 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
679 // Asks helper to detect colliding child. 619 // Asks helper to detect colliding child.
...@@ -682,9 +622,9 @@ public class YangList extends YangNode ...@@ -682,9 +622,9 @@ public class YangList extends YangNode
682 622
683 @Override 623 @Override
684 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 624 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
685 - if (this.getName().equals(identifierName)) { 625 + if (getName().equals(identifierName)) {
686 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" + 626 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
687 - this.getName() + "\""); 627 + getName() + "\"");
688 } 628 }
689 } 629 }
690 } 630 }
......
...@@ -15,20 +15,14 @@ ...@@ -15,20 +15,14 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
19 -
20 -import java.io.IOException;
21 import java.util.LinkedList; 18 import java.util.LinkedList;
22 import java.util.List; 19 import java.util.List;
23 20
24 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
25 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
26 -import org.onosproject.yangutils.translator.CachedFileHandle;
27 -import org.onosproject.yangutils.translator.CodeGenerator;
28 -import org.onosproject.yangutils.translator.GeneratedFileType;
29 -import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
30 import org.onosproject.yangutils.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
31 -import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; 24 +
25 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
32 26
33 /*- 27 /*-
34 * Reference:RFC 6020. 28 * Reference:RFC 6020.
...@@ -74,7 +68,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; ...@@ -74,7 +68,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
74 * Data model node to maintain information defined in YANG module. 68 * Data model node to maintain information defined in YANG module.
75 */ 69 */
76 public class YangModule extends YangNode 70 public class YangModule extends YangNode
77 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator, CollisionDetector { 71 + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
78 72
79 /** 73 /**
80 * Name of the module. 74 * Name of the module.
...@@ -157,11 +151,6 @@ public class YangModule extends YangNode ...@@ -157,11 +151,6 @@ public class YangModule extends YangNode
157 */ 151 */
158 private byte version; 152 private byte version;
159 153
160 - /**
161 - * Cached Java File Handle.
162 - */
163 - private CachedFileHandle fileHandle;
164 -
165 /*- 154 /*-
166 * Reference RFC 6020. 155 * Reference RFC 6020.
167 * 156 *
...@@ -510,52 +499,6 @@ public class YangModule extends YangNode ...@@ -510,52 +499,6 @@ public class YangModule extends YangNode
510 } 499 }
511 500
512 /** 501 /**
513 - * Get the mapped java package.
514 - *
515 - * @return the java package
516 - */
517 - @Override
518 - public String getPackage() {
519 - if (getFileHandle() != null) {
520 - return getFileHandle().getRelativeFilePath().replace("/", ".");
521 - }
522 - return null;
523 - }
524 -
525 - /**
526 - * Set the mapped java package.
527 - *
528 - * @param pcg the package to set
529 - */
530 - @Override
531 - public void setPackage(String pcg) {
532 - if (getFileHandle() != null) {
533 - pcg.replace(".", "/");
534 - getFileHandle().setRelativeFilePath(pcg);
535 - }
536 - }
537 -
538 - /**
539 - * Get the cached file handle.
540 - *
541 - * @return the fileHandle
542 - */
543 - @Override
544 - public CachedFileHandle getFileHandle() {
545 - return fileHandle;
546 - }
547 -
548 - /**
549 - * Set the cached file handle.
550 - *
551 - * @param handle the fileHandle to set
552 - */
553 - @Override
554 - public void setFileHandle(CachedFileHandle handle) {
555 - fileHandle = handle;
556 - }
557 -
558 - /**
559 * Get the list of nested reference's which required resolution. 502 * Get the list of nested reference's which required resolution.
560 * 503 *
561 * @return list of nested reference's which required resolution 504 * @return list of nested reference's which required resolution
...@@ -623,64 +566,6 @@ public class YangModule extends YangNode ...@@ -623,64 +566,6 @@ public class YangModule extends YangNode
623 } 566 }
624 567
625 /** 568 /**
626 - * Generates java code for module.
627 - *
628 - * @param codeGenDir code generation directory
629 - * @throws IOException when fails to generate the source files
630 - */
631 - @Override
632 - public void generateJavaCodeEntry(String codeGenDir) throws IOException {
633 - String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
634 - getRevision().getRevDate());
635 -
636 - modPkg = JavaIdentifierSyntax.getCamelCase(modPkg);
637 - CachedFileHandle handle = null;
638 - try {
639 - FileSystemUtil.createPackage(codeGenDir + modPkg, getName());
640 - handle = FileSystemUtil.createSourceFiles(modPkg, getName(),
641 - GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
642 - handle.setCodeGenFilePath(codeGenDir);
643 - } catch (IOException e) {
644 - throw new IOException("Failed to create the source files.");
645 - }
646 -
647 - setFileHandle(handle);
648 - addLeavesAttributes();
649 - addLeafListAttributes();
650 - }
651 -
652 - @Override
653 - public void generateJavaCodeExit() throws IOException {
654 - getFileHandle().close();
655 - return;
656 - }
657 -
658 - /**
659 - * Adds leaf attributes in generated files.
660 - */
661 - private void addLeavesAttributes() {
662 -
663 - List<YangLeaf> leaves = getListOfLeaf();
664 - if (leaves != null) {
665 - for (YangLeaf leaf : leaves) {
666 - getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
667 - }
668 - }
669 - }
670 -
671 - /**
672 - * Adds leaf list's attributes in generated files.
673 - */
674 - private void addLeafListAttributes() {
675 - List<YangLeafList> leavesList = getListOfLeafList();
676 - if (leavesList != null) {
677 - for (YangLeafList leafList : leavesList) {
678 - getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
679 - }
680 - }
681 - }
682 -
683 - /**
684 * Add a type to resolve the nested references. 569 * Add a type to resolve the nested references.
685 * 570 *
686 * @param node grouping or typedef node which needs to be resolved 571 * @param node grouping or typedef node which needs to be resolved
...@@ -715,4 +600,5 @@ public class YangModule extends YangNode ...@@ -715,4 +600,5 @@ public class YangModule extends YangNode
715 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 600 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
716 // Not required as module doesn't have any parent. 601 // Not required as module doesn't have any parent.
717 } 602 }
603 +
718 } 604 }
......
...@@ -16,13 +16,11 @@ ...@@ -16,13 +16,11 @@
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;
20 -import org.onosproject.yangutils.translator.CodeGenerator;
21 19
22 /** 20 /**
23 * Base class of a node in data model tree. 21 * Base class of a node in data model tree.
24 */ 22 */
25 -public abstract class YangNode implements CodeGenerator { 23 +public abstract class YangNode {
26 24
27 /** 25 /**
28 * Type of node. 26 * Type of node.
...@@ -50,6 +48,20 @@ public abstract class YangNode implements CodeGenerator { ...@@ -50,6 +48,20 @@ public abstract class YangNode implements CodeGenerator {
50 private YangNode previousSibling; 48 private YangNode previousSibling;
51 49
52 /** 50 /**
51 + * Get the nodes name.
52 + *
53 + * @return nodes name
54 + */
55 + public abstract String getName();
56 +
57 + /**
58 + * Set the nodes name.
59 + *
60 + * @param name nodes name
61 + */
62 + public abstract void setName(String name);
63 +
64 + /**
53 * Default constructor is made private to ensure node type is always set. 65 * Default constructor is made private to ensure node type is always set.
54 */ 66 */
55 @SuppressWarnings("unused") 67 @SuppressWarnings("unused")
...@@ -195,19 +207,25 @@ public abstract class YangNode implements CodeGenerator { ...@@ -195,19 +207,25 @@ public abstract class YangNode implements CodeGenerator {
195 YangNode curNode; 207 YangNode curNode;
196 curNode = getChild(); 208 curNode = getChild();
197 209
198 - /* If the new node needs to be the first child */ 210 + /*-
211 + * If the new node needs to be the first child
199 if (newChild.getNodeType().ordinal() < curNode.getNodeType().ordinal()) { 212 if (newChild.getNodeType().ordinal() < curNode.getNodeType().ordinal()) {
200 newChild.setNextSibling(curNode); 213 newChild.setNextSibling(curNode);
201 curNode.setPreviousSibling(newChild); 214 curNode.setPreviousSibling(newChild);
202 setChild(newChild); 215 setChild(newChild);
203 return; 216 return;
204 } 217 }
218 + */
205 219
206 /* 220 /*
207 * Get the predecessor child of new child 221 * Get the predecessor child of new child
208 */ 222 */
209 while (curNode.getNextSibling() != null 223 while (curNode.getNextSibling() != null
210 - && newChild.getNodeType().ordinal() >= curNode.getNextSibling().getNodeType().ordinal()) { 224 + /*
225 + * && newChild.getNodeType().ordinal() >=
226 + * curNode.getNextSibling().getNodeType().ordinal()
227 + */) {
228 +
211 curNode = curNode.getNextSibling(); 229 curNode = curNode.getNextSibling();
212 } 230 }
213 231
...@@ -218,54 +236,13 @@ public abstract class YangNode implements CodeGenerator { ...@@ -218,54 +236,13 @@ public abstract class YangNode implements CodeGenerator {
218 return; 236 return;
219 } 237 }
220 238
221 - /* Insert the new node in child node list sorted by type */ 239 + /*-
240 + * Insert the new node in child node list sorted by type
222 newChild.setNextSibling(curNode.getNextSibling()); 241 newChild.setNextSibling(curNode.getNextSibling());
223 newChild.setPreviousSibling(curNode); 242 newChild.setPreviousSibling(curNode);
224 curNode.getNextSibling().setPreviousSibling(newChild); 243 curNode.getNextSibling().setPreviousSibling(newChild);
225 curNode.setNextSibling(newChild); 244 curNode.setNextSibling(newChild);
226 return; 245 return;
246 + */
227 } 247 }
228 -
229 - /**
230 - * Get the YANG name of the node.
231 - *
232 - * @return the name of node as defined in YANG file.
233 - */
234 - public abstract String getName();
235 -
236 - /**
237 - * Set the YANG name of the node.
238 - *
239 - * @param name the name of node as defined in YANG file.
240 - */
241 - public abstract void setName(String name);
242 -
243 - /**
244 - * Get the mapped java package.
245 - *
246 - * @return the java package
247 - */
248 - public abstract String getPackage();
249 -
250 - /**
251 - * Set the mapped java package.
252 - *
253 - * @param pkg the package to set
254 - */
255 - public abstract void setPackage(String pkg);
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 -
271 } 248 }
......
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.LinkedList;
19 +import java.util.List;
20 +
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
21 -import org.onosproject.yangutils.translator.CachedFileHandle;
22 import org.onosproject.yangutils.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
23 24
24 -import java.util.LinkedList; 25 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25 -import java.util.List;
26 26
27 /* 27 /*
28 * Reference RFC 6020. 28 * Reference RFC 6020.
...@@ -144,11 +144,6 @@ public class YangSubModule extends YangNode ...@@ -144,11 +144,6 @@ public class YangSubModule extends YangNode
144 private byte version; 144 private byte version;
145 145
146 /** 146 /**
147 - * package of the generated java code.
148 - */
149 - private String pkg;
150 -
151 - /**
152 * Create a sub module node. 147 * Create a sub module node.
153 */ 148 */
154 public YangSubModule() { 149 public YangSubModule() {
...@@ -468,57 +463,6 @@ public class YangSubModule extends YangNode ...@@ -468,57 +463,6 @@ public class YangSubModule extends YangNode
468 // TODO auto-generated method stub, to be implemented by parser 463 // TODO auto-generated method stub, to be implemented by parser
469 } 464 }
470 465
471 - /**
472 - * Generates java code for sub-module.
473 - *
474 - * @param codeGenDir code generation directory.
475 - */
476 - @Override
477 - public void generateJavaCodeEntry(String codeGenDir) {
478 - // TODO Auto-generated method stub
479 - }
480 -
481 - /**
482 - * Free resources used to generate code.
483 - */
484 - @Override
485 - public void generateJavaCodeExit() {
486 - // TODO Auto-generated method stub
487 -
488 - }
489 -
490 - /**
491 - * Get the mapped java package.
492 - *
493 - * @return the java package
494 - */
495 - @Override
496 - public String getPackage() {
497 - return pkg;
498 - }
499 -
500 - /**
501 - * Set the mapped java package.
502 - *
503 - * @param pakg the package to set
504 - */
505 - @Override
506 - public void setPackage(String pakg) {
507 - pkg = pakg;
508 - }
509 -
510 - @Override
511 - public CachedFileHandle getFileHandle() {
512 - // TODO Auto-generated method stub
513 - return null;
514 - }
515 -
516 - @Override
517 - public void setFileHandle(CachedFileHandle fileHandle) {
518 - // TODO Auto-generated method stub
519 -
520 - }
521 -
522 @Override 466 @Override
523 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 467 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
524 // Asks helper to detect colliding child. 468 // Asks helper to detect colliding child.
......
...@@ -15,16 +15,9 @@ ...@@ -15,16 +15,9 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 -import java.io.IOException;
19 -
20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 import org.onosproject.yangutils.parser.Parsable; 19 import org.onosproject.yangutils.parser.Parsable;
22 -import org.onosproject.yangutils.translator.CachedFileHandle;
23 -import org.onosproject.yangutils.translator.GeneratedFileType;
24 -import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
25 -import org.onosproject.yangutils.utils.UtilConstants;
26 import org.onosproject.yangutils.utils.YangConstructType; 20 import org.onosproject.yangutils.utils.YangConstructType;
27 -import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
28 21
29 /*- 22 /*-
30 * Reference RFC 6020. 23 * Reference RFC 6020.
...@@ -92,16 +85,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -92,16 +85,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
92 private String units; 85 private String units;
93 86
94 /** 87 /**
95 - * package of the generated java code.
96 - */
97 - private String pkg;
98 -
99 - /**
100 - * Cached Java File Handle.
101 - */
102 - private CachedFileHandle fileHandle;
103 -
104 - /**
105 * Create a typedef node. 88 * Create a typedef node.
106 */ 89 */
107 public YangTypeDef() { 90 public YangTypeDef() {
...@@ -307,103 +290,4 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -307,103 +290,4 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
307 getDerivedType().setDataType(YangDataTypes.DERIVED); 290 getDerivedType().setDataType(YangDataTypes.DERIVED);
308 } 291 }
309 292
310 - /**
311 - * Generate java code snippet corresponding to YANG typedef.
312 - *
313 - * @param codeGenDir code generation directory
314 - * @throws IOException when fails to generate files for typedef
315 - */
316 - @Override
317 - public void generateJavaCodeEntry(String codeGenDir) throws IOException {
318 -
319 - YangNode parent = getParent();
320 - String typeDefPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName());
321 -
322 - typeDefPkg = JavaIdentifierSyntax.getCamelCase(typeDefPkg).toLowerCase();
323 - setPackage(typeDefPkg);
324 -
325 - CachedFileHandle handle = null;
326 - try {
327 - FileSystemUtil.createPackage(codeGenDir + getPackage(), parent.getName() + UtilConstants.CHILDREN);
328 - handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
329 - GeneratedFileType.GENERATE_TYPEDEF_CLASS);
330 - handle.setRelativeFilePath(getPackage().replace(".", "/"));
331 - handle.setCodeGenFilePath(codeGenDir);
332 - } catch (IOException e) {
333 - throw new IOException("Failed to create the source files.");
334 - }
335 - setFileHandle(handle);
336 - getDerivedType().getDataTypeExtendedInfo().getBaseType().setJavaPackage(getPackage());
337 - addAttributeInfo();
338 - addAttributeInParent();
339 - }
340 -
341 - /**
342 - * Adds current node attribute to parent file.
343 - */
344 - private void addAttributeInParent() {
345 - if (getParent() != null) {
346 - getParent().getFileHandle().addAttributeInfo(null, getName(), false);
347 - }
348 - }
349 -
350 - /**
351 - * Adds attribute to file handle.
352 - */
353 - private void addAttributeInfo() {
354 - getFileHandle().addAttributeInfo(getDerivedType().getDataTypeExtendedInfo().getBaseType(),
355 - JavaIdentifierSyntax.getCamelCase(getName()), false);
356 - }
357 -
358 - /**
359 - * Free resource used for code generation of YANG typedef.
360 - *
361 - * @throws IOException when fails to generate files
362 - */
363 - @Override
364 - public void generateJavaCodeExit() throws IOException {
365 - getFileHandle().close();
366 - return;
367 - }
368 -
369 - /**
370 - * Get the mapped java package.
371 - *
372 - * @return the java package
373 - */
374 - @Override
375 - public String getPackage() {
376 - return pkg;
377 - }
378 -
379 - /**
380 - * Set the mapped java package.
381 - *
382 - * @param pakg mapped java package
383 - */
384 - @Override
385 - public void setPackage(String pakg) {
386 - pkg = pakg;
387 -
388 - }
389 -
390 - /**
391 - * Get the file handle of the cached file used during code generation.
392 - *
393 - * @return cached file handle
394 - */
395 - @Override
396 - public CachedFileHandle getFileHandle() {
397 - return fileHandle;
398 - }
399 -
400 - /**
401 - * Set the file handle to be used used for code generation.
402 - *
403 - * @param handle cached file handle
404 - */
405 - @Override
406 - public void setFileHandle(CachedFileHandle handle) {
407 - fileHandle = handle;
408 - }
409 } 293 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel; ...@@ -18,7 +18,6 @@ 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.utils.YangConstructType; 20 import org.onosproject.yangutils.utils.YangConstructType;
21 -import org.onosproject.yangutils.translator.CachedFileHandle;
22 21
23 /*- 22 /*-
24 * Reference RFC 6020. 23 * Reference RFC 6020.
...@@ -213,51 +212,26 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -213,51 +212,26 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
213 // TODO auto-generated method stub, to be implemented by parser 212 // TODO auto-generated method stub, to be implemented by parser
214 } 213 }
215 214
215 + /**
216 + * Get uses name.
217 + *
218 + * @return uses name
219 + */
216 @Override 220 @Override
217 public String getName() { 221 public String getName() {
218 // TODO Auto-generated method stub 222 // TODO Auto-generated method stub
219 return null; 223 return null;
220 } 224 }
221 225
226 + /**
227 + * Set uses name.
228 + *
229 + * @param name uses name
230 + */
222 @Override 231 @Override
223 public void setName(String name) { 232 public void setName(String name) {
224 // TODO Auto-generated method stub 233 // TODO Auto-generated method stub
225 234
226 } 235 }
227 236
228 - @Override
229 - public void generateJavaCodeEntry(String codeGenDir) {
230 - // TODO Auto-generated method stub
231 -
232 - }
233 -
234 - @Override
235 - public void generateJavaCodeExit() {
236 - // TODO Auto-generated method stub
237 -
238 - }
239 -
240 - @Override
241 - public String getPackage() {
242 - // TODO Auto-generated method stub
243 - return null;
244 - }
245 -
246 - @Override
247 - public void setPackage(String pkg) {
248 - // TODO Auto-generated method stub
249 -
250 - }
251 -
252 - @Override
253 - public CachedFileHandle getFileHandle() {
254 - // TODO Auto-generated method stub
255 - return null;
256 - }
257 -
258 - @Override
259 - public void setFileHandle(CachedFileHandle fileHandle) {
260 - // TODO Auto-generated method stub
261 -
262 - }
263 } 237 }
......
...@@ -63,7 +63,7 @@ public final class DataModelUtils { ...@@ -63,7 +63,7 @@ public final class DataModelUtils {
63 } 63 }
64 } 64 }
65 node = node.getChild(); 65 node = node.getChild();
66 - while ((node != null)) { 66 + while (node != null) {
67 if (node instanceof CollisionDetector) { 67 if (node instanceof CollisionDetector) {
68 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); 68 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
69 } 69 }
......
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 +package org.onosproject.yangutils.datamodel.utils;
17 +
18 +/**
19 + * The target language in which the YANG information is modeled.
20 + */
21 +public enum GeneratedLanguage {
22 + /**
23 + * Java.
24 + */
25 + JAVA_GENERATION;
26 +}
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 +package org.onosproject.yangutils.datamodel.utils;
17 +
18 +import org.onosproject.yangutils.datamodel.YangAugment;
19 +import org.onosproject.yangutils.datamodel.YangCase;
20 +import org.onosproject.yangutils.datamodel.YangChoice;
21 +import org.onosproject.yangutils.datamodel.YangContainer;
22 +import org.onosproject.yangutils.datamodel.YangGrouping;
23 +import org.onosproject.yangutils.datamodel.YangList;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangSubModule;
26 +import org.onosproject.yangutils.datamodel.YangTypeDef;
27 +import org.onosproject.yangutils.datamodel.YangUses;
28 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
29 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
30 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
31 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
32 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
33 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
34 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
35 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
36 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
37 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
38 +
39 +/**
40 + * Factory to create data model objects based on the target file type.
41 + */
42 +public final class YangDataModelFactory {
43 +
44 + /**
45 + * Utility class, hence private to prevent creating objects.
46 + */
47 + private YangDataModelFactory() {
48 + }
49 +
50 + /**
51 + * Based on the target language generate the inherited data model node.
52 + *
53 + * @param targetLanguage target language in which YANG mapping needs to be
54 + * generated.
55 + * @return the corresponding inherited node based on the target language.
56 + */
57 + public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
58 + switch (targetLanguage) {
59 + case JAVA_GENERATION: {
60 + return new YangJavaModule();
61 + }
62 + default: {
63 + throw new RuntimeException("Only YANG to Java is supported.");
64 + }
65 + }
66 + }
67 +
68 + /**
69 + * Based on the target language generate the inherited data model node.
70 + *
71 + * @param targetLanguage target language in which YANG mapping needs to be
72 + * generated.
73 + * @return the corresponding inherited node based on the target language.
74 + */
75 + public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
76 + switch (targetLanguage) {
77 + case JAVA_GENERATION: {
78 + return new YangJavaAugment();
79 + }
80 + default: {
81 + throw new RuntimeException("Only YANG to Java is supported.");
82 + }
83 + }
84 + }
85 +
86 + /**
87 + * Based on the target language generate the inherited data model node.
88 + *
89 + * @param targetLanguage target language in which YANG mapping needs to be
90 + * generated.
91 + * @return the corresponding inherited node based on the target language.
92 + */
93 + public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
94 + switch (targetLanguage) {
95 + case JAVA_GENERATION: {
96 + return new YangJavaCase();
97 + }
98 + default: {
99 + throw new RuntimeException("Only YANG to Java is supported.");
100 + }
101 + }
102 + }
103 +
104 + /**
105 + * Based on the target language generate the inherited data model node.
106 + *
107 + * @param targetLanguage target language in which YANG mapping needs to be
108 + * generated.
109 + * @return the corresponding inherited node based on the target language.
110 + */
111 + public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
112 + switch (targetLanguage) {
113 + case JAVA_GENERATION: {
114 + return new YangJavaChoice();
115 + }
116 + default: {
117 + throw new RuntimeException("Only YANG to Java is supported.");
118 + }
119 + }
120 + }
121 +
122 + /**
123 + * Based on the target language generate the inherited data model node.
124 + *
125 + * @param targetLanguage target language in which YANG mapping needs to be
126 + * generated.
127 + * @return the corresponding inherited node based on the target language.
128 + */
129 + public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
130 + switch (targetLanguage) {
131 + case JAVA_GENERATION: {
132 + return new YangJavaContainer();
133 + }
134 + default: {
135 + throw new RuntimeException("Only YANG to Java is supported.");
136 + }
137 + }
138 + }
139 +
140 + /**
141 + * Based on the target language generate the inherited data model node.
142 + *
143 + * @param targetLanguage target language in which YANG mapping needs to be
144 + * generated.
145 + * @return the corresponding inherited node based on the target language.
146 + */
147 + public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
148 + switch (targetLanguage) {
149 + case JAVA_GENERATION: {
150 + return new YangJavaGrouping();
151 + }
152 + default: {
153 + throw new RuntimeException("Only YANG to Java is supported.");
154 + }
155 + }
156 + }
157 +
158 + /**
159 + * Based on the target language generate the inherited data model node.
160 + *
161 + * @param targetLanguage target language in which YANG mapping needs to be
162 + * generated.
163 + * @return the corresponding inherited node based on the target language.
164 + */
165 + public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
166 + switch (targetLanguage) {
167 + case JAVA_GENERATION: {
168 + return new YangJavaList();
169 + }
170 + default: {
171 + throw new RuntimeException("Only YANG to Java is supported.");
172 + }
173 + }
174 + }
175 +
176 + /**
177 + * Based on the target language generate the inherited data model node.
178 + *
179 + * @param targetLanguage target language in which YANG mapping needs to be
180 + * generated.
181 + * @return the corresponding inherited node based on the target language.
182 + */
183 + public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
184 + switch (targetLanguage) {
185 + case JAVA_GENERATION: {
186 + return new YangJavaSubModule();
187 + }
188 + default: {
189 + throw new RuntimeException("Only YANG to Java is supported.");
190 + }
191 + }
192 + }
193 +
194 + /**
195 + * Based on the target language generate the inherited data model node.
196 + *
197 + * @param targetLanguage target language in which YANG mapping needs to be
198 + * generated.
199 + * @return the corresponding inherited node based on the target language.
200 + */
201 + public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
202 + switch (targetLanguage) {
203 + case JAVA_GENERATION: {
204 + return new YangJavaTypeDef();
205 + }
206 + default: {
207 + throw new RuntimeException("Only YANG to Java is supported.");
208 + }
209 + }
210 + }
211 +
212 + /**
213 + * Based on the target language generate the inherited data model node.
214 + *
215 + * @param targetLanguage target language in which YANG mapping needs to be
216 + * generated.
217 + * @return the corresponding inherited node based on the target language.
218 + */
219 + public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
220 + switch (targetLanguage) {
221 + case JAVA_GENERATION: {
222 + return new YangJavaUses();
223 + }
224 + default: {
225 + throw new RuntimeException("Only YANG to Java is supported.");
226 + }
227 + }
228 + }
229 +}
...@@ -24,11 +24,12 @@ import org.onosproject.yangutils.parser.Parsable; ...@@ -24,11 +24,12 @@ import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 import org.onosproject.yangutils.parser.exceptions.ParserException; 25 import org.onosproject.yangutils.parser.exceptions.ParserException;
26 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 26 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 +
27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
28 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA; 34 import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
34 35
...@@ -98,4 +99,4 @@ public final class ConfigListener { ...@@ -98,4 +99,4 @@ public final class ConfigListener {
98 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONFIG_DATA, "", ENTRY)); 99 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONFIG_DATA, "", ENTRY));
99 } 100 }
100 } 101 }
101 -}
...\ No newline at end of file ...\ No newline at end of file
102 +}
......
...@@ -27,7 +27,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -27,7 +27,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
27 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
28 import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; 28 import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
29 29
30 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; 30 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
31 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangContainerNode;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
...@@ -37,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp ...@@ -37,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; 43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
42 import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA; 44 import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA;
...@@ -110,7 +112,7 @@ public final class ContainerListener { ...@@ -110,7 +112,7 @@ public final class ContainerListener {
110 int charPositionInLine = ctx.getStart().getCharPositionInLine(); 112 int charPositionInLine = ctx.getStart().getCharPositionInLine();
111 detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CONTAINER_DATA); 113 detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CONTAINER_DATA);
112 114
113 - YangContainer container = new YangContainer(); 115 + YangContainer container = getYangContainerNode(JAVA_GENERATION);
114 container.setName(identifier); 116 container.setName(identifier);
115 117
116 /* 118 /*
...@@ -123,14 +125,14 @@ public final class ContainerListener { ...@@ -123,14 +125,14 @@ public final class ContainerListener {
123 } 125 }
124 126
125 Parsable curData = listener.getParsedDataStack().peek(); 127 Parsable curData = listener.getParsedDataStack().peek();
126 - if ((curData instanceof YangModule) || (curData instanceof YangContainer) 128 + if (curData instanceof YangModule || curData instanceof YangContainer
127 - || (curData instanceof YangList)) { 129 + || curData instanceof YangList) {
128 YangNode curNode = (YangNode) curData; 130 YangNode curNode = (YangNode) curData;
129 try { 131 try {
130 curNode.addChild(container); 132 curNode.addChild(container);
131 } catch (DataModelException e) { 133 } catch (DataModelException e) {
132 throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, 134 throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
133 - CONTAINER_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); 135 + CONTAINER_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
134 } 136 }
135 listener.getParsedDataStack().push(container); 137 listener.getParsedDataStack().push(container);
136 } else { 138 } else {
...@@ -163,7 +165,7 @@ public final class ContainerListener { ...@@ -163,7 +165,7 @@ public final class ContainerListener {
163 listener.getParsedDataStack().pop(); 165 listener.getParsedDataStack().pop();
164 } else { 166 } else {
165 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA, 167 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA,
166 - ctx.identifier().getText(), EXIT)); 168 + ctx.identifier().getText(), EXIT));
167 } 169 }
168 } 170 }
169 171
......
...@@ -27,7 +27,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -27,7 +27,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
27 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
28 import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; 28 import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
29 29
30 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; 30 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
31 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangListNode;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
...@@ -37,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp ...@@ -37,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; 43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; 44 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero;
...@@ -117,7 +119,7 @@ public final class ListListener { ...@@ -117,7 +119,7 @@ public final class ListListener {
117 int charPositionInLine = ctx.getStart().getCharPositionInLine(); 119 int charPositionInLine = ctx.getStart().getCharPositionInLine();
118 detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LIST_DATA); 120 detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LIST_DATA);
119 121
120 - YangList yangList = new YangList(); 122 + YangList yangList = getYangListNode(JAVA_GENERATION);
121 yangList.setName(identifier); 123 yangList.setName(identifier);
122 124
123 /* 125 /*
...@@ -142,7 +144,7 @@ public final class ListListener { ...@@ -142,7 +144,7 @@ public final class ListListener {
142 listener.getParsedDataStack().push(yangList); 144 listener.getParsedDataStack().push(yangList);
143 } else { 145 } else {
144 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA, 146 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA,
145 - ctx.identifier().getText(), ENTRY)); 147 + ctx.identifier().getText(), ENTRY));
146 } 148 }
147 } 149 }
148 150
...@@ -169,7 +171,7 @@ public final class ListListener { ...@@ -169,7 +171,7 @@ public final class ListListener {
169 listener.getParsedDataStack().pop(); 171 listener.getParsedDataStack().pop();
170 } else { 172 } else {
171 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA, 173 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA,
172 - ctx.identifier().getText(), EXIT)); 174 + ctx.identifier().getText(), EXIT));
173 } 175 }
174 } 176 }
175 177
......
...@@ -21,13 +21,15 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -21,13 +21,15 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
21 import org.onosproject.yangutils.parser.exceptions.ParserException; 21 import org.onosproject.yangutils.parser.exceptions.ParserException;
22 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 22 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
23 23
24 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; 24 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
25 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangModuleNode;
25 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 26 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
26 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA; 35 import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA;
...@@ -76,7 +78,7 @@ public final class ModuleListener { ...@@ -76,7 +78,7 @@ public final class ModuleListener {
76 78
77 String identifier = getValidIdentifier(ctx.identifier().getText(), MODULE_DATA, ctx); 79 String identifier = getValidIdentifier(ctx.identifier().getText(), MODULE_DATA, ctx);
78 80
79 - YangModule yangModule = new YangModule(); 81 + YangModule yangModule = getYangModuleNode(JAVA_GENERATION);
80 yangModule.setName(identifier); 82 yangModule.setName(identifier);
81 83
82 if (ctx.moduleBody().moduleHeaderStatement().yangVersionStatement() == null) { 84 if (ctx.moduleBody().moduleHeaderStatement().yangVersionStatement() == null) {
...@@ -100,7 +102,7 @@ public final class ModuleListener { ...@@ -100,7 +102,7 @@ public final class ModuleListener {
100 102
101 if (!(listener.getParsedDataStack().peek() instanceof YangModule)) { 103 if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
102 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, 104 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
103 - ctx.identifier().getText(), EXIT)); 105 + ctx.identifier().getText(), EXIT));
104 } 106 }
105 } 107 }
106 } 108 }
......
...@@ -21,13 +21,15 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -21,13 +21,15 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
21 import org.onosproject.yangutils.parser.exceptions.ParserException; 21 import org.onosproject.yangutils.parser.exceptions.ParserException;
22 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 22 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
23 23
24 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; 24 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
25 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangSubModuleNode;
25 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 26 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
26 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA; 35 import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA;
...@@ -71,15 +73,15 @@ public final class SubModuleListener { ...@@ -71,15 +73,15 @@ public final class SubModuleListener {
71 * @param ctx context object of the grammar rule 73 * @param ctx context object of the grammar rule
72 */ 74 */
73 public static void processSubModuleEntry(TreeWalkListener listener, 75 public static void processSubModuleEntry(TreeWalkListener listener,
74 - GeneratedYangParser.SubModuleStatementContext ctx) { 76 + GeneratedYangParser.SubModuleStatementContext ctx) {
75 77
76 // Check if stack is empty. 78 // Check if stack is empty.
77 checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), 79 checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
78 - ENTRY); 80 + ENTRY);
79 81
80 String identifier = getValidIdentifier(ctx.identifier().getText(), SUB_MODULE_DATA, ctx); 82 String identifier = getValidIdentifier(ctx.identifier().getText(), SUB_MODULE_DATA, ctx);
81 83
82 - YangSubModule yangSubModule = new YangSubModule(); 84 + YangSubModule yangSubModule = getYangSubModuleNode(JAVA_GENERATION);
83 yangSubModule.setName(identifier); 85 yangSubModule.setName(identifier);
84 86
85 if (ctx.submoduleBody().submoduleHeaderStatement().yangVersionStatement() == null) { 87 if (ctx.submoduleBody().submoduleHeaderStatement().yangVersionStatement() == null) {
...@@ -97,15 +99,15 @@ public final class SubModuleListener { ...@@ -97,15 +99,15 @@ public final class SubModuleListener {
97 * @param ctx context object of the grammar rule 99 * @param ctx context object of the grammar rule
98 */ 100 */
99 public static void processSubModuleExit(TreeWalkListener listener, 101 public static void processSubModuleExit(TreeWalkListener listener,
100 - GeneratedYangParser.SubModuleStatementContext ctx) { 102 + GeneratedYangParser.SubModuleStatementContext ctx) {
101 103
102 // Check for stack to be non empty. 104 // Check for stack to be non empty.
103 checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), 105 checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
104 - EXIT); 106 + EXIT);
105 107
106 if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) { 108 if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
107 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, 109 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
108 - ctx.identifier().getText(), EXIT)); 110 + ctx.identifier().getText(), EXIT));
109 } 111 }
110 } 112 }
111 } 113 }
......
...@@ -31,7 +31,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -31,7 +31,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
31 import org.onosproject.yangutils.parser.exceptions.ParserException; 31 import org.onosproject.yangutils.parser.exceptions.ParserException;
32 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 32 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
33 33
34 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; 34 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
35 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
...@@ -41,6 +42,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp ...@@ -41,6 +42,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; 44 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
45 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
44 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 46 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
45 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne; 47 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
46 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; 48 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
...@@ -121,7 +123,7 @@ public final class TypeDefListener { ...@@ -121,7 +123,7 @@ public final class TypeDefListener {
121 derivedType.setDataType(YangDataTypes.DERIVED); 123 derivedType.setDataType(YangDataTypes.DERIVED);
122 derivedType.setDataTypeName(identifier); 124 derivedType.setDataTypeName(identifier);
123 125
124 - YangTypeDef typeDefNode = new YangTypeDef(); 126 + YangTypeDef typeDefNode = getYangTypeDefNode(JAVA_GENERATION);
125 typeDefNode.setDerivedType(derivedType); 127 typeDefNode.setDerivedType(derivedType);
126 128
127 Parsable curData = listener.getParsedDataStack().peek(); 129 Parsable curData = listener.getParsedDataStack().peek();
......
...@@ -33,13 +33,16 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -33,13 +33,16 @@ import org.onosproject.yangutils.datamodel.YangNode;
33 import org.onosproject.yangutils.parser.YangUtilsParser; 33 import org.onosproject.yangutils.parser.YangUtilsParser;
34 import org.onosproject.yangutils.parser.exceptions.ParserException; 34 import org.onosproject.yangutils.parser.exceptions.ParserException;
35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
36 -import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
37 import org.onosproject.yangutils.utils.UtilConstants; 36 import org.onosproject.yangutils.utils.UtilConstants;
38 -import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
39 import org.onosproject.yangutils.utils.io.impl.YangFileScanner; 37 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
40 -import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
41 import org.sonatype.plexus.build.incremental.BuildContext; 38 import org.sonatype.plexus.build.incremental.BuildContext;
42 39
40 +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
41 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
42 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
43 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
44 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
45 +
43 /** 46 /**
44 * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase 47 * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase
45 * in generate-sources requiresDependencyResolution at compile time. 48 * in generate-sources requiresDependencyResolution at compile time.
...@@ -70,7 +73,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -70,7 +73,7 @@ public class YangUtilManager extends AbstractMojo {
70 * Output directory. 73 * Output directory.
71 */ 74 */
72 @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes") 75 @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes")
73 - private File outputDirectory; 76 + private String outputDirectory;
74 77
75 /** 78 /**
76 * Current maven project. 79 * Current maven project.
...@@ -84,6 +87,9 @@ public class YangUtilManager extends AbstractMojo { ...@@ -84,6 +87,9 @@ public class YangUtilManager extends AbstractMojo {
84 @Component 87 @Component
85 private BuildContext context; 88 private BuildContext context;
86 89
90 + private static final String DEFAULT_PKG = File.separator
91 + + UtilConstants.DEFAULT_BASE_PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
92 +
87 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); 93 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
88 private String searchDir; 94 private String searchDir;
89 private String codeGenDir; 95 private String codeGenDir;
...@@ -94,6 +100,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -94,6 +100,7 @@ public class YangUtilManager extends AbstractMojo {
94 * @param curProject maven project 100 * @param curProject maven project
95 */ 101 */
96 public void setCurrentProject(final MavenProject curProject) { 102 public void setCurrentProject(final MavenProject curProject) {
103 +
97 project = curProject; 104 project = curProject;
98 } 105 }
99 106
...@@ -102,15 +109,14 @@ public class YangUtilManager extends AbstractMojo { ...@@ -102,15 +109,14 @@ public class YangUtilManager extends AbstractMojo {
102 109
103 try { 110 try {
104 111
105 - CopyrightHeader.parseCopyrightHeader();
106 -
107 /** 112 /**
108 * For deleting the generated code in previous build. 113 * For deleting the generated code in previous build.
109 */ 114 */
110 - YangIoUtils.clean(baseDir); 115 + clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
116 + clean(getDirectory(baseDir, outputDirectory));
111 117
112 - searchDir = baseDir + File.separator + yangFilesDir; 118 + searchDir = getDirectory(baseDir, yangFilesDir);
113 - codeGenDir = baseDir + File.separator + genFilesDir + File.separator; 119 + codeGenDir = getDirectory(baseDir, genFilesDir) + File.separator;
114 120
115 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); 121 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
116 Iterator<String> yangFileIterator = yangFiles.iterator(); 122 Iterator<String> yangFileIterator = yangFiles.iterator();
...@@ -118,7 +124,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -118,7 +124,7 @@ public class YangUtilManager extends AbstractMojo {
118 String yangFile = yangFileIterator.next(); 124 String yangFile = yangFileIterator.next();
119 try { 125 try {
120 YangNode yangNode = yangUtilsParser.getDataModel(yangFile); 126 YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
121 - JavaCodeGenerator.generateJavaCode(yangNode, codeGenDir); 127 + generateJavaCode(yangNode, codeGenDir);
122 } catch (ParserException e) { 128 } catch (ParserException e) {
123 String logInfo = "Error in file: " + e.getFileName(); 129 String logInfo = "Error in file: " + e.getFileName();
124 if (e.getLineNumber() != 0) { 130 if (e.getLineNumber() != 0) {
...@@ -127,16 +133,17 @@ public class YangUtilManager extends AbstractMojo { ...@@ -127,16 +133,17 @@ public class YangUtilManager extends AbstractMojo {
127 133
128 } 134 }
129 if (e.getMessage() != null) { 135 if (e.getMessage() != null) {
130 - logInfo = logInfo + "\n" + e.getMessage(); 136 + logInfo = logInfo + UtilConstants.NEW_LINE + e.getMessage();
131 } 137 }
132 getLog().info(logInfo); 138 getLog().info(logInfo);
133 } 139 }
134 } 140 }
135 141
136 - YangIoUtils.addToSource(baseDir + File.separator + UtilConstants.YANG_GEN_DIR, project, context); 142 + addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
143 + copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project);
137 } catch (Exception e) { 144 } catch (Exception e) {
138 getLog().info(e); 145 getLog().info(e);
146 + //throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage());
139 } 147 }
140 } 148 }
141 -
142 -}
...\ No newline at end of file ...\ No newline at end of file
149 +}
......
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;
18 -
19 -import java.io.FileNotFoundException;
20 -import java.io.IOException;
21 -
22 -import org.onosproject.yangutils.datamodel.YangType;
23 -import org.onosproject.yangutils.translator.tojava.utils.TempDataStoreTypes;
24 -
25 -/**
26 - * Cached java file handle, which supports the addition of member attributes and
27 - * methods.
28 - */
29 -public interface CachedFileHandle {
30 -
31 - /**
32 - * Add a new attribute to the file(s).
33 - *
34 - * @param attrType data type of the added attribute
35 - * @param name name of the attribute
36 - * @param isListAttr if the current added attribute needs to be maintained
37 - * in a list
38 - */
39 - void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr);
40 -
41 - /**
42 - * Flushes the cached contents to the target file, frees used resources.
43 - *
44 - * @throws IOException when failes to generated java files
45 - */
46 - void close() throws IOException;
47 -
48 - /**
49 - * Sets directory package path for code generation.
50 - *
51 - * @param filePath directory package path for code generation
52 - */
53 - void setRelativeFilePath(String filePath);
54 -
55 - /**
56 - * Gets directory package path for code generation.
57 - *
58 - * @return directory package path for code generation
59 - */
60 - String getRelativeFilePath();
61 -
62 - /**
63 - * Gets base directory package path for code generation.
64 - *
65 - * @return directory package path for code generation
66 - */
67 - String getCodeGenFilePath();
68 -
69 - /**
70 - * Sets base directory package path for code generation.
71 - *
72 - * @param path base directory path
73 - */
74 - void setCodeGenFilePath(String path);
75 -
76 - /**
77 - * Writes specific info to a Temp file.
78 - *
79 - * @param data data to be stored
80 - * @param type type of Temp data store
81 - * @param className class name
82 - * @param genDir generated directory
83 - * @throws IOException when fails to create a Temp data file
84 - */
85 - void setTempData(String data, TempDataStoreTypes type, String className, String genDir) throws IOException;
86 -
87 - /**
88 - * Get the Temp data.
89 - *
90 - * @param type type of Temp data store
91 - * @param className name of the class
92 - * @param genDir generated directory
93 - * @return temp data
94 - * @throws IOException when fails to read from the file
95 - * @throws ClassNotFoundException when class is missing
96 - * @throws FileNotFoundException when file is missing
97 - */
98 - String getTempData(TempDataStoreTypes type, String className, String genDir)
99 - throws IOException, FileNotFoundException, ClassNotFoundException;
100 -}
...@@ -14,17 +14,17 @@ ...@@ -14,17 +14,17 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.translator; 17 +package org.onosproject.yangutils.translator.tojava;
18 18
19 /** 19 /**
20 * Type of files generated. 20 * Type of files generated.
21 */ 21 */
22 -public final class GeneratedFileType { 22 +public final class GeneratedJavaFileType {
23 23
24 /** 24 /**
25 * prevent creating attributes. 25 * prevent creating attributes.
26 */ 26 */
27 - private GeneratedFileType() { 27 + private GeneratedJavaFileType() {
28 } 28 }
29 29
30 /** 30 /**
......
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 +/**
20 + * Type of files generated.
21 + */
22 +public final class GeneratedTempFileType {
23 +
24 + /**
25 + * prevent creating attributes.
26 + */
27 + private GeneratedTempFileType() {
28 + }
29 +
30 + /**
31 + * attributes definition temporary file.
32 + */
33 + public static final int ATTRIBUTES_MASK = 1;
34 +
35 + /**
36 + * getter methods for interface.
37 + */
38 + public static final int GETTER_FOR_INTERFACE_MASK = 2;
39 +
40 + /**
41 + * getter methods for class.
42 + */
43 + public static final int GETTER_FOR_CLASS_MASK = 4;
44 +
45 + /**
46 + * setter methods for interface.
47 + */
48 + public static final int SETTER_FOR_INTERFACE_MASK = 8;
49 +
50 + /**
51 + * setter methods for class.
52 + */
53 + public static final int SETTER_FOR_CLASS_MASK = 16;
54 +
55 + /**
56 + * constructor method of class.
57 + */
58 + public static final int CONSTRUCTOR_IMPL_MASK = 32;
59 +
60 + /**
61 + * hash code implementation of class.
62 + */
63 + public static final int HASH_CODE_IMPL_MASK = 64;
64 +
65 + /**
66 + * equals implementation of class.
67 + */
68 + public static final int EQUALS_IMPL_MASK = 128;
69 +
70 + /**
71 + * to string implementation of class.
72 + */
73 + public static final int TO_STRING_IMPL_MASK = 256;
74 +}
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 +package org.onosproject.yangutils.translator.tojava;
17 +
18 +/**
19 + * Data model nodes which are required to generate java classes, need to support
20 + * java file info.
21 + */
22 +public interface HasJavaFileInfo {
23 + /**
24 + * Get the generated java file information.
25 + *
26 + * @return generated java file information
27 + */
28 + public JavaFileInfo getJavaFileInfo();
29 +
30 + /**
31 + * Set the java file info object.
32 + *
33 + * @param javaInfo java file info object
34 + */
35 + public void setJavaFileInfo(JavaFileInfo javaInfo);
36 +}
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 +package org.onosproject.yangutils.translator.tojava;
17 +
18 +/**
19 + * Maintains the information of the java import data.
20 + */
21 +public interface HasJavaImportData {
22 + /**
23 + * Get the data of java imports to be included in generated file.
24 + *
25 + * @return data of java imports to be included in generated file
26 + */
27 + public JavaImportData getJavaImportData();
28 +
29 + /**
30 + * Set the data of java imports to be included in generated file.
31 + *
32 + * @param javaImportData data of java imports to be included in generated
33 + * file
34 + */
35 + public void setJavaImportData(JavaImportData javaImportData);
36 +}
...@@ -13,29 +13,23 @@ ...@@ -13,29 +13,23 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 - 16 +package org.onosproject.yangutils.translator.tojava;
17 -package org.onosproject.yangutils.translator;
18 -
19 -import java.io.IOException;
20 17
21 /** 18 /**
22 - * Abstraction of an entity which provides Code generator functionalities. 19 + * Has temporary file handle.
23 */ 20 */
24 -public interface CodeGenerator { 21 +public interface HasTempJavaCodeFragmentFiles {
25 -
26 /** 22 /**
27 - * Traverse the schema of application and generate corresponding code. 23 + * Get the temporary file handle.
28 * 24 *
29 - * @param codeGenDir code generation directory 25 + * @return temporary file handle
30 - * @throws IOException when fails to translate the data model tree
31 */ 26 */
32 - void generateJavaCodeEntry(String codeGenDir) throws IOException; 27 + TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles();
33 28
34 /** 29 /**
35 - * Traverse the schema of application and generate corresponding code. 30 + * Set temporary file handle.
36 * 31 *
37 - * @throws IOException when fails to generate java code 32 + * @param fileHandle temporary file handle
38 */ 33 */
39 - void generateJavaCodeExit() throws IOException; 34 + void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle);
40 -
41 } 35 }
......
...@@ -16,12 +16,18 @@ ...@@ -16,12 +16,18 @@
16 16
17 package org.onosproject.yangutils.translator.tojava; 17 package org.onosproject.yangutils.translator.tojava;
18 18
19 +import org.onosproject.yangutils.datamodel.YangNode;
19 import org.onosproject.yangutils.datamodel.YangType; 20 import org.onosproject.yangutils.datamodel.YangType;
20 21
22 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
23 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
24 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfLeafAttribute;
25 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
26 +
21 /** 27 /**
22 * Maintains the attribute info corresponding to class/interface generated. 28 * Maintains the attribute info corresponding to class/interface generated.
23 */ 29 */
24 -public class AttributeInfo { 30 +public final class JavaAttributeInfo {
25 31
26 /** 32 /**
27 * The data type info of attribute. 33 * The data type info of attribute.
...@@ -47,12 +53,12 @@ public class AttributeInfo { ...@@ -47,12 +53,12 @@ public class AttributeInfo {
47 * The class info will be used to set the attribute type and package info 53 * The class info will be used to set the attribute type and package info
48 * will be use for qualified name. 54 * will be use for qualified name.
49 */ 55 */
50 - private ImportInfo importInfo; 56 + private JavaQualifiedTypeInfo importInfo;
51 57
52 /** 58 /**
53 * Default constructor. 59 * Default constructor.
54 */ 60 */
55 - public AttributeInfo() { 61 + private JavaAttributeInfo() {
56 } 62 }
57 63
58 /** 64 /**
...@@ -61,6 +67,10 @@ public class AttributeInfo { ...@@ -61,6 +67,10 @@ public class AttributeInfo {
61 * @return the data type info of attribute 67 * @return the data type info of attribute
62 */ 68 */
63 public YangType<?> getAttributeType() { 69 public YangType<?> getAttributeType() {
70 +
71 + if (attrType == null) {
72 + throw new RuntimeException("Expected java attribute type is null");
73 + }
64 return attrType; 74 return attrType;
65 } 75 }
66 76
...@@ -80,6 +90,10 @@ public class AttributeInfo { ...@@ -80,6 +90,10 @@ public class AttributeInfo {
80 * @return name of the attribute 90 * @return name of the attribute
81 */ 91 */
82 public String getAttributeName() { 92 public String getAttributeName() {
93 +
94 + if (name == null) {
95 + throw new RuntimeException("Expected java attribute name is null");
96 + }
83 return name; 97 return name;
84 } 98 }
85 99
...@@ -89,6 +103,7 @@ public class AttributeInfo { ...@@ -89,6 +103,7 @@ public class AttributeInfo {
89 * @param attrName name of the attribute 103 * @param attrName name of the attribute
90 */ 104 */
91 public void setAttributeName(String attrName) { 105 public void setAttributeName(String attrName) {
106 +
92 name = attrName; 107 name = attrName;
93 } 108 }
94 109
...@@ -98,6 +113,7 @@ public class AttributeInfo { ...@@ -98,6 +113,7 @@ public class AttributeInfo {
98 * @return the if the added attribute is a list of info 113 * @return the if the added attribute is a list of info
99 */ 114 */
100 public boolean isListAttr() { 115 public boolean isListAttr() {
116 +
101 return isListAttr; 117 return isListAttr;
102 } 118 }
103 119
...@@ -107,6 +123,7 @@ public class AttributeInfo { ...@@ -107,6 +123,7 @@ public class AttributeInfo {
107 * @param isList if the added attribute is a list of info 123 * @param isList if the added attribute is a list of info
108 */ 124 */
109 public void setListAttr(boolean isList) { 125 public void setListAttr(boolean isList) {
126 +
110 isListAttr = isList; 127 isListAttr = isList;
111 } 128 }
112 129
...@@ -118,6 +135,7 @@ public class AttributeInfo { ...@@ -118,6 +135,7 @@ public class AttributeInfo {
118 * qualified manner. 135 * qualified manner.
119 */ 136 */
120 public boolean isQualifiedName() { 137 public boolean isQualifiedName() {
138 +
121 return isQualifiedName; 139 return isQualifiedName;
122 } 140 }
123 141
...@@ -128,7 +146,8 @@ public class AttributeInfo { ...@@ -128,7 +146,8 @@ public class AttributeInfo {
128 * @param isQualified if the added attribute has to be accessed in a fully 146 * @param isQualified if the added attribute has to be accessed in a fully
129 * qualified manner 147 * qualified manner
130 */ 148 */
131 - public void setQualifiedName(boolean isQualified) { 149 + public void setIsQualifiedAccess(boolean isQualified) {
150 +
132 isQualifiedName = isQualified; 151 isQualifiedName = isQualified;
133 } 152 }
134 153
...@@ -138,7 +157,8 @@ public class AttributeInfo { ...@@ -138,7 +157,8 @@ public class AttributeInfo {
138 * 157 *
139 * @return import info 158 * @return import info
140 */ 159 */
141 - public ImportInfo getImportInfo() { 160 + public JavaQualifiedTypeInfo getImportInfo() {
161 +
142 return importInfo; 162 return importInfo;
143 } 163 }
144 164
...@@ -147,8 +167,83 @@ public class AttributeInfo { ...@@ -147,8 +167,83 @@ public class AttributeInfo {
147 * 167 *
148 * @param importInfo import info for the attribute type 168 * @param importInfo import info for the attribute type
149 */ 169 */
150 - public void setImportInfo(ImportInfo importInfo) { 170 + public void setImportInfo(JavaQualifiedTypeInfo importInfo) {
171 +
151 this.importInfo = importInfo; 172 this.importInfo = importInfo;
152 } 173 }
153 174
175 + /**
176 + * Create an attribute info object corresponding to the passed leaf
177 + * information and return it.
178 + *
179 + * @param curNode current data model node for which the java file is being
180 + * generated
181 + * @param attributeType leaf data type
182 + * @param attributeName leaf name
183 + * @param isListAttribute is the current added attribute needs to be a list
184 + * @return AttributeInfo attribute details required to add in temporary
185 + * files
186 + */
187 + public static JavaAttributeInfo getAttributeInfoOfLeaf(YangNode curNode,
188 + YangType<?> attributeType, String attributeName,
189 + boolean isListAttribute) {
190 +
191 + JavaAttributeInfo newAttr = new JavaAttributeInfo();
192 +
193 + /*
194 + * Get the import info corresponding to the attribute for import in
195 + * generated java files or qualified access
196 + */
197 + JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
198 + attributeType, attributeName, isListAttribute);
199 + newAttr.setImportInfo(importInfo);
200 + newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(
201 + curNode, importInfo));
202 + newAttr.setAttributeName(getCamelCase(attributeName));
203 + newAttr.setListAttr(isListAttribute);
204 + newAttr.setImportInfo(importInfo);
205 + newAttr.setAttributeType(attributeType);
206 +
207 + return newAttr;
208 + }
209 +
210 + /**
211 + * Create an attribute info object corresponding to a data model node and
212 + * return it.
213 + *
214 + * @param curNode current data model node for which the java code generation
215 + * is being handled
216 + * @param parentNode parent node in which the current node is an attribute
217 + * @param isListNode is the current added attribute needs to be a list
218 + * @return AttributeInfo attribute details required to add in temporary
219 + * files
220 + */
221 + public static JavaAttributeInfo getCurNodeAsAttributeInParent(
222 + YangNode curNode, YangNode parentNode, boolean isListNode) {
223 +
224 + JavaAttributeInfo newAttr = new JavaAttributeInfo();
225 +
226 + // if (curNode instanceof HasJavaFileInfo) {
227 + // throw new RuntimeException("translator data model node does not have java info");
228 + // }
229 +
230 + String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName();
231 +
232 + /*
233 + * Get the import info corresponding to the attribute for import in
234 + * generated java files or qualified access
235 + */
236 + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
237 + curNodeName, isListNode);
238 + newAttr.setImportInfo(qualifiedTypeInfo);
239 + newAttr.setIsQualifiedAccess(
240 + getIsQualifiedAccessOrAddToImportList(parentNode,
241 + qualifiedTypeInfo));
242 + newAttr.setAttributeName(getCamelCase(curNodeName));
243 + newAttr.setListAttr(isListNode);
244 + newAttr.setImportInfo(qualifiedTypeInfo);
245 + newAttr.setAttributeType(null);
246 +
247 + return newAttr;
248 + }
154 } 249 }
......
...@@ -18,46 +18,24 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -18,46 +18,24 @@ package org.onosproject.yangutils.translator.tojava;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 20
21 -import org.onosproject.yangutils.datamodel.YangNode;
22 -
23 /** 21 /**
24 - * Implementation of Java code generator based on application schema. 22 + * Abstraction of an entity which provides Code generator functionalities.
25 */ 23 */
26 -public final class JavaCodeGenerator { 24 +public interface JavaCodeGenerator {
27 25
28 /** 26 /**
29 - * Default constructor. 27 + * Traverse the schema of application and generate corresponding code.
28 + *
29 + * @param codeGenDir code generation directory
30 + * @throws IOException when fails to translate the data model tree
30 */ 31 */
31 - private JavaCodeGenerator() { 32 + void generateCodeEntry(String codeGenDir) throws IOException;
32 - }
33 33
34 /** 34 /**
35 - * Generate Java code files corresponding to the YANG schema. 35 + * Traverse the schema of application and generate corresponding code.
36 * 36 *
37 - * @param rootNode root node of the data model tree 37 + * @throws IOException when fails to generate java code
38 - * @param codeGenDir code generation directory
39 - * @throws IOException when fails to generate java code file the current node
40 */ 38 */
41 - public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException { 39 + void generateCodeExit() throws IOException;
42 - YangNode curNode = rootNode;
43 - TraversalType curTraversal = TraversalType.ROOT;
44 40
45 - while (!(curNode == null)) {
46 - if (curTraversal != TraversalType.PARENT) {
47 - curNode.generateJavaCodeEntry(codeGenDir);
48 - }
49 - if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
50 - curTraversal = TraversalType.CHILD;
51 - curNode = curNode.getChild();
52 - } else if (curNode.getNextSibling() != null) {
53 - curNode.generateJavaCodeExit();
54 - curTraversal = TraversalType.SIBILING;
55 - curNode = curNode.getNextSibling();
56 - } else {
57 - curNode.generateJavaCodeExit();
58 - curTraversal = TraversalType.PARENT;
59 - curNode = curNode.getParent();
60 - }
61 - }
62 - }
63 } 41 }
......
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.IOException;
20 +
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +
23 +/**
24 + * Implementation of Java code generator based on application schema.
25 + */
26 +public final class JavaCodeGeneratorUtil {
27 +
28 + /**
29 + * Default constructor.
30 + */
31 + private JavaCodeGeneratorUtil() {
32 + }
33 +
34 + /**
35 + * Generate Java code files corresponding to the YANG schema.
36 + *
37 + * @param rootNode root node of the data model tree
38 + * @param codeGenDir code generation directory
39 + * @throws IOException when fails to generate java code file the current
40 + * node
41 + */
42 + public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
43 + YangNode curNode = rootNode;
44 + TraversalType curTraversal = TraversalType.ROOT;
45 +
46 + while (!(curNode == null)) {
47 + if (curTraversal != TraversalType.PARENT) {
48 + generateCodeEntry(curNode, codeGenDir);
49 + }
50 + if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
51 + curTraversal = TraversalType.CHILD;
52 + curNode = curNode.getChild();
53 + } else if (curNode.getNextSibling() != null) {
54 + generateCodeExit(curNode);
55 + curTraversal = TraversalType.SIBILING;
56 + curNode = curNode.getNextSibling();
57 + } else {
58 + generateCodeExit(curNode);
59 + curTraversal = TraversalType.PARENT;
60 + curNode = curNode.getParent();
61 + }
62 + }
63 + }
64 +
65 + /**
66 + * Generates the current nodes code snippet.
67 + *
68 + * @param curNode current data model node for which the code needs to be
69 + * generated
70 + * @param codeGenDir the base directory where the code needs to be generated
71 + * @throws IOException IO operation exception
72 + */
73 + private static void generateCodeEntry(YangNode curNode,
74 + String codeGenDir) throws IOException {
75 +
76 + if (curNode instanceof JavaCodeGenerator) {
77 + ((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir);
78 + } else {
79 + throw new RuntimeException(
80 + "Gnenerated data model node cannot be translated to target language code");
81 + }
82 + }
83 +
84 + /**
85 + * Generates the current nodes code target code from the snippet.
86 + *
87 + * @param curNode current data model node for which the code needs to be
88 + * generated
89 + * @throws IOException IO operation exception
90 + */
91 + private static void generateCodeExit(YangNode curNode) throws IOException {
92 +
93 + if (curNode instanceof JavaCodeGenerator) {
94 + ((JavaCodeGenerator) curNode).generateCodeExit();
95 + } else {
96 + throw new RuntimeException(
97 + "Gnenerated data model node cannot be translated to target language code");
98 + }
99 + }
100 +}
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 +/**
20 + * Cached java file handle, which supports the addition of member attributes and
21 + * methods.
22 + */
23 +public class JavaFileInfo {
24 + /**
25 + * The type(s) of java source file(s) to be generated when the cached file
26 + * handle is closed.
27 + */
28 + private int genFileTypes;
29 +
30 + /**
31 + * Name of the module.
32 + */
33 + private String javaName;
34 +
35 + /**
36 + * java Package of the mapped java class.
37 + */
38 + private String pkg;
39 +
40 + /**
41 + * File generation directory path.
42 + */
43 + private String relativeFilePath;
44 +
45 + /**
46 + * File generation base directory path.
47 + */
48 + private String codeGenDirFilePath;
49 +
50 + /**
51 + * Get the types of files being generated corresponding to the YANG
52 + * definition.
53 + *
54 + * @return the types of files being generated corresponding to the YANG
55 + * definition
56 + */
57 + public int getGeneratedFileTypes() {
58 + return genFileTypes;
59 + }
60 +
61 + /**
62 + * Set the types of files being generated corresponding to the YANG
63 + * definition.
64 + *
65 + * @param fileTypes the types of files being generated corresponding to the
66 + * YANG definition
67 + */
68 + public void setGeneratedFileTypes(int fileTypes) {
69 + genFileTypes = fileTypes;
70 + }
71 +
72 + /**
73 + * Get the java name of the node.
74 + *
75 + * @return the java name of node
76 + */
77 + public String getJavaName() {
78 + return javaName;
79 + }
80 +
81 + /**
82 + * Set the java name of the node.
83 + *
84 + * @param name the java name of node
85 + */
86 + public void setJavaName(String name) {
87 + javaName = name;
88 + }
89 +
90 + /**
91 + * Get the mapped java package.
92 + *
93 + * @return the java package
94 + */
95 + public String getPackage() {
96 + if (pkg == null) {
97 + throw new RuntimeException("Referencing package of a generated java file which is not set");
98 + }
99 + return pkg;
100 + }
101 +
102 + /**
103 + * Set the node's package.
104 + *
105 + * @param nodePackage node's package
106 + */
107 + public void setPackage(String nodePackage) {
108 + pkg = nodePackage;
109 + }
110 +
111 + /**
112 + * Sets directory package path for code generation.
113 + *
114 + * @param path directory package path for code generation
115 + */
116 + public void setPackageFilePath(String path) {
117 + relativeFilePath = path;
118 + }
119 +
120 + /**
121 + * Gets directory package path for code generation.
122 + *
123 + * @return directory package path for code generation
124 + */
125 + public String getPackageFilePath() {
126 + return relativeFilePath;
127 + }
128 +
129 + /**
130 + * Gets base directory package path for code generation.
131 + *
132 + * @return directory package path for code generation
133 + */
134 + public String getBaseCodeGenPath() {
135 + return codeGenDirFilePath;
136 + }
137 +
138 + /**
139 + * Sets base directory package path for code generation.
140 + *
141 + * @param path base directory path
142 + */
143 + public void setBaseCodeGenPath(String path) {
144 + codeGenDirFilePath = path;
145 + }
146 +}
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 +package org.onosproject.yangutils.translator.tojava;
17 +
18 +import java.util.SortedSet;
19 +import java.util.TreeSet;
20 +
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +
23 +/**
24 + * Generated Java file can contain imports.
25 + */
26 +public class JavaImportData {
27 +
28 + /**
29 + * Flag to denote if any list in imported.
30 + */
31 + private boolean isListToImport;
32 +
33 + /**
34 + * Sorted set of import info, to be used to maintain the set of classes to
35 + * be imported in the generated class.
36 + */
37 + private SortedSet<JavaQualifiedTypeInfo> importSet;
38 +
39 + /**
40 + * Default constructor.
41 + */
42 + public JavaImportData() {
43 + setImportSet(new TreeSet<JavaQualifiedTypeInfo>());
44 + }
45 +
46 + /**
47 + * Get if the list needs to be imported.
48 + *
49 + * @return true if any of the attribute needs to be maintained as a list.
50 + */
51 + public boolean getIfListImported() {
52 + return isListToImport;
53 + }
54 +
55 + /**
56 + * Set the status of importing list.
57 + *
58 + * @param isList status to mention list is bing imported.
59 + */
60 + public void setIfListImported(boolean isList) {
61 + isListToImport = isList;
62 + }
63 +
64 + /**
65 + * Get the set containing the imported class/interface info.
66 + *
67 + * @return the set containing the imported class/interface info
68 + */
69 + public SortedSet<JavaQualifiedTypeInfo> getImportSet() {
70 + return importSet;
71 + }
72 +
73 + /**
74 + * Assign the set containing the imported class/interface info.
75 + *
76 + * @param importSet the set containing the imported class/interface info
77 + */
78 + private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) {
79 + this.importSet = importSet;
80 + }
81 +
82 + /**
83 + * Add an imported class/interface info if it is not already part of the
84 + * collection.
85 + *
86 + * If already part of the collection, check if the packages are same, if so
87 + * then return true, to denote it is already in the import collection, and
88 + * it can be accessed without qualified access. If the packages do not
89 + * match, then do not add to the import collection, and return false to
90 + * denote, it is not added to import collection and needs to be accessed in
91 + * a qualified manner.
92 + *
93 + * @param curNode current data model node
94 + * @param newImportInfo class/interface info being imported
95 + * @return status of new addition of class/interface to the import set
96 + */
97 + public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) {
98 + if (!(curNode instanceof HasJavaImportData)) {
99 + throw new RuntimeException("missing import info in data model node");
100 + }
101 + for (JavaQualifiedTypeInfo curImportInfo : ((HasJavaImportData) curNode).getJavaImportData().getImportSet()) {
102 + if (curImportInfo.getClassInfo()
103 + .contentEquals(newImportInfo.getClassInfo())) {
104 + return curImportInfo.getPkgInfo()
105 + .contentEquals(newImportInfo.getPkgInfo());
106 + }
107 + }
108 + ((HasJavaImportData) curNode).getJavaImportData().getImportSet().add(newImportInfo);
109 + return true;
110 + }
111 +}
...@@ -18,12 +18,16 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -18,12 +18,16 @@ package org.onosproject.yangutils.translator.tojava;
18 18
19 import java.util.Objects; 19 import java.util.Objects;
20 20
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +import org.onosproject.yangutils.datamodel.YangType;
23 +import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
24 +
21 import com.google.common.base.MoreObjects; 25 import com.google.common.base.MoreObjects;
22 26
23 /** 27 /**
24 * Maintains the information about individual imports in the generated file. 28 * Maintains the information about individual imports in the generated file.
25 */ 29 */
26 -public class ImportInfo implements Comparable { 30 +public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> {
27 31
28 /** 32 /**
29 * Package location where the imported class/interface is defined. 33 * Package location where the imported class/interface is defined.
...@@ -38,7 +42,7 @@ public class ImportInfo implements Comparable { ...@@ -38,7 +42,7 @@ public class ImportInfo implements Comparable {
38 /** 42 /**
39 * Default constructor. 43 * Default constructor.
40 */ 44 */
41 - public ImportInfo() { 45 + public JavaQualifiedTypeInfo() {
42 } 46 }
43 47
44 /** 48 /**
...@@ -47,6 +51,7 @@ public class ImportInfo implements Comparable { ...@@ -47,6 +51,7 @@ public class ImportInfo implements Comparable {
47 * @return the imported package info 51 * @return the imported package info
48 */ 52 */
49 public String getPkgInfo() { 53 public String getPkgInfo() {
54 +
50 return pkgInfo; 55 return pkgInfo;
51 } 56 }
52 57
...@@ -56,6 +61,7 @@ public class ImportInfo implements Comparable { ...@@ -56,6 +61,7 @@ public class ImportInfo implements Comparable {
56 * @param pkgInfo the imported package info 61 * @param pkgInfo the imported package info
57 */ 62 */
58 public void setPkgInfo(String pkgInfo) { 63 public void setPkgInfo(String pkgInfo) {
64 +
59 this.pkgInfo = pkgInfo; 65 this.pkgInfo = pkgInfo;
60 } 66 }
61 67
...@@ -65,6 +71,7 @@ public class ImportInfo implements Comparable { ...@@ -65,6 +71,7 @@ public class ImportInfo implements Comparable {
65 * @return the imported class/interface info 71 * @return the imported class/interface info
66 */ 72 */
67 public String getClassInfo() { 73 public String getClassInfo() {
74 +
68 return classInfo; 75 return classInfo;
69 } 76 }
70 77
...@@ -74,21 +81,187 @@ public class ImportInfo implements Comparable { ...@@ -74,21 +81,187 @@ public class ImportInfo implements Comparable {
74 * @param classInfo the imported class/interface info 81 * @param classInfo the imported class/interface info
75 */ 82 */
76 public void setClassInfo(String classInfo) { 83 public void setClassInfo(String classInfo) {
84 +
77 this.classInfo = classInfo; 85 this.classInfo = classInfo;
78 } 86 }
79 87
88 + /**
89 + * Get the import info for an attribute, which needs to be used for code
90 + * generation for import or for qualified access.
91 + *
92 + * @param curNode current data model node for which the java file is being
93 + * generated.
94 + * @param attrType type of attribute being added, it will be null, when the
95 + * child class is added as an attribute
96 + * @param attributeName name of the attribute being added, it will used in
97 + * import info for child class.
98 + * @param isListAttr is the added attribute going to be used as a list
99 + * @return return the import info for this attribute
100 + */
101 + public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfLeafAttribute(YangNode curNode,
102 + YangType<?> attrType, String attributeName,
103 + boolean isListAttr) {
104 +
105 + JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
106 +
107 + if (attrType == null) {
108 + throw new RuntimeException("missing data type of leaf " + attributeName);
109 + }
110 +
111 + /*
112 + * Current leaves holder is adding a leaf info as a attribute to the
113 + * current class.
114 + */
115 + String className = AttributesJavaDataType.getJavaImportClass(attrType, isListAttr);
116 + if (className != null) {
117 + /*
118 + * Corresponding to the attribute type a class needs to be imported,
119 + * since it can be a derived type or a usage of wrapper classes.
120 + */
121 + importInfo.setClassInfo(className);
122 + String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className);
123 + if (classPkg == null) {
124 + throw new RuntimeException("import package cannot be null when the class is used");
125 + }
126 + importInfo.setPkgInfo(classPkg);
127 + } else {
128 + /*
129 + * The attribute does not need a class to be imported, for example
130 + * built in java types.
131 + */
132 + String dataTypeName = AttributesJavaDataType.getJavaDataType(attrType);
133 + if (dataTypeName == null) {
134 + throw new RuntimeException("not supported data type");
135 + }
136 + importInfo.setClassInfo(dataTypeName);
137 + }
138 + return importInfo;
139 + }
140 +
141 + /**
142 + * Get the import info for an attribute, which needs to be used for code
143 + * generation for import or for qualified access.
144 + *
145 + * @param curNode current data model node for which the java file is being
146 + * generated.
147 + * @param attributeName name of the attribute being added, it will used in
148 + * import info for child class.
149 + * @param isListAttr is the added attribute going to be used as a list
150 + * @return return the import info for this attribute
151 + */
152 + public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode,
153 + String attributeName, boolean isListAttr) {
154 +
155 + JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
156 +
157 + if (!(curNode instanceof HasJavaFileInfo)) {
158 + throw new RuntimeException("missing java file information to get the package details "
159 + + "of attribute corresponding to child node");
160 + }
161 + /*
162 + * The scenario when we need to add the child class as an attribute in
163 + * the current class. The child class is in the package of the current
164 + * classes package with current classes name.
165 + */
166 + importInfo.setClassInfo(attributeName);
167 + importInfo.setPkgInfo((((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage() + "."
168 + + ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName()).toLowerCase());
169 +
170 + return importInfo;
171 + }
172 +
173 + /**
174 + * Get if the attribute needs to be accessed in a qualified manner or not,
175 + * if it needs to be imported, then the same needs to be done.
176 + *
177 + * @param curNode current cache of the data model node for which java file
178 + * is bing generated
179 + * @param importInfo import info for the current attribute being added
180 + * @return status of the qualified access to the attribute
181 + */
182 + public static boolean getIsQualifiedAccessOrAddToImportList(YangNode curNode,
183 + JavaQualifiedTypeInfo importInfo) {
184 +
185 + boolean isImportPkgEqualCurNodePkg;
186 + if (!(curNode instanceof HasJavaFileInfo)) {
187 + throw new RuntimeException("missing java file info for getting the qualified access");
188 + }
189 + if (importInfo.getClassInfo().contentEquals(
190 + ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName())) {
191 + /*
192 + * if the current class name is same as the attribute class name,
193 + * then the attribute must be accessed in a qualified manner.
194 + */
195 + return true;
196 + } else if (importInfo.getPkgInfo() != null) {
197 + /*
198 + * If the attribute type is having the package info, it is contender
199 + * for import list and also need to check if it needs to be a
200 + * qualified access.
201 + */
202 + isImportPkgEqualCurNodePkg = isImportPkgEqualCurNodePkg(curNode, importInfo);
203 + if (!isImportPkgEqualCurNodePkg) {
204 + /*
205 + * If the package of the attribute added is not same as the
206 + * current class package, then it must either be imported for
207 + * access or it must be a qualified access.
208 + */
209 + if (!(curNode instanceof HasJavaImportData)) {
210 + /*
211 + * If the current data model node is not supposed to import
212 + * data, then this is a usage issue and needs to be fixed.
213 + */
214 + throw new RuntimeException("Current node needs to support Imports");
215 + }
216 +
217 + boolean isImportAdded = ((HasJavaImportData) curNode).getJavaImportData()
218 + .addImportInfo(curNode, importInfo);
219 + if (!isImportAdded) {
220 + /*
221 + * If the attribute type info is not imported, then it must
222 + * be a qualified access.
223 + */
224 + return true;
225 + }
226 + }
227 + }
228 + return false;
229 + }
230 +
231 + /**
232 + * Check if the import info is same as the package of the current generated
233 + * java file.
234 + *
235 + * @param curNode Java identifier of the current data model node
236 + * @param importInfo import info for an attribute
237 + * @return true if the import info is same as the current nodes package
238 + * false otherwise
239 + */
240 + public static boolean isImportPkgEqualCurNodePkg(
241 + YangNode curNode, JavaQualifiedTypeInfo importInfo) {
242 +
243 + if (!(curNode instanceof HasJavaFileInfo)) {
244 + throw new RuntimeException("missing java file info for the data model node");
245 + }
246 + return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage()
247 + .contentEquals(importInfo.getPkgInfo()
248 + + "." + importInfo.getClassInfo());
249 + }
250 +
80 @Override 251 @Override
81 public int hashCode() { 252 public int hashCode() {
253 +
82 return Objects.hash(pkgInfo, classInfo); 254 return Objects.hash(pkgInfo, classInfo);
83 } 255 }
84 256
85 @Override 257 @Override
86 public boolean equals(Object obj) { 258 public boolean equals(Object obj) {
259 +
87 if (this == obj) { 260 if (this == obj) {
88 return true; 261 return true;
89 } 262 }
90 - if (obj instanceof ImportInfo) { 263 + if (obj instanceof JavaQualifiedTypeInfo) {
91 - ImportInfo other = (ImportInfo) obj; 264 + JavaQualifiedTypeInfo other = (JavaQualifiedTypeInfo) obj;
92 return Objects.equals(pkgInfo, other.pkgInfo) && 265 return Objects.equals(pkgInfo, other.pkgInfo) &&
93 Objects.equals(classInfo, other.classInfo); 266 Objects.equals(classInfo, other.classInfo);
94 } 267 }
...@@ -101,7 +274,8 @@ public class ImportInfo implements Comparable { ...@@ -101,7 +274,8 @@ public class ImportInfo implements Comparable {
101 * @param importInfo matched import 274 * @param importInfo matched import
102 * @return if equal or not 275 * @return if equal or not
103 */ 276 */
104 - public boolean exactMatch(ImportInfo importInfo) { 277 + public boolean exactMatch(JavaQualifiedTypeInfo importInfo) {
278 +
105 return equals(importInfo) 279 return equals(importInfo)
106 && Objects.equals(pkgInfo, importInfo.getPkgInfo()) 280 && Objects.equals(pkgInfo, importInfo.getPkgInfo())
107 && Objects.equals(classInfo, importInfo.getClassInfo()); 281 && Objects.equals(classInfo, importInfo.getClassInfo());
...@@ -109,6 +283,7 @@ public class ImportInfo implements Comparable { ...@@ -109,6 +283,7 @@ public class ImportInfo implements Comparable {
109 283
110 @Override 284 @Override
111 public String toString() { 285 public String toString() {
286 +
112 return MoreObjects.toStringHelper(getClass()) 287 return MoreObjects.toStringHelper(getClass())
113 .add("pkgInfo", pkgInfo) 288 .add("pkgInfo", pkgInfo)
114 .add("classInfo", classInfo).toString(); 289 .add("classInfo", classInfo).toString();
...@@ -117,16 +292,11 @@ public class ImportInfo implements Comparable { ...@@ -117,16 +292,11 @@ public class ImportInfo implements Comparable {
117 /** 292 /**
118 * Check that there is no 2 objects with the same class name. 293 * Check that there is no 2 objects with the same class name.
119 * 294 *
120 - * @param o compared import info. 295 + * @param other compared import info.
121 */ 296 */
122 @Override 297 @Override
123 - public int compareTo(Object o) { 298 + public int compareTo(JavaQualifiedTypeInfo other) {
124 - ImportInfo other; 299 +
125 - if (o instanceof ImportInfo) {
126 - other = (ImportInfo) o;
127 - } else {
128 - return -1;
129 - }
130 return getClassInfo().compareTo(other.getClassInfo()); 300 return getClassInfo().compareTo(other.getClassInfo());
131 } 301 }
132 302
......
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangAugment;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
35 +
36 +/**
37 + * Augment information extended to support java code generation.
38 + */
39 +public class YangJavaAugment extends YangAugment
40 + implements JavaCodeGenerator, HasJavaFileInfo,
41 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
42 +
43 + /**
44 + * Contains the information of the java file being generated.
45 + */
46 + private JavaFileInfo javaFileInfo;
47 +
48 + /**
49 + * Contains information of the imports to be inserted in the java file
50 + * generated.
51 + */
52 + private JavaImportData javaImportData;
53 +
54 + /**
55 + * File handle to maintain temporary java code fragments as per the code
56 + * snippet types.
57 + */
58 + private TempJavaCodeFragmentFiles tempFileHandle;
59 +
60 + /**
61 + * Default constructor.
62 + */
63 + public YangJavaAugment() {
64 + super();
65 + setJavaFileInfo(new JavaFileInfo());
66 + setJavaImportData(new JavaImportData());
67 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
68 + }
69 +
70 + /**
71 + * Get the generated java file information.
72 + *
73 + * @return generated java file information
74 + */
75 + @Override
76 + public JavaFileInfo getJavaFileInfo() {
77 +
78 + if (javaFileInfo == null) {
79 + throw new RuntimeException("Missing java info in java datamodel node");
80 + }
81 + return javaFileInfo;
82 + }
83 +
84 + /**
85 + * Set the java file info object.
86 + *
87 + * @param javaInfo java file info object
88 + */
89 + @Override
90 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
91 +
92 + javaFileInfo = javaInfo;
93 + }
94 +
95 + /**
96 + * Get the data of java imports to be included in generated file.
97 + *
98 + * @return data of java imports to be included in generated file
99 + */
100 + @Override
101 + public JavaImportData getJavaImportData() {
102 +
103 + return javaImportData;
104 + }
105 +
106 + /**
107 + * Set the data of java imports to be included in generated file.
108 + *
109 + * @param javaImportData data of java imports to be included in generated
110 + * file
111 + */
112 + @Override
113 + public void setJavaImportData(JavaImportData javaImportData) {
114 +
115 + this.javaImportData = javaImportData;
116 + }
117 +
118 + /**
119 + * Get the temporary file handle.
120 + *
121 + * @return temporary file handle
122 + */
123 + @Override
124 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
125 +
126 + if (tempFileHandle == null) {
127 + throw new RuntimeException("missing temp file hand for current node "
128 + + getJavaFileInfo().getJavaName());
129 + }
130 + return tempFileHandle;
131 + }
132 +
133 + /**
134 + * Set temporary file handle.
135 + *
136 + * @param fileHandle temporary file handle
137 + */
138 + @Override
139 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
140 +
141 + tempFileHandle = fileHandle;
142 + }
143 +
144 + /**
145 + * Prepare the information for java code generation corresponding to YANG
146 + * augment info.
147 + *
148 + * @param codeGenDir code generation directory
149 + * @throws IOException IO operation fail
150 + */
151 + @Override
152 + public void generateCodeEntry(String codeGenDir) throws IOException {
153 +
154 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
155 + getJavaFileInfo().setPackage(getCurNodePackage(this));
156 + getJavaFileInfo().setPackageFilePath(
157 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
158 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
159 +
160 + String absloutePath = getAbsolutePackagePath(
161 + getJavaFileInfo().getBaseCodeGenPath(),
162 + getJavaFileInfo().getPackageFilePath());
163 +
164 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
165 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
166 + getJavaFileInfo().getJavaName()));
167 +
168 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
171 + }
172 +
173 + /**
174 + * Create a java file using the YANG grouping info.
175 + */
176 + @Override
177 + public void generateCodeExit() {
178 + // TODO Auto-generated method stub
179 +
180 + }
181 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangCase;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
35 +
36 +/**
37 + * Case information extended to support java code generation.
38 + */
39 +public class YangJavaCase extends YangCase
40 + implements JavaCodeGenerator, HasJavaFileInfo,
41 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
42 +
43 + /**
44 + * Contains the information of the java file being generated.
45 + */
46 + private JavaFileInfo javaFileInfo;
47 +
48 + /**
49 + * Contains information of the imports to be inserted in the java file
50 + * generated.
51 + */
52 + private JavaImportData javaImportData;
53 +
54 + /**
55 + * File handle to maintain temporary java code fragments as per the code
56 + * snippet types.
57 + */
58 + private TempJavaCodeFragmentFiles tempFileHandle;
59 +
60 + /**
61 + * Default constructor.
62 + */
63 + public YangJavaCase() {
64 + super();
65 + setJavaFileInfo(new JavaFileInfo());
66 + setJavaImportData(new JavaImportData());
67 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
68 + }
69 +
70 + /**
71 + * Get the generated java file information.
72 + *
73 + * @return generated java file information
74 + */
75 + @Override
76 + public JavaFileInfo getJavaFileInfo() {
77 +
78 + if (javaFileInfo == null) {
79 + throw new RuntimeException("Missing java info in java datamodel node");
80 + }
81 + return javaFileInfo;
82 + }
83 +
84 + /**
85 + * Set the java file info object.
86 + *
87 + * @param javaInfo java file info object
88 + */
89 + @Override
90 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
91 +
92 + javaFileInfo = javaInfo;
93 + }
94 +
95 + /**
96 + * Get the data of java imports to be included in generated file.
97 + *
98 + * @return data of java imports to be included in generated file
99 + */
100 + @Override
101 + public JavaImportData getJavaImportData() {
102 +
103 + return javaImportData;
104 + }
105 +
106 + /**
107 + * Set the data of java imports to be included in generated file.
108 + *
109 + * @param javaImportData data of java imports to be included in generated
110 + * file
111 + */
112 + @Override
113 + public void setJavaImportData(JavaImportData javaImportData) {
114 +
115 + this.javaImportData = javaImportData;
116 + }
117 +
118 + /**
119 + * Get the temporary file handle.
120 + *
121 + * @return temporary file handle
122 + */
123 + @Override
124 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
125 +
126 + if (tempFileHandle == null) {
127 + throw new RuntimeException("missing temp file hand for current node "
128 + + getJavaFileInfo().getJavaName());
129 + }
130 + return tempFileHandle;
131 + }
132 +
133 + /**
134 + * Set temporary file handle.
135 + *
136 + * @param fileHandle temporary file handle
137 + */
138 + @Override
139 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
140 +
141 + tempFileHandle = fileHandle;
142 + }
143 +
144 + /**
145 + * Prepare the information for java code generation corresponding to YANG
146 + * case info.
147 + *
148 + * @param codeGenDir code generation directory
149 + * @throws IOException IO operation fail
150 + */
151 + @Override
152 + public void generateCodeEntry(String codeGenDir) throws IOException {
153 +
154 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
155 + getJavaFileInfo().setPackage(getCurNodePackage(this));
156 + getJavaFileInfo().setPackageFilePath(
157 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
158 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
159 +
160 + String absloutePath = getAbsolutePackagePath(
161 + getJavaFileInfo().getBaseCodeGenPath(),
162 + getJavaFileInfo().getPackageFilePath());
163 +
164 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
165 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
166 + getJavaFileInfo().getJavaName()));
167 +
168 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
171 + }
172 +
173 + /**
174 + * Create a java file using the YANG grouping info.
175 + */
176 + @Override
177 + public void generateCodeExit() {
178 + // TODO Auto-generated method stub
179 +
180 + }
181 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangChoice;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
35 +
36 +/**
37 + * Choice information extended to support java code generation.
38 + */
39 +public class YangJavaChoice extends YangChoice
40 + implements JavaCodeGenerator, HasJavaFileInfo,
41 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
42 +
43 + /**
44 + * Contains the information of the java file being generated.
45 + */
46 + private JavaFileInfo javaFileInfo;
47 +
48 + /**
49 + * Contains information of the imports to be inserted in the java file
50 + * generated.
51 + */
52 + private JavaImportData javaImportData;
53 +
54 + /**
55 + * File handle to maintain temporary java code fragments as per the code
56 + * snippet types.
57 + */
58 + private TempJavaCodeFragmentFiles tempFileHandle;
59 +
60 + /**
61 + * Default constructor.
62 + */
63 + public YangJavaChoice() {
64 + super();
65 + setJavaFileInfo(new JavaFileInfo());
66 + setJavaImportData(new JavaImportData());
67 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
68 + }
69 +
70 + /**
71 + * Get the generated java file information.
72 + *
73 + * @return generated java file information
74 + */
75 + @Override
76 + public JavaFileInfo getJavaFileInfo() {
77 +
78 + if (javaFileInfo == null) {
79 + throw new RuntimeException("Missing java info in java datamodel node");
80 + }
81 + return javaFileInfo;
82 + }
83 +
84 + /**
85 + * Set the java file info object.
86 + *
87 + * @param javaInfo java file info object
88 + */
89 + @Override
90 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
91 +
92 + javaFileInfo = javaInfo;
93 + }
94 +
95 + /**
96 + * Get the data of java imports to be included in generated file.
97 + *
98 + * @return data of java imports to be included in generated file
99 + */
100 + @Override
101 + public JavaImportData getJavaImportData() {
102 +
103 + return javaImportData;
104 + }
105 +
106 + /**
107 + * Set the data of java imports to be included in generated file.
108 + *
109 + * @param javaImportData data of java imports to be included in generated
110 + * file
111 + */
112 + @Override
113 + public void setJavaImportData(JavaImportData javaImportData) {
114 +
115 + this.javaImportData = javaImportData;
116 + }
117 +
118 + /**
119 + * Get the temporary file handle.
120 + *
121 + * @return temporary file handle
122 + */
123 + @Override
124 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
125 +
126 + if (tempFileHandle == null) {
127 + throw new RuntimeException("missing temp file hand for current node "
128 + + getJavaFileInfo().getJavaName());
129 + }
130 + return tempFileHandle;
131 + }
132 +
133 + /**
134 + * Set temporary file handle.
135 + *
136 + * @param fileHandle temporary file handle
137 + */
138 + @Override
139 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
140 +
141 + tempFileHandle = fileHandle;
142 + }
143 +
144 + /**
145 + * Prepare the information for java code generation corresponding to YANG
146 + * case info.
147 + *
148 + * @param codeGenDir code generation directory
149 + * @throws IOException IO operation fail
150 + */
151 + @Override
152 + public void generateCodeEntry(String codeGenDir) throws IOException {
153 +
154 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
155 + getJavaFileInfo().setPackage(getCurNodePackage(this));
156 + getJavaFileInfo().setPackageFilePath(
157 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
158 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
159 +
160 + String absloutePath = getAbsolutePackagePath(
161 + getJavaFileInfo().getBaseCodeGenPath(),
162 + getJavaFileInfo().getPackageFilePath());
163 +
164 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
165 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
166 + getJavaFileInfo().getJavaName()));
167 +
168 + // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
171 + }
172 +
173 + /**
174 + * Create a java file using the YANG grouping info.
175 + */
176 + @Override
177 + public void generateCodeExit() {
178 + // TODO Auto-generated method stub
179 +
180 + }
181 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangContainer;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
35 +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
36 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
37 +
38 +/**
39 + * Container information extended to support java code generation.
40 + */
41 +public class YangJavaContainer extends YangContainer
42 + implements JavaCodeGenerator, HasJavaFileInfo,
43 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
44 +
45 + /**
46 + * Contains the information of the java file being generated.
47 + */
48 + private JavaFileInfo javaFileInfo;
49 +
50 + /**
51 + * Contains information of the imports to be inserted in the java file
52 + * generated.
53 + */
54 + private JavaImportData javaImportData;
55 +
56 + /**
57 + * File handle to maintain temporary java code fragments as per the code
58 + * snippet types.
59 + */
60 + private TempJavaCodeFragmentFiles tempFileHandle;
61 +
62 + /**
63 + * Default constructor.
64 + */
65 + public YangJavaContainer() {
66 + super();
67 + setJavaFileInfo(new JavaFileInfo());
68 + setJavaImportData(new JavaImportData());
69 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
70 + }
71 +
72 + /**
73 + * Get the generated java file information.
74 + *
75 + * @return generated java file information
76 + */
77 + @Override
78 + public JavaFileInfo getJavaFileInfo() {
79 +
80 + if (javaFileInfo == null) {
81 + throw new RuntimeException("Missing java info in java datamodel node");
82 + }
83 + return javaFileInfo;
84 + }
85 +
86 + /**
87 + * Set the java file info object.
88 + *
89 + * @param javaInfo java file info object
90 + */
91 + @Override
92 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
93 +
94 + javaFileInfo = javaInfo;
95 + }
96 +
97 + /**
98 + * Get the data of java imports to be included in generated file.
99 + *
100 + * @return data of java imports to be included in generated file
101 + */
102 + @Override
103 + public JavaImportData getJavaImportData() {
104 +
105 + return javaImportData;
106 + }
107 +
108 + /**
109 + * Set the data of java imports to be included in generated file.
110 + *
111 + * @param javaImportData data of java imports to be included in generated
112 + * file
113 + */
114 + @Override
115 + public void setJavaImportData(JavaImportData javaImportData) {
116 +
117 + this.javaImportData = javaImportData;
118 + }
119 +
120 + /**
121 + * Get the temporary file handle.
122 + *
123 + * @return temporary file handle
124 + */
125 + @Override
126 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
127 +
128 + if (tempFileHandle == null) {
129 + throw new RuntimeException("Missing temp file handle for current node "
130 + + getJavaFileInfo().getJavaName());
131 + }
132 + return tempFileHandle;
133 + }
134 +
135 + /**
136 + * Set temporary file handle.
137 + *
138 + * @param fileHandle temporary file handle
139 + */
140 + @Override
141 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
142 +
143 + tempFileHandle = fileHandle;
144 + }
145 +
146 + /**
147 + * Prepare the information for java code generation corresponding to YANG
148 + * container info.
149 + *
150 + * @param codeGenDir code generation directory
151 + * @throws IOException IO operation fail
152 + */
153 + @Override
154 + public void generateCodeEntry(String codeGenDir) throws IOException {
155 +
156 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
157 + getJavaFileInfo().setPackage(getCurNodePackage(this));
158 + getJavaFileInfo().setPackageFilePath(
159 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
160 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
161 +
162 + String absloutePath = getAbsolutePackagePath(
163 + getJavaFileInfo().getBaseCodeGenPath(),
164 + getJavaFileInfo().getPackageFilePath());
165 + createPackage(absloutePath, getName());
166 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
167 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
168 + getJavaFileInfo().getJavaName()));
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
171 +
172 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
173 + }
174 +
175 + /**
176 + * Create a java file using the YANG grouping info.
177 + *
178 + * @throws IOException IO operation fail
179 + */
180 + @Override
181 + public void generateCodeExit() throws IOException {
182 +
183 + generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
184 + getTempJavaCodeFragmentFiles().close();
185 + }
186 +
187 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangGrouping;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
35 +
36 +/**
37 + * Grouping information extended to support java code generation.
38 + */
39 +public class YangJavaGrouping extends YangGrouping
40 + implements JavaCodeGenerator, HasJavaFileInfo,
41 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
42 +
43 + /**
44 + * Contains the information of the java file being generated.
45 + */
46 + private JavaFileInfo javaFileInfo;
47 +
48 + /**
49 + * Contains information of the imports to be inserted in the java file
50 + * generated.
51 + */
52 + private JavaImportData javaImportData;
53 +
54 + /**
55 + * File handle to maintain temporary java code fragments as per the code
56 + * snippet types.
57 + */
58 + private TempJavaCodeFragmentFiles tempFileHandle;
59 +
60 + /**
61 + * Default constructor.
62 + */
63 + public YangJavaGrouping() {
64 + super();
65 + setJavaFileInfo(new JavaFileInfo());
66 + setJavaImportData(new JavaImportData());
67 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
68 + }
69 +
70 + /**
71 + * Get the generated java file information.
72 + *
73 + * @return generated java file information
74 + */
75 + @Override
76 + public JavaFileInfo getJavaFileInfo() {
77 +
78 + if (javaFileInfo == null) {
79 + throw new RuntimeException("Missing java info in java datamodel node");
80 + }
81 + return javaFileInfo;
82 + }
83 +
84 + /**
85 + * Set the java file info object.
86 + *
87 + * @param javaInfo java file info object
88 + */
89 + @Override
90 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
91 +
92 + javaFileInfo = javaInfo;
93 + }
94 +
95 + /**
96 + * Get the data of java imports to be included in generated file.
97 + *
98 + * @return data of java imports to be included in generated file
99 + */
100 + @Override
101 + public JavaImportData getJavaImportData() {
102 +
103 + return javaImportData;
104 + }
105 +
106 + /**
107 + * Set the data of java imports to be included in generated file.
108 + *
109 + * @param javaImportData data of java imports to be included in generated
110 + * file
111 + */
112 + @Override
113 + public void setJavaImportData(JavaImportData javaImportData) {
114 +
115 + this.javaImportData = javaImportData;
116 + }
117 +
118 + /**
119 + * Get the temporary file handle.
120 + *
121 + * @return temporary file handle
122 + */
123 + @Override
124 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
125 +
126 + if (tempFileHandle == null) {
127 + throw new RuntimeException("missing temp file hand for current node "
128 + + getJavaFileInfo().getJavaName());
129 + }
130 + return tempFileHandle;
131 + }
132 +
133 + /**
134 + * Set temporary file handle.
135 + *
136 + * @param fileHandle temporary file handle
137 + */
138 + @Override
139 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
140 +
141 + tempFileHandle = fileHandle;
142 + }
143 +
144 + /**
145 + * Prepare the information for java code generation corresponding to YANG
146 + * container info.
147 + *
148 + * @param codeGenDir code generation directory
149 + * @throws IOException IO operation fail
150 + */
151 + @Override
152 + public void generateCodeEntry(String codeGenDir) throws IOException {
153 +
154 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
155 + getJavaFileInfo().setPackage(getCurNodePackage(this));
156 + getJavaFileInfo().setPackageFilePath(
157 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
158 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
159 +
160 + String absloutePath = getAbsolutePackagePath(
161 + getJavaFileInfo().getBaseCodeGenPath(),
162 + getJavaFileInfo().getPackageFilePath());
163 +
164 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
165 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
166 + getJavaFileInfo().getJavaName()));
167 +
168 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
171 + }
172 +
173 + /**
174 + * Create a java file using the YANG grouping info.
175 + */
176 + @Override
177 + public void generateCodeExit() {
178 + // TODO Auto-generated method stub
179 +
180 + }
181 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangList;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
35 +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
36 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
37 +
38 +/**
39 + * YANG List information extended to support java code generation.
40 + */
41 +public class YangJavaList extends YangList
42 + implements JavaCodeGenerator, HasJavaFileInfo,
43 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
44 +
45 + /**
46 + * Contains the information of the java file being generated.
47 + */
48 + private JavaFileInfo javaFileInfo;
49 +
50 + /**
51 + * Contains information of the imports to be inserted in the java file
52 + * generated.
53 + */
54 + private JavaImportData javaImportData;
55 +
56 + /**
57 + * File handle to maintain temporary java code fragments as per the code
58 + * snippet types.
59 + */
60 + private TempJavaCodeFragmentFiles tempFileHandle;
61 +
62 + /**
63 + * Default constructor.
64 + */
65 + public YangJavaList() {
66 + super();
67 + setJavaFileInfo(new JavaFileInfo());
68 + setJavaImportData(new JavaImportData());
69 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
70 + }
71 +
72 + /**
73 + * Get the generated java file information.
74 + *
75 + * @return generated java file information
76 + */
77 + @Override
78 + public JavaFileInfo getJavaFileInfo() {
79 +
80 + if (javaFileInfo == null) {
81 + throw new RuntimeException("Missing java info in java datamodel node");
82 + }
83 + return javaFileInfo;
84 + }
85 +
86 + /**
87 + * Set the java file info object.
88 + *
89 + * @param javaInfo java file info object
90 + */
91 + @Override
92 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
93 +
94 + javaFileInfo = javaInfo;
95 + }
96 +
97 + /**
98 + * Get the data of java imports to be included in generated file.
99 + *
100 + * @return data of java imports to be included in generated file
101 + */
102 + @Override
103 + public JavaImportData getJavaImportData() {
104 +
105 + return javaImportData;
106 + }
107 +
108 + /**
109 + * Set the data of java imports to be included in generated file.
110 + *
111 + * @param javaImportData data of java imports to be included in generated
112 + * file
113 + */
114 + @Override
115 + public void setJavaImportData(JavaImportData javaImportData) {
116 +
117 + this.javaImportData = javaImportData;
118 + }
119 +
120 + /**
121 + * Get the temporary file handle.
122 + *
123 + * @return temporary file handle
124 + */
125 + @Override
126 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
127 +
128 + if (tempFileHandle == null) {
129 + throw new RuntimeException("missing temp file hand for current node "
130 + + getJavaFileInfo().getJavaName());
131 + }
132 + return tempFileHandle;
133 + }
134 +
135 + /**
136 + * Set temporary file handle.
137 + *
138 + * @param fileHandle temporary file handle
139 + */
140 + @Override
141 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
142 +
143 + tempFileHandle = fileHandle;
144 + }
145 +
146 + /**
147 + * Prepare the information for java code generation corresponding to YANG
148 + * container info.
149 + *
150 + * @param codeGenDir code generation directory
151 + * @throws IOException IO operation fail
152 + */
153 + @Override
154 + public void generateCodeEntry(String codeGenDir) throws IOException {
155 +
156 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
157 + getJavaFileInfo().setPackage(getCurNodePackage(this));
158 + getJavaFileInfo().setPackageFilePath(
159 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
160 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
161 + String absloutePath = getAbsolutePackagePath(
162 + getJavaFileInfo().getBaseCodeGenPath(),
163 + getJavaFileInfo().getPackageFilePath());
164 + createPackage(absloutePath, getName());
165 +
166 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
167 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
168 + getJavaFileInfo().getJavaName()));
169 +
170 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
171 +
172 + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, true);
173 + }
174 +
175 + /**
176 + * Create a java file using the YANG grouping info.
177 + *
178 + * @throws IOException IO operation fail
179 + */
180 + @Override
181 + public void generateCodeExit() throws IOException {
182 +
183 + generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
184 + getTempJavaCodeFragmentFiles().close();
185 + }
186 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangModule;
21 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
25 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
27 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
30 +import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
35 +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
36 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
37 +
38 +/**
39 + * Module information extended to support java code generation.
40 + */
41 +public class YangJavaModule extends YangModule
42 + implements JavaCodeGenerator, HasJavaFileInfo,
43 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
44 +
45 + /**
46 + * Contains the information of the java file being generated.
47 + */
48 + private JavaFileInfo javaFileInfo;
49 +
50 + /**
51 + * Contains information of the imports to be inserted in the java file
52 + * generated.
53 + */
54 + private JavaImportData javaImportData;
55 +
56 + /**
57 + * File handle to maintain temporary java code fragments as per the code
58 + * snippet types.
59 + */
60 + private TempJavaCodeFragmentFiles tempFileHandle;
61 +
62 + /**
63 + * Create a YANG node of module type.
64 + */
65 + public YangJavaModule() {
66 + super();
67 + setJavaFileInfo(new JavaFileInfo());
68 + setJavaImportData(new JavaImportData());
69 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
70 + }
71 +
72 + /**
73 + * Get the generated java file information.
74 + *
75 + * @return generated java file information
76 + */
77 + @Override
78 + public JavaFileInfo getJavaFileInfo() {
79 +
80 + if (javaFileInfo == null) {
81 + throw new RuntimeException("Missing java info in java datamodel node");
82 + }
83 + return javaFileInfo;
84 + }
85 +
86 + /**
87 + * Set the java file info object.
88 + *
89 + * @param javaInfo java file info object
90 + */
91 + @Override
92 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
93 +
94 + javaFileInfo = javaInfo;
95 + }
96 +
97 + /**
98 + * Get the data of java imports to be included in generated file.
99 + *
100 + * @return data of java imports to be included in generated file
101 + */
102 + @Override
103 + public JavaImportData getJavaImportData() {
104 +
105 + return javaImportData;
106 + }
107 +
108 + /**
109 + * Set the data of java imports to be included in generated file.
110 + *
111 + * @param javaImportData data of java imports to be included in generated
112 + * file
113 + */
114 + @Override
115 + public void setJavaImportData(JavaImportData javaImportData) {
116 +
117 + this.javaImportData = javaImportData;
118 + }
119 +
120 + /**
121 + * Get the temporary file handle.
122 + *
123 + * @return temporary file handle
124 + */
125 + @Override
126 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
127 +
128 + if (tempFileHandle == null) {
129 + throw new RuntimeException("missing temp file hand for current node "
130 + + getJavaFileInfo().getJavaName());
131 + }
132 + return tempFileHandle;
133 + }
134 +
135 + /**
136 + * Set temporary file handle.
137 + *
138 + * @param fileHandle temporary file handle
139 + */
140 + @Override
141 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
142 +
143 + tempFileHandle = fileHandle;
144 + }
145 +
146 + /**
147 + * Generates java code for module.
148 + *
149 + * @param baseCodeGenDir code generation directory
150 + * @throws IOException when fails to generate the source files
151 + */
152 + @Override
153 + public void generateCodeEntry(String baseCodeGenDir) throws IOException {
154 +
155 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
156 + getJavaFileInfo().setPackage(getRootPackage(getVersion(), getNameSpace().getUri(),
157 + getRevision().getRevDate()));
158 + getJavaFileInfo().setPackageFilePath(
159 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
160 + getJavaFileInfo().setBaseCodeGenPath(baseCodeGenDir);
161 +
162 + String absloutePath = getAbsolutePackagePath(
163 + getJavaFileInfo().getBaseCodeGenPath(),
164 + getJavaFileInfo().getPackageFilePath());
165 +
166 + createPackage(absloutePath, getName());
167 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
168 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
169 + getJavaFileInfo().getJavaName()));
170 +
171 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
172 + }
173 +
174 + @Override
175 + public void generateCodeExit() throws IOException {
176 +
177 + generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
178 + getTempJavaCodeFragmentFiles().close();
179 + return;
180 + }
181 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import java.io.IOException;
19 +
20 +import org.onosproject.yangutils.datamodel.YangBelongsTo;
21 +import org.onosproject.yangutils.datamodel.YangSubModule;
22 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
23 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
24 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
26 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
28 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
29 +
30 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
31 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
33 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
35 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
36 +
37 +/**
38 + * Sub module information extended to support java code generation.
39 + */
40 +public class YangJavaSubModule extends YangSubModule
41 + implements JavaCodeGenerator, HasJavaFileInfo,
42 + HasJavaImportData, HasTempJavaCodeFragmentFiles {
43 +
44 + /**
45 + * Contains the information of the java file being generated.
46 + */
47 + private JavaFileInfo javaFileInfo;
48 +
49 + /**
50 + * Contains information of the imports to be inserted in the java file
51 + * generated.
52 + */
53 + private JavaImportData javaImportData;
54 +
55 + /**
56 + * File handle to maintain temporary java code fragments as per the code
57 + * snippet types.
58 + */
59 + private TempJavaCodeFragmentFiles tempFileHandle;
60 +
61 + /**
62 + * Default constructor.
63 + */
64 + public YangJavaSubModule() {
65 + super();
66 + setJavaFileInfo(new JavaFileInfo());
67 + setJavaImportData(new JavaImportData());
68 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
69 + }
70 +
71 + /**
72 + * Get the generated java file information.
73 + *
74 + * @return generated java file information
75 + */
76 + @Override
77 + public JavaFileInfo getJavaFileInfo() {
78 + if (javaFileInfo == null) {
79 + throw new RuntimeException("Missing java info in java datamodel node");
80 + }
81 + return javaFileInfo;
82 + }
83 +
84 + /**
85 + * Set the java file info object.
86 + *
87 + * @param javaInfo java file info object
88 + */
89 + @Override
90 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
91 + javaFileInfo = javaInfo;
92 + }
93 +
94 + /**
95 + * Get the data of java imports to be included in generated file.
96 + *
97 + * @return data of java imports to be included in generated file
98 + */
99 + @Override
100 + public JavaImportData getJavaImportData() {
101 + return javaImportData;
102 + }
103 +
104 + /**
105 + * Set the data of java imports to be included in generated file.
106 + *
107 + * @param javaImportData data of java imports to be included in generated
108 + * file
109 + */
110 + @Override
111 + public void setJavaImportData(JavaImportData javaImportData) {
112 + this.javaImportData = javaImportData;
113 + }
114 +
115 + /**
116 + * Get the temporary file handle.
117 + *
118 + * @return temporary file handle
119 + */
120 + @Override
121 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
122 + if (tempFileHandle == null) {
123 + throw new RuntimeException("missing temp file hand for current node "
124 + + getJavaFileInfo().getJavaName());
125 + }
126 + return tempFileHandle;
127 + }
128 +
129 + /**
130 + * Set temporary file handle.
131 + *
132 + * @param fileHandle temporary file handle
133 + */
134 + @Override
135 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
136 + tempFileHandle = fileHandle;
137 + }
138 +
139 + /**
140 + * Get the name space of the module to which the sub module belongs to.
141 + *
142 + * @param belongsToInfo Information of the module to which the sub module
143 + * belongs
144 + * @return the name space string of the module.
145 + */
146 + private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
147 + // TODO Auto-generated method stub
148 + return "";
149 + }
150 +
151 + /**
152 + * Prepare the information for java code generation corresponding to YANG
153 + * container info.
154 + *
155 + * @param codeGenDir code generation directory
156 + * @throws IOException IO operation fail
157 + */
158 + @Override
159 + public void generateCodeEntry(String codeGenDir) throws IOException {
160 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
161 + getJavaFileInfo().setPackage(getRootPackage(getVersion(),
162 + getNameSpaceFromModule(getBelongsTo()),
163 + getRevision().getRevDate()));
164 + getJavaFileInfo().setPackageFilePath(
165 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
166 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
167 +
168 + String absloutePath = getAbsolutePackagePath(
169 + getJavaFileInfo().getBaseCodeGenPath(),
170 + getJavaFileInfo().getPackageFilePath());
171 +
172 + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
173 + getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
174 + getJavaFileInfo().getJavaName()));
175 +
176 + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
177 + }
178 +
179 + /**
180 + * Create a java file using the YANG grouping info.
181 + */
182 + @Override
183 + public void generateCodeExit() {
184 + // TODO Auto-generated method stub
185 +
186 + }
187 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.YangTypeDef;
19 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
20 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
21 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 +
25 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
26 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
27 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
28 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
29 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
30 +
31 +/**
32 + * Type define information extended to support java code generation.
33 + */
34 +public class YangJavaTypeDef extends YangTypeDef
35 + implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData {
36 +
37 + /**
38 + * Contains the information of the java file being generated.
39 + */
40 + private JavaFileInfo javaFileInfo;
41 +
42 + /**
43 + * Contains information of the imports to be inserted in the java file
44 + * generated.
45 + */
46 + private JavaImportData javaImportData;
47 +
48 + /**
49 + * Default constructor.
50 + */
51 + public YangJavaTypeDef() {
52 + super();
53 + setJavaFileInfo(new JavaFileInfo());
54 + setJavaImportData(new JavaImportData());
55 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
56 + }
57 +
58 + /**
59 + * Get the generated java file information.
60 + *
61 + * @return generated java file information
62 + */
63 + @Override
64 + public JavaFileInfo getJavaFileInfo() {
65 + if (javaFileInfo == null) {
66 + throw new RuntimeException("Missing java info in java datamodel node");
67 + }
68 + return javaFileInfo;
69 + }
70 +
71 + /**
72 + * Set the java file info object.
73 + *
74 + * @param javaInfo java file info object
75 + */
76 + @Override
77 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
78 + javaFileInfo = javaInfo;
79 + }
80 +
81 + /**
82 + * Get the data of java imports to be included in generated file.
83 + *
84 + * @return data of java imports to be included in generated file
85 + */
86 + @Override
87 + public JavaImportData getJavaImportData() {
88 + return javaImportData;
89 + }
90 +
91 + /**
92 + * Set the data of java imports to be included in generated file.
93 + *
94 + * @param javaImportData data of java imports to be included in generated
95 + * file
96 + */
97 + @Override
98 + public void setJavaImportData(JavaImportData javaImportData) {
99 + this.javaImportData = javaImportData;
100 + }
101 +
102 + /**
103 + * Prepare the information for java code generation corresponding to YANG
104 + * container info.
105 + *
106 + * @param codeGenDir code generation directory
107 + */
108 + @Override
109 + public void generateCodeEntry(String codeGenDir) {
110 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
111 + getJavaFileInfo().setPackage(getCurNodePackage(this));
112 + getJavaFileInfo().setPackageFilePath(
113 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
114 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
115 + // TODO: generate type define temporary files
116 + }
117 +
118 + /**
119 + * Create a java file using the YANG grouping info.
120 + */
121 + @Override
122 + public void generateCodeExit() {
123 + // TODO Auto-generated method stub
124 +
125 + }
126 +
127 +}
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.YangUses;
19 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
20 +import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
21 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 +
25 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
26 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
27 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
28 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
29 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
30 +
31 +/**
32 + * Uses information extended to support java code generation.
33 + */
34 +public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData {
35 +
36 + /**
37 + * Contains the information of the java file being generated.
38 + */
39 + private JavaFileInfo javaFileInfo;
40 +
41 + /**
42 + * Contains information of the imports to be inserted in the java file
43 + * generated.
44 + */
45 + private JavaImportData javaImportData;
46 +
47 + /**
48 + * Default constructor.
49 + */
50 + public YangJavaUses() {
51 + super();
52 + setJavaFileInfo(new JavaFileInfo());
53 + setJavaImportData(new JavaImportData());
54 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
55 + }
56 +
57 + /**
58 + * Get the generated java file information.
59 + *
60 + * @return generated java file information
61 + */
62 + @Override
63 + public JavaFileInfo getJavaFileInfo() {
64 + if (javaFileInfo == null) {
65 + throw new RuntimeException("Missing java info in java datamodel node");
66 + }
67 + return javaFileInfo;
68 + }
69 +
70 + /**
71 + * Set the java file info object.
72 + *
73 + * @param javaInfo java file info object
74 + */
75 + @Override
76 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
77 + javaFileInfo = javaInfo;
78 + }
79 +
80 + /**
81 + * Get the data of java imports to be included in generated file.
82 + *
83 + * @return data of java imports to be included in generated file
84 + */
85 + @Override
86 + public JavaImportData getJavaImportData() {
87 + return javaImportData;
88 + }
89 +
90 + /**
91 + * Set the data of java imports to be included in generated file.
92 + *
93 + * @param javaImportData data of java imports to be included in generated
94 + * file
95 + */
96 + @Override
97 + public void setJavaImportData(JavaImportData javaImportData) {
98 + this.javaImportData = javaImportData;
99 + }
100 +
101 + /**
102 + * Prepare the information for java code generation corresponding to YANG
103 + * container info.
104 + *
105 + * @param codeGenDir code generation directory
106 + */
107 + @Override
108 + public void generateCodeEntry(String codeGenDir) {
109 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
110 + getJavaFileInfo().setPackage(getCurNodePackage(this));
111 + getJavaFileInfo().setPackageFilePath(
112 + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
113 + getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
114 + //TODO:addCurNodeLeavesInfoToTempFiles(this);
115 + //TODO:addCurNodeInfoInParentTempFile(this, false);
116 + }
117 +
118 + /**
119 + * Create a java file using the YANG grouping info.
120 + */
121 + @Override
122 + public void generateCodeExit() {
123 + // TODO Auto-generated method stub
124 +
125 + }
126 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * 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, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +
17 +/**
18 + * Maintains application's schema mapped to java classes / interfaces.
19 + */
20 +package org.onosproject.yangutils.translator.tojava.javamodel;
...@@ -16,8 +16,12 @@ ...@@ -16,8 +16,12 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 +import java.util.Set;
20 +import java.util.TreeSet;
21 +
19 import org.onosproject.yangutils.datamodel.YangDataTypes; 22 import org.onosproject.yangutils.datamodel.YangDataTypes;
20 import org.onosproject.yangutils.datamodel.YangType; 23 import org.onosproject.yangutils.datamodel.YangType;
24 +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
21 import org.onosproject.yangutils.utils.UtilConstants; 25 import org.onosproject.yangutils.utils.UtilConstants;
22 26
23 /** 27 /**
...@@ -25,6 +29,8 @@ import org.onosproject.yangutils.utils.UtilConstants; ...@@ -25,6 +29,8 @@ import org.onosproject.yangutils.utils.UtilConstants;
25 */ 29 */
26 public final class AttributesJavaDataType { 30 public final class AttributesJavaDataType {
27 31
32 + private static Set<JavaQualifiedTypeInfo> importInfo = new TreeSet<>();
33 +
28 /** 34 /**
29 * Default constructor. 35 * Default constructor.
30 */ 36 */
...@@ -32,6 +38,24 @@ public final class AttributesJavaDataType { ...@@ -32,6 +38,24 @@ public final class AttributesJavaDataType {
32 } 38 }
33 39
34 /** 40 /**
41 + * Returns import info.
42 + *
43 + * @return import info
44 + */
45 + public static Set<JavaQualifiedTypeInfo> getImportInfo() {
46 + return importInfo;
47 + }
48 +
49 + /**
50 + * Adds import info to the import info set.
51 + *
52 + * @param importData import info
53 + */
54 + public static void addImportInfo(JavaQualifiedTypeInfo importData) {
55 + getImportInfo().add(importData);
56 + }
57 +
58 + /**
35 * Returns java type. 59 * Returns java type.
36 * 60 *
37 * @param yangType YANG type 61 * @param yangType YANG type
...@@ -134,7 +158,8 @@ public final class AttributesJavaDataType { ...@@ -134,7 +158,8 @@ public final class AttributesJavaDataType {
134 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { 158 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
135 //TODO:INSTANCE_IDENTIFIER 159 //TODO:INSTANCE_IDENTIFIER
136 } else if (type.equals(YangDataTypes.DERIVED)) { 160 } else if (type.equals(YangDataTypes.DERIVED)) {
137 - //TODO:DERIVED 161 + return JavaIdentifierSyntax
162 + .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName()));
138 } 163 }
139 } else { 164 } else {
140 if (type.equals(YangDataTypes.UINT64)) { 165 if (type.equals(YangDataTypes.UINT64)) {
...@@ -160,7 +185,8 @@ public final class AttributesJavaDataType { ...@@ -160,7 +185,8 @@ public final class AttributesJavaDataType {
160 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { 185 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
161 //TODO:INSTANCE_IDENTIFIER 186 //TODO:INSTANCE_IDENTIFIER
162 } else if (type.equals(YangDataTypes.DERIVED)) { 187 } else if (type.equals(YangDataTypes.DERIVED)) {
163 - //TODO:DERIVED 188 + return JavaIdentifierSyntax
189 + .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName()));
164 } 190 }
165 } 191 }
166 return null; 192 return null;
...@@ -171,9 +197,10 @@ public final class AttributesJavaDataType { ...@@ -171,9 +197,10 @@ public final class AttributesJavaDataType {
171 * 197 *
172 * @param yangType YANG type 198 * @param yangType YANG type
173 * @param isListAttr if the attribute is of list type 199 * @param isListAttr if the attribute is of list type
200 + * @param classInfo java import class info
174 * @return java import package 201 * @return java import package
175 */ 202 */
176 - public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr) { 203 + public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
177 YangDataTypes type = yangType.getDataType(); 204 YangDataTypes type = yangType.getDataType();
178 205
179 if (isListAttr) { 206 if (isListAttr) {
...@@ -208,7 +235,11 @@ public final class AttributesJavaDataType { ...@@ -208,7 +235,11 @@ public final class AttributesJavaDataType {
208 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { 235 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
209 //TODO:INSTANCE_IDENTIFIER 236 //TODO:INSTANCE_IDENTIFIER
210 } else if (type.equals(YangDataTypes.DERIVED)) { 237 } else if (type.equals(YangDataTypes.DERIVED)) {
211 - //TODO:DERIVED 238 + for (JavaQualifiedTypeInfo imports : getImportInfo()) {
239 + if (imports.getClassInfo().equals(classInfo)) {
240 + return imports.getPkgInfo();
241 + }
242 + }
212 } 243 }
213 } else { 244 } else {
214 245
...@@ -235,7 +266,11 @@ public final class AttributesJavaDataType { ...@@ -235,7 +266,11 @@ public final class AttributesJavaDataType {
235 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { 266 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
236 //TODO:INSTANCE_IDENTIFIER 267 //TODO:INSTANCE_IDENTIFIER
237 } else if (type.equals(YangDataTypes.DERIVED)) { 268 } else if (type.equals(YangDataTypes.DERIVED)) {
238 - //TODO:DERIVED 269 + for (JavaQualifiedTypeInfo imports : getImportInfo()) {
270 + if (imports.getClassInfo().equals(classInfo)) {
271 + return imports.getPkgInfo();
272 + }
273 + }
239 } 274 }
240 } 275 }
241 return null; 276 return null;
......