Bharat saraswal

[ONOS-4616] grouping linker issues fixed and other defect fixed.

Change-Id: I1b23f9ed0293edbc2d551efe82982559eb916ede
Showing 109 changed files with 4222 additions and 1445 deletions
...@@ -225,9 +225,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -225,9 +225,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
225 * @throws DataModelException a violation in data mode rule 225 * @throws DataModelException a violation in data mode rule
226 */ 226 */
227 public ResolvableStatus resolve() throws DataModelException { 227 public ResolvableStatus resolve() throws DataModelException {
228 -
229 YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType(); 228 YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
230 -
231 /* 229 /*
232 * Checks the data type of the referred typedef, if it's derived, 230 * Checks the data type of the referred typedef, if it's derived,
233 * obtain effective built-in type and restrictions from it's derived 231 * obtain effective built-in type and restrictions from it's derived
...@@ -240,7 +238,6 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -240,7 +238,6 @@ public class YangDerivedInfo<T> implements LocationInfo {
240 if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) { 238 if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
241 throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); 239 throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
242 } 240 }
243 -
244 /* 241 /*
245 * Check if the referred typedef is intra file resolved, if yes sets 242 * Check if the referred typedef is intra file resolved, if yes sets
246 * current status also to intra file resolved . 243 * current status also to intra file resolved .
...@@ -250,7 +247,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -250,7 +247,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
250 } 247 }
251 setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo()) 248 setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
252 .getEffectiveBuiltInType()); 249 .getEffectiveBuiltInType());
253 - YangDerivedInfo refDerivedInfo = ((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo()); 250 + YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
254 /* 251 /*
255 * Check whether the effective built-in type can have range 252 * Check whether the effective built-in type can have range
256 * restrictions, if yes call resolution of range. 253 * restrictions, if yes call resolution of range.
...@@ -327,7 +324,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -327,7 +324,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
327 } 324 }
328 } 325 }
329 } else { 326 } else {
330 - setEffectiveBuiltInType((baseType.getDataType())); 327 + setEffectiveBuiltInType(baseType.getDataType());
331 /* 328 /*
332 * Check whether the effective built-in type can have range 329 * Check whether the effective built-in type can have range
333 * restrictions, if yes call resolution of range. 330 * restrictions, if yes call resolution of range.
...@@ -404,7 +401,6 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -404,7 +401,6 @@ public class YangDerivedInfo<T> implements LocationInfo {
404 } 401 }
405 } 402 }
406 } 403 }
407 -
408 /* 404 /*
409 * Check if the data type is the one which can't be restricted, in 405 * Check if the data type is the one which can't be restricted, in
410 * this case check whether no self restrictions should be present. 406 * this case check whether no self restrictions should be present.
...@@ -418,7 +414,6 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -418,7 +414,6 @@ public class YangDerivedInfo<T> implements LocationInfo {
418 throw new DataModelException("YANG file error: Restrictions can't be applied to a given type"); 414 throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
419 } 415 }
420 } 416 }
421 -
422 // Throw exception for unsupported types 417 // Throw exception for unsupported types
423 throw new DataModelException("Linker error: Unable to process the derived type."); 418 throw new DataModelException("Linker error: Unable to process the derived type.");
424 } 419 }
...@@ -438,7 +433,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -438,7 +433,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
438 * Check that range restriction should be null when built-in type is 433 * Check that range restriction should be null when built-in type is
439 * string. 434 * string.
440 */ 435 */
441 - if (!(Strings.isNullOrEmpty(getRangeRestrictionString()))) { 436 + if (!Strings.isNullOrEmpty(getRangeRestrictionString())) {
442 DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " + 437 DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
443 "should't be present for string data type."); 438 "should't be present for string data type.");
444 dataModelException.setLine(lineNumber); 439 dataModelException.setLine(lineNumber);
...@@ -605,7 +600,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -605,7 +600,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
605 * Check that string restriction should be null when built-in type is 600 * Check that string restriction should be null when built-in type is
606 * of range type. 601 * of range type.
607 */ 602 */
608 - if (!(Strings.isNullOrEmpty(getLengthRestrictionString())) || getPatternRestriction() != null) { 603 + if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) {
609 DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " + 604 DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
610 "restriction should't be present for int/uint/decimal data type."); 605 "restriction should't be present for int/uint/decimal data type.");
611 dataModelException.setLine(lineNumber); 606 dataModelException.setLine(lineNumber);
...@@ -660,12 +655,12 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -660,12 +655,12 @@ public class YangDerivedInfo<T> implements LocationInfo {
660 * @return true, if data type can't be restricted, false otherwise 655 * @return true, if data type can't be restricted, false otherwise
661 */ 656 */
662 private boolean isOfValidNonRestrictedType(YangDataTypes dataType) { 657 private boolean isOfValidNonRestrictedType(YangDataTypes dataType) {
663 - return (dataType == BOOLEAN 658 + return dataType == BOOLEAN
664 || dataType == ENUMERATION 659 || dataType == ENUMERATION
665 || dataType == BITS 660 || dataType == BITS
666 || dataType == EMPTY 661 || dataType == EMPTY
667 || dataType == UNION 662 || dataType == UNION
668 || dataType == IDENTITYREF 663 || dataType == IDENTITYREF
669 - || dataType == LEAFREF); 664 + || dataType == LEAFREF;
670 } 665 }
671 } 666 }
......
...@@ -50,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -50,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
50 /** 50 /**
51 * Represents the ENUM data type information. 51 * Represents the ENUM data type information.
52 */ 52 */
53 -public class YangEnum implements YangCommonInfo, Parsable { 53 +public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum> {
54 54
55 /** 55 /**
56 * Named value for the ENUM. 56 * Named value for the ENUM.
...@@ -226,4 +226,12 @@ public class YangEnum implements YangCommonInfo, Parsable { ...@@ -226,4 +226,12 @@ public class YangEnum implements YangCommonInfo, Parsable {
226 public void validateDataOnExit() throws DataModelException { 226 public void validateDataOnExit() throws DataModelException {
227 // TODO auto-generated method stub, to be implemented by parser 227 // TODO auto-generated method stub, to be implemented by parser
228 } 228 }
229 +
230 + @Override
231 + public int compareTo(YangEnum otherEnum) {
232 + if (this.namedValue.equals(otherEnum.getNamedValue())) {
233 + return 0;
234 + }
235 + return new Integer(this.value).compareTo(otherEnum.getValue());
236 + }
229 } 237 }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 -import java.util.HashSet; 19 +import java.util.SortedSet;
20 -import java.util.Set; 20 +import java.util.TreeSet;
21 21
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
...@@ -31,10 +31,10 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -31,10 +31,10 @@ import org.onosproject.yangutils.utils.YangConstructType;
31 /** 31 /**
32 * Represents the enumeration data type information. 32 * Represents the enumeration data type information.
33 */ 33 */
34 -public class YangEnumeration extends YangNode implements Parsable { 34 +public class YangEnumeration extends YangNode implements Parsable, CollisionDetector {
35 35
36 // Enumeration info set. 36 // Enumeration info set.
37 - private Set<YangEnum> enumSet; 37 + private SortedSet<YangEnum> enumSet;
38 38
39 // Enumeration name. 39 // Enumeration name.
40 private String name; 40 private String name;
...@@ -44,7 +44,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -44,7 +44,7 @@ public class YangEnumeration extends YangNode implements Parsable {
44 */ 44 */
45 public YangEnumeration() { 45 public YangEnumeration() {
46 super(YangNodeType.ENUMERATION_NODE); 46 super(YangNodeType.ENUMERATION_NODE);
47 - setEnumSet(new HashSet<YangEnum>()); 47 + setEnumSet(new TreeSet<YangEnum>());
48 } 48 }
49 49
50 /** 50 /**
...@@ -52,7 +52,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -52,7 +52,7 @@ public class YangEnumeration extends YangNode implements Parsable {
52 * 52 *
53 * @return the ENUM set 53 * @return the ENUM set
54 */ 54 */
55 - public Set<YangEnum> getEnumSet() { 55 + public SortedSet<YangEnum> getEnumSet() {
56 return enumSet; 56 return enumSet;
57 } 57 }
58 58
...@@ -61,7 +61,7 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -61,7 +61,7 @@ public class YangEnumeration extends YangNode implements Parsable {
61 * 61 *
62 * @param enumSet the ENUM set to set 62 * @param enumSet the ENUM set to set
63 */ 63 */
64 - private void setEnumSet(Set<YangEnum> enumSet) { 64 + private void setEnumSet(SortedSet<YangEnum> enumSet) {
65 this.enumSet = enumSet; 65 this.enumSet = enumSet;
66 } 66 }
67 67
...@@ -126,4 +126,18 @@ public class YangEnumeration extends YangNode implements Parsable { ...@@ -126,4 +126,18 @@ public class YangEnumeration extends YangNode implements Parsable {
126 public void validateDataOnExit() throws DataModelException { 126 public void validateDataOnExit() throws DataModelException {
127 // TODO auto-generated method stub, to be implemented by parser 127 // TODO auto-generated method stub, to be implemented by parser
128 } 128 }
129 +
130 + @Override
131 + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
132 + /*
133 + Do nothing.The implementation for this is not required.
134 + */
135 + }
136 +
137 + @Override
138 + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
139 + /*
140 + Do nothing.The implementation for this is not required.
141 + */
142 + }
129 } 143 }
......
...@@ -444,8 +444,8 @@ public class YangList extends YangNode ...@@ -444,8 +444,8 @@ public class YangList extends YangNode
444 validateConfig(leaves, leafLists); 444 validateConfig(leaves, leafLists);
445 445
446 /* A list must have atleast one key leaf if config is true */ 446 /* A list must have atleast one key leaf if config is true */
447 - if (isConfig 447 + if (isConfig && (keys == null || leaves == null && leafLists == null) && !isUsesPresentInList()
448 - && (keys == null || leaves == null && leafLists == null && !isUsesPresentInList())) { 448 + && !isListPresentInGrouping()) {
449 throw new DataModelException("A list must have atleast one key leaf if config is true;"); 449 throw new DataModelException("A list must have atleast one key leaf if config is true;");
450 } else if (keys != null) { 450 } else if (keys != null) {
451 validateKey(leaves, leafLists, keys); 451 validateKey(leaves, leafLists, keys);
...@@ -565,7 +565,7 @@ public class YangList extends YangNode ...@@ -565,7 +565,7 @@ public class YangList extends YangNode
565 } 565 }
566 } 566 }
567 567
568 - if (!leafFound && !isUsesPresentInList()) { 568 + if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) {
569 throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); 569 throw new DataModelException("An identifier, in key, must refer to a child leaf of the list");
570 } 570 }
571 leafFound = false; 571 leafFound = false;
...@@ -617,6 +617,18 @@ public class YangList extends YangNode ...@@ -617,6 +617,18 @@ public class YangList extends YangNode
617 node = node.getNextSibling(); 617 node = node.getNextSibling();
618 } 618 }
619 return false; 619 return false;
620 + // TODO When grouping linking is done this method has to be modified.
620 } 621 }
621 622
623 + private boolean isListPresentInGrouping() {
624 + YangNode node = this.getParent();
625 + while (node != null) {
626 + if (node instanceof YangGrouping) {
627 + return true;
628 + }
629 + node = node.getParent();
630 + }
631 + return false;
632 + // TODO When grouping linking is done this method has to be modified.
633 + }
622 } 634 }
......
...@@ -271,6 +271,7 @@ public class YangModule extends YangNode ...@@ -271,6 +271,7 @@ public class YangModule extends YangNode
271 * 271 *
272 * @return the list of imported modules 272 * @return the list of imported modules
273 */ 273 */
274 + @Override
274 public List<YangImport> getImportList() { 275 public List<YangImport> getImportList() {
275 return importList; 276 return importList;
276 } 277 }
...@@ -280,6 +281,7 @@ public class YangModule extends YangNode ...@@ -280,6 +281,7 @@ public class YangModule extends YangNode
280 * 281 *
281 * @param importedModule module being imported 282 * @param importedModule module being imported
282 */ 283 */
284 + @Override
283 public void addToImportList(YangImport importedModule) { 285 public void addToImportList(YangImport importedModule) {
284 getImportList().add(importedModule); 286 getImportList().add(importedModule);
285 } 287 }
...@@ -294,6 +296,7 @@ public class YangModule extends YangNode ...@@ -294,6 +296,7 @@ public class YangModule extends YangNode
294 * 296 *
295 * @return the included list of sub modules 297 * @return the included list of sub modules
296 */ 298 */
299 + @Override
297 public List<YangInclude> getIncludeList() { 300 public List<YangInclude> getIncludeList() {
298 return includeList; 301 return includeList;
299 } 302 }
...@@ -303,6 +306,7 @@ public class YangModule extends YangNode ...@@ -303,6 +306,7 @@ public class YangModule extends YangNode
303 * 306 *
304 * @param includeModule submodule being included 307 * @param includeModule submodule being included
305 */ 308 */
309 + @Override
306 public void addToIncludeList(YangInclude includeModule) { 310 public void addToIncludeList(YangInclude includeModule) {
307 getIncludeList().add(includeModule); 311 getIncludeList().add(includeModule);
308 } 312 }
...@@ -393,6 +397,7 @@ public class YangModule extends YangNode ...@@ -393,6 +397,7 @@ public class YangModule extends YangNode
393 * 397 *
394 * @return the prefix 398 * @return the prefix
395 */ 399 */
400 + @Override
396 public String getPrefix() { 401 public String getPrefix() {
397 return prefix; 402 return prefix;
398 } 403 }
...@@ -402,6 +407,7 @@ public class YangModule extends YangNode ...@@ -402,6 +407,7 @@ public class YangModule extends YangNode
402 * 407 *
403 * @param prefix the prefix to set 408 * @param prefix the prefix to set
404 */ 409 */
410 + @Override
405 public void setPrefix(String prefix) { 411 public void setPrefix(String prefix) {
406 this.prefix = prefix; 412 this.prefix = prefix;
407 } 413 }
......
...@@ -285,6 +285,7 @@ public class YangSubModule extends YangNode ...@@ -285,6 +285,7 @@ public class YangSubModule extends YangNode
285 * 285 *
286 * @return the list of imported modules 286 * @return the list of imported modules
287 */ 287 */
288 + @Override
288 public List<YangImport> getImportList() { 289 public List<YangImport> getImportList() {
289 return importList; 290 return importList;
290 } 291 }
...@@ -294,6 +295,7 @@ public class YangSubModule extends YangNode ...@@ -294,6 +295,7 @@ public class YangSubModule extends YangNode
294 * 295 *
295 * @param importedModule module being imported 296 * @param importedModule module being imported
296 */ 297 */
298 + @Override
297 public void addToImportList(YangImport importedModule) { 299 public void addToImportList(YangImport importedModule) {
298 getImportList().add(importedModule); 300 getImportList().add(importedModule);
299 } 301 }
...@@ -308,6 +310,7 @@ public class YangSubModule extends YangNode ...@@ -308,6 +310,7 @@ public class YangSubModule extends YangNode
308 * 310 *
309 * @return the included list of sub modules 311 * @return the included list of sub modules
310 */ 312 */
313 + @Override
311 public List<YangInclude> getIncludeList() { 314 public List<YangInclude> getIncludeList() {
312 return includeList; 315 return includeList;
313 } 316 }
...@@ -317,6 +320,7 @@ public class YangSubModule extends YangNode ...@@ -317,6 +320,7 @@ public class YangSubModule extends YangNode
317 * 320 *
318 * @param includeModule submodule being included 321 * @param includeModule submodule being included
319 */ 322 */
323 + @Override
320 public void addToIncludeList(YangInclude includeModule) { 324 public void addToIncludeList(YangInclude includeModule) {
321 getIncludeList().add(includeModule); 325 getIncludeList().add(includeModule);
322 } 326 }
......
...@@ -21,6 +21,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; ...@@ -21,6 +21,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
22 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
23 23
24 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25 +
24 /*- 26 /*-
25 * Reference RFC 6020. 27 * Reference RFC 6020.
26 * 28 *
...@@ -54,7 +56,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -54,7 +56,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
54 /** 56 /**
55 * Represents data model node to maintain information defined in YANG typedef. 57 * Represents data model node to maintain information defined in YANG typedef.
56 */ 58 */
57 -public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder { 59 +public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector {
58 60
59 /** 61 /**
60 * Default value in string, needs to be converted to the target object, 62 * Default value in string, needs to be converted to the target object,
...@@ -185,7 +187,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y ...@@ -185,7 +187,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y
185 * @return the data type 187 * @return the data type
186 */ 188 */
187 public YangType<?> getTypeDefBaseType() { 189 public YangType<?> getTypeDefBaseType() {
188 - if (!(getTypeList().isEmpty())) { 190 + if (!getTypeList().isEmpty()) {
189 return getTypeList().get(0); 191 return getTypeList().get(0);
190 } 192 }
191 return null; 193 return null;
...@@ -272,4 +274,18 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y ...@@ -272,4 +274,18 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y
272 public List<YangType<?>> getTypeList() { 274 public List<YangType<?>> getTypeList() {
273 return typeList; 275 return typeList;
274 } 276 }
277 +
278 + @Override
279 + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
280 + // Asks helper to detect colliding child.
281 + detectCollidingChildUtil(identifierName, dataType, this);
282 + }
283 +
284 + @Override
285 + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
286 + if (getName().equals(identifierName)) {
287 + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as typedef \""
288 + + getName() + "\"");
289 + }
290 + }
275 } 291 }
......
...@@ -271,8 +271,8 @@ public class YangUses ...@@ -271,8 +271,8 @@ public class YangUses
271 } 271 }
272 272
273 YangNode usesParentNode = getParentNodeInGenCode(this); 273 YangNode usesParentNode = getParentNodeInGenCode(this);
274 - if ((!(usesParentNode instanceof YangLeavesHolder)) 274 + if (!(usesParentNode instanceof YangLeavesHolder)
275 - || (!(usesParentNode instanceof CollisionDetector))) { 275 + || !(usesParentNode instanceof CollisionDetector)) {
276 throw new LinkerException("Linker Exception: YANG uses holder construct is wrong"); 276 throw new LinkerException("Linker Exception: YANG uses holder construct is wrong");
277 } 277 }
278 278
......
...@@ -65,8 +65,8 @@ public final class DataModelUtils { ...@@ -65,8 +65,8 @@ public final class DataModelUtils {
65 while (node != null) { 65 while (node != null) {
66 Parsable parsable = (Parsable) node; 66 Parsable parsable = (Parsable) node;
67 if (node instanceof CollisionDetector 67 if (node instanceof CollisionDetector
68 - && (parsable.getYangConstructType() != YangConstructType.USES_DATA) 68 + && parsable.getYangConstructType() != YangConstructType.USES_DATA
69 - && (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) { 69 + && parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) {
70 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); 70 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
71 } 71 }
72 node = node.getNextSibling(); 72 node = node.getNextSibling();
...@@ -90,7 +90,7 @@ public final class DataModelUtils { ...@@ -90,7 +90,7 @@ public final class DataModelUtils {
90 while (node != null) { 90 while (node != null) {
91 Parsable parsable = (Parsable) node; 91 Parsable parsable = (Parsable) node;
92 if (node instanceof CollisionDetector 92 if (node instanceof CollisionDetector
93 - && (parsable.getYangConstructType() == dataType)) { 93 + && parsable.getYangConstructType() == dataType) {
94 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); 94 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
95 } 95 }
96 node = node.getNextSibling(); 96 node = node.getNextSibling();
......
...@@ -34,6 +34,8 @@ import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_ ...@@ -34,6 +34,8 @@ import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_
34 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED; 34 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
35 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED; 35 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
36 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED; 36 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
37 +import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
38 +import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
37 39
38 /** 40 /**
39 * Represents resolution object which will be resolved by linker. 41 * Represents resolution object which will be resolved by linker.
...@@ -180,9 +182,14 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -180,9 +182,14 @@ public class YangResolutionInfo<T> implements LocationInfo {
180 182
181 if (resolvable.getResolvableStatus() == UNRESOLVED) { 183 if (resolvable.getResolvableStatus() == UNRESOLVED) {
182 // If current entity is still not resolved, then linking/resolution has failed. 184 // If current entity is still not resolved, then linking/resolution has failed.
185 + String errorInfo;
186 + if (resolvable instanceof YangType) {
187 + errorInfo = TYPEDEF_LINKER_ERROR;
188 + } else {
189 + errorInfo = GROUPING_LINKER_ERROR;
190 + }
183 DataModelException dataModelException = 191 DataModelException dataModelException =
184 - new DataModelException("YANG file error: Unable to find base " 192 + new DataModelException(errorInfo);
185 - + "typedef/grouping for given type/uses");
186 dataModelException.setLine(getLineNumber()); 193 dataModelException.setLine(getLineNumber());
187 dataModelException.setCharPosition(getCharPosition()); 194 dataModelException.setCharPosition(getCharPosition());
188 throw dataModelException; 195 throw dataModelException;
...@@ -689,7 +696,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -689,7 +696,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
689 * Check if prefix is null or not, to identify whether to search 696 * Check if prefix is null or not, to identify whether to search
690 * in import list or include list. 697 * in import list or include list.
691 */ 698 */
692 - if (getRefPrefix() != null && !(getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix()))) { 699 + if (getRefPrefix() != null && !getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
693 if (resolveWithImport()) { 700 if (resolveWithImport()) {
694 return; 701 return;
695 } 702 }
......
...@@ -45,6 +45,8 @@ import org.onosproject.yangutils.datamodel.YangBits; ...@@ -45,6 +45,8 @@ import org.onosproject.yangutils.datamodel.YangBits;
45 import org.onosproject.yangutils.datamodel.YangLeaf; 45 import org.onosproject.yangutils.datamodel.YangLeaf;
46 import org.onosproject.yangutils.datamodel.YangLeafList; 46 import org.onosproject.yangutils.datamodel.YangLeafList;
47 import org.onosproject.yangutils.datamodel.YangType; 47 import org.onosproject.yangutils.datamodel.YangType;
48 +import org.onosproject.yangutils.datamodel.YangTypeDef;
49 +import org.onosproject.yangutils.datamodel.YangUnion;
48 import org.onosproject.yangutils.parser.Parsable; 50 import org.onosproject.yangutils.parser.Parsable;
49 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 51 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
50 import org.onosproject.yangutils.parser.exceptions.ParserException; 52 import org.onosproject.yangutils.parser.exceptions.ParserException;
...@@ -101,6 +103,12 @@ public final class BitsListener { ...@@ -101,6 +103,12 @@ public final class BitsListener {
101 case LEAF_LIST_DATA: 103 case LEAF_LIST_DATA:
102 bitsNode.setBitsName(((YangLeafList) tmpData).getName()); 104 bitsNode.setBitsName(((YangLeafList) tmpData).getName());
103 break; 105 break;
106 + case TYPEDEF_DATA:
107 + bitsNode.setBitsName(((YangTypeDef) tmpData).getName());
108 + break;
109 + case UNION_DATA:
110 + bitsNode.setBitsName(((YangUnion) tmpData).getName());
111 + break;
104 // TODO typedef, union, deviate. 112 // TODO typedef, union, deviate.
105 default: 113 default:
106 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, 114 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
......
...@@ -138,8 +138,8 @@ public final class EnumerationListener { ...@@ -138,8 +138,8 @@ public final class EnumerationListener {
138 * integer number, this is done because under union there 138 * integer number, this is done because under union there
139 * could be multiple child union types. 139 * could be multiple child union types.
140 */ 140 */
141 - enumerationNode.setName(yangUnion.getName() + yangUnion.getChildUnionNumber() 141 + enumerationNode.setName(yangUnion.getName() + ENUMERATION_CLASS_SUFFIX
142 - + ENUMERATION_CLASS_SUFFIX); 142 + + yangUnion.getChildUnionNumber());
143 // Increment the running number. 143 // Increment the running number.
144 yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1); 144 yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1);
145 // Add union as a child to parent union. 145 // Add union as a child to parent union.
......
...@@ -106,7 +106,16 @@ public final class MaxElementsListener { ...@@ -106,7 +106,16 @@ public final class MaxElementsListener {
106 if (value.equals(UNBOUNDED_KEYWORD)) { 106 if (value.equals(UNBOUNDED_KEYWORD)) {
107 maxElementsValue = Integer.MAX_VALUE; 107 maxElementsValue = Integer.MAX_VALUE;
108 } else if (value.matches(POSITIVE_INTEGER_PATTERN)) { 108 } else if (value.matches(POSITIVE_INTEGER_PATTERN)) {
109 - maxElementsValue = Integer.parseInt(value); 109 + try {
110 + maxElementsValue = Integer.parseInt(value);
111 + } catch (NumberFormatException e) {
112 + ParserException parserException = new ParserException("YANG file error : " +
113 + YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " +
114 + "valid.");
115 + parserException.setLine(ctx.getStart().getLine());
116 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
117 + throw parserException;
118 + }
110 } else { 119 } else {
111 ParserException parserException = new ParserException("YANG file error : " + 120 ParserException parserException = new ParserException("YANG file error : " +
112 YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " + 121 YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " +
......
...@@ -35,6 +35,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; ...@@ -35,6 +35,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
35 35
36 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; 36 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
37 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode; 37 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
...@@ -117,6 +118,11 @@ public final class TypeDefListener { ...@@ -117,6 +118,11 @@ public final class TypeDefListener {
117 // Validate sub statement cardinality. 118 // Validate sub statement cardinality.
118 validateSubStatementsCardinality(ctx); 119 validateSubStatementsCardinality(ctx);
119 120
121 + // Check for identifier collision
122 + int line = ctx.getStart().getLine();
123 + int charPositionInLine = ctx.getStart().getCharPositionInLine();
124 + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, TYPEDEF_DATA);
125 +
120 /* 126 /*
121 * Create a derived type information, the base type must be set in type 127 * Create a derived type information, the base type must be set in type
122 * listener. 128 * listener.
......
...@@ -34,12 +34,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; ...@@ -34,12 +34,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
34 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 34 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
35 import static org.onosproject.yangutils.utils.UtilConstants.COLON; 35 import static org.onosproject.yangutils.utils.UtilConstants.COLON;
36 import static org.onosproject.yangutils.utils.UtilConstants.CARET; 36 import static org.onosproject.yangutils.utils.UtilConstants.CARET;
37 +import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
37 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; 38 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
38 import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; 39 import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
39 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 40 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
40 import static org.onosproject.yangutils.utils.UtilConstants.TRUE; 41 import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
41 import static org.onosproject.yangutils.utils.UtilConstants.FALSE; 42 import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
42 import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; 43 import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
44 +import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
45 +import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
46 +import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER;
43 47
44 /** 48 /**
45 * Represents an utility for listener. 49 * Represents an utility for listener.
...@@ -50,6 +54,7 @@ public final class ListenerUtil { ...@@ -50,6 +54,7 @@ public final class ListenerUtil {
50 private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; 54 private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])";
51 private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; 55 private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+";
52 private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+"); 56 private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+");
57 + private static final String XML = "xml";
53 private static final String ONE = "1"; 58 private static final String ONE = "1";
54 private static final int IDENTIFIER_LENGTH = 64; 59 private static final int IDENTIFIER_LENGTH = 64;
55 private static final String DATE_FORMAT = "yyyy-MM-dd"; 60 private static final String DATE_FORMAT = "yyyy-MM-dd";
...@@ -98,6 +103,10 @@ public final class ListenerUtil { ...@@ -98,6 +103,10 @@ public final class ListenerUtil {
98 parserException = new ParserException("YANG file error : " + 103 parserException = new ParserException("YANG file error : " +
99 YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " + 104 YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " +
100 "valid."); 105 "valid.");
106 + } else if (identifierString.toLowerCase().startsWith(XML)) {
107 + parserException = new ParserException("YANG file error : " +
108 + YangConstructType.getYangConstructType(yangConstruct) + " identifier " + identifierString +
109 + " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
101 } else { 110 } else {
102 return identifierString; 111 return identifierString;
103 } 112 }
...@@ -171,7 +180,18 @@ public final class ListenerUtil { ...@@ -171,7 +180,18 @@ public final class ListenerUtil {
171 throw parserException; 180 throw parserException;
172 } 181 }
173 182
174 - return Integer.parseInt(value); 183 + int valueInInteger;
184 + try {
185 + valueInInteger = Integer.parseInt(value);
186 + } catch (NumberFormatException e) {
187 + ParserException parserException = new ParserException("YANG file error : " +
188 + YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
189 + "valid.");
190 + parserException.setLine(ctx.getStart().getLine());
191 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
192 + throw parserException;
193 + }
194 + return valueInInteger;
175 } 195 }
176 196
177 /** 197 /**
...@@ -263,6 +283,7 @@ public final class ListenerUtil { ...@@ -263,6 +283,7 @@ public final class ListenerUtil {
263 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); 283 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
264 if (tmpData.length == 1) { 284 if (tmpData.length == 1) {
265 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); 285 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
286 + checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
266 nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx)); 287 nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
267 return nodeIdentifier; 288 return nodeIdentifier;
268 } else if (tmpData.length == 2) { 289 } else if (tmpData.length == 2) {
...@@ -281,6 +302,30 @@ public final class ListenerUtil { ...@@ -281,6 +302,30 @@ public final class ListenerUtil {
281 } 302 }
282 303
283 /** 304 /**
305 + * Checks whether the type is an unsupported type.
306 + *
307 + * @param typeName name of the type
308 + * @param yangConstruct yang construct to check if it is type
309 + * @param ctx yang construct's context to get the line number and character position
310 + */
311 + private static void checkForUnsupportedTypes(String typeName,
312 + YangConstructType yangConstruct, ParserRuleContext ctx) {
313 +
314 + if (yangConstruct == YangConstructType.TYPE_DATA) {
315 + if (typeName.equalsIgnoreCase(LEAFREF)) {
316 + handleUnsupportedYangConstruct(YangConstructType.LEAFREF_DATA,
317 + ctx, CURRENTLY_UNSUPPORTED);
318 + } else if (typeName.equalsIgnoreCase(IDENTITYREF)) {
319 + handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
320 + ctx, CURRENTLY_UNSUPPORTED);
321 + } else if (typeName.equalsIgnoreCase(INSTANCE_IDENTIFIER)) {
322 + handleUnsupportedYangConstruct(YangConstructType.INSTANCE_IDENTIFIER_DATA,
323 + ctx, CURRENTLY_UNSUPPORTED);
324 + }
325 + }
326 + }
327 +
328 + /**
284 * Checks and return valid absolute schema node id. 329 * Checks and return valid absolute schema node id.
285 * 330 *
286 * @param argumentString string from yang file 331 * @param argumentString string from yang file
......
...@@ -21,6 +21,7 @@ import java.util.HashSet; ...@@ -21,6 +21,7 @@ import java.util.HashSet;
21 import java.util.Iterator; 21 import java.util.Iterator;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Set; 23 import java.util.Set;
24 +
24 import org.apache.maven.plugin.AbstractMojo; 25 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException; 26 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException; 27 import org.apache.maven.plugin.MojoFailureException;
...@@ -35,7 +36,6 @@ import org.onosproject.yangutils.linker.impl.YangLinkerManager; ...@@ -35,7 +36,6 @@ import org.onosproject.yangutils.linker.impl.YangLinkerManager;
35 import org.onosproject.yangutils.parser.YangUtilsParser; 36 import org.onosproject.yangutils.parser.YangUtilsParser;
36 import org.onosproject.yangutils.parser.exceptions.ParserException; 37 import org.onosproject.yangutils.parser.exceptions.ParserException;
37 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 38 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
38 -import org.onosproject.yangutils.translator.exception.TranslatorException;
39 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 39 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
40 import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; 40 import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
41 import org.onosproject.yangutils.utils.io.impl.YangFileScanner; 41 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
...@@ -69,6 +69,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -69,6 +69,7 @@ public class YangUtilManager extends AbstractMojo {
69 private Set<YangFileInfo> yangFileInfoSet = new HashSet<>(); 69 private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
70 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); 70 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
71 private YangLinker yangLinker = new YangLinkerManager(); 71 private YangLinker yangLinker = new YangLinkerManager();
72 + private YangFileInfo curYangFileInfo = new YangFileInfo();
72 73
73 private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); 74 private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
74 75
...@@ -121,6 +122,12 @@ public class YangUtilManager extends AbstractMojo { ...@@ -121,6 +122,12 @@ public class YangUtilManager extends AbstractMojo {
121 private String replacementForHyphen; 122 private String replacementForHyphen;
122 123
123 /** 124 /**
125 + * Prefix which is required for adding with the identifier.
126 + */
127 + @Parameter(property = "prefixForIdentifier")
128 + private String prefixForIdentifier;
129 +
130 + /**
124 * Build context. 131 * Build context.
125 */ 132 */
126 @Component 133 @Component
...@@ -145,6 +152,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -145,6 +152,7 @@ public class YangUtilManager extends AbstractMojo {
145 conflictResolver.setReplacementForPeriod(replacementForPeriod); 152 conflictResolver.setReplacementForPeriod(replacementForPeriod);
146 conflictResolver.setReplacementForHyphen(replacementForHyphen); 153 conflictResolver.setReplacementForHyphen(replacementForHyphen);
147 conflictResolver.setReplacementForUnderscore(replacementForUnderscore); 154 conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
155 + conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
148 YangPluginConfig yangPlugin = new YangPluginConfig(); 156 YangPluginConfig yangPlugin = new YangPluginConfig();
149 yangPlugin.setCodeGenDir(codeGenDir); 157 yangPlugin.setCodeGenDir(codeGenDir);
150 yangPlugin.setConflictResolver(conflictResolver); 158 yangPlugin.setConflictResolver(conflictResolver);
...@@ -161,7 +169,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -161,7 +169,7 @@ public class YangUtilManager extends AbstractMojo {
161 return; 169 return;
162 } 170 }
163 171
164 - //Carry out the parsing for all the YANG files. 172 + // Carry out the parsing for all the YANG files.
165 parseYangFileInfoSet(); 173 parseYangFileInfoSet();
166 174
167 // Resolve dependencies using linker. 175 // Resolve dependencies using linker.
...@@ -170,13 +178,13 @@ public class YangUtilManager extends AbstractMojo { ...@@ -170,13 +178,13 @@ public class YangUtilManager extends AbstractMojo {
170 // Perform translation to JAVA. 178 // Perform translation to JAVA.
171 translateToJava(getYangFileInfoSet(), yangPlugin); 179 translateToJava(getYangFileInfoSet(), yangPlugin);
172 180
173 - addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); 181 + addToSource(getDirectory(baseDir, genFilesDir), project, context);
174 182
175 copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); 183 copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
176 - } catch (Exception e) { 184 + } catch (IOException | ParserException e) {
177 String fileName = ""; 185 String fileName = "";
178 - if (e instanceof TranslatorException) { 186 + if (getCurYangFileInfo() != null) {
179 - fileName = ((TranslatorException) e).getFileName(); 187 + fileName = getCurYangFileInfo().getYangFileName();
180 } 188 }
181 try { 189 try {
182 translatorErrorHandler(getRootNode()); 190 translatorErrorHandler(getRootNode());
...@@ -198,6 +206,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -198,6 +206,7 @@ public class YangUtilManager extends AbstractMojo {
198 */ 206 */
199 public void resolveDependenciesUsingLinker() throws MojoExecutionException { 207 public void resolveDependenciesUsingLinker() throws MojoExecutionException {
200 for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { 208 for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
209 + setCurYangFileInfo(yangFileInfo);
201 try { 210 try {
202 yangLinker.resolveDependencies(getYangFileInfoSet()); 211 yangLinker.resolveDependencies(getYangFileInfoSet());
203 } catch (LinkerException e) { 212 } catch (LinkerException e) {
...@@ -213,6 +222,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -213,6 +222,7 @@ public class YangUtilManager extends AbstractMojo {
213 */ 222 */
214 public void parseYangFileInfoSet() throws IOException { 223 public void parseYangFileInfoSet() throws IOException {
215 for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { 224 for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
225 + setCurYangFileInfo(yangFileInfo);
216 try { 226 try {
217 YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName()); 227 YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
218 yangFileInfo.setRootNode(yangNode); 228 yangFileInfo.setRootNode(yangNode);
...@@ -264,7 +274,8 @@ public class YangUtilManager extends AbstractMojo { ...@@ -264,7 +274,8 @@ public class YangUtilManager extends AbstractMojo {
264 Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator(); 274 Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
265 while (yangFileIterator.hasNext()) { 275 while (yangFileIterator.hasNext()) {
266 YangFileInfo yangFileInfo = yangFileIterator.next(); 276 YangFileInfo yangFileInfo = yangFileIterator.next();
267 - generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName()); 277 + setCurYangFileInfo(yangFileInfo);
278 + generateJavaCode(yangFileInfo.getRootNode(), yangPlugin);
268 } 279 }
269 } 280 }
270 281
...@@ -298,4 +309,22 @@ public class YangUtilManager extends AbstractMojo { ...@@ -298,4 +309,22 @@ public class YangUtilManager extends AbstractMojo {
298 public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) { 309 public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
299 this.yangFileInfoSet = yangFileInfoSet; 310 this.yangFileInfoSet = yangFileInfoSet;
300 } 311 }
312 +
313 + /**
314 + * Returns current YANG file's info.
315 + *
316 + * @return the yangFileInfo
317 + */
318 + public YangFileInfo getCurYangFileInfo() {
319 + return curYangFileInfo;
320 + }
321 +
322 + /**
323 + * Sets current YANG file's info.
324 + *
325 + * @param yangFileInfo the yangFileInfo to set
326 + */
327 + public void setCurYangFileInfo(YangFileInfo yangFileInfo) {
328 + this.curYangFileInfo = yangFileInfo;
329 + }
301 } 330 }
......
...@@ -84,6 +84,11 @@ public final class GeneratedJavaFileType { ...@@ -84,6 +84,11 @@ public final class GeneratedJavaFileType {
84 public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512; 84 public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
85 85
86 /** 86 /**
87 + * Event listener class.
88 + */
89 + public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
90 +
91 + /**
87 * Creates an instance of generate java file type. 92 * Creates an instance of generate java file type.
88 */ 93 */
89 private GeneratedJavaFileType() { 94 private GeneratedJavaFileType() {
......
...@@ -97,6 +97,31 @@ public final class GeneratedTempFileType { ...@@ -97,6 +97,31 @@ public final class GeneratedTempFileType {
97 public static final int RPC_IMPL_MASK = 16384; 97 public static final int RPC_IMPL_MASK = 16384;
98 98
99 /** 99 /**
100 + * Event enum implementation of class.
101 + */
102 + public static final int EVENT_ENUM_MASK = 32768;
103 +
104 + /**
105 + * Event method implementation of class.
106 + */
107 + public static final int EVENT_METHOD_MASK = 65536;
108 +
109 + /**
110 + * Event subject attribute implementation of class.
111 + */
112 + public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 131072;
113 +
114 + /**
115 + * Event subject getter implementation of class.
116 + */
117 + public static final int EVENT_SUBJECT_GETTER_MASK = 262144;
118 +
119 + /**
120 + * Event subject setter implementation of class.
121 + */
122 + public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
123 +
124 + /**
100 * Creates an instance of generated temp file type. 125 * Creates an instance of generated temp file type.
101 */ 126 */
102 private GeneratedTempFileType() { 127 private GeneratedTempFileType() {
......
...@@ -66,11 +66,10 @@ public final class JavaCodeGeneratorUtil { ...@@ -66,11 +66,10 @@ public final class JavaCodeGeneratorUtil {
66 * 66 *
67 * @param rootNode root node of the data model tree 67 * @param rootNode root node of the data model tree
68 * @param yangPlugin YANG plugin config 68 * @param yangPlugin YANG plugin config
69 - * @param fileName YANG file name
70 * @throws TranslatorException when fails to generate java code file the current 69 * @throws TranslatorException when fails to generate java code file the current
71 * node 70 * node
72 */ 71 */
73 - public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName) 72 + public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
74 throws TranslatorException { 73 throws TranslatorException {
75 74
76 YangNode codeGenNode = rootNode; 75 YangNode codeGenNode = rootNode;
...@@ -78,33 +77,18 @@ public final class JavaCodeGeneratorUtil { ...@@ -78,33 +77,18 @@ public final class JavaCodeGeneratorUtil {
78 77
79 while (codeGenNode != null) { 78 while (codeGenNode != null) {
80 if (curTraversal != PARENT) { 79 if (curTraversal != PARENT) {
81 - if (codeGenNode instanceof JavaCodeGenerator) { 80 + setCurNode(codeGenNode);
82 - setCurNode(codeGenNode); 81 + generateCodeEntry(codeGenNode, yangPlugin);
83 - generateCodeEntry(codeGenNode, yangPlugin, fileName);
84 - } else {
85 - /*
86 - * For grouping and uses, there is no code generation, skip the generation for the child.
87 - */
88 - if (codeGenNode.getNextSibling() != null) {
89 - curTraversal = SIBILING;
90 - codeGenNode = codeGenNode.getNextSibling();
91 - } else {
92 - curTraversal = PARENT;
93 - codeGenNode = codeGenNode.getParent();
94 - }
95 - continue;
96 - }
97 -
98 } 82 }
99 if (curTraversal != PARENT && codeGenNode.getChild() != null) { 83 if (curTraversal != PARENT && codeGenNode.getChild() != null) {
100 curTraversal = CHILD; 84 curTraversal = CHILD;
101 codeGenNode = codeGenNode.getChild(); 85 codeGenNode = codeGenNode.getChild();
102 } else if (codeGenNode.getNextSibling() != null) { 86 } else if (codeGenNode.getNextSibling() != null) {
103 - generateCodeExit(codeGenNode, fileName); 87 + generateCodeExit(codeGenNode);
104 curTraversal = SIBILING; 88 curTraversal = SIBILING;
105 codeGenNode = codeGenNode.getNextSibling(); 89 codeGenNode = codeGenNode.getNextSibling();
106 } else { 90 } else {
107 - generateCodeExit(codeGenNode, fileName); 91 + generateCodeExit(codeGenNode);
108 curTraversal = PARENT; 92 curTraversal = PARENT;
109 codeGenNode = codeGenNode.getParent(); 93 codeGenNode = codeGenNode.getParent();
110 } 94 }
...@@ -117,20 +101,17 @@ public final class JavaCodeGeneratorUtil { ...@@ -117,20 +101,17 @@ public final class JavaCodeGeneratorUtil {
117 * @param codeGenNode current data model node for which the code needs to be 101 * @param codeGenNode current data model node for which the code needs to be
118 * generated 102 * generated
119 * @param yangPlugin YANG plugin config 103 * @param yangPlugin YANG plugin config
120 - * @param fileName YANG file name
121 * @throws TranslatorException when fails to generate java code file the current 104 * @throws TranslatorException when fails to generate java code file the current
122 * node 105 * node
123 */ 106 */
124 - private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName) 107 + private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
125 throws TranslatorException { 108 throws TranslatorException {
126 109
127 if (codeGenNode instanceof JavaCodeGenerator) { 110 if (codeGenNode instanceof JavaCodeGenerator) {
128 ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); 111 ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
129 } else { 112 } else {
130 - TranslatorException ex = new TranslatorException( 113 + throw new TranslatorException(
131 "Generated data model node cannot be translated to target language code"); 114 "Generated data model node cannot be translated to target language code");
132 - ex.setFileName(fileName);
133 - throw ex;
134 } 115 }
135 } 116 }
136 117
...@@ -139,19 +120,16 @@ public final class JavaCodeGeneratorUtil { ...@@ -139,19 +120,16 @@ public final class JavaCodeGeneratorUtil {
139 * 120 *
140 * @param codeGenNode current data model node for which the code needs to be 121 * @param codeGenNode current data model node for which the code needs to be
141 * generated 122 * generated
142 - * @param fileName YANG file name
143 * @throws TranslatorException when fails to generate java code file the current 123 * @throws TranslatorException when fails to generate java code file the current
144 * node 124 * node
145 */ 125 */
146 - private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException { 126 + private static void generateCodeExit(YangNode codeGenNode) throws TranslatorException {
147 127
148 if (codeGenNode instanceof JavaCodeGenerator) { 128 if (codeGenNode instanceof JavaCodeGenerator) {
149 ((JavaCodeGenerator) codeGenNode).generateCodeExit(); 129 ((JavaCodeGenerator) codeGenNode).generateCodeExit();
150 } else { 130 } else {
151 - TranslatorException ex = new TranslatorException( 131 + throw new TranslatorException(
152 "Generated data model node cannot be translated to target language code"); 132 "Generated data model node cannot be translated to target language code");
153 - ex.setFileName(fileName);
154 - throw ex;
155 } 133 }
156 } 134 }
157 135
...@@ -162,26 +140,28 @@ public final class JavaCodeGeneratorUtil { ...@@ -162,26 +140,28 @@ public final class JavaCodeGeneratorUtil {
162 private static void freeRestResources() { 140 private static void freeRestResources() {
163 141
164 YangNode freedNode = getCurNode(); 142 YangNode freedNode = getCurNode();
165 - YangNode tempNode = freedNode; 143 + if (getCurNode() != null) {
166 - TraversalType curTraversal = ROOT; 144 + YangNode tempNode = freedNode;
167 - 145 + TraversalType curTraversal = ROOT;
168 - while (freedNode != tempNode.getParent()) { 146 +
169 - 147 + while (freedNode != tempNode.getParent()) {
170 - if (curTraversal != PARENT && freedNode.getChild() != null) { 148 +
171 - curTraversal = CHILD; 149 + if (curTraversal != PARENT && freedNode.getChild() != null) {
172 - freedNode = freedNode.getChild(); 150 + curTraversal = CHILD;
173 - } else if (freedNode.getNextSibling() != null) { 151 + freedNode = freedNode.getChild();
174 - curTraversal = SIBILING; 152 + } else if (freedNode.getNextSibling() != null) {
175 - if (freedNode != tempNode) { 153 + curTraversal = SIBILING;
176 - free(freedNode); 154 + if (freedNode != tempNode) {
177 - } 155 + free(freedNode);
178 - freedNode = freedNode.getNextSibling(); 156 + }
179 - } else { 157 + freedNode = freedNode.getNextSibling();
180 - curTraversal = PARENT; 158 + } else {
181 - if (freedNode != tempNode) { 159 + curTraversal = PARENT;
182 - free(freedNode); 160 + if (freedNode != tempNode) {
161 + free(freedNode);
162 + }
163 + freedNode = freedNode.getParent();
183 } 164 }
184 - freedNode = freedNode.getParent();
185 } 165 }
186 } 166 }
187 } 167 }
...@@ -213,36 +193,38 @@ public final class JavaCodeGeneratorUtil { ...@@ -213,36 +193,38 @@ public final class JavaCodeGeneratorUtil {
213 public static void translatorErrorHandler(YangNode rootNode) 193 public static void translatorErrorHandler(YangNode rootNode)
214 throws IOException { 194 throws IOException {
215 195
216 - /** 196 + if (rootNode != null) {
217 - * Free other resources where translator has failed. 197 + /**
218 - */ 198 + * Free other resources where translator has failed.
219 - freeRestResources(); 199 + */
200 + freeRestResources();
220 201
221 - /** 202 + /**
222 - * Start removing all open files. 203 + * Start removing all open files.
223 - */ 204 + */
224 - YangNode tempNode = rootNode; 205 + YangNode tempNode = rootNode;
225 - setCurNode(tempNode.getChild()); 206 + setCurNode(tempNode.getChild());
226 - TraversalType curTraversal = ROOT; 207 + TraversalType curTraversal = ROOT;
227 208
228 - while (tempNode != null) { 209 + while (tempNode != null) {
229 210
230 - if (curTraversal != PARENT) { 211 + if (curTraversal != PARENT) {
231 - close(tempNode); 212 + close(tempNode);
232 - } 213 + }
233 - if (curTraversal != PARENT && tempNode.getChild() != null) { 214 + if (curTraversal != PARENT && tempNode.getChild() != null) {
234 - curTraversal = CHILD; 215 + curTraversal = CHILD;
235 - tempNode = tempNode.getChild(); 216 + tempNode = tempNode.getChild();
236 - } else if (tempNode.getNextSibling() != null) { 217 + } else if (tempNode.getNextSibling() != null) {
237 - curTraversal = SIBILING; 218 + curTraversal = SIBILING;
238 - tempNode = tempNode.getNextSibling(); 219 + tempNode = tempNode.getNextSibling();
239 - } else { 220 + } else {
240 - curTraversal = PARENT; 221 + curTraversal = PARENT;
241 - tempNode = tempNode.getParent(); 222 + tempNode = tempNode.getParent();
223 + }
242 } 224 }
243 - }
244 225
245 - freeRestResources(); 226 + freeRestResources();
227 + }
246 } 228 }
247 229
248 /** 230 /**
...@@ -254,8 +236,8 @@ public final class JavaCodeGeneratorUtil { ...@@ -254,8 +236,8 @@ public final class JavaCodeGeneratorUtil {
254 */ 236 */
255 private static void close(YangNode node) 237 private static void close(YangNode node)
256 throws IOException { 238 throws IOException {
257 - 239 + if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
258 - if (((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles() != null) { 240 + .getTempJavaCodeFragmentFiles() != null) {
259 ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true); 241 ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
260 } 242 }
261 } 243 }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.yangutils.translator.tojava; 17 package org.onosproject.yangutils.translator.tojava;
18 18
19 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
20 +
19 /** 21 /**
20 * Represents cached java file handle, which supports the addition of member attributes and 22 * Represents cached java file handle, which supports the addition of member attributes and
21 * methods. 23 * methods.
...@@ -49,6 +51,11 @@ public class JavaFileInfo { ...@@ -49,6 +51,11 @@ public class JavaFileInfo {
49 private String codeGenDirFilePath; 51 private String codeGenDirFilePath;
50 52
51 /** 53 /**
54 + * Plugin configuration for naming convention.
55 + */
56 + private YangPluginConfig pluginConfig;
57 +
58 + /**
52 * Returns the types of files being generated corresponding to the YANG 59 * Returns the types of files being generated corresponding to the YANG
53 * definition. 60 * definition.
54 * 61 *
...@@ -152,4 +159,22 @@ public class JavaFileInfo { ...@@ -152,4 +159,22 @@ public class JavaFileInfo {
152 public void setBaseCodeGenPath(String path) { 159 public void setBaseCodeGenPath(String path) {
153 codeGenDirFilePath = path; 160 codeGenDirFilePath = path;
154 } 161 }
162 +
163 + /**
164 + * Returns plugin configurations.
165 + *
166 + * @return the pluginConfig
167 + */
168 + public YangPluginConfig getPluginConfig() {
169 + return pluginConfig;
170 + }
171 +
172 + /**
173 + * Sets plugin configurations.
174 + *
175 + * @param pluginConfig the pluginConfig to set
176 + */
177 + public void setPluginConfig(YangPluginConfig pluginConfig) {
178 + this.pluginConfig = pluginConfig;
179 + }
155 } 180 }
......
...@@ -22,12 +22,14 @@ import java.util.TreeSet; ...@@ -22,12 +22,14 @@ import java.util.TreeSet;
22 22
23 import static java.util.Collections.sort; 23 import static java.util.Collections.sort;
24 24
25 +import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
25 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; 26 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
26 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS; 27 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
27 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS; 28 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
28 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG; 29 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
29 import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; 30 import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
30 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 31 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
32 +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
31 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; 33 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
32 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; 34 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
33 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; 35 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
...@@ -35,10 +37,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; ...@@ -35,10 +37,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
35 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; 37 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
36 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; 38 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
37 import static org.onosproject.yangutils.utils.UtilConstants.LIST; 39 import static org.onosproject.yangutils.utils.UtilConstants.LIST;
38 -import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
39 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; 40 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
40 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; 41 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
41 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 42 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
43 +import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
42 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 44 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
43 import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG; 45 import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
44 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 46 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
...@@ -218,7 +220,7 @@ public class JavaImportData { ...@@ -218,7 +220,7 @@ public class JavaImportData {
218 * @return import string for ListenerService class 220 * @return import string for ListenerService class
219 */ 221 */
220 public String getListenerServiceImport() { 222 public String getListenerServiceImport() {
221 - return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE; 223 + return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
222 } 224 }
223 225
224 /** 226 /**
...@@ -227,6 +229,24 @@ public class JavaImportData { ...@@ -227,6 +229,24 @@ public class JavaImportData {
227 * @return import string for ListenerRegistry class 229 * @return import string for ListenerRegistry class
228 */ 230 */
229 public String getListenerRegistryImport() { 231 public String getListenerRegistryImport() {
230 - return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE; 232 + return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
233 + }
234 +
235 + /**
236 + * Returns import string for AbstractEvent class.
237 + *
238 + * @return import string for AbstractEvent class
239 + */
240 + public String getAbstractEventsImport() {
241 + return IMPORT + ONOS_EVENT_PKG + PERIOD + ABSTRACT_EVENT + SEMI_COLAN + NEW_LINE;
242 + }
243 +
244 + /**
245 + * Returns import string for EventListener class.
246 + *
247 + * @return import string for EventListener class
248 + */
249 + public String getEventListenerImport() {
250 + return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
231 } 251 }
232 } 252 }
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 22 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; 23 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
24 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; 24 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
25 26
26 import com.google.common.base.MoreObjects; 27 import com.google.common.base.MoreObjects;
27 28
...@@ -88,7 +89,7 @@ public class JavaQualifiedTypeInfo ...@@ -88,7 +89,7 @@ public class JavaQualifiedTypeInfo
88 /** 89 /**
89 * Updates the leaf's java information. 90 * Updates the leaf's java information.
90 * 91 *
91 - * @param leaf leaf whose jave information is being updated 92 + * @param leaf leaf whose java information is being updated
92 */ 93 */
93 public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) { 94 public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) {
94 95
...@@ -102,7 +103,8 @@ public class JavaQualifiedTypeInfo ...@@ -102,7 +103,8 @@ public class JavaQualifiedTypeInfo
102 * Current leaves holder is adding a leaf info as a attribute to the 103 * Current leaves holder is adding a leaf info as a attribute to the
103 * current class. 104 * current class.
104 */ 105 */
105 - String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList()); 106 + String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
107 + leaf.getConflictResolveConfig());
106 if (className != null) { 108 if (className != null) {
107 /* 109 /*
108 * Corresponding to the attribute type a class needs to be imported, 110 * Corresponding to the attribute type a class needs to be imported,
...@@ -110,7 +112,7 @@ public class JavaQualifiedTypeInfo ...@@ -110,7 +112,7 @@ public class JavaQualifiedTypeInfo
110 */ 112 */
111 importInfo.setClassInfo(className); 113 importInfo.setClassInfo(className);
112 String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(), 114 String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(),
113 - leaf.isLeafList(), className); 115 + leaf.isLeafList(), leaf.getConflictResolveConfig());
114 if (classPkg == null) { 116 if (classPkg == null) {
115 throw new TranslatorException("import package cannot be null when the class is used"); 117 throw new TranslatorException("import package cannot be null when the class is used");
116 } 118 }
...@@ -163,19 +165,22 @@ public class JavaQualifiedTypeInfo ...@@ -163,19 +165,22 @@ public class JavaQualifiedTypeInfo
163 * Returns the java qualified type information for the wrapper classes. 165 * Returns the java qualified type information for the wrapper classes.
164 * 166 *
165 * @param referredTypesAttrInfo attribute of referred type 167 * @param referredTypesAttrInfo attribute of referred type
168 + * @param conflictResolver plugin configurations
166 * @return return the import info for this attribute 169 * @return return the import info for this attribute
167 */ 170 */
168 - public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) { 171 + public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo,
172 + YangToJavaNamingConflictUtil conflictResolver) {
169 173
170 /* 174 /*
171 * Get the java qualified type information for the wrapper classes and 175 * Get the java qualified type information for the wrapper classes and
172 * set it in new java attribute information. 176 * set it in new java attribute information.
173 */ 177 */
174 JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo(); 178 JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo();
179 +
175 qualifiedInfoOfFromString.setClassInfo( 180 qualifiedInfoOfFromString.setClassInfo(
176 - getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true)); 181 + getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, conflictResolver));
177 qualifiedInfoOfFromString.setPkgInfo( 182 qualifiedInfoOfFromString.setPkgInfo(
178 - getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null)); 183 + getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, conflictResolver));
179 return qualifiedInfoOfFromString; 184 return qualifiedInfoOfFromString;
180 } 185 }
181 186
......
...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava;
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 21
22 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
23 +
22 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 24 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
23 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; 25 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
24 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 26 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
...@@ -84,10 +86,10 @@ public class TempJavaBeanFragmentFiles ...@@ -84,10 +86,10 @@ public class TempJavaBeanFragmentFiles
84 * @param attr attribute info 86 * @param attr attribute info
85 * @throws IOException when fails to append to temporary file 87 * @throws IOException when fails to append to temporary file
86 */ 88 */
87 - private void addConstructor(JavaAttributeInfo attr) 89 + private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
88 throws IOException { 90 throws IOException {
89 appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr, 91 appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
90 - getGeneratedJavaFiles())); 92 + getGeneratedJavaFiles(), pluginConfig));
91 } 93 }
92 94
93 /** 95 /**
...@@ -98,10 +100,10 @@ public class TempJavaBeanFragmentFiles ...@@ -98,10 +100,10 @@ public class TempJavaBeanFragmentFiles
98 * @throws IOException IO operation fail 100 * @throws IOException IO operation fail
99 */ 101 */
100 @Override 102 @Override
101 - void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) 103 + void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
102 throws IOException { 104 throws IOException {
103 - super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); 105 + super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
104 - addConstructor(newAttrInfo); 106 + addConstructor(newAttrInfo, pluginConfig);
105 } 107 }
106 108
107 /** 109 /**
......
...@@ -21,10 +21,9 @@ import java.io.IOException; ...@@ -21,10 +21,9 @@ import java.io.IOException;
21 import org.onosproject.yangutils.datamodel.YangNode; 21 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.datamodel.YangTypeHolder; 22 import org.onosproject.yangutils.datamodel.YangTypeHolder;
23 import org.onosproject.yangutils.translator.exception.TranslatorException; 23 import org.onosproject.yangutils.translator.exception.TranslatorException;
24 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
24 25
25 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
26 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
27 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
...@@ -57,16 +56,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -57,16 +56,6 @@ public class TempJavaCodeFragmentFiles {
57 private TempJavaEnumerationFragmentFiles enumerationTempFiles; 56 private TempJavaEnumerationFragmentFiles enumerationTempFiles;
58 57
59 /** 58 /**
60 - * Has the temporary files required for generated event classes.
61 - */
62 - private TempJavaEventFragmentFiles eventTempFiles;
63 -
64 - /**
65 - * Has the temporary files required for generated event listenerclasses.
66 - */
67 - private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
68 -
69 - /**
70 * Creates an instance of temporary java code fragment. 59 * Creates an instance of temporary java code fragment.
71 * 60 *
72 * @param javaFileInfo generated java file info 61 * @param javaFileInfo generated java file info
...@@ -79,16 +68,10 @@ public class TempJavaCodeFragmentFiles { ...@@ -79,16 +68,10 @@ public class TempJavaCodeFragmentFiles {
79 setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo)); 68 setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo));
80 } 69 }
81 70
82 - /**
83 - * Creates user defined data type class file.
84 - */
85 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) { 71 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) {
86 setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo)); 72 setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo));
87 } 73 }
88 74
89 - /**
90 - * Creates enumeration class file.
91 - */
92 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) { 75 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) {
93 setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo)); 76 setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
94 } 77 }
...@@ -97,13 +80,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -97,13 +80,6 @@ public class TempJavaCodeFragmentFiles {
97 setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo)); 80 setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
98 } 81 }
99 82
100 - if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) {
101 - setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo));
102 - }
103 -
104 - if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
105 - setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo));
106 - }
107 } 83 }
108 84
109 /** 85 /**
...@@ -180,43 +156,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -180,43 +156,6 @@ public class TempJavaCodeFragmentFiles {
180 } 156 }
181 157
182 /** 158 /**
183 - * Retrieves the temp file handle for event file generation.
184 - *
185 - * @return temp file handle for event file generation
186 - */
187 - public TempJavaEventFragmentFiles getEventTempFiles() {
188 - return eventTempFiles;
189 - }
190 -
191 - /**
192 - * Sets temp file handle for event file generation.
193 - *
194 - * @param eventTempFiles temp file handle for event file generation
195 - */
196 - public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) {
197 - this.eventTempFiles = eventTempFiles;
198 - }
199 -
200 - /**
201 - * Retrieves the temp file handle for event listener file generation.
202 - *
203 - * @return temp file handle for event listener file generation
204 - */
205 - public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() {
206 - return eventListenerTempFiles;
207 - }
208 -
209 - /**
210 - * Sets temp file handle for event listener file generation.
211 - *
212 - * @param eventListenerTempFiles temp file handle for event listener file generation
213 - */
214 - public void setEventListenerTempFiles(
215 - TempJavaEventListenerFragmentFiles eventListenerTempFiles) {
216 - this.eventListenerTempFiles = eventListenerTempFiles;
217 - }
218 -
219 - /**
220 * Constructs java code exit. 159 * Constructs java code exit.
221 * 160 *
222 * @param fileType generated file type 161 * @param fileType generated file type
...@@ -238,7 +177,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -238,7 +177,7 @@ public class TempJavaCodeFragmentFiles {
238 } 177 }
239 178
240 /* 179 /*
241 - * Creats service and manager class file. 180 + * Creates service and manager class file.
242 */ 181 */
243 if (fileType == GENERATE_SERVICE_AND_MANAGER) { 182 if (fileType == GENERATE_SERVICE_AND_MANAGER) {
244 getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); 183 getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
...@@ -251,22 +190,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -251,22 +190,6 @@ public class TempJavaCodeFragmentFiles {
251 getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode); 190 getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
252 } 191 }
253 192
254 - if ((fileType & GENERATE_EVENT_CLASS) != 0) {
255 - /*
256 - * Creates event class file.
257 - */
258 - if (getEventTempFiles() != null) {
259 - getEventTempFiles().generateJavaFile(fileType, curNode);
260 - }
261 - }
262 -
263 - if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
264 - /**
265 - * Creates event listener class file.
266 - */
267 - getEventListenerTempFiles().generateJavaFile(fileType, curNode);
268 - }
269 -
270 freeTemporaryResources(false); 193 freeTemporaryResources(false);
271 } 194 }
272 195
...@@ -275,14 +198,16 @@ public class TempJavaCodeFragmentFiles { ...@@ -275,14 +198,16 @@ public class TempJavaCodeFragmentFiles {
275 * 198 *
276 * @param newAttrInfo the attribute info that needs to be added to temporary 199 * @param newAttrInfo the attribute info that needs to be added to temporary
277 * files 200 * files
201 + * @param pluginConfig plugin configurations
278 * @throws IOException IO operation fail 202 * @throws IOException IO operation fail
279 */ 203 */
280 - public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) 204 + public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
205 + YangPluginConfig pluginConfig)
281 throws IOException { 206 throws IOException {
282 207
283 if (getBeanTempFiles() != null) { 208 if (getBeanTempFiles() != null) {
284 getBeanTempFiles() 209 getBeanTempFiles()
285 - .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); 210 + .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
286 } 211 }
287 212
288 /** 213 /**
...@@ -290,7 +215,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -290,7 +215,7 @@ public class TempJavaCodeFragmentFiles {
290 */ 215 */
291 if (getTypeTempFiles() != null) { 216 if (getTypeTempFiles() != null) {
292 getTypeTempFiles() 217 getTypeTempFiles()
293 - .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); 218 + .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
294 } 219 }
295 } 220 }
296 221
...@@ -299,24 +224,26 @@ public class TempJavaCodeFragmentFiles { ...@@ -299,24 +224,26 @@ public class TempJavaCodeFragmentFiles {
299 * generated temporary file. 224 * generated temporary file.
300 * 225 *
301 * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef 226 * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
227 + * @param pluginConfig plugin configurations for naming convention
302 * @throws IOException IO operation fail 228 * @throws IOException IO operation fail
303 */ 229 */
304 - public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder) 230 + public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
305 throws IOException { 231 throws IOException {
306 getTypeTempFiles() 232 getTypeTempFiles()
307 - .addTypeInfoToTempFiles(yangTypeHolder); 233 + .addTypeInfoToTempFiles(yangTypeHolder, pluginConfig);
308 } 234 }
309 235
310 /** 236 /**
311 * Adds build method for interface. 237 * Adds build method for interface.
312 * 238 *
239 + * @param pluginConfig plugin configurations
313 * @return build method for interface 240 * @return build method for interface
314 * @throws IOException when fails to append to temporary file 241 * @throws IOException when fails to append to temporary file
315 */ 242 */
316 - public String addBuildMethodForInterface() 243 + public String addBuildMethodForInterface(YangPluginConfig pluginConfig)
317 throws IOException { 244 throws IOException {
318 if (getBeanTempFiles() != null) { 245 if (getBeanTempFiles() != null) {
319 - return getBeanTempFiles().addBuildMethodForInterface(); 246 + return getBeanTempFiles().addBuildMethodForInterface(pluginConfig);
320 } 247 }
321 throw new TranslatorException("build method only supported for bean class"); 248 throw new TranslatorException("build method only supported for bean class");
322 } 249 }
...@@ -326,18 +253,19 @@ public class TempJavaCodeFragmentFiles { ...@@ -326,18 +253,19 @@ public class TempJavaCodeFragmentFiles {
326 * 253 *
327 * @param modifier modifier for constructor. 254 * @param modifier modifier for constructor.
328 * @param toAppend string which need to be appended with the class name 255 * @param toAppend string which need to be appended with the class name
256 + * @param pluginConfig plugin configurations
329 * @return default constructor for class 257 * @return default constructor for class
330 * @throws IOException when fails to append to file 258 * @throws IOException when fails to append to file
331 */ 259 */
332 - public String addDefaultConstructor(String modifier, String toAppend) 260 + public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
333 throws IOException { 261 throws IOException {
334 if (getTypeTempFiles() != null) { 262 if (getTypeTempFiles() != null) {
335 return getTypeTempFiles() 263 return getTypeTempFiles()
336 - .addDefaultConstructor(modifier, toAppend); 264 + .addDefaultConstructor(modifier, toAppend, pluginConfig);
337 } 265 }
338 266
339 if (getBeanTempFiles() != null) { 267 if (getBeanTempFiles() != null) {
340 - return getBeanTempFiles().addDefaultConstructor(modifier, toAppend); 268 + return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
341 } 269 }
342 270
343 throw new TranslatorException("default constructor should not be added"); 271 throw new TranslatorException("default constructor should not be added");
...@@ -380,13 +308,10 @@ public class TempJavaCodeFragmentFiles { ...@@ -380,13 +308,10 @@ public class TempJavaCodeFragmentFiles {
380 getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred); 308 getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
381 } 309 }
382 310
383 - if (getEventTempFiles() != null) { 311 + if (getServiceTempFiles() != null) {
384 - getEventTempFiles().freeTemporaryResources(isErrorOccurred); 312 + getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
385 } 313 }
386 314
387 - if (getEventListenerTempFiles() != null) {
388 - getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred);
389 - }
390 } 315 }
391 316
392 } 317 }
......
...@@ -28,13 +28,18 @@ import org.onosproject.yangutils.datamodel.YangEnumeration; ...@@ -28,13 +28,18 @@ import org.onosproject.yangutils.datamodel.YangEnumeration;
28 import org.onosproject.yangutils.datamodel.YangNode; 28 import org.onosproject.yangutils.datamodel.YangNode;
29 import org.onosproject.yangutils.translator.exception.TranslatorException; 29 import org.onosproject.yangutils.translator.exception.TranslatorException;
30 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; 30 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
31 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
31 32
32 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
33 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; 34 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
34 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; 35 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
35 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; 36 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
37 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
38 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPrefixForIdentifier;
36 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 39 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
37 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 40 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
41 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
42 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
38 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 43 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
39 44
40 /** 45 /**
...@@ -172,29 +177,41 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { ...@@ -172,29 +177,41 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
172 /** 177 /**
173 * Adds enum class attributes to temporary file. 178 * Adds enum class attributes to temporary file.
174 * 179 *
175 - * @param curEnumInfo current YANG enum 180 + * @param curEnumName current YANG enum
176 * @throws IOException when fails to do IO operations. 181 * @throws IOException when fails to do IO operations.
177 */ 182 */
178 - private void addAttributesForEnumClass(String curEnumName) throws IOException { 183 + private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException {
179 - appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue())); 184 + appendToFile(getEnumClassTempFileHandle(),
185 + generateEnumAttributeString(curEnumName, getEnumValue(), pluginConfig));
180 } 186 }
181 187
182 /** 188 /**
183 * Adds enum attributes to temporary files. 189 * Adds enum attributes to temporary files.
184 * 190 *
185 * @param curNode current YANG node 191 * @param curNode current YANG node
192 + * @param pluginConfig plugin configurations
186 * @throws IOException when fails to do IO operations 193 * @throws IOException when fails to do IO operations
187 */ 194 */
188 - public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException { 195 + public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
189 196
190 - super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum()); 197 + super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
191 if (curNode instanceof YangEnumeration) { 198 if (curNode instanceof YangEnumeration) {
192 YangEnumeration enumeration = (YangEnumeration) curNode; 199 YangEnumeration enumeration = (YangEnumeration) curNode;
193 for (YangEnum curEnum : enumeration.getEnumSet()) { 200 for (YangEnum curEnum : enumeration.getEnumSet()) {
201 + String enumName = curEnum.getNamedValue();
202 + String prefixForIdentifier = null;
203 + if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) {
204 + prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver());
205 + if (prefixForIdentifier != null) {
206 + curEnum.setNamedValue(prefixForIdentifier + enumName);
207 + } else {
208 + curEnum.setNamedValue(YANG_AUTO_PREFIX + enumName);
209 + }
210 + }
194 setEnumValue(curEnum.getValue()); 211 setEnumValue(curEnum.getValue());
195 addToEnumStringList(curEnum.getNamedValue()); 212 addToEnumStringList(curEnum.getNamedValue());
196 addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); 213 addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue());
197 - addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue()); 214 + addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue(), pluginConfig);
198 } 215 }
199 } else { 216 } else {
200 throw new TranslatorException("current node should be of enumeration type."); 217 throw new TranslatorException("current node should be of enumeration type.");
...@@ -204,13 +221,14 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { ...@@ -204,13 +221,14 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
204 /** 221 /**
205 * Returns java attribute for enum class. 222 * Returns java attribute for enum class.
206 * 223 *
224 + * @param pluginConfig plugin configurations
207 * @return java attribute 225 * @return java attribute
208 */ 226 */
209 - public JavaAttributeInfo getJavaAttributeForEnum() { 227 + public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
210 YangJavaType<?> javaType = new YangJavaType<>(); 228 YangJavaType<?> javaType = new YangJavaType<>();
211 javaType.setDataType(YangDataTypes.INT32); 229 javaType.setDataType(YangDataTypes.INT32);
212 javaType.setDataTypeName("int"); 230 javaType.setDataTypeName("int");
213 - javaType.updateJavaQualifiedInfo(); 231 + javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
214 return getAttributeInfoForTheData( 232 return getAttributeInfoForTheData(
215 javaType.getJavaQualifiedInfo(), 233 javaType.getJavaQualifiedInfo(),
216 javaType.getDataTypeName(), javaType, 234 javaType.getDataTypeName(), javaType,
...@@ -224,7 +242,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { ...@@ -224,7 +242,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
224 * @param curEnumName current enum name 242 * @param curEnumName current enum name
225 */ 243 */
226 private void addToEnumSetJavaMap(String curEnumName, int value) { 244 private void addToEnumSetJavaMap(String curEnumName, int value) {
227 - getEnumSetJavaMap().put(curEnumName.toUpperCase(), value); 245 + getEnumSetJavaMap().put(getEnumJavaAttribute(curEnumName).toUpperCase(), value);
228 } 246 }
229 247
230 /** 248 /**
...@@ -234,8 +252,9 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { ...@@ -234,8 +252,9 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
234 * files 252 * files
235 * @throws IOException IO operation fail 253 * @throws IOException IO operation fail
236 */ 254 */
237 - void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException { 255 + void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
238 - addAttributesForEnumClass(curEnumName); 256 + throws IOException {
257 + addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig);
239 } 258 }
240 259
241 /** 260 /**
...@@ -274,7 +293,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { ...@@ -274,7 +293,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
274 * @param curEnumValue current enum value 293 * @param curEnumValue current enum value
275 */ 294 */
276 private void addToEnumStringList(String curEnumValue) { 295 private void addToEnumStringList(String curEnumValue) {
277 - getEnumStringList().add(curEnumValue.toUpperCase()); 296 + getEnumStringList().add(getEnumJavaAttribute(curEnumValue).toUpperCase());
278 } 297 }
279 298
280 /** 299 /**
......
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.yangutils.translator.tojava;
18 -
19 -import java.io.File;
20 -import java.io.IOException;
21 -
22 -import org.onosproject.yangutils.datamodel.YangNode;
23 -import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
24 -
25 -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
26 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
27 -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
28 -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
29 -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
30 -
31 -/**
32 - * Represents implementation of java bean code fragments temporary implementations.
33 - * Maintains the temp files required specific for event java snippet generation.
34 - */
35 -public class TempJavaEventFragmentFiles
36 - extends TempJavaFragmentFiles {
37 -
38 - /**
39 - * File name for generated class file for special type like union, typedef
40 - * suffix.
41 - */
42 - private static final String EVENT_FILE_NAME_SUFFIX = "Event";
43 -
44 - /**
45 - * Java file handle for event file.
46 - */
47 - private File eventJavaFileHandle;
48 -
49 - /**
50 - * Creates an instance of temporary java code fragment.
51 - *
52 - * @param javaFileInfo generated java file info
53 - * @throws IOException when fails to create new file handle
54 - */
55 - public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
56 - throws IOException {
57 - setJavaExtendsListHolder(new JavaExtendsListHolder());
58 - setJavaImportData(new JavaImportData());
59 - setJavaFileInfo(javaFileInfo);
60 -
61 - setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
62 - getJavaFileInfo().getPackageFilePath()));
63 -
64 - }
65 -
66 - /**
67 - * Returns event's java file handle.
68 - *
69 - * @return java file handle
70 - */
71 - private File getEventJavaFileHandle() {
72 - return eventJavaFileHandle;
73 - }
74 -
75 - /**
76 - * Sets event's java file handle.
77 - *
78 - * @param eventJavaFileHandle file handle for event
79 - */
80 - private void setEventJavaFileHandle(File eventJavaFileHandle) {
81 - this.eventJavaFileHandle = eventJavaFileHandle;
82 - }
83 -
84 - /**
85 - * Constructs java code exit.
86 - *
87 - * @param fileType generated file type
88 - * @param curNode current YANG node
89 - * @throws IOException when fails to generate java files
90 - */
91 - @Override
92 - public void generateJavaFile(int fileType, YangNode curNode)
93 - throws IOException {
94 -
95 - createPackage(curNode);
96 - String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
97 - .getJavaFileInfo().getJavaName());
98 -
99 - /**
100 - * Creates event interface file.
101 - */
102 - setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX));
103 - generateEventFile(getEventJavaFileHandle(), curNode, null);
104 -
105 - /**
106 - * Close all the file handles.
107 - */
108 - freeTemporaryResources(false);
109 - }
110 -
111 - /**
112 - * Removes all temporary file handles.
113 - *
114 - * @param isErrorOccurred when translator fails to generate java files we
115 - * need to close all open file handles include temporary files
116 - * and java files.
117 - * @throws IOException when failed to delete the temporary files
118 - */
119 - @Override
120 - public void freeTemporaryResources(boolean isErrorOccurred)
121 - throws IOException {
122 - boolean isError = isErrorOccurred;
123 - /**
124 - * Close all java file handles and when error occurs delete the files.
125 - */
126 - closeFile(getEventJavaFileHandle(), isError);
127 -
128 - super.freeTemporaryResources(isErrorOccurred);
129 -
130 - }
131 -}
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.yangutils.translator.tojava;
18 -
19 -import java.io.File;
20 -import java.io.IOException;
21 -
22 -import org.onosproject.yangutils.datamodel.YangNode;
23 -import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
24 -
25 -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
26 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
27 -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
28 -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
29 -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
30 -
31 -/**
32 - * Represents implementation of java bean code fragments temporary implementations.
33 - * Maintains the temp files required specific for event listener java snippet generation.
34 - */
35 -public class TempJavaEventListenerFragmentFiles
36 - extends TempJavaFragmentFiles {
37 -
38 - /**
39 - * File name for generated class file for special type like union, typedef
40 - * suffix.
41 - */
42 - private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
43 -
44 - /**
45 - * Java file handle for event listener file.
46 - */
47 - private File eventListenerJavaFileHandle;
48 -
49 - /**
50 - * Creates an instance of temporary java code fragment.
51 - *
52 - * @param javaFileInfo generated java file info
53 - * @throws IOException when fails to create new file handle
54 - */
55 - public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
56 - throws IOException {
57 - setJavaExtendsListHolder(new JavaExtendsListHolder());
58 - setJavaImportData(new JavaImportData());
59 - setJavaFileInfo(javaFileInfo);
60 - setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
61 - getJavaFileInfo().getPackageFilePath()));
62 - }
63 -
64 - /**
65 - * Returns event listeners's java file handle.
66 - *
67 - * @return java file handle
68 - */
69 - private File getEventListenerJavaFileHandle() {
70 - return eventListenerJavaFileHandle;
71 - }
72 -
73 - /**
74 - * Sets event's java file handle.
75 - *
76 - * @param eventListenerJavaFileHandle file handle for event
77 - */
78 - private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
79 - this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
80 - }
81 -
82 - /**
83 - * Constructs java code exit.
84 - *
85 - * @param fileType generated file type
86 - * @param curNode current YANG node
87 - * @throws IOException when fails to generate java files
88 - */
89 - @Override
90 - public void generateJavaFile(int fileType, YangNode curNode)
91 - throws IOException {
92 -
93 - createPackage(curNode);
94 - String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
95 - .getJavaFileInfo().getJavaName());
96 - /**
97 - * Creates event listener interface file.
98 - */
99 - setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
100 - generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
101 -
102 - /**
103 - * Close all the file handles.
104 - */
105 - freeTemporaryResources(false);
106 - }
107 -
108 - /**
109 - * Removes all temporary file handles.
110 - *
111 - * @param isErrorOccurred when translator fails to generate java files we
112 - * need to close all open file handles include temporary files
113 - * and java files.
114 - * @throws IOException when failed to delete the temporary files
115 - */
116 - @Override
117 - public void freeTemporaryResources(boolean isErrorOccurred)
118 - throws IOException {
119 - boolean isError = isErrorOccurred;
120 - /**
121 - * Close all java file handles and when error occurs delete the files.
122 - */
123 - closeFile(getEventListenerJavaFileHandle(), isError);
124 -
125 - super.freeTemporaryResources(isErrorOccurred);
126 - }
127 -
128 -}
...@@ -28,6 +28,12 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; ...@@ -28,6 +28,12 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder;
28 import org.onosproject.yangutils.datamodel.YangNode; 28 import org.onosproject.yangutils.datamodel.YangNode;
29 import org.onosproject.yangutils.translator.exception.TranslatorException; 29 import org.onosproject.yangutils.translator.exception.TranslatorException;
30 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; 30 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
31 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
32 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
33 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
34 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
35 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
36 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
31 import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; 37 import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
32 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 38 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
33 39
...@@ -61,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy ...@@ -61,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
61 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 67 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
62 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; 68 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
63 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; 69 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
70 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; 71 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
65 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; 72 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
66 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; 73 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
...@@ -795,35 +802,40 @@ public class TempJavaFragmentFiles { ...@@ -795,35 +802,40 @@ public class TempJavaFragmentFiles {
795 * Adds attribute for class. 802 * Adds attribute for class.
796 * 803 *
797 * @param attr attribute info 804 * @param attr attribute info
805 + * @param pluginConfig plugin configurations
798 * @throws IOException when fails to append to temporary file 806 * @throws IOException when fails to append to temporary file
799 */ 807 */
800 - private void addAttribute(JavaAttributeInfo attr) 808 + private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
801 throws IOException { 809 throws IOException {
802 - appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); 810 + appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
811 + + FOUR_SPACE_INDENTATION);
803 } 812 }
804 813
805 /** 814 /**
806 * Adds getter for interface. 815 * Adds getter for interface.
807 * 816 *
808 * @param attr attribute info 817 * @param attr attribute info
818 + * @param pluginConfig plugin configurations
809 * @throws IOException when fails to append to temporary file 819 * @throws IOException when fails to append to temporary file
810 */ 820 */
811 - private void addGetterForInterface(JavaAttributeInfo attr) 821 + private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
812 throws IOException { 822 throws IOException {
813 appendToFile(getGetterInterfaceTempFileHandle(), 823 appendToFile(getGetterInterfaceTempFileHandle(),
814 - getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE); 824 + getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
815 } 825 }
816 826
817 /** 827 /**
818 * Adds setter for interface. 828 * Adds setter for interface.
819 * 829 *
820 * @param attr attribute info 830 * @param attr attribute info
831 + * @param pluginConfig plugin configurations
821 * @throws IOException when fails to append to temporary file 832 * @throws IOException when fails to append to temporary file
822 */ 833 */
823 - private void addSetterForInterface(JavaAttributeInfo attr) 834 + private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
824 throws IOException { 835 throws IOException {
825 appendToFile(getSetterInterfaceTempFileHandle(), 836 appendToFile(getSetterInterfaceTempFileHandle(),
826 - getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE); 837 + getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
838 + + NEW_LINE);
827 } 839 }
828 840
829 /** 841 /**
...@@ -844,9 +856,10 @@ public class TempJavaFragmentFiles { ...@@ -844,9 +856,10 @@ public class TempJavaFragmentFiles {
844 * Adds getter method's impl for class. 856 * Adds getter method's impl for class.
845 * 857 *
846 * @param attr attribute info 858 * @param attr attribute info
859 + * @param pluginConfig plugin configurations
847 * @throws IOException when fails to append to temporary file 860 * @throws IOException when fails to append to temporary file
848 */ 861 */
849 - private void addGetterImpl(JavaAttributeInfo attr) 862 + private void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
850 throws IOException { 863 throws IOException {
851 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 864 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
852 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { 865 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
...@@ -854,7 +867,7 @@ public class TempJavaFragmentFiles { ...@@ -854,7 +867,7 @@ public class TempJavaFragmentFiles {
854 getGeneratedJavaFiles()) + NEW_LINE); 867 getGeneratedJavaFiles()) + NEW_LINE);
855 } else { 868 } else {
856 appendToFile(getGetterImplTempFileHandle(), 869 appendToFile(getGetterImplTempFileHandle(),
857 - getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false) 870 + getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
858 + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); 871 + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
859 } 872 }
860 } 873 }
...@@ -863,11 +876,12 @@ public class TempJavaFragmentFiles { ...@@ -863,11 +876,12 @@ public class TempJavaFragmentFiles {
863 * Adds build method for interface. 876 * Adds build method for interface.
864 * 877 *
865 * @return build method for interface 878 * @return build method for interface
879 + * @param pluginConfig plugin configurations
866 * @throws IOException when fails to append to temporary file 880 * @throws IOException when fails to append to temporary file
867 */ 881 */
868 - String addBuildMethodForInterface() 882 + String addBuildMethodForInterface(YangPluginConfig pluginConfig)
869 throws IOException { 883 throws IOException {
870 - return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName()); 884 + return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
871 } 885 }
872 886
873 /** 887 /**
...@@ -886,23 +900,26 @@ public class TempJavaFragmentFiles { ...@@ -886,23 +900,26 @@ public class TempJavaFragmentFiles {
886 * 900 *
887 * @param modifier modifier for constructor. 901 * @param modifier modifier for constructor.
888 * @param toAppend string which need to be appended with the class name 902 * @param toAppend string which need to be appended with the class name
903 + * @param pluginConfig plugin configurations
889 * @return default constructor for class 904 * @return default constructor for class
890 * @throws IOException when fails to append to file 905 * @throws IOException when fails to append to file
891 */ 906 */
892 - String addDefaultConstructor(String modifier, String toAppend) 907 + String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
893 throws IOException { 908 throws IOException {
894 - return NEW_LINE + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier); 909 + return NEW_LINE
910 + + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig);
895 } 911 }
896 912
897 /** 913 /**
898 * Adds default constructor for class. 914 * Adds default constructor for class.
899 * 915 *
916 + * @param pluginCnfig plugin configurations
900 * @return default constructor for class 917 * @return default constructor for class
901 * @throws IOException when fails to append to file 918 * @throws IOException when fails to append to file
902 */ 919 */
903 - public String addOfMethod() 920 + public String addOfMethod(YangPluginConfig pluginCnfig)
904 throws IOException { 921 throws IOException {
905 - return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false) 922 + return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig)
906 + getOfMethod(getGeneratedJavaClassName(), null); 923 + getOfMethod(getGeneratedJavaClassName(), null);
907 } 924 }
908 925
...@@ -994,6 +1011,7 @@ public class TempJavaFragmentFiles { ...@@ -994,6 +1011,7 @@ public class TempJavaFragmentFiles {
994 */ 1011 */
995 public String getTemporaryDataFromFileHandle(File file) 1012 public String getTemporaryDataFromFileHandle(File file)
996 throws IOException { 1013 throws IOException {
1014 +
997 String path = getTempDirPath(); 1015 String path = getTempDirPath();
998 if (new File(path + file.getName()).exists()) { 1016 if (new File(path + file.getName()).exists()) {
999 return readAppendFile(path + file.getName(), EMPTY_STRING); 1017 return readAppendFile(path + file.getName(), EMPTY_STRING);
...@@ -1017,13 +1035,14 @@ public class TempJavaFragmentFiles { ...@@ -1017,13 +1035,14 @@ public class TempJavaFragmentFiles {
1017 * Parses attribute to get the attribute string. 1035 * Parses attribute to get the attribute string.
1018 * 1036 *
1019 * @param attr attribute info 1037 * @param attr attribute info
1038 + * @param pluginConfig plugin configurations
1020 * @return attribute string 1039 * @return attribute string
1021 */ 1040 */
1022 - private String parseAttribute(JavaAttributeInfo attr) { 1041 + public String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
1023 /* 1042 /*
1024 * TODO: check if this utility needs to be called or move to the caller 1043 * TODO: check if this utility needs to be called or move to the caller
1025 */ 1044 */
1026 - String attributeName = getCamelCase(attr.getAttributeName(), null); 1045 + String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
1027 if (attr.isQualifiedName()) { 1046 if (attr.isQualifiedName()) {
1028 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), 1047 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
1029 attr.getImportInfo().getClassInfo(), 1048 attr.getImportInfo().getClassInfo(),
...@@ -1056,22 +1075,26 @@ public class TempJavaFragmentFiles { ...@@ -1056,22 +1075,26 @@ public class TempJavaFragmentFiles {
1056 * @param curNode current node which needs to be added as an attribute in 1075 * @param curNode current node which needs to be added as an attribute in
1057 * the parent generated code 1076 * the parent generated code
1058 * @param isList is list construct 1077 * @param isList is list construct
1078 + * @param pluginConfig plugin configurations
1059 * @throws IOException IO operation exception 1079 * @throws IOException IO operation exception
1060 */ 1080 */
1061 public static void addCurNodeInfoInParentTempFile(YangNode curNode, 1081 public static void addCurNodeInfoInParentTempFile(YangNode curNode,
1062 - boolean isList) 1082 + boolean isList, YangPluginConfig pluginConfig)
1063 throws IOException { 1083 throws IOException {
1064 YangNode parent = getParentNodeInGenCode(curNode); 1084 YangNode parent = getParentNodeInGenCode(curNode);
1065 if (!(parent instanceof JavaCodeGenerator)) { 1085 if (!(parent instanceof JavaCodeGenerator)) {
1066 throw new TranslatorException("missing parent node to contain current node info in generated file"); 1086 throw new TranslatorException("missing parent node to contain current node info in generated file");
1067 } 1087 }
1088 + if (curNode instanceof YangJavaUses) {
1089 + curNode = ((YangJavaUses) curNode).getRefGroup();
1090 + }
1068 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, 1091 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode,
1069 parent, isList); 1092 parent, isList);
1070 if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) { 1093 if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
1071 throw new TranslatorException("missing parent temp file handle"); 1094 throw new TranslatorException("missing parent temp file handle");
1072 } 1095 }
1073 getNodesInterfaceFragmentFiles(parent) 1096 getNodesInterfaceFragmentFiles(parent)
1074 - .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 1097 + .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
1075 } 1098 }
1076 1099
1077 /** 1100 /**
...@@ -1087,23 +1110,57 @@ public class TempJavaFragmentFiles { ...@@ -1087,23 +1110,57 @@ public class TempJavaFragmentFiles {
1087 */ 1110 */
1088 public static JavaAttributeInfo getCurNodeAsAttributeInParent( 1111 public static JavaAttributeInfo getCurNodeAsAttributeInParent(
1089 YangNode curNode, YangNode parentNode, boolean isListNode) { 1112 YangNode curNode, YangNode parentNode, boolean isListNode) {
1090 - String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); 1113 +
1091 - /* 1114 + YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parentNode).getJavaFileInfo().getPluginConfig();
1092 - * Get the import info corresponding to the attribute for import in 1115 + JavaFileInfo curNodeJavaInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1093 - * generated java files or qualified access 1116 + String curNodeName = null;
1094 - */ 1117 +
1095 - JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, 1118 + if (curNodeJavaInfo.getJavaName() != null) {
1096 - getCapitalCase(curNodeName)); 1119 + curNodeName = curNodeJavaInfo.getJavaName();
1120 + } else {
1121 + curNodeName = getCamelCase(curNode.getName(), pluginConfig.getConflictResolver());
1122 + }
1123 +
1097 if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) { 1124 if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
1098 throw new TranslatorException("Parent node does not have file info"); 1125 throw new TranslatorException("Parent node does not have file info");
1099 } 1126 }
1127 +
1100 TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); 1128 TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode);
1101 boolean isQualified = true; 1129 boolean isQualified = true;
1102 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); 1130 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
1103 if (isListNode) { 1131 if (isListNode) {
1104 parentImportData.setIfListImported(true); 1132 parentImportData.setIfListImported(true);
1105 } 1133 }
1106 - if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) { 1134 +
1135 + /*
1136 + * Get the import info corresponding to the attribute for import in
1137 + * generated java files or qualified access
1138 + */
1139 +
1140 + JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
1141 + if (curNode instanceof YangJavaGrouping) {
1142 + qualifiedTypeInfo = resolveGroupingsQuailifiedInfo(curNode, pluginConfig);
1143 + } else {
1144 + qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
1145 + getCapitalCase(curNodeName));
1146 + }
1147 +
1148 + if (parentNode instanceof YangJavaModule
1149 + || parentNode instanceof YangJavaSubModule
1150 + || parentNode instanceof YangJavaInput
1151 + || parentNode instanceof YangJavaOutput) {
1152 + parentImportData.addImportInfo(qualifiedTypeInfo);
1153 + isQualified = false;
1154 + } else if (curNode instanceof YangJavaGrouping) {
1155 + JavaFileInfo parentsClassInfo = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
1156 + if (qualifiedTypeInfo.getClassInfo().equals(parentsClassInfo.getJavaName())) {
1157 + isQualified = true;
1158 + }
1159 + if (!qualifiedTypeInfo.getPkgInfo().equals(parentsClassInfo.getPackage())) {
1160 + parentImportData.addImportInfo(qualifiedTypeInfo);
1161 + isQualified = false;
1162 + }
1163 + } else if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) {
1107 parentImportData.addImportInfo(qualifiedTypeInfo); 1164 parentImportData.addImportInfo(qualifiedTypeInfo);
1108 isQualified = false; 1165 isQualified = false;
1109 } 1166 }
...@@ -1111,6 +1168,63 @@ public class TempJavaFragmentFiles { ...@@ -1111,6 +1168,63 @@ public class TempJavaFragmentFiles {
1111 } 1168 }
1112 1169
1113 /** 1170 /**
1171 + * Resolves groupings java qualified info.
1172 + *
1173 + * @param curNode grouping node
1174 + * @param pluginConfig plugin configurations
1175 + * @return groupings java qualified info
1176 + */
1177 + public static JavaQualifiedTypeInfo resolveGroupingsQuailifiedInfo(YangNode curNode,
1178 + YangPluginConfig pluginConfig) {
1179 +
1180 + JavaFileInfo groupingFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1181 + JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
1182 + if (groupingFileInfo.getPackage() == null) {
1183 + List<String> parentNames = new ArrayList<>();
1184 +
1185 + YangNode tempNode = curNode.getParent();
1186 + YangNode groupingSuperParent = null;
1187 + while (tempNode != null) {
1188 + parentNames.add(tempNode.getName());
1189 + groupingSuperParent = tempNode;
1190 + tempNode = tempNode.getParent();
1191 + }
1192 +
1193 + String pkg = null;
1194 + JavaFileInfo parentInfo = ((JavaFileInfoContainer) groupingSuperParent).getJavaFileInfo();
1195 + if (parentInfo.getPackage() == null) {
1196 + if (groupingSuperParent instanceof YangJavaModule) {
1197 + YangJavaModule module = (YangJavaModule) groupingSuperParent;
1198 + String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
1199 + .getRevision().getRevDate(), pluginConfig.getConflictResolver());
1200 + pkg = modulePkg;
1201 + } else if (groupingSuperParent instanceof YangJavaSubModule) {
1202 + YangJavaSubModule submodule = (YangJavaSubModule) groupingSuperParent;
1203 + String subModulePkg = getRootPackage(submodule.getVersion(),
1204 + submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
1205 + submodule.getRevision().getRevDate(), pluginConfig.getConflictResolver());
1206 + pkg = subModulePkg;
1207 + }
1208 + } else {
1209 + pkg = parentInfo.getPackage();
1210 + }
1211 + for (String name : parentNames) {
1212 + pkg = pkg + PERIOD + getCamelCase(name, pluginConfig.getConflictResolver());
1213 + }
1214 +
1215 + qualifiedTypeInfo.setPkgInfo(pkg.toLowerCase());
1216 + qualifiedTypeInfo.setClassInfo(
1217 + getCapitalCase(getCamelCase(curNode.getName(), pluginConfig.getConflictResolver())));
1218 + return qualifiedTypeInfo;
1219 +
1220 + } else {
1221 + qualifiedTypeInfo.setPkgInfo(groupingFileInfo.getPackage().toLowerCase());
1222 + qualifiedTypeInfo.setClassInfo(getCapitalCase(groupingFileInfo.getJavaName()));
1223 + return qualifiedTypeInfo;
1224 + }
1225 + }
1226 +
1227 + /**
1114 * Returns interface fragment files for node. 1228 * Returns interface fragment files for node.
1115 * 1229 *
1116 * @param node YANG node 1230 * @param node YANG node
...@@ -1134,8 +1248,9 @@ public class TempJavaFragmentFiles { ...@@ -1134,8 +1248,9 @@ public class TempJavaFragmentFiles {
1134 * Adds parent's info to current node import list. 1248 * Adds parent's info to current node import list.
1135 * 1249 *
1136 * @param curNode current node for which import list needs to be updated 1250 * @param curNode current node for which import list needs to be updated
1251 + * @param pluginConfig plugin configurations
1137 */ 1252 */
1138 - public void addParentInfoInCurNodeTempFile(YangNode curNode) { 1253 + public void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
1139 caseImportInfo = new JavaQualifiedTypeInfo(); 1254 caseImportInfo = new JavaQualifiedTypeInfo();
1140 YangNode parent = getParentNodeInGenCode(curNode); 1255 YangNode parent = getParentNodeInGenCode(curNode);
1141 if (!(parent instanceof JavaCodeGenerator)) { 1256 if (!(parent instanceof JavaCodeGenerator)) {
...@@ -1145,7 +1260,8 @@ public class TempJavaFragmentFiles { ...@@ -1145,7 +1260,8 @@ public class TempJavaFragmentFiles {
1145 throw new TranslatorException("missing java file information to get the package details " 1260 throw new TranslatorException("missing java file information to get the package details "
1146 + "of attribute corresponding to child node"); 1261 + "of attribute corresponding to child node");
1147 } 1262 }
1148 - caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), null))); 1263 + caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1264 + pluginConfig.getConflictResolver())));
1149 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); 1265 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
1150 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 1266 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
1151 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo); 1267 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo);
...@@ -1167,6 +1283,7 @@ public class TempJavaFragmentFiles { ...@@ -1167,6 +1283,7 @@ public class TempJavaFragmentFiles {
1167 throw new TranslatorException("Leaf does not have java information"); 1283 throw new TranslatorException("Leaf does not have java information");
1168 } 1284 }
1169 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; 1285 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
1286 + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1170 javaLeaf.updateJavaQualifiedInfo(); 1287 javaLeaf.updateJavaQualifiedInfo();
1171 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( 1288 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
1172 javaLeaf.getJavaQualifiedInfo(), 1289 javaLeaf.getJavaQualifiedInfo(),
...@@ -1174,7 +1291,7 @@ public class TempJavaFragmentFiles { ...@@ -1174,7 +1291,7 @@ public class TempJavaFragmentFiles {
1174 javaLeaf.getDataType(), 1291 javaLeaf.getDataType(),
1175 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), 1292 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1176 false); 1293 false);
1177 - addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 1294 + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
1178 } 1295 }
1179 } 1296 }
1180 } 1297 }
...@@ -1194,6 +1311,7 @@ public class TempJavaFragmentFiles { ...@@ -1194,6 +1311,7 @@ public class TempJavaFragmentFiles {
1194 throw new TranslatorException("Leaf-list does not have java information"); 1311 throw new TranslatorException("Leaf-list does not have java information");
1195 } 1312 }
1196 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; 1313 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
1314 + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1197 javaLeaf.updateJavaQualifiedInfo(); 1315 javaLeaf.updateJavaQualifiedInfo();
1198 getJavaImportData().setIfListImported(true); 1316 getJavaImportData().setIfListImported(true);
1199 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( 1317 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
...@@ -1202,7 +1320,7 @@ public class TempJavaFragmentFiles { ...@@ -1202,7 +1320,7 @@ public class TempJavaFragmentFiles {
1202 javaLeaf.getDataType(), 1320 javaLeaf.getDataType(),
1203 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), 1321 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1204 true); 1322 true);
1205 - addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 1323 + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
1206 } 1324 }
1207 } 1325 }
1208 } 1326 }
...@@ -1231,21 +1349,22 @@ public class TempJavaFragmentFiles { ...@@ -1231,21 +1349,22 @@ public class TempJavaFragmentFiles {
1231 * 1349 *
1232 * @param newAttrInfo the attribute info that needs to be added to temporary 1350 * @param newAttrInfo the attribute info that needs to be added to temporary
1233 * files 1351 * files
1352 + * @param pluginConfig plugin configurations
1234 * @throws IOException IO operation fail 1353 * @throws IOException IO operation fail
1235 */ 1354 */
1236 - void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) 1355 + void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
1237 throws IOException { 1356 throws IOException {
1238 setAttributePresent(true); 1357 setAttributePresent(true);
1239 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { 1358 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1240 - addAttribute(newAttrInfo); 1359 + addAttribute(newAttrInfo, pluginConfig);
1241 } 1360 }
1242 1361
1243 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { 1362 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
1244 - addGetterForInterface(newAttrInfo); 1363 + addGetterForInterface(newAttrInfo, pluginConfig);
1245 } 1364 }
1246 1365
1247 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { 1366 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
1248 - addSetterForInterface(newAttrInfo); 1367 + addSetterForInterface(newAttrInfo, pluginConfig);
1249 } 1368 }
1250 1369
1251 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { 1370 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
...@@ -1253,7 +1372,7 @@ public class TempJavaFragmentFiles { ...@@ -1253,7 +1372,7 @@ public class TempJavaFragmentFiles {
1253 } 1372 }
1254 1373
1255 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { 1374 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1256 - addGetterImpl(newAttrInfo); 1375 + addGetterImpl(newAttrInfo, pluginConfig);
1257 } 1376 }
1258 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { 1377 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1259 addHashCodeMethod(newAttrInfo); 1378 addHashCodeMethod(newAttrInfo);
...@@ -1266,7 +1385,8 @@ public class TempJavaFragmentFiles { ...@@ -1266,7 +1385,8 @@ public class TempJavaFragmentFiles {
1266 } 1385 }
1267 1386
1268 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { 1387 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1269 - JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo); 1388 + JavaQualifiedTypeInfo qualifiedInfoOfFromString =
1389 + getQualifiedInfoOfFromString(newAttrInfo, pluginConfig.getConflictResolver());
1270 /* 1390 /*
1271 * Create a new java attribute info with qualified information of 1391 * Create a new java attribute info with qualified information of
1272 * wrapper classes. 1392 * wrapper classes.
...@@ -1309,9 +1429,8 @@ public class TempJavaFragmentFiles { ...@@ -1309,9 +1429,8 @@ public class TempJavaFragmentFiles {
1309 public void generateJavaFile(int fileType, YangNode curNode) 1429 public void generateJavaFile(int fileType, YangNode curNode)
1310 throws IOException { 1430 throws IOException {
1311 List<String> imports = new ArrayList<>(); 1431 List<String> imports = new ArrayList<>();
1312 - if (isAttributePresent()) { 1432 + imports = getJavaImportData().getImports();
1313 - imports = getJavaImportData().getImports(); 1433 +
1314 - }
1315 createPackage(curNode); 1434 createPackage(curNode);
1316 1435
1317 /* 1436 /*
...@@ -1319,19 +1438,6 @@ public class TempJavaFragmentFiles { ...@@ -1319,19 +1438,6 @@ public class TempJavaFragmentFiles {
1319 */ 1438 */
1320 if ((fileType & INTERFACE_MASK) != 0 || (fileType & 1439 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1321 BUILDER_INTERFACE_MASK) != 0) { 1440 BUILDER_INTERFACE_MASK) != 0) {
1322 - /*
1323 - * Adds import for case.
1324 - */
1325 - if (curNode instanceof YangCase) {
1326 - List<String> importData =
1327 - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
1328 - .getBeanTempFiles().getJavaImportData().getImports();
1329 - for (String importInfo : importData) {
1330 - if (!imports.contains(importInfo)) {
1331 - imports.add(importInfo);
1332 - }
1333 - }
1334 - }
1335 1441
1336 /* 1442 /*
1337 * Create interface file. 1443 * Create interface file.
......
...@@ -22,26 +22,60 @@ import java.util.ArrayList; ...@@ -22,26 +22,60 @@ import java.util.ArrayList;
22 import java.util.List; 22 import java.util.List;
23 23
24 import org.onosproject.yangutils.datamodel.YangNode; 24 import org.onosproject.yangutils.datamodel.YangNode;
25 -import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; 25 +import org.onosproject.yangutils.datamodel.YangNotification;
26 - 26 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
27 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
28 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
29 +
30 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
31 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
33 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
34 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
35 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
36 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
37 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
27 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
40 +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
41 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
42 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType;
43 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; 44 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
45 +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute;
46 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
47 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
48 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile;
30 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile; 49 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
31 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile; 50 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
51 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
52 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 53 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
54 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
55 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
56 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
33 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; 57 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
34 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; 58 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
59 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
60 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAnnotationsImports;
35 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport; 61 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
36 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 62 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
63 +import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
37 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 64 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
65 +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
66 +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
38 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; 67 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
39 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; 68 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
40 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 69 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
41 import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; 70 import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
71 +import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
42 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 72 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
43 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 73 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
44 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; 74 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
75 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
76 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
77 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
78 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
45 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 79 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
46 80
47 /** 81 /**
...@@ -62,6 +96,30 @@ public class TempJavaServiceFragmentFiles ...@@ -62,6 +96,30 @@ public class TempJavaServiceFragmentFiles
62 private static final String RPC_IMPL_FILE_NAME = "RpcImpl"; 96 private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
63 97
64 /** 98 /**
99 + * File name for event enum temp file.
100 + */
101 + private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
102 +
103 + /**
104 + * File name for event method temp file.
105 + */
106 + private static final String EVENT_METHOD_FILE_NAME = "EventMethod";
107 +
108 + /**
109 + * File name for event subject attribute temp file.
110 + */
111 + private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute";
112 +
113 + /**
114 + * File name for event subject getter temp file.
115 + */
116 + private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter";
117 +
118 + /**
119 + * File name for event subject setter temp file.
120 + */
121 + private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
122 + /**
65 * File name for generated class file for service 123 * File name for generated class file for service
66 * suffix. 124 * suffix.
67 */ 125 */
...@@ -74,6 +132,41 @@ public class TempJavaServiceFragmentFiles ...@@ -74,6 +132,41 @@ public class TempJavaServiceFragmentFiles
74 private static final String MANAGER_FILE_NAME_SUFFIX = "Manager"; 132 private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
75 133
76 /** 134 /**
135 + * File name for generated class file for special type like union, typedef
136 + * suffix.
137 + */
138 + private static final String EVENT_FILE_NAME_SUFFIX = "Event";
139 +
140 + /**
141 + * File name for generated class file for special type like union, typedef
142 + * suffix.
143 + */
144 + private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
145 +
146 + /**
147 + * File name for generated class file for special type like union, typedef
148 + * suffix.
149 + */
150 + public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
151 +
152 + private static final String JAVA_FILE_EXTENSION = ".java";
153 +
154 + /**
155 + * Java file handle for event subject file.
156 + */
157 + private File eventSubjectJavaFileHandle;
158 +
159 + /**
160 + * Java file handle for event listener file.
161 + */
162 + private File eventListenerJavaFileHandle;
163 +
164 + /**
165 + * Java file handle for event file.
166 + */
167 + private File eventJavaFileHandle;
168 +
169 + /**
77 * Temporary file handle for rpc interface. 170 * Temporary file handle for rpc interface.
78 */ 171 */
79 private File rpcInterfaceTempFileHandle; 172 private File rpcInterfaceTempFileHandle;
...@@ -94,6 +187,31 @@ public class TempJavaServiceFragmentFiles ...@@ -94,6 +187,31 @@ public class TempJavaServiceFragmentFiles
94 private File managerJavaFileHandle; 187 private File managerJavaFileHandle;
95 188
96 /** 189 /**
190 + * Java file handle for event enum impl file.
191 + */
192 + private File eventEnumTempFileHandle;
193 +
194 + /**
195 + * Java file handle for event method impl file.
196 + */
197 + private File eventMethodTempFileHandle;
198 +
199 + /**
200 + * Java file handle for event subject attribute file.
201 + */
202 + private File eventSubjectAttributeTempFileHandle;
203 +
204 + /**
205 + * Java file handle for event subject getter impl file.
206 + */
207 + private File eventSubjectGetterTempFileHandle;
208 +
209 + /**
210 + * Java file handle for event subject setter impl file.
211 + */
212 + private File eventSubjectSetterTempFileHandle;
213 +
214 + /**
97 * Returns rpc method's java file handle. 215 * Returns rpc method's java file handle.
98 * 216 *
99 * @return java file handle 217 * @return java file handle
...@@ -166,6 +284,60 @@ public class TempJavaServiceFragmentFiles ...@@ -166,6 +284,60 @@ public class TempJavaServiceFragmentFiles
166 } 284 }
167 285
168 /** 286 /**
287 + * Returns event's java file handle.
288 + *
289 + * @return java file handle
290 + */
291 + private File getEventJavaFileHandle() {
292 + return eventJavaFileHandle;
293 + }
294 +
295 + /**
296 + * Sets event's java file handle.
297 + *
298 + * @param eventJavaFileHandle file handle for event
299 + */
300 + private void setEventJavaFileHandle(File eventJavaFileHandle) {
301 + this.eventJavaFileHandle = eventJavaFileHandle;
302 + }
303 +
304 + /**
305 + * Returns event listeners's java file handle.
306 + *
307 + * @return java file handle
308 + */
309 + private File getEventListenerJavaFileHandle() {
310 + return eventListenerJavaFileHandle;
311 + }
312 +
313 + /**
314 + * Sets event's java file handle.
315 + *
316 + * @param eventListenerJavaFileHandle file handle for event
317 + */
318 + private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
319 + this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
320 + }
321 +
322 + /**
323 + * Returns event subject's java file handle.
324 + *
325 + * @return java file handle
326 + */
327 + private File getEventSubjectJavaFileHandle() {
328 + return eventSubjectJavaFileHandle;
329 + }
330 +
331 + /**
332 + * Sets event's subject java file handle.
333 + *
334 + * @param eventSubjectJavaFileHandle file handle for event's subject
335 + */
336 + private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) {
337 + this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle;
338 + }
339 +
340 + /**
169 * Creates an instance of temporary java code fragment. 341 * Creates an instance of temporary java code fragment.
170 * 342 *
171 * @param javaFileInfo generated file information 343 * @param javaFileInfo generated file information
...@@ -176,11 +348,22 @@ public class TempJavaServiceFragmentFiles ...@@ -176,11 +348,22 @@ public class TempJavaServiceFragmentFiles
176 super(javaFileInfo); 348 super(javaFileInfo);
177 349
178 addGeneratedTempFile(RPC_INTERFACE_MASK); 350 addGeneratedTempFile(RPC_INTERFACE_MASK);
179 -
180 addGeneratedTempFile(RPC_IMPL_MASK); 351 addGeneratedTempFile(RPC_IMPL_MASK);
181 352
353 + addGeneratedTempFile(EVENT_ENUM_MASK);
354 + addGeneratedTempFile(EVENT_METHOD_MASK);
355 + addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
356 + addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
357 + addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
358 +
182 setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME)); 359 setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
183 setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME)); 360 setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
361 +
362 + setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
363 + setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
364 + setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
365 + setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
366 + setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
184 } 367 }
185 368
186 /** 369 /**
...@@ -199,13 +382,14 @@ public class TempJavaServiceFragmentFiles ...@@ -199,13 +382,14 @@ public class TempJavaServiceFragmentFiles
199 createPackage(curNode); 382 createPackage(curNode);
200 383
201 boolean isNotification = false; 384 boolean isNotification = false;
202 - YangNode tempNode = curNode.getChild(); 385 + if (curNode instanceof YangJavaModule) {
203 - while (tempNode != null) { 386 + if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) {
204 - if (tempNode instanceof YangJavaNotification) { 387 + isNotification = true;
388 + }
389 + } else if (curNode instanceof YangJavaSubModule) {
390 + if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) {
205 isNotification = true; 391 isNotification = true;
206 - break;
207 } 392 }
208 - tempNode = tempNode.getNextSibling();
209 } 393 }
210 394
211 if (isNotification) { 395 if (isNotification) {
...@@ -221,6 +405,7 @@ public class TempJavaServiceFragmentFiles ...@@ -221,6 +405,7 @@ public class TempJavaServiceFragmentFiles
221 addListnersImport(curNode, imports, false, LISTENER_SERVICE); 405 addListnersImport(curNode, imports, false, LISTENER_SERVICE);
222 addListnersImport(curNode, imports, true, LISTENER_REG); 406 addListnersImport(curNode, imports, true, LISTENER_REG);
223 } 407 }
408 + addAnnotationsImports(imports, true);
224 /** 409 /**
225 * Create builder class file. 410 * Create builder class file.
226 */ 411 */
...@@ -231,6 +416,14 @@ public class TempJavaServiceFragmentFiles ...@@ -231,6 +416,14 @@ public class TempJavaServiceFragmentFiles
231 if (isNotification) { 416 if (isNotification) {
232 addListnersImport(curNode, imports, false, LISTENER_REG); 417 addListnersImport(curNode, imports, false, LISTENER_REG);
233 } 418 }
419 + addAnnotationsImports(imports, false);
420 +
421 + if (isNotification) {
422 + generateEventJavaFile(GENERATE_EVENT_CLASS, curNode);
423 + generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode);
424 + generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode);
425 + }
426 +
234 /** 427 /**
235 * Close all the file handles. 428 * Close all the file handles.
236 */ 429 */
...@@ -243,22 +436,115 @@ public class TempJavaServiceFragmentFiles ...@@ -243,22 +436,115 @@ public class TempJavaServiceFragmentFiles
243 * @param javaAttributeInfoOfInput rpc's input node attribute info 436 * @param javaAttributeInfoOfInput rpc's input node attribute info
244 * @param javaAttributeInfoOfOutput rpc's output node attribute info 437 * @param javaAttributeInfoOfOutput rpc's output node attribute info
245 * @param rpcName name of the rpc function 438 * @param rpcName name of the rpc function
439 + * @param pluginConfig plugin configurations
246 * @throws IOException IO operation fail 440 * @throws IOException IO operation fail
247 */ 441 */
248 private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, 442 private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
249 - JavaAttributeInfo javaAttributeInfoOfOutput, 443 + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
250 String rpcName) throws IOException { 444 String rpcName) throws IOException {
251 String rpcInput = EMPTY_STRING; 445 String rpcInput = EMPTY_STRING;
252 String rpcOutput = VOID; 446 String rpcOutput = VOID;
447 + String rpcInputJavaDoc = EMPTY_STRING;
253 if (javaAttributeInfoOfInput != null) { 448 if (javaAttributeInfoOfInput != null) {
254 rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName()); 449 rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName());
255 } 450 }
256 if (javaAttributeInfoOfOutput != null) { 451 if (javaAttributeInfoOfOutput != null) {
257 rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); 452 rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName());
258 } 453 }
259 - appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput) 454 + if (!rpcInput.equals(EMPTY_STRING)) {
260 - + getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); 455 + rpcInputJavaDoc = RPC_INPUT_VAR_NAME;
261 - appendToFile(getRpcImplTempFileHandle(), getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); 456 + }
457 + appendToFile(getRpcInterfaceTempFileHandle(),
458 + generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig)
459 + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
460 + appendToFile(getRpcImplTempFileHandle(),
461 + getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
462 + }
463 +
464 + /**
465 + * Adds rpc string information to applicable temp file.
466 + *
467 + * @param javaAttributeInfoOfInput rpc's input node attribute info
468 + * @param javaAttributeInfoOfOutput rpc's output node attribute info
469 + * @param rpcName name of the rpc function
470 + * @param pluginConfig plugin configurations
471 + * @param isInputLeafHolder if input node is leaf holder
472 + * @param isOutputLeafHolder if output node is leaf holder
473 + * @param isInputSingleChildHolder if input node is single child holder
474 + * @param isOutputSingleChildHolder if input node is single child holder
475 + * @throws IOException IO operation fail
476 + */
477 + public void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
478 + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
479 + String rpcName, boolean isInputLeafHolder, boolean isOutputLeafHolder,
480 + boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder) throws IOException {
481 + String rpcInput = EMPTY_STRING;
482 + String rpcOutput = VOID;
483 + String rpcInputJavaDoc = EMPTY_STRING;
484 + if (javaAttributeInfoOfInput != null) {
485 + rpcInput = getInputOutputNames(javaAttributeInfoOfInput, isInputLeafHolder, isInputSingleChildHolder,
486 + pluginConfig);
487 + }
488 + if (javaAttributeInfoOfOutput != null) {
489 + rpcOutput =
490 + getInputOutputNames(javaAttributeInfoOfOutput, isOutputLeafHolder, isOutputSingleChildHolder,
491 + pluginConfig);
492 + }
493 + if (!rpcInput.equals(EMPTY_STRING)) {
494 + rpcInputJavaDoc = RPC_INPUT_VAR_NAME;
495 + }
496 +
497 + appendToFile(getRpcInterfaceTempFileHandle(),
498 + generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig)
499 + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
500 + appendToFile(getRpcImplTempFileHandle(),
501 + getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
502 + }
503 +
504 + /**
505 + * Returns names for input and output.
506 + *
507 + * @param attr attribute info
508 + * @param isLeafHolder if leaf holder
509 + * @param isSinglechildHolder if single child holder
510 + * @param pluginConfig plugin configurations
511 + * @return names for input and output
512 + */
513 + private String getInputOutputNames(JavaAttributeInfo attr, boolean isLeafHolder, boolean isSinglechildHolder,
514 + YangPluginConfig pluginConfig) {
515 + if (!attr.isListAttr()) {
516 + if (!isLeafHolder || isSinglechildHolder) {
517 + String attrName = "";
518 + if (!attr.isQualifiedName()) {
519 + attrName = getCapitalCase(attr.getAttributeName());
520 + } else {
521 + attrName = attr.getImportInfo().getPkgInfo() + "." + getCapitalCase(attr.getAttributeName());
522 + }
523 + return attrName;
524 + } else {
525 + String rpcInput = getJavaImportClass(attr.getAttributeType(), false,
526 + pluginConfig.getConflictResolver());
527 + if (rpcInput == null) {
528 + rpcInput = getJavaDataType(attr.getAttributeType());
529 + }
530 + return rpcInput;
531 + }
532 + } else {
533 + if (!isLeafHolder || isSinglechildHolder) {
534 + String attrName = "";
535 + if (!attr.isQualifiedName()) {
536 + attrName = getCapitalCase(attr.getAttributeName());
537 + } else {
538 + attrName = attr.getImportInfo().getPkgInfo() + "." + getCapitalCase(attr.getAttributeName());
539 + }
540 + return getListAttribute(attrName);
541 +
542 + } else {
543 + return getListAttribute(getJavaImportClass(attr.getAttributeType(), true,
544 + pluginConfig.getConflictResolver()));
545 +
546 + }
547 + }
262 } 548 }
263 549
264 /** 550 /**
...@@ -266,14 +552,105 @@ public class TempJavaServiceFragmentFiles ...@@ -266,14 +552,105 @@ public class TempJavaServiceFragmentFiles
266 * 552 *
267 * @param javaAttributeInfoOfInput rpc's input node attribute info 553 * @param javaAttributeInfoOfInput rpc's input node attribute info
268 * @param javaAttributeInfoOfOutput rpc's output node attribute info 554 * @param javaAttributeInfoOfOutput rpc's output node attribute info
555 + * @param pluginConfig plugin configurations
269 * @param rpcName name of the rpc function 556 * @param rpcName name of the rpc function
557 + * @param isInputLeafHolder if input node is leaf holder
558 + * @param isOutputLeafHolder if output node is leaf holder
559 + * @param isInputSingleChildHolder if input node is single child holder
560 + * @param isOutputSingleChildHolder if input node is single child holder
270 * @throws IOException IO operation fail 561 * @throws IOException IO operation fail
271 */ 562 */
272 public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, 563 public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
273 - JavaAttributeInfo javaAttributeInfoOfOutput, 564 + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
274 - String rpcName) 565 + String rpcName, boolean isInputLeafHolder, boolean isOutputLeafHolder,
566 + boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder)
275 throws IOException { 567 throws IOException {
276 - addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName); 568 + addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName, isInputLeafHolder,
569 + isOutputLeafHolder, isInputSingleChildHolder, isOutputSingleChildHolder);
570 + }
571 +
572 + /**
573 + * Constructs java code exit.
574 + *
575 + * @param fileType generated file type
576 + * @param curNode current YANG node
577 + * @throws IOException when fails to generate java files
578 + */
579 + public void generateEventJavaFile(int fileType, YangNode curNode)
580 + throws IOException {
581 +
582 + List<String> imports = new ArrayList<>();
583 +
584 + imports.add(getJavaImportData().getAbstractEventsImport());
585 + String curNodeInfo =
586 + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName());
587 + String nodeName = curNodeInfo + EVENT_STRING;
588 +
589 + addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
590 +
591 + /**
592 + * Creates event interface file.
593 + */
594 + setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
595 + generateEventFile(getEventJavaFileHandle(), curNode, imports);
596 +
597 + /**
598 + * Close all the file handles.
599 + */
600 + freeTemporaryResources(false);
601 + }
602 +
603 + /**
604 + * Constructs java code exit.
605 + *
606 + * @param fileType generated file type
607 + * @param curNode current YANG node
608 + * @throws IOException when fails to generate java files
609 + */
610 + public void generateEventListenerJavaFile(int fileType, YangNode curNode)
611 + throws IOException {
612 +
613 + List<String> imports = new ArrayList<>();
614 +
615 + imports.add(getJavaImportData().getEventListenerImport());
616 + String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
617 + .getJavaFileInfo().getJavaName());
618 + /**
619 + * Creates event listener interface file.
620 + */
621 + setEventListenerJavaFileHandle(
622 + getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
623 + generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
624 +
625 + /**
626 + * Close all the file handles.
627 + */
628 + freeTemporaryResources(false);
629 + }
630 +
631 + /**
632 + * Constructs java code exit.
633 + *
634 + * @param fileType generated file type
635 + * @param curNode current YANG node
636 + * @throws IOException when fails to generate java files
637 + */
638 + public void generateEventSubjectJavaFile(int fileType, YangNode curNode)
639 + throws IOException {
640 +
641 + String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
642 + .getJavaFileInfo().getJavaName());
643 + /**
644 + * Creates event interface file.
645 + */
646 + setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
647 + EVENT_SUBJECT_NAME_SUFFIX));
648 + generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
649 +
650 + /**
651 + * Close all the file handles.
652 + */
653 + freeTemporaryResources(false);
277 } 654 }
278 655
279 /** 656 /**
...@@ -290,6 +667,18 @@ public class TempJavaServiceFragmentFiles ...@@ -290,6 +667,18 @@ public class TempJavaServiceFragmentFiles
290 boolean isError = isErrorOccurred; 667 boolean isError = isErrorOccurred;
291 668
292 closeFile(getServiceInterfaceJavaFileHandle(), isError); 669 closeFile(getServiceInterfaceJavaFileHandle(), isError);
670 + closeFile(getManagerJavaFileHandle(), isError);
671 +
672 + if (getEventJavaFileHandle() != null) {
673 + closeFile(getEventJavaFileHandle(), isError);
674 + }
675 + if (getEventListenerJavaFileHandle() != null) {
676 + closeFile(getEventListenerJavaFileHandle(), isError);
677 + }
678 + if (getEventSubjectJavaFileHandle() != null) {
679 + closeFile(getEventSubjectJavaFileHandle(), isError);
680 + }
681 +
293 closeFile(getRpcInterfaceTempFileHandle(), true); 682 closeFile(getRpcInterfaceTempFileHandle(), true);
294 closeFile(getRpcImplTempFileHandle(), true); 683 closeFile(getRpcImplTempFileHandle(), true);
295 closeFile(getGetterInterfaceTempFileHandle(), true); 684 closeFile(getGetterInterfaceTempFileHandle(), true);
...@@ -299,4 +688,207 @@ public class TempJavaServiceFragmentFiles ...@@ -299,4 +688,207 @@ public class TempJavaServiceFragmentFiles
299 super.freeTemporaryResources(isErrorOccurred); 688 super.freeTemporaryResources(isErrorOccurred);
300 689
301 } 690 }
691 +
692 + /**
693 + * Returns event enum temp file.
694 + *
695 + * @return event enum temp file
696 + */
697 + public File getEventEnumTempFileHandle() {
698 + return eventEnumTempFileHandle;
699 + }
700 +
701 + /**
702 + * Sets event enum temp file.
703 + *
704 + * @param eventEnumTempFileHandle event enum temp file
705 + */
706 + public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
707 + this.eventEnumTempFileHandle = eventEnumTempFileHandle;
708 + }
709 +
710 + /**
711 + * Returns event method temp file.
712 + *
713 + * @return event method temp file
714 + */
715 + public File getEventMethodTempFileHandle() {
716 + return eventMethodTempFileHandle;
717 + }
718 +
719 + /**
720 + * Sets event method temp file.
721 + *
722 + * @param eventMethodTempFileHandle event method temp file
723 + */
724 + public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
725 + this.eventMethodTempFileHandle = eventMethodTempFileHandle;
726 + }
727 +
728 + /**
729 + * Returns event subject attribute temp file.
730 + *
731 + * @return event subject attribute temp file
732 + */
733 + public File getEventSubjectAttributeTempFileHandle() {
734 + return eventSubjectAttributeTempFileHandle;
735 + }
736 +
737 + /**
738 + * Sets event subject attribute temp file.
739 + *
740 + * @param eventSubjectAttributeTempFileHandle event subject attribute temp file
741 + */
742 + public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
743 + this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
744 + }
745 +
746 + /**
747 + * Returns event subject getter temp file.
748 + *
749 + * @return event subject getter temp file
750 + */
751 + public File getEventSubjectGetterTempFileHandle() {
752 + return eventSubjectGetterTempFileHandle;
753 + }
754 +
755 + /**
756 + * Sets event subject getter temp file.
757 + *
758 + * @param eventSubjectGetterTempFileHandle event subject getter temp file
759 + */
760 + public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
761 + this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
762 + }
763 +
764 + /**
765 + * Returns event subject setter temp file.
766 + *
767 + * @return event subject setter temp file
768 + */
769 + public File getEventSubjectSetterTempFileHandle() {
770 + return eventSubjectSetterTempFileHandle;
771 + }
772 +
773 + /**
774 + * Sets event subject setter temp file.
775 + *
776 + * @param eventSubjectSetterTempFileHandle event subject setter temp file
777 + */
778 + public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
779 + this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
780 + }
781 +
782 + /**
783 + * Adds java snippet for events to event subject file.
784 + *
785 + * @param curNode current node
786 + * @param pluginConfig plugin configurations
787 + * @throws IOException when fails to do IO operations
788 + */
789 + public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
790 +
791 + String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(),
792 + pluginConfig.getConflictResolver()));
793 + String notificationName = ((YangNotification) curNode).getName();
794 +
795 + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(),
796 + getCapitalCase(currentInfo));
797 +
798 + JavaAttributeInfo javaAttributeInfo =
799 + getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
800 + null, false, false);
801 +
802 + /*Adds java info for event in respective temp files.*/
803 + addEventEnum(notificationName, pluginConfig);
804 + addEventSubjectAttribute(javaAttributeInfo, pluginConfig);
805 + addEventSubjectGetter(javaAttributeInfo, pluginConfig);
806 + addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo);
807 + }
808 +
809 + /*Adds event to enum temp file.*/
810 + private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException {
811 + appendToFile(getEventEnumTempFileHandle(),
812 + getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
813 + + getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
814 + }
815 +
816 + /*Adds event method in event class*/
817 + private void addEnumMethod(String eventClassname, String className) throws IOException {
818 + appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
819 + }
820 +
821 + /*Adds event method contents to event file.*/
822 + private static String getEventFileContents(String eventClassname, String classname) {
823 + return "\n" +
824 + " /**\n" +
825 + " * Creates " + classname + " event with type and subject.\n" +
826 + " *\n" +
827 + " * @param type event type\n" +
828 + " * @param subject subject " + classname + "\n" +
829 + " */\n" +
830 + " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
831 + " super(type, subject);\n" +
832 + " }\n" +
833 + "\n" +
834 + " /**\n" +
835 + " * Creates " + classname + " event with type, subject and time.\n" +
836 + " *\n" +
837 + " * @param type event type\n" +
838 + " * @param subject subject " + classname + "\n" +
839 + " * @param time time of event\n" +
840 + " */\n" +
841 + " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
842 + + " subject, long time) {\n" +
843 + " super(type, subject, time);\n" +
844 + " }\n" +
845 + "\n";
846 + }
847 +
848 + /*Adds events to event subject file.*/
849 + private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
850 + throws IOException {
851 + appendToFile(getEventSubjectAttributeTempFileHandle(),
852 + FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig));
853 + }
854 +
855 + /*Adds getter method for event in event subject class.*/
856 + private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
857 + appendToFile(getEventSubjectGetterTempFileHandle(),
858 + getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
859 + + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
860 + }
861 +
862 + /*Adds setter method for event in event subject class.*/
863 + private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
864 + throws IOException {
865 + appendToFile(getEventSubjectSetterTempFileHandle(),
866 + getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
867 + + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
868 + }
869 +
870 + /**
871 + * Returns a temporary file handle for the event's file type.
872 + *
873 + * @param fileName file name
874 + * @return temporary file handle
875 + * @throws IOException when fails to create new file handle
876 + */
877 + private File getJavaFileHandle(YangNode curNode, String name)
878 + throws IOException {
879 +
880 + JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
881 +
882 + return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
883 + parentInfo);
884 + }
885 +
886 + /**
887 + * Returns the directory path.
888 + *
889 + * @return directory path
890 + */
891 + private String getDirPath(JavaFileInfo parentInfo) {
892 + return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
893 + }
302 } 894 }
......
...@@ -26,8 +26,8 @@ import org.onosproject.yangutils.datamodel.YangType; ...@@ -26,8 +26,8 @@ import org.onosproject.yangutils.datamodel.YangType;
26 import org.onosproject.yangutils.datamodel.YangTypeHolder; 26 import org.onosproject.yangutils.datamodel.YangTypeHolder;
27 import org.onosproject.yangutils.translator.exception.TranslatorException; 27 import org.onosproject.yangutils.translator.exception.TranslatorException;
28 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; 28 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
29 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
29 30
30 -import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
...@@ -196,9 +196,10 @@ public class TempJavaTypeFragmentFiles ...@@ -196,9 +196,10 @@ public class TempJavaTypeFragmentFiles
196 * 196 *
197 * @param yangTypeHolder YANG java data model node which has type info, eg union / 197 * @param yangTypeHolder YANG java data model node which has type info, eg union /
198 * typedef 198 * typedef
199 + * @param pluginConfig plugin configurations for naming conventions
199 * @throws IOException IO operation fail 200 * @throws IOException IO operation fail
200 */ 201 */
201 - public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder) 202 + public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
202 throws IOException { 203 throws IOException {
203 204
204 List<YangType<?>> typeList = yangTypeHolder.getTypeList(); 205 List<YangType<?>> typeList = yangTypeHolder.getTypeList();
...@@ -208,18 +209,16 @@ public class TempJavaTypeFragmentFiles ...@@ -208,18 +209,16 @@ public class TempJavaTypeFragmentFiles
208 throw new TranslatorException("Type does not have Java info"); 209 throw new TranslatorException("Type does not have Java info");
209 } 210 }
210 YangJavaType<?> javaType = (YangJavaType<?>) yangType; 211 YangJavaType<?> javaType = (YangJavaType<?>) yangType;
211 - javaType.updateJavaQualifiedInfo(); 212 + javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
212 String typeName = javaType.getDataTypeName(); 213 String typeName = javaType.getDataTypeName();
213 - 214 + typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
214 - if (javaType.getDataType().equals(DERIVED)) {
215 - typeName = getCamelCase(typeName, null);
216 - }
217 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( 215 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
218 javaType.getJavaQualifiedInfo(), 216 javaType.getJavaQualifiedInfo(),
219 typeName, javaType, 217 typeName, javaType,
220 getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), 218 getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
221 false); 219 false);
222 - addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo); 220 + addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo,
221 + pluginConfig);
223 } 222 }
224 } 223 }
225 } 224 }
...@@ -231,18 +230,20 @@ public class TempJavaTypeFragmentFiles ...@@ -231,18 +230,20 @@ public class TempJavaTypeFragmentFiles
231 * @param hasType the node for which the type is being added as an attribute 230 * @param hasType the node for which the type is being added as an attribute
232 * @param javaAttributeInfo the attribute info that needs to be added to 231 * @param javaAttributeInfo the attribute info that needs to be added to
233 * temporary files 232 * temporary files
233 + * @param pluginConfig plugin configurations
234 * @throws IOException IO operation fail 234 * @throws IOException IO operation fail
235 */ 235 */
236 - private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo) 236 + private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo,
237 + YangPluginConfig pluginConfig)
237 throws IOException { 238 throws IOException {
238 239
239 - super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 240 + super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
240 241
241 if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) { 242 if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
242 - addOfStringMethod(javaAttributeInfo); 243 + addOfStringMethod(javaAttributeInfo, pluginConfig);
243 } 244 }
244 if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { 245 if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
245 - addTypeConstructor(javaAttributeInfo); 246 + addTypeConstructor(javaAttributeInfo, pluginConfig);
246 } 247 }
247 } 248 }
248 249
...@@ -250,24 +251,26 @@ public class TempJavaTypeFragmentFiles ...@@ -250,24 +251,26 @@ public class TempJavaTypeFragmentFiles
250 * Adds type constructor. 251 * Adds type constructor.
251 * 252 *
252 * @param attr attribute info 253 * @param attr attribute info
254 + * @param pluginConfig plugin configurations
253 * @throws IOException when fails to append to temporary file 255 * @throws IOException when fails to append to temporary file
254 */ 256 */
255 - private void addTypeConstructor(JavaAttributeInfo attr) 257 + private void addTypeConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
256 throws IOException { 258 throws IOException {
257 appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr, 259 appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
258 - getGeneratedJavaClassName()) + NEW_LINE); 260 + getGeneratedJavaClassName(), pluginConfig) + NEW_LINE);
259 } 261 }
260 262
261 /** 263 /**
262 * Adds of string for type. 264 * Adds of string for type.
263 * 265 *
264 * @param attr attribute info 266 * @param attr attribute info
267 + * @param pluginConfig plugin configurations
265 * @throws IOException when fails to append to temporary file 268 * @throws IOException when fails to append to temporary file
266 */ 269 */
267 - private void addOfStringMethod(JavaAttributeInfo attr) 270 + private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
268 throws IOException { 271 throws IOException {
269 appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, 272 appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
270 - getGeneratedJavaClassName()) 273 + getGeneratedJavaClassName(), pluginConfig)
271 + NEW_LINE); 274 + NEW_LINE);
272 } 275 }
273 276
......
...@@ -57,4 +57,19 @@ public interface JavaLeafInfoContainer ...@@ -57,4 +57,19 @@ public interface JavaLeafInfoContainer
57 * updates the qualified info. 57 * updates the qualified info.
58 */ 58 */
59 void updateJavaQualifiedInfo(); 59 void updateJavaQualifiedInfo();
60 +
61 + /**
62 + * Returns java naming conflict resolver.
63 + *
64 + * @return java naming conflict resolver
65 + */
66 + YangToJavaNamingConflictUtil getConflictResolveConfig();
67 +
68 + /**
69 + * Sets java naming conflict resolver.
70 + *
71 + * @param conflictResolveConfig java naming conflict resolver
72 + */
73 + void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig);
74 +
60 } 75 }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer; 18 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
19 - 19 +import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
20 20
21 /** 21 /**
22 * Represent java based identification of the YANG leaves. 22 * Represent java based identification of the YANG leaves.
...@@ -26,6 +26,8 @@ public interface JavaQualifiedTypeResolver ...@@ -26,6 +26,8 @@ public interface JavaQualifiedTypeResolver
26 26
27 /** 27 /**
28 * updates the qualified access details of the type. 28 * updates the qualified access details of the type.
29 + *
30 + * @param confilictResolver plugin configurations
29 */ 31 */
30 - void updateJavaQualifiedInfo(); 32 + void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver);
31 } 33 }
......
...@@ -15,18 +15,116 @@ ...@@ -15,18 +15,116 @@
15 */ 15 */
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 +import java.io.IOException;
19 +
18 import org.onosproject.yangutils.datamodel.YangGrouping; 20 import org.onosproject.yangutils.datamodel.YangGrouping;
21 +import org.onosproject.yangutils.translator.exception.TranslatorException;
22 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 +
27 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
19 29
20 /** 30 /**
21 * Represents grouping information extended to support java code generation. 31 * Represents grouping information extended to support java code generation.
22 */ 32 */
23 public class YangJavaGrouping 33 public class YangJavaGrouping
24 - extends YangGrouping { 34 + extends YangGrouping implements JavaCodeGeneratorInfo, JavaCodeGenerator {
35 +
36 + /**
37 + * Contains the information of the java file being generated.
38 + */
39 + private JavaFileInfo javaFileInfo;
40 +
41 + /**
42 + * File handle to maintain temporary java code fragments as per the code
43 + * snippet types.
44 + */
45 + private TempJavaCodeFragmentFiles tempFileHandle;
25 46
26 /** 47 /**
27 * Creates YANG Java grouping object. 48 * Creates YANG Java grouping object.
28 */ 49 */
29 public YangJavaGrouping() { 50 public YangJavaGrouping() {
30 super(); 51 super();
52 + setJavaFileInfo(new JavaFileInfo());
53 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
31 } 54 }
55 +
56 + /**
57 + * Returns the generated java file information.
58 + *
59 + * @return generated java file information
60 + */
61 + @Override
62 + public JavaFileInfo getJavaFileInfo() {
63 + if (javaFileInfo == null) {
64 + throw new TranslatorException("Missing java info in java datamodel node");
65 + }
66 + return javaFileInfo;
67 + }
68 +
69 + /**
70 + * Sets the java file info object.
71 + *
72 + * @param javaInfo java file info object
73 + */
74 + @Override
75 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
76 + javaFileInfo = javaInfo;
77 + }
78 +
79 + /**
80 + * Returns the temporary file handle.
81 + *
82 + * @return temporary file handle
83 + */
84 + @Override
85 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
86 + return tempFileHandle;
87 + }
88 +
89 + /**
90 + * Sets temporary file handle.
91 + *
92 + * @param fileHandle temporary file handle
93 + */
94 + @Override
95 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
96 + tempFileHandle = fileHandle;
97 + }
98 +
99 + /**
100 + * Prepare the information for java code generation corresponding to YANG
101 + * grouping info.
102 + *
103 + * @param yangPlugin YANG plugin config
104 + * @throws TranslatorException translator operation fail
105 + */
106 + @Override
107 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
108 + try {
109 + generateCodeOfNode(this, yangPlugin);
110 + } catch (IOException e) {
111 + throw new TranslatorException(
112 + "Failed to prepare generate code entry for container node " + this.getName());
113 + }
114 + }
115 +
116 + /**
117 + * Create a java file using the YANG grouping info.
118 + *
119 + * @throws TranslatorException translator operation fail
120 + */
121 + @Override
122 + public void generateCodeExit() throws TranslatorException {
123 + try {
124 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
125 + } catch (IOException e) {
126 + throw new TranslatorException("Failed to generate code for container node " + this.getName());
127 + }
128 + }
129 +
32 } 130 }
......
...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 27
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
29 -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 29 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
30 30
31 /** 31 /**
32 * Represents input information extended to support java code generation. 32 * Represents input information extended to support java code generation.
...@@ -46,6 +46,8 @@ public class YangJavaInput ...@@ -46,6 +46,8 @@ public class YangJavaInput
46 */ 46 */
47 private TempJavaCodeFragmentFiles tempFileHandle; 47 private TempJavaCodeFragmentFiles tempFileHandle;
48 48
49 + private boolean codeGenFlag;
50 +
49 /** 51 /**
50 * Creates an instance of java input. 52 * Creates an instance of java input.
51 */ 53 */
...@@ -108,7 +110,7 @@ public class YangJavaInput ...@@ -108,7 +110,7 @@ public class YangJavaInput
108 @Override 110 @Override
109 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { 111 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
110 try { 112 try {
111 - generateCodeOfNode(this, yangPlugin); 113 + generateCodeOfAugmentableNode(this, yangPlugin);
112 } catch (IOException e) { 114 } catch (IOException e) {
113 throw new TranslatorException( 115 throw new TranslatorException(
114 "Failed to prepare generate code entry for input node " + this.getName()); 116 "Failed to prepare generate code entry for input node " + this.getName());
...@@ -123,9 +125,29 @@ public class YangJavaInput ...@@ -123,9 +125,29 @@ public class YangJavaInput
123 @Override 125 @Override
124 public void generateCodeExit() throws TranslatorException { 126 public void generateCodeExit() throws TranslatorException {
125 try { 127 try {
126 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 128 + if (isCodeGenFlag()) {
129 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
130 + }
127 } catch (IOException e) { 131 } catch (IOException e) {
128 throw new TranslatorException("Failed to generate code for input node " + this.getName()); 132 throw new TranslatorException("Failed to generate code for input node " + this.getName());
129 } 133 }
130 } 134 }
135 +
136 + /**
137 + * Returns code generator flag.
138 + *
139 + * @return code generator flag
140 + */
141 + public boolean isCodeGenFlag() {
142 + return codeGenFlag;
143 + }
144 +
145 + /**
146 + * Sets code generator flag.
147 + *
148 + * @param codeGenFlag code generator flag
149 + */
150 + public void setCodeGenFlag(boolean codeGenFlag) {
151 + this.codeGenFlag = codeGenFlag;
152 + }
131 } 153 }
......
...@@ -30,6 +30,7 @@ public class YangJavaLeaf ...@@ -30,6 +30,7 @@ public class YangJavaLeaf
30 implements JavaLeafInfoContainer { 30 implements JavaLeafInfoContainer {
31 31
32 private JavaQualifiedTypeInfo javaQualifiedAccess; 32 private JavaQualifiedTypeInfo javaQualifiedAccess;
33 + private YangToJavaNamingConflictUtil conflictResolveConfig;
33 34
34 /** 35 /**
35 * Returns a new YANG leaf object with java qualified access details. 36 * Returns a new YANG leaf object with java qualified access details.
...@@ -50,6 +51,7 @@ public class YangJavaLeaf ...@@ -50,6 +51,7 @@ public class YangJavaLeaf
50 51
51 } 52 }
52 53
54 + @Override
53 public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) { 55 public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
54 return getCamelCase(getName(), conflictResolveConfig); 56 return getCamelCase(getName(), conflictResolveConfig);
55 } 57 }
...@@ -63,4 +65,25 @@ public class YangJavaLeaf ...@@ -63,4 +65,25 @@ public class YangJavaLeaf
63 public void updateJavaQualifiedInfo() { 65 public void updateJavaQualifiedInfo() {
64 updateLeavesJavaQualifiedInfo(this); 66 updateLeavesJavaQualifiedInfo(this);
65 } 67 }
68 +
69 + /**
70 + * Returns java naming conflict resolve configurations.
71 + *
72 + * @return java naming conflict resolve configurations
73 + */
74 + @Override
75 + public YangToJavaNamingConflictUtil getConflictResolveConfig() {
76 + return conflictResolveConfig;
77 + }
78 +
79 + /**
80 + * Sets java naming conflict resolve configurations.
81 + *
82 + * @param conflictResolveConfig java naming conflict resolve configurations
83 + */
84 + @Override
85 + public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
86 + this.conflictResolveConfig = conflictResolveConfig;
87 + }
88 +
66 } 89 }
......
...@@ -29,6 +29,7 @@ public class YangJavaLeafList ...@@ -29,6 +29,7 @@ public class YangJavaLeafList
29 extends YangLeafList 29 extends YangLeafList
30 implements JavaLeafInfoContainer { 30 implements JavaLeafInfoContainer {
31 private JavaQualifiedTypeInfo javaQualifiedAccess; 31 private JavaQualifiedTypeInfo javaQualifiedAccess;
32 + private YangToJavaNamingConflictUtil conflictResolveConfig;
32 33
33 /** 34 /**
34 * Returns a new YANG leaf object with java qualified access details. 35 * Returns a new YANG leaf object with java qualified access details.
...@@ -62,4 +63,24 @@ public class YangJavaLeafList ...@@ -62,4 +63,24 @@ public class YangJavaLeafList
62 public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) { 63 public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
63 javaQualifiedAccess = typeInfo; 64 javaQualifiedAccess = typeInfo;
64 } 65 }
66 +
67 + /**
68 + * Returns java naming conflict resolve configurations.
69 + *
70 + * @return java naming conflict resolve configurations
71 + */
72 + @Override
73 + public YangToJavaNamingConflictUtil getConflictResolveConfig() {
74 + return conflictResolveConfig;
75 + }
76 +
77 + /**
78 + * Sets java naming conflict resolve configurations.
79 + *
80 + * @param conflictResolveConfig java naming conflict resolve configurations
81 + */
82 + @Override
83 + public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
84 + this.conflictResolveConfig = conflictResolveConfig;
85 + }
65 } 86 }
......
...@@ -16,14 +16,21 @@ ...@@ -16,14 +16,21 @@
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 import java.io.IOException; 18 import java.io.IOException;
19 +import java.util.ArrayList;
20 +import java.util.List;
19 21
20 import org.onosproject.yangutils.datamodel.YangModule; 22 import org.onosproject.yangutils.datamodel.YangModule;
23 +import org.onosproject.yangutils.datamodel.YangNode;
24 +import org.onosproject.yangutils.datamodel.YangNotification;
21 import org.onosproject.yangutils.translator.exception.TranslatorException; 25 import org.onosproject.yangutils.translator.exception.TranslatorException;
22 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 26 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 28 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 29 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 30
31 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
33 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
28 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 35 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
29 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode; 36 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
...@@ -48,12 +55,24 @@ public class YangJavaModule ...@@ -48,12 +55,24 @@ public class YangJavaModule
48 private TempJavaCodeFragmentFiles tempFileHandle; 55 private TempJavaCodeFragmentFiles tempFileHandle;
49 56
50 /** 57 /**
58 + * List of notifications nodes.
59 + */
60 + private List<YangNode> notificationNodes;
61 +
62 + /**
51 * Creates a YANG node of module type. 63 * Creates a YANG node of module type.
52 */ 64 */
53 public YangJavaModule() { 65 public YangJavaModule() {
54 super(); 66 super();
55 setJavaFileInfo(new JavaFileInfo()); 67 setJavaFileInfo(new JavaFileInfo());
56 - getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); 68 + setNotificationNodes(new ArrayList<>());
69 + int gentype = GENERATE_SERVICE_AND_MANAGER;
70 + if (isNotificationChildNodePresent(this)) {
71 + gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
72 + | GENERATE_EVENT_LISTENER_INTERFACE;
73 + }
74 + getJavaFileInfo().setGeneratedFileTypes(gentype);
75 +
57 } 76 }
58 77
59 /** 78 /**
...@@ -107,7 +126,8 @@ public class YangJavaModule ...@@ -107,7 +126,8 @@ public class YangJavaModule
107 */ 126 */
108 @Override 127 @Override
109 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { 128 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
110 - String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); 129 + String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate(),
130 + yangPlugin.getConflictResolver());
111 try { 131 try {
112 generateCodeOfRootNode(this, yangPlugin, modulePkg); 132 generateCodeOfRootNode(this, yangPlugin, modulePkg);
113 } catch (IOException e) { 133 } catch (IOException e) {
...@@ -121,6 +141,15 @@ public class YangJavaModule ...@@ -121,6 +141,15 @@ public class YangJavaModule
121 */ 141 */
122 @Override 142 @Override
123 public void generateCodeExit() throws TranslatorException { 143 public void generateCodeExit() throws TranslatorException {
144 + /**
145 + * As part of the notification support the following files needs to be generated.
146 + * 1) Subject of the notification(event), this is simple interface with builder class.
147 + * 2) Event class extending "AbstractEvent" and defining event type enum.
148 + * 3) Event listener interface extending "EventListener".
149 + * 4) Event subject class.
150 + *
151 + * The manager class needs to extend the "ListenerRegistry".
152 + */
124 try { 153 try {
125 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 154 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
126 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + 155 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
...@@ -129,4 +158,53 @@ public class YangJavaModule ...@@ -129,4 +158,53 @@ public class YangJavaModule
129 throw new TranslatorException("Failed to generate code for module node " + this.getName()); 158 throw new TranslatorException("Failed to generate code for module node " + this.getName());
130 } 159 }
131 } 160 }
161 +
162 + /**
163 + * Returns notifications node list.
164 + *
165 + * @return notification nodes
166 + */
167 + public List<YangNode> getNotificationNodes() {
168 + return notificationNodes;
169 + }
170 +
171 + /**
172 + * Sets notifications list.
173 + *
174 + * @param notificationNodes notification list
175 + */
176 + private void setNotificationNodes(List<YangNode> notificationNodes) {
177 + this.notificationNodes = notificationNodes;
178 + }
179 +
180 + /**
181 + * Adds to notification node list.
182 + *
183 + * @param curNode notification node
184 + */
185 + private void addToNotificaitonList(YangNode curNode) {
186 + getNotificationNodes().add(curNode);
187 + }
188 +
189 + /**
190 + * Checks if there is any rpc defined in the module or sub-module.
191 + *
192 + * @param rootNode root node of the data model
193 + * @return status of rpc's existence
194 + */
195 + public boolean isNotificationChildNodePresent(YangNode rootNode) {
196 + YangNode childNode = rootNode.getChild();
197 +
198 + while (childNode != null) {
199 + if (childNode instanceof YangNotification) {
200 + addToNotificaitonList(childNode);
201 + }
202 + childNode = childNode.getNextSibling();
203 + }
204 +
205 + if (!getNotificationNodes().isEmpty()) {
206 + return true;
207 + }
208 + return false;
209 + }
132 } 210 }
......
...@@ -30,8 +30,6 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesCont ...@@ -30,8 +30,6 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesCont
30 import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; 30 import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
31 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 31 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
32 32
33 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
34 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
36 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 34 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
37 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode; 35 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
...@@ -62,8 +60,7 @@ public class YangJavaNotification ...@@ -62,8 +60,7 @@ public class YangJavaNotification
62 public YangJavaNotification() { 60 public YangJavaNotification() {
63 super(); 61 super();
64 setJavaFileInfo(new JavaFileInfo()); 62 setJavaFileInfo(new JavaFileInfo());
65 - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER 63 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
66 - | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE);
67 } 64 }
68 65
69 /** 66 /**
...@@ -167,17 +164,8 @@ public class YangJavaNotification ...@@ -167,17 +164,8 @@ public class YangJavaNotification
167 */ 164 */
168 @Override 165 @Override
169 public void generateCodeExit() throws TranslatorException { 166 public void generateCodeExit() throws TranslatorException {
170 - /**
171 - * As part of the notification support the following files needs to be generated.
172 - * 1) Subject of the notification(event), this is simple interface with builder class.
173 - * 2) Event class extending "AbstractEvent" and defining event type enum.
174 - * 3) Event listener interface extending "EventListener".
175 - *
176 - * The manager class needs to extend the "ListenerRegistry".
177 - */
178 try { 167 try {
179 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER 168 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
180 - | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
181 } catch (IOException e) { 169 } catch (IOException e) {
182 throw new TranslatorException("Failed to generate code for notification node " + this.getName()); 170 throw new TranslatorException("Failed to generate code for notification node " + this.getName());
183 } 171 }
......
...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 27
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
29 -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 29 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
30 30
31 /** 31 /**
32 * Represents output information extended to support java code generation. 32 * Represents output information extended to support java code generation.
...@@ -46,6 +46,8 @@ public class YangJavaOutput ...@@ -46,6 +46,8 @@ public class YangJavaOutput
46 */ 46 */
47 private TempJavaCodeFragmentFiles tempFileHandle; 47 private TempJavaCodeFragmentFiles tempFileHandle;
48 48
49 + private boolean codeGenFlag;
50 +
49 /** 51 /**
50 * Creates an instance of java output. 52 * Creates an instance of java output.
51 */ 53 */
...@@ -108,7 +110,7 @@ public class YangJavaOutput ...@@ -108,7 +110,7 @@ public class YangJavaOutput
108 @Override 110 @Override
109 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { 111 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
110 try { 112 try {
111 - generateCodeOfNode(this, yangPlugin); 113 + generateCodeOfAugmentableNode(this, yangPlugin);
112 } catch (IOException e) { 114 } catch (IOException e) {
113 throw new TranslatorException( 115 throw new TranslatorException(
114 "Failed to prepare generate code entry for output node " + this.getName()); 116 "Failed to prepare generate code entry for output node " + this.getName());
...@@ -124,10 +126,30 @@ public class YangJavaOutput ...@@ -124,10 +126,30 @@ public class YangJavaOutput
124 @Override 126 @Override
125 public void generateCodeExit() throws TranslatorException { 127 public void generateCodeExit() throws TranslatorException {
126 try { 128 try {
127 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 129 + if (isCodeGenFlag()) {
130 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
131 + }
128 } catch (IOException e) { 132 } catch (IOException e) {
129 throw new TranslatorException( 133 throw new TranslatorException(
130 "Failed to prepare generate code exit for output node " + this.getName()); 134 "Failed to prepare generate code exit for output node " + this.getName());
131 } 135 }
132 } 136 }
137 +
138 + /**
139 + * Returns code generator flag.
140 + *
141 + * @return code generator flag
142 + */
143 + public boolean isCodeGenFlag() {
144 + return codeGenFlag;
145 + }
146 +
147 + /**
148 + * Sets code generator flag.
149 + *
150 + * @param codeGenFlag code generator flag
151 + */
152 + public void setCodeGenFlag(boolean codeGenFlag) {
153 + this.codeGenFlag = codeGenFlag;
154 + }
133 } 155 }
......
...@@ -17,26 +17,36 @@ ...@@ -17,26 +17,36 @@
17 package org.onosproject.yangutils.translator.tojava.javamodel; 17 package org.onosproject.yangutils.translator.tojava.javamodel;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 +import java.util.List;
20 21
21 import org.onosproject.yangutils.datamodel.RpcNotificationContainer; 22 import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
22 import org.onosproject.yangutils.datamodel.YangInput; 23 import org.onosproject.yangutils.datamodel.YangInput;
24 +import org.onosproject.yangutils.datamodel.YangLeaf;
25 +import org.onosproject.yangutils.datamodel.YangLeafList;
26 +import org.onosproject.yangutils.datamodel.YangLeavesHolder;
23 import org.onosproject.yangutils.datamodel.YangNode; 27 import org.onosproject.yangutils.datamodel.YangNode;
24 import org.onosproject.yangutils.datamodel.YangOutput; 28 import org.onosproject.yangutils.datamodel.YangOutput;
25 import org.onosproject.yangutils.datamodel.YangRpc; 29 import org.onosproject.yangutils.datamodel.YangRpc;
30 +import org.onosproject.yangutils.datamodel.YangType;
26 import org.onosproject.yangutils.translator.exception.TranslatorException; 31 import org.onosproject.yangutils.translator.exception.TranslatorException;
27 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; 32 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
28 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 33 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
29 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 34 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
30 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; 35 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
31 -import org.onosproject.yangutils.translator.tojava.JavaImportData;
32 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 36 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
33 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 37 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
34 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 38 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
35 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; 39 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
36 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 40 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
37 41
42 +import static org.onosproject.yangutils.datamodel.YangNodeType.LIST_NODE;
38 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; 43 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
39 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; 44 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
45 +import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.resolveGroupingsQuailifiedInfo;
46 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType;
47 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
48 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
49 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
40 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 50 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
41 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; 51 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
42 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo; 52 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
...@@ -58,6 +68,11 @@ public class YangJavaRpc ...@@ -58,6 +68,11 @@ public class YangJavaRpc
58 */ 68 */
59 private TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles; 69 private TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
60 70
71 + private boolean isInputLeafHolder;
72 + private boolean isOutputLeafHolder;
73 + private boolean isInputSingleChildHolder;
74 + private boolean isOutputSingleChildHolder;
75 +
61 /** 76 /**
62 * Creates an instance of YANG java rpc. 77 * Creates an instance of YANG java rpc.
63 */ 78 */
...@@ -67,6 +82,40 @@ public class YangJavaRpc ...@@ -67,6 +82,40 @@ public class YangJavaRpc
67 } 82 }
68 83
69 /** 84 /**
85 + * Returns the generated java file information.
86 + *
87 + * @return generated java file information
88 + */
89 + @Override
90 + public JavaFileInfo getJavaFileInfo() {
91 +
92 + if (javaFileInfo == null) {
93 + throw new TranslatorException("missing java info in java datamodel node");
94 + }
95 + return javaFileInfo;
96 + }
97 +
98 + /**
99 + * Sets the java file info object.
100 + *
101 + * @param javaInfo java file info object
102 + */
103 + @Override
104 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
105 + javaFileInfo = javaInfo;
106 + }
107 +
108 + @Override
109 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
110 + return tempJavaCodeFragmentFiles;
111 + }
112 +
113 + @Override
114 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
115 + tempJavaCodeFragmentFiles = fileHandle;
116 + }
117 +
118 + /**
70 * Prepares the information for java code generation corresponding to YANG 119 * Prepares the information for java code generation corresponding to YANG
71 * RPC info. 120 * RPC info.
72 * 121 *
...@@ -83,6 +132,12 @@ public class YangJavaRpc ...@@ -83,6 +132,12 @@ public class YangJavaRpc
83 // Add package information for rpc and create corresponding folder. 132 // Add package information for rpc and create corresponding folder.
84 try { 133 try {
85 updatePackageInfo(this, yangPlugin); 134 updatePackageInfo(this, yangPlugin);
135 + if (this.getChild() != null) {
136 + processNodeEntry(this.getChild(), yangPlugin);
137 + if (this.getChild().getNextSibling() != null) {
138 + processNodeEntry(this.getChild().getNextSibling(), yangPlugin);
139 + }
140 + }
86 } catch (IOException e) { 141 } catch (IOException e) {
87 throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName()); 142 throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName());
88 } 143 }
...@@ -116,9 +171,10 @@ public class YangJavaRpc ...@@ -116,9 +171,10 @@ public class YangJavaRpc
116 YangNode yangNode = this.getChild(); 171 YangNode yangNode = this.getChild();
117 while (yangNode != null) { 172 while (yangNode != null) {
118 if (yangNode instanceof YangInput) { 173 if (yangNode instanceof YangInput) {
119 - javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this); 174 + javaAttributeInfoOfInput = processNodeExit(yangNode, getJavaFileInfo().getPluginConfig());
175 +
120 } else if (yangNode instanceof YangOutput) { 176 } else if (yangNode instanceof YangOutput) {
121 - javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this); 177 + javaAttributeInfoOfOutput = processNodeExit(yangNode, getJavaFileInfo().getPluginConfig());
122 } else { 178 } else {
123 // TODO throw exception 179 // TODO throw exception
124 } 180 }
...@@ -135,7 +191,9 @@ public class YangJavaRpc ...@@ -135,7 +191,9 @@ public class YangJavaRpc
135 try { 191 try {
136 ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() 192 ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
137 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, 193 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
138 - ((YangNode) this).getName()); 194 + ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(),
195 + ((YangNode) this).getName(), isInputLeafHolder(), isOutputLeafHolder(),
196 + isInputSingleChildHolder(), isOutputSingleChildHolder());
139 } catch (IOException e) { 197 } catch (IOException e) {
140 throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); 198 throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
141 } 199 }
...@@ -152,7 +210,7 @@ public class YangJavaRpc ...@@ -152,7 +210,7 @@ public class YangJavaRpc
152 * @return AttributeInfo attribute details required to add in temporary 210 * @return AttributeInfo attribute details required to add in temporary
153 * files 211 * files
154 */ 212 */
155 - public static JavaAttributeInfo getChildNodeAsAttributeInParentService( 213 + public JavaAttributeInfo getChildNodeAsAttributeInParentService(
156 YangNode childNode, YangNode currentNode) { 214 YangNode childNode, YangNode currentNode) {
157 215
158 YangNode parentNode = getParentNodeInGenCode(currentNode); 216 YangNode parentNode = getParentNodeInGenCode(currentNode);
...@@ -176,44 +234,368 @@ public class YangJavaRpc ...@@ -176,44 +234,368 @@ public class YangJavaRpc
176 if (tempJavaFragmentFiles == null) { 234 if (tempJavaFragmentFiles == null) {
177 throw new TranslatorException("Parent node does not have service file info"); 235 throw new TranslatorException("Parent node does not have service file info");
178 } 236 }
179 - 237 + boolean isQualified = addImportToService(qualifiedTypeInfo);
180 - JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
181 - boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
182 return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false); 238 return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
183 } 239 }
184 240
185 /** 241 /**
186 - * Returns the generated java file information. 242 + * Process input/output nodes.
187 * 243 *
188 - * @return generated java file information 244 + * @param node YANG node
245 + * @param yangPluginConfig plugin configurations
189 */ 246 */
190 - @Override 247 + private void processNodeEntry(YangNode node, YangPluginConfig yangPluginConfig) {
191 - public JavaFileInfo getJavaFileInfo() { 248 + YangLeavesHolder holder = (YangLeavesHolder) node;
249 + if (node.getChild() == null) {
250 + if (holder.getListOfLeaf() != null && holder.getListOfLeafList().isEmpty()
251 + && holder.getListOfLeaf().size() == 1) {
252 + setCodeGenFlagForNode(node, false);
253 + } else if (holder.getListOfLeaf().isEmpty() && holder.getListOfLeafList() != null
254 + && holder.getListOfLeafList().size() == 1) {
255 + setCodeGenFlagForNode(node, false);
256 + } else {
257 + setCodeGenFlagForNode(node, true);
258 + }
259 + } else if (node.getChild() != null && holder.getListOfLeaf().isEmpty()
260 + && holder.getListOfLeafList().isEmpty()) {
261 + if (getNumberOfChildNodes(node) == 1) {
262 + setCodeGenFlagForNode(node, false);
263 + } else {
264 + setCodeGenFlagForNode(node, true);
265 + }
266 + } else {
267 + setCodeGenFlagForNode(node, true);
268 + }
269 + }
192 270
193 - if (javaFileInfo == null) { 271 + /**
194 - throw new TranslatorException("missing java info in java datamodel node"); 272 + * Process input/output nodes.
273 + *
274 + * @param node YANG node
275 + * @param yangPluginConfig plugin configurations
276 + * @return java attribute info
277 + */
278 + private JavaAttributeInfo processNodeExit(YangNode node, YangPluginConfig yangPluginConfig) {
279 + YangLeavesHolder holder = (YangLeavesHolder) node;
280 + if (node.getChild() == null) {
281 + if (holder.getListOfLeaf() != null && holder.getListOfLeafList().isEmpty()
282 + && holder.getListOfLeaf().size() == 1) {
283 + return processNodeWhenOnlyOneLeafIsPresent(node, yangPluginConfig);
284 +
285 + } else if (holder.getListOfLeaf().isEmpty() && holder.getListOfLeafList() != null
286 + && holder.getListOfLeafList().size() == 1) {
287 + return processNodeWhenOnlyOneLeafListIsPresent(node, yangPluginConfig);
288 + } else {
289 + return processNodeWhenMultipleContaintsArePresent(node);
290 + }
291 + } else if (node.getChild() != null && holder.getListOfLeaf().isEmpty()
292 + && holder.getListOfLeafList().isEmpty()) {
293 + if (getNumberOfChildNodes(node) == 1) {
294 + return processNodeWhenOnlyOneChildNodeIsPresent(node, yangPluginConfig);
295 + } else {
296 + return processNodeWhenMultipleContaintsArePresent(node);
297 + }
298 + } else {
299 + return processNodeWhenMultipleContaintsArePresent(node);
195 } 300 }
196 - return javaFileInfo;
197 } 301 }
198 302
199 /** 303 /**
200 - * Sets the java file info object. 304 + * Process input/output node when one leaf is present.
201 * 305 *
202 - * @param javaInfo java file info object 306 + * @param node input/output node
307 + * @param yangPluginConfig plugin configurations
308 + * @return java attribute for node
203 */ 309 */
204 - @Override 310 + private JavaAttributeInfo processNodeWhenOnlyOneLeafIsPresent(YangNode node,
205 - public void setJavaFileInfo(JavaFileInfo javaInfo) { 311 + YangPluginConfig yangPluginConfig) {
206 - javaFileInfo = javaInfo; 312 +
313 + YangLeavesHolder holder = (YangLeavesHolder) node;
314 + List<YangLeaf> listOfLeaves = holder.getListOfLeaf();
315 +
316 + for (YangLeaf leaf : listOfLeaves) {
317 + if (!(leaf instanceof JavaLeafInfoContainer)) {
318 + throw new TranslatorException("Leaf does not have java information");
319 + }
320 + JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
321 + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
322 + javaLeaf.updateJavaQualifiedInfo();
323 + JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
324 + javaLeaf.getJavaQualifiedInfo(),
325 + javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
326 + javaLeaf.getDataType(),
327 + addTypeImport(javaLeaf.getDataType(), false, yangPluginConfig), false);
328 + setLeafHolderFlag(node, true);
329 + return javaAttributeInfo;
330 + }
331 + return null;
207 } 332 }
208 333
209 - @Override 334 + /**
210 - public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { 335 + * Process input/output node when one leaf list is present.
211 - return tempJavaCodeFragmentFiles; 336 + *
337 + * @param node input/output node
338 + * @param yangPluginConfig plugin configurations
339 + * @return java attribute for node
340 + */
341 + private JavaAttributeInfo processNodeWhenOnlyOneLeafListIsPresent(YangNode node,
342 + YangPluginConfig yangPluginConfig) {
343 +
344 + YangLeavesHolder holder = (YangLeavesHolder) node;
345 + List<YangLeafList> listOfLeafList = holder.getListOfLeafList();
346 +
347 + for (YangLeafList leafList : listOfLeafList) {
348 + if (!(leafList instanceof JavaLeafInfoContainer)) {
349 + throw new TranslatorException("Leaf-list does not have java information");
350 + }
351 + JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
352 + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
353 + javaLeaf.updateJavaQualifiedInfo();
354 + ((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
355 + .getServiceTempFiles().getJavaImportData().setIfListImported(true);
356 + JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
357 + javaLeaf.getJavaQualifiedInfo(),
358 + javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
359 + javaLeaf.getDataType(),
360 + addTypeImport(javaLeaf.getDataType(), true, yangPluginConfig),
361 + true);
362 + setLeafHolderFlag(node, true);
363 + return javaAttributeInfo;
364 + }
365 + return null;
212 } 366 }
213 367
214 - @Override 368 + /**
215 - public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { 369 + * Process input/output node when one child node is present.
216 - tempJavaCodeFragmentFiles = fileHandle; 370 + *
371 + * @param node input/output node
372 + * @param yangPluginConfig plugin configurations
373 + * @return java attribute for node
374 + */
375 + private JavaAttributeInfo processNodeWhenOnlyOneChildNodeIsPresent(YangNode node,
376 + YangPluginConfig yangPluginConfig) {
377 + JavaFileInfo rpcInfo = getJavaFileInfo();
378 + String clsInfo = "";
379 + JavaQualifiedTypeInfo childInfo = new JavaQualifiedTypeInfo();
380 + if (node.getChild() instanceof YangJavaUses) {
381 + childInfo = resolveGroupingsQuailifiedInfo(((YangJavaUses) node.getChild()).getRefGroup(),
382 + yangPluginConfig);
383 + clsInfo = getCapitalCase(getCamelCase(((YangJavaUses) node.getChild()).getRefGroup().getName(),
384 + yangPluginConfig.getConflictResolver()));
385 + } else {
386 + String pkg = (rpcInfo.getPackage() + "." + rpcInfo.getJavaName() + "."
387 + + getCamelCase(node.getName(), yangPluginConfig.getConflictResolver())).toLowerCase();
388 + clsInfo = getCapitalCase(
389 + getCamelCase(node.getChild().getName(), yangPluginConfig.getConflictResolver()));
390 + childInfo.setPkgInfo(pkg);
391 + childInfo.setClassInfo(clsInfo);
392 + }
393 + boolean isList = false;
394 + if (node.getChild().getNodeType().equals(LIST_NODE)) {
395 + isList = true;
396 + }
397 + boolean isQualified = addImportToService(childInfo);
398 +
399 + JavaAttributeInfo javaAttributeInfo =
400 + getAttributeInfoForTheData(childInfo, clsInfo, null, isQualified, isList);
401 +
402 + setLeafHolderFlag(node, false);
403 + setSingleChildHolderFlag(node, true);
404 + return javaAttributeInfo;
405 + }
406 +
407 + /**
408 + * Process input/output node when multiple leaf and child nodes are present.
409 + *
410 + * @param node input/output node
411 + * @return java attribute for node
412 + */
413 + private JavaAttributeInfo processNodeWhenMultipleContaintsArePresent(YangNode node) {
414 +
415 + setLeafHolderFlag(node, false);
416 + setSingleChildHolderFlag(node, false);
417 + return getChildNodeAsAttributeInParentService(node, this);
418 + }
419 +
420 + /**
421 + * Adds type import to the RPC import list.
422 + *
423 + * @param type YANG type
424 + * @param isList is list attribute
425 + * @param pluginConfig plugin configurations
426 + * @return type import to the RPC import list
427 + */
428 + private boolean addTypeImport(YangType<?> type, boolean isList, YangPluginConfig pluginConfig) {
429 +
430 + String classInfo = getJavaImportClass(type, isList, pluginConfig.getConflictResolver());
431 + if (classInfo == null) {
432 + classInfo = getJavaDataType(type);
433 + return false;
434 + } else {
435 + classInfo = getJavaImportClass(type, isList, pluginConfig.getConflictResolver());
436 + String pkgInfo = getJavaImportPackage(type, isList, pluginConfig.getConflictResolver());
437 + JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
438 + importInfo.setPkgInfo(pkgInfo);
439 + importInfo.setClassInfo(classInfo);
440 + if (!((JavaFileInfoContainer) this.getParent()).getJavaFileInfo().getJavaName().equals(classInfo)) {
441 + return addImportToService(importInfo);
442 + } else {
443 + return true;
444 + }
445 + }
446 + }
447 +
448 + /**
449 + * Adds to service class import list.
450 + *
451 + * @param importInfo import info
452 + * @return true or false
453 + */
454 + private boolean addImportToService(JavaQualifiedTypeInfo importInfo) {
455 + if (((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
456 + .getServiceTempFiles().getJavaImportData().addImportInfo(importInfo)) {
457 + return !((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
458 + .getServiceTempFiles().getJavaImportData().getImportSet().contains(importInfo);
459 + } else {
460 + return true;
461 + }
462 + }
463 +
464 + /**
465 + * Sets leaf holder flag for input/output.
466 + *
467 + * @param node input/output node
468 + * @param flag true or false
469 + */
470 + private void setLeafHolderFlag(YangNode node, boolean flag) {
471 + if (node instanceof YangJavaInput) {
472 + setInputLeafHolder(flag);
473 + } else {
474 + setOutputLeafHolder(flag);
475 + }
476 + }
477 +
478 + /**
479 + * Sets sing child holder flag for input/output.
480 + *
481 + * @param node input/output node
482 + * @param flag true or false
483 + */
484 + private void setSingleChildHolderFlag(YangNode node, boolean flag) {
485 + if (node instanceof YangJavaInput) {
486 + setInputSingleChildHolder(flag);
487 + } else {
488 + setOutputSingleChildHolder(flag);
489 + }
490 + }
491 +
492 + /**
493 + * Sets code generator flag for input and output.
494 + *
495 + * @param node YANG node
496 + * @param flag cod generator flag
497 + */
498 + private void setCodeGenFlagForNode(YangNode node, boolean flag) {
499 + if (node instanceof YangJavaInput) {
500 + ((YangJavaInput) node).setCodeGenFlag(flag);
501 + } else {
502 + ((YangJavaOutput) node).setCodeGenFlag(flag);
503 + }
504 +
505 + }
506 +
507 + /**
508 + * Counts the number of child nodes of a YANG node.
509 + *
510 + * @param node YANG node
511 + * @return count of children
512 + */
513 + private int getNumberOfChildNodes(YangNode node) {
514 + YangNode tempNode = node.getChild();
515 + int count = 0;
516 + if (tempNode != null) {
517 + count = 1;
518 + }
519 + while (tempNode != null) {
520 +
521 + tempNode = tempNode.getNextSibling();
522 + if (tempNode != null) {
523 + count++;
524 + }
525 + }
526 + return count;
527 + }
528 +
529 + /**
530 + * Returns true if input is a leaf holder.
531 + *
532 + * @return true if input is a leaf holder
533 + */
534 + public boolean isInputLeafHolder() {
535 + return isInputLeafHolder;
536 + }
537 +
538 + /**
539 + * Sets true if input is a leaf holder.
540 + *
541 + * @param isInputLeafHolder true if input is a leaf holder
542 + */
543 + public void setInputLeafHolder(boolean isInputLeafHolder) {
544 + this.isInputLeafHolder = isInputLeafHolder;
545 + }
546 +
547 + /**
548 + * Returns true if output is a leaf holder.
549 + *
550 + * @return true if output is a leaf holder
551 + */
552 + public boolean isOutputLeafHolder() {
553 + return isOutputLeafHolder;
554 + }
555 +
556 + /**
557 + * Sets true if output is a leaf holder.
558 + *
559 + * @param isOutputLeafHolder true if output is a leaf holder
560 + */
561 + public void setOutputLeafHolder(boolean isOutputLeafHolder) {
562 + this.isOutputLeafHolder = isOutputLeafHolder;
563 + }
564 +
565 + /**
566 + * Returns true if input is single child holder.
567 + *
568 + * @return true if input is single child holder
569 + */
570 + public boolean isInputSingleChildHolder() {
571 + return isInputSingleChildHolder;
572 + }
573 +
574 + /**
575 + * Sets true if input is single child holder.
576 + *
577 + * @param isInputSingleChildHolder true if input is single child holder
578 + */
579 + public void setInputSingleChildHolder(boolean isInputSingleChildHolder) {
580 + this.isInputSingleChildHolder = isInputSingleChildHolder;
581 + }
582 +
583 + /**
584 + * Returns true if output is single child holder.
585 + *
586 + * @return true if output is single child holder
587 + */
588 + public boolean isOutputSingleChildHolder() {
589 + return isOutputSingleChildHolder;
590 + }
591 +
592 + /**
593 + * Sets true if output is single child holder.
594 + *
595 + * @param isOutputSingleChildHolder true if output is single child holder
596 + */
597 + public void setOutputSingleChildHolder(boolean isOutputSingleChildHolder) {
598 + this.isOutputSingleChildHolder = isOutputSingleChildHolder;
217 } 599 }
218 600
219 } 601 }
......
...@@ -16,8 +16,13 @@ ...@@ -16,8 +16,13 @@
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 import java.io.IOException; 18 import java.io.IOException;
19 +import java.util.ArrayList;
20 +import java.util.List;
21 +
19 import org.onosproject.yangutils.datamodel.YangBelongsTo; 22 import org.onosproject.yangutils.datamodel.YangBelongsTo;
20 import org.onosproject.yangutils.datamodel.YangModule; 23 import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNotification;
21 import org.onosproject.yangutils.datamodel.YangSubModule; 26 import org.onosproject.yangutils.datamodel.YangSubModule;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 27 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 28 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
...@@ -25,6 +30,9 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; ...@@ -25,6 +30,9 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 30 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 31 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 32
33 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
34 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
35 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 37 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
30 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode; 38 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
...@@ -49,12 +57,22 @@ public class YangJavaSubModule ...@@ -49,12 +57,22 @@ public class YangJavaSubModule
49 private TempJavaCodeFragmentFiles tempFileHandle; 57 private TempJavaCodeFragmentFiles tempFileHandle;
50 58
51 /** 59 /**
60 + * List of notifications nodes.
61 + */
62 + private List<YangNode> notificationNodes = new ArrayList<>();
63 +
64 + /**
52 * Creates YANG java sub module object. 65 * Creates YANG java sub module object.
53 */ 66 */
54 public YangJavaSubModule() { 67 public YangJavaSubModule() {
55 super(); 68 super();
56 setJavaFileInfo(new JavaFileInfo()); 69 setJavaFileInfo(new JavaFileInfo());
57 - getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); 70 + int gentype = GENERATE_SERVICE_AND_MANAGER;
71 + if (isNotificationChildNodePresent(this)) {
72 + gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
73 + | GENERATE_EVENT_LISTENER_INTERFACE;
74 + }
75 + getJavaFileInfo().setGeneratedFileTypes(gentype);
58 } 76 }
59 77
60 /** 78 /**
...@@ -121,7 +139,7 @@ public class YangJavaSubModule ...@@ -121,7 +139,7 @@ public class YangJavaSubModule
121 @Override 139 @Override
122 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { 140 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
123 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), 141 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
124 - getRevision().getRevDate()); 142 + getRevision().getRevDate(), yangPlugin.getConflictResolver());
125 try { 143 try {
126 generateCodeOfRootNode(this, yangPlugin, subModulePkg); 144 generateCodeOfRootNode(this, yangPlugin, subModulePkg);
127 } catch (IOException e) { 145 } catch (IOException e) {
...@@ -136,6 +154,15 @@ public class YangJavaSubModule ...@@ -136,6 +154,15 @@ public class YangJavaSubModule
136 */ 154 */
137 @Override 155 @Override
138 public void generateCodeExit() throws TranslatorException { 156 public void generateCodeExit() throws TranslatorException {
157 + /**
158 + * As part of the notification support the following files needs to be generated.
159 + * 1) Subject of the notification(event), this is simple interface with builder class.
160 + * 2) Event class extending "AbstractEvent" and defining event type enum.
161 + * 3) Event listener interface extending "EventListener".
162 + * 4) Event subject class.
163 + *
164 + * The manager class needs to extend the "ListenerRegistry".
165 + */
139 try { 166 try {
140 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 167 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
141 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + 168 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
...@@ -144,4 +171,44 @@ public class YangJavaSubModule ...@@ -144,4 +171,44 @@ public class YangJavaSubModule
144 throw new TranslatorException("Failed to generate code for submodule node " + this.getName()); 171 throw new TranslatorException("Failed to generate code for submodule node " + this.getName());
145 } 172 }
146 } 173 }
174 +
175 + /**
176 + * Returns notifications node list.
177 + *
178 + * @return notification nodes
179 + */
180 + public List<YangNode> getNotificationNodes() {
181 + return notificationNodes;
182 + }
183 +
184 + /**
185 + * Adds to notification node list.
186 + *
187 + * @param curNode notification node
188 + */
189 + private void addToNotificaitonList(YangNode curNode) {
190 + getNotificationNodes().add(curNode);
191 + }
192 +
193 + /**
194 + * Checks if there is any rpc defined in the module or sub-module.
195 + *
196 + * @param rootNode root node of the data model
197 + * @return status of rpc's existence
198 + */
199 + public boolean isNotificationChildNodePresent(YangNode rootNode) {
200 + YangNode childNode = rootNode.getChild();
201 +
202 + while (childNode != null) {
203 + if (childNode instanceof YangNotification) {
204 + addToNotificaitonList(childNode);
205 + }
206 + childNode = childNode.getNextSibling();
207 + }
208 +
209 + if (!getNotificationNodes().isEmpty()) {
210 + return true;
211 + }
212 + return false;
213 + }
147 } 214 }
......
...@@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.YangType; ...@@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.YangType;
19 import org.onosproject.yangutils.translator.exception.TranslatorException; 19 import org.onosproject.yangutils.translator.exception.TranslatorException;
20 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 20 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
21 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; 21 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
22 +import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
22 23
23 /** 24 /**
24 * Represents java information corresponding to the YANG type. 25 * Represents java information corresponding to the YANG type.
...@@ -40,13 +41,13 @@ public class YangJavaType<T> ...@@ -40,13 +41,13 @@ public class YangJavaType<T>
40 } 41 }
41 42
42 @Override 43 @Override
43 - public void updateJavaQualifiedInfo() { 44 + public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil conflictResolver) {
44 JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo(); 45 JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
45 46
46 /* 47 /*
47 * Type is added as an attribute in the class. 48 * Type is added as an attribute in the class.
48 */ 49 */
49 - String className = AttributesJavaDataType.getJavaImportClass(this, false); 50 + String className = AttributesJavaDataType.getJavaImportClass(this, false, conflictResolver);
50 if (className != null) { 51 if (className != null) {
51 /* 52 /*
52 * Corresponding to the attribute type a class needs to be imported, 53 * Corresponding to the attribute type a class needs to be imported,
...@@ -54,7 +55,7 @@ public class YangJavaType<T> ...@@ -54,7 +55,7 @@ public class YangJavaType<T>
54 */ 55 */
55 importInfo.setClassInfo(className); 56 importInfo.setClassInfo(className);
56 String classPkg = AttributesJavaDataType.getJavaImportPackage(this, 57 String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
57 - false, className); 58 + false, conflictResolver);
58 if (classPkg == null) { 59 if (classPkg == null) {
59 throw new TranslatorException("import package cannot be null when the class is used"); 60 throw new TranslatorException("import package cannot be null when the class is used");
60 } 61 }
......
...@@ -15,18 +15,113 @@ ...@@ -15,18 +15,113 @@
15 */ 15 */
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 +import java.io.IOException;
19 +
18 import org.onosproject.yangutils.datamodel.YangUses; 20 import org.onosproject.yangutils.datamodel.YangUses;
21 +import org.onosproject.yangutils.translator.exception.TranslatorException;
22 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 +
27 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28 +import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
19 29
20 /** 30 /**
21 * Represents uses information extended to support java code generation. 31 * Represents uses information extended to support java code generation.
22 */ 32 */
23 public class YangJavaUses 33 public class YangJavaUses
24 - extends YangUses { 34 + extends YangUses implements JavaCodeGeneratorInfo, JavaCodeGenerator {
35 +
36 +
37 + /**
38 + * Contains the information of the java file being generated.
39 + */
40 + private JavaFileInfo javaFileInfo;
41 +
42 + /**
43 + * File handle to maintain temporary java code fragments as per the code
44 + * snippet types.
45 + */
46 + private TempJavaCodeFragmentFiles tempFileHandle;
25 47
26 /** 48 /**
27 * Creates YANG java uses object. 49 * Creates YANG java uses object.
28 */ 50 */
29 public YangJavaUses() { 51 public YangJavaUses() {
30 super(); 52 super();
53 + setJavaFileInfo(new JavaFileInfo());
54 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
55 + }
56 +
57 + /**
58 + * Returns 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 TranslatorException("Missing java info in java datamodel node");
66 + }
67 + return javaFileInfo;
68 + }
69 +
70 + /**
71 + * Sets 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;
31 } 78 }
79 +
80 + /**
81 + * Returns the temporary file handle.
82 + *
83 + * @return temporary file handle
84 + */
85 + @Override
86 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
87 + return tempFileHandle;
88 + }
89 +
90 + /**
91 + * Sets temporary file handle.
92 + *
93 + * @param fileHandle temporary file handle
94 + */
95 + @Override
96 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
97 + tempFileHandle = fileHandle;
98 + }
99 +
100 + /**
101 + * Prepare the information for java code generation corresponding to YANG
102 + * uses info.
103 + *
104 + * @param yangPlugin YANG plugin config
105 + * @throws TranslatorException translator operation fail
106 + */
107 + @Override
108 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
109 + try {
110 + addCurNodeInfoInParentTempFile(this, false, yangPlugin);
111 + } catch (IOException e) {
112 + throw new TranslatorException(
113 + "Failed to prepare generate code entry for container node " + this.getName());
114 + }
115 + }
116 +
117 + /**
118 + * Create a java file using the YANG uses info.
119 + *
120 + * @throws TranslatorException translator operation fail
121 + */
122 + @Override
123 + public void generateCodeExit() throws TranslatorException {
124 + // no code generation will be done for uses.
125 + }
126 +
32 } 127 }
......
...@@ -49,6 +49,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; ...@@ -49,6 +49,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
49 import static org.onosproject.yangutils.utils.UtilConstants.LONG; 49 import static org.onosproject.yangutils.utils.UtilConstants.LONG;
50 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; 50 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
51 import static org.onosproject.yangutils.utils.UtilConstants.NEW; 51 import static org.onosproject.yangutils.utils.UtilConstants.NEW;
52 +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
52 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; 53 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
53 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; 54 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
54 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; 55 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
...@@ -58,6 +59,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SHORT; ...@@ -58,6 +59,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
58 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; 59 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
59 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 60 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
60 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 61 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
62 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
63 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
64 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
65 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
61 66
62 /** 67 /**
63 * Represents java data types info corresponding to YANG type. 68 * Represents java data types info corresponding to YANG type.
...@@ -97,8 +102,10 @@ public final class AttributesJavaDataType { ...@@ -97,8 +102,10 @@ public final class AttributesJavaDataType {
97 return LONG; 102 return LONG;
98 case UINT64: 103 case UINT64:
99 return BIG_INTEGER; 104 return BIG_INTEGER;
105 + case BINARY:
106 + return YANG_BINARY_CLASS;
100 case DECIMAL64: 107 case DECIMAL64:
101 - //TODO: DECIMAL64. 108 + return YANG_DECIMAL64_CLASS;
102 case STRING: 109 case STRING:
103 return STRING_DATA_TYPE; 110 return STRING_DATA_TYPE;
104 case BOOLEAN: 111 case BOOLEAN:
...@@ -112,7 +119,7 @@ public final class AttributesJavaDataType { ...@@ -112,7 +119,7 @@ public final class AttributesJavaDataType {
112 * Returns from string method parsed string. 119 * Returns from string method parsed string.
113 * 120 *
114 * @param targetDataType target data type 121 * @param targetDataType target data type
115 - * @param yangType YANG type 122 + * @param yangType YANG type
116 * @return parsed string 123 * @return parsed string
117 */ 124 */
118 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) { 125 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
...@@ -136,18 +143,16 @@ public final class AttributesJavaDataType { ...@@ -136,18 +143,16 @@ public final class AttributesJavaDataType {
136 return LONG_WRAPPER + PERIOD + PARSE_LONG; 143 return LONG_WRAPPER + PERIOD + PARSE_LONG;
137 case UINT64: 144 case UINT64:
138 return NEW + SPACE + BIG_INTEGER; 145 return NEW + SPACE + BIG_INTEGER;
139 - case DECIMAL64:
140 - //TODO: DECIMAL64.
141 case STRING: 146 case STRING:
142 return EMPTY_STRING; 147 return EMPTY_STRING;
148 + case EMPTY:
143 case BOOLEAN: 149 case BOOLEAN:
144 - return BOOLEAN_DATA_TYPE; 150 + return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
145 - case ENUMERATION: 151 + case DECIMAL64:
146 - //TODO:ENUMERATION.
147 case BITS: 152 case BITS:
148 - //TODO:BITS
149 case BINARY: 153 case BINARY:
150 - //TODO:BINARY 154 + case UNION:
155 + case ENUMERATION:
151 case DERIVED: 156 case DERIVED:
152 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; 157 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
153 default: 158 default:
...@@ -158,11 +163,13 @@ public final class AttributesJavaDataType { ...@@ -158,11 +163,13 @@ public final class AttributesJavaDataType {
158 /** 163 /**
159 * Returns java import class. 164 * Returns java import class.
160 * 165 *
161 - * @param yangType YANG type 166 + * @param yangType YANG type
162 * @param isListAttr if the attribute need to be a list 167 * @param isListAttr if the attribute need to be a list
168 + * @param pluginConfig plugin configurations
163 * @return java import class 169 * @return java import class
164 */ 170 */
165 - public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) { 171 + public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr,
172 + YangToJavaNamingConflictUtil pluginConfig) {
166 173
167 YangDataTypes type = yangType.getDataType(); 174 YangDataTypes type = yangType.getDataType();
168 175
...@@ -185,21 +192,19 @@ public final class AttributesJavaDataType { ...@@ -185,21 +192,19 @@ public final class AttributesJavaDataType {
185 case UINT64: 192 case UINT64:
186 return BIG_INTEGER; 193 return BIG_INTEGER;
187 case DECIMAL64: 194 case DECIMAL64:
188 - //TODO: DECIMAL64. 195 + return YANG_DECIMAL64_CLASS;
189 - break;
190 case STRING: 196 case STRING:
191 return STRING_DATA_TYPE; 197 return STRING_DATA_TYPE;
192 case BOOLEAN: 198 case BOOLEAN:
193 return BOOLEAN_WRAPPER; 199 return BOOLEAN_WRAPPER;
194 case ENUMERATION: 200 case ENUMERATION:
195 return getCapitalCase( 201 return getCapitalCase(
196 - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); 202 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
203 + pluginConfig));
197 case BITS: 204 case BITS:
198 - //TODO:BITS 205 + return YANG_BITS_CLASS;
199 - break;
200 case BINARY: 206 case BINARY:
201 - //TODO:BINARY 207 + return YANG_BINARY_CLASS;
202 - break;
203 case LEAFREF: 208 case LEAFREF:
204 //TODO:LEAFREF 209 //TODO:LEAFREF
205 break; 210 break;
...@@ -210,11 +215,13 @@ public final class AttributesJavaDataType { ...@@ -210,11 +215,13 @@ public final class AttributesJavaDataType {
210 return BOOLEAN_WRAPPER; 215 return BOOLEAN_WRAPPER;
211 case UNION: 216 case UNION:
212 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 217 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
213 - null)); 218 + pluginConfig));
214 case INSTANCE_IDENTIFIER: 219 case INSTANCE_IDENTIFIER:
215 //TODO:INSTANCE_IDENTIFIER 220 //TODO:INSTANCE_IDENTIFIER
221 + break;
216 case DERIVED: 222 case DERIVED:
217 - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); 223 + return getCapitalCase(
224 + getCamelCase(yangType.getDataTypeName(), pluginConfig));
218 default: 225 default:
219 throw new TranslatorException("given data type is not supported."); 226 throw new TranslatorException("given data type is not supported.");
220 } 227 }
...@@ -223,19 +230,17 @@ public final class AttributesJavaDataType { ...@@ -223,19 +230,17 @@ public final class AttributesJavaDataType {
223 case UINT64: 230 case UINT64:
224 return BIG_INTEGER; 231 return BIG_INTEGER;
225 case DECIMAL64: 232 case DECIMAL64:
226 - //TODO: DECIMAL64. 233 + return YANG_DECIMAL64_CLASS;
227 - break;
228 case STRING: 234 case STRING:
229 return STRING_DATA_TYPE; 235 return STRING_DATA_TYPE;
230 case ENUMERATION: 236 case ENUMERATION:
231 return getCapitalCase( 237 return getCapitalCase(
232 - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); 238 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
239 + pluginConfig));
233 case BITS: 240 case BITS:
234 - //TODO:BITS 241 + return YANG_BITS_CLASS;
235 - break;
236 case BINARY: 242 case BINARY:
237 - //TODO:BINARY 243 + return YANG_BINARY_CLASS;
238 - break;
239 case LEAFREF: 244 case LEAFREF:
240 //TODO:LEAFREF 245 //TODO:LEAFREF
241 break; 246 break;
...@@ -243,16 +248,16 @@ public final class AttributesJavaDataType { ...@@ -243,16 +248,16 @@ public final class AttributesJavaDataType {
243 //TODO:IDENTITYREF 248 //TODO:IDENTITYREF
244 break; 249 break;
245 case EMPTY: 250 case EMPTY:
246 - //TODO:EMPTY 251 + return BOOLEAN_DATA_TYPE;
247 - break;
248 case UNION: 252 case UNION:
249 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 253 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
250 - null)); 254 + pluginConfig));
251 case INSTANCE_IDENTIFIER: 255 case INSTANCE_IDENTIFIER:
252 //TODO:INSTANCE_IDENTIFIER 256 //TODO:INSTANCE_IDENTIFIER
253 break; 257 break;
254 case DERIVED: 258 case DERIVED:
255 - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); 259 + return getCapitalCase(
260 + getCamelCase(yangType.getDataTypeName(), pluginConfig));
256 default: 261 default:
257 return null; 262 return null;
258 } 263 }
...@@ -263,12 +268,13 @@ public final class AttributesJavaDataType { ...@@ -263,12 +268,13 @@ public final class AttributesJavaDataType {
263 /** 268 /**
264 * Returns java import package. 269 * Returns java import package.
265 * 270 *
266 - * @param yangType YANG type 271 + * @param yangType YANG type
267 * @param isListAttr if the attribute is of list type 272 * @param isListAttr if the attribute is of list type
268 - * @param classInfo java import class info 273 + * @param conflictResolver object of YANG to java naming conflict util
269 * @return java import package 274 * @return java import package
270 */ 275 */
271 - public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { 276 + public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr,
277 + YangToJavaNamingConflictUtil conflictResolver) {
272 278
273 YangDataTypes type = yangType.getDataType(); 279 YangDataTypes type = yangType.getDataType();
274 280
...@@ -283,36 +289,29 @@ public final class AttributesJavaDataType { ...@@ -283,36 +289,29 @@ public final class AttributesJavaDataType {
283 case UINT32: 289 case UINT32:
284 case STRING: 290 case STRING:
285 case BOOLEAN: 291 case BOOLEAN:
292 + case EMPTY:
286 return JAVA_LANG; 293 return JAVA_LANG;
287 case UINT64: 294 case UINT64:
288 return JAVA_MATH; 295 return JAVA_MATH;
289 - case DECIMAL64:
290 - //TODO: DECIMAL64.
291 - break;
292 case ENUMERATION: 296 case ENUMERATION:
293 - return getEnumsPackage(yangType); 297 + return getEnumsPackage(yangType, conflictResolver);
298 + case DECIMAL64:
294 case BITS: 299 case BITS:
295 - //TODO:BITS
296 - break;
297 case BINARY: 300 case BINARY:
298 - //TODO:BINARY 301 + return YANG_TYPES_PKG;
299 - break;
300 case LEAFREF: 302 case LEAFREF:
301 //TODO:LEAFREF 303 //TODO:LEAFREF
302 break; 304 break;
303 case IDENTITYREF: 305 case IDENTITYREF:
304 //TODO:IDENTITYREF 306 //TODO:IDENTITYREF
305 break; 307 break;
306 - case EMPTY:
307 - //TODO:EMPTY
308 - break;
309 case UNION: 308 case UNION:
310 - return getUnionPackage(yangType); 309 + return getUnionPackage(yangType, conflictResolver);
311 case INSTANCE_IDENTIFIER: 310 case INSTANCE_IDENTIFIER:
312 //TODO:INSTANCE_IDENTIFIER 311 //TODO:INSTANCE_IDENTIFIER
313 break; 312 break;
314 case DERIVED: 313 case DERIVED:
315 - return getTypDefsPackage(yangType); 314 + return getTypDefsPackage(yangType, conflictResolver);
316 default: 315 default:
317 throw new TranslatorException("given data type is not supported."); 316 throw new TranslatorException("given data type is not supported.");
318 } 317 }
...@@ -320,19 +319,14 @@ public final class AttributesJavaDataType { ...@@ -320,19 +319,14 @@ public final class AttributesJavaDataType {
320 switch (type) { 319 switch (type) {
321 case UINT64: 320 case UINT64:
322 return JAVA_MATH; 321 return JAVA_MATH;
323 - case DECIMAL64:
324 - //TODO: DECIMAL64
325 - break;
326 case STRING: 322 case STRING:
327 return JAVA_LANG; 323 return JAVA_LANG;
328 case ENUMERATION: 324 case ENUMERATION:
329 - return getEnumsPackage(yangType); 325 + return getEnumsPackage(yangType, conflictResolver);
326 + case DECIMAL64:
330 case BITS: 327 case BITS:
331 - //TODO:BITS
332 - break;
333 case BINARY: 328 case BINARY:
334 - //TODO:BINARY 329 + return YANG_TYPES_PKG;
335 - break;
336 case LEAFREF: 330 case LEAFREF:
337 //TODO:LEAFREF 331 //TODO:LEAFREF
338 break; 332 break;
...@@ -340,15 +334,14 @@ public final class AttributesJavaDataType { ...@@ -340,15 +334,14 @@ public final class AttributesJavaDataType {
340 //TODO:IDENTITYREF 334 //TODO:IDENTITYREF
341 break; 335 break;
342 case EMPTY: 336 case EMPTY:
343 - //TODO:EMPTY 337 + return JAVA_LANG;
344 - break;
345 case UNION: 338 case UNION:
346 - return getUnionPackage(yangType); 339 + return getUnionPackage(yangType, conflictResolver);
347 case INSTANCE_IDENTIFIER: 340 case INSTANCE_IDENTIFIER:
348 //TODO:INSTANCE_IDENTIFIER 341 //TODO:INSTANCE_IDENTIFIER
349 break; 342 break;
350 case DERIVED: 343 case DERIVED:
351 - return getTypDefsPackage(yangType); 344 + return getTypDefsPackage(yangType, conflictResolver);
352 default: 345 default:
353 return null; 346 return null;
354 } 347 }
...@@ -360,9 +353,10 @@ public final class AttributesJavaDataType { ...@@ -360,9 +353,10 @@ public final class AttributesJavaDataType {
360 * Returns java package for typedef node. 353 * Returns java package for typedef node.
361 * 354 *
362 * @param type YANG type 355 * @param type YANG type
356 + * @param conflictResolver object of YANG to java naming conflict util
363 * @return java package for typedef node 357 * @return java package for typedef node
364 */ 358 */
365 - private static String getTypDefsPackage(YangType<?> type) { 359 + private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
366 Object var = type.getDataTypeExtendedInfo(); 360 Object var = type.getDataTypeExtendedInfo();
367 if (!(var instanceof YangDerivedInfo)) { 361 if (!(var instanceof YangDerivedInfo)) {
368 throw new TranslatorException("type should have been derived."); 362 throw new TranslatorException("type should have been derived.");
...@@ -374,7 +368,7 @@ public final class AttributesJavaDataType { ...@@ -374,7 +368,7 @@ public final class AttributesJavaDataType {
374 368
375 YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef(); 369 YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef();
376 if (typedef.getJavaFileInfo().getPackage() == null) { 370 if (typedef.getJavaFileInfo().getPackage() == null) {
377 - return getPackageFromParent(typedef.getParent()); 371 + return getPackageFromParent(typedef.getParent(), conflictResolver);
378 } 372 }
379 return typedef.getJavaFileInfo().getPackage(); 373 return typedef.getJavaFileInfo().getPackage();
380 } 374 }
...@@ -383,9 +377,10 @@ public final class AttributesJavaDataType { ...@@ -383,9 +377,10 @@ public final class AttributesJavaDataType {
383 * Returns java package for union node. 377 * Returns java package for union node.
384 * 378 *
385 * @param type YANG type 379 * @param type YANG type
380 + * @param conflictResolver object of YANG to java naming conflict util
386 * @return java package for union node 381 * @return java package for union node
387 */ 382 */
388 - private static String getUnionPackage(YangType<?> type) { 383 + private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
389 384
390 if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) { 385 if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
391 throw new TranslatorException("type should have been union."); 386 throw new TranslatorException("type should have been union.");
...@@ -393,7 +388,7 @@ public final class AttributesJavaDataType { ...@@ -393,7 +388,7 @@ public final class AttributesJavaDataType {
393 388
394 YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo(); 389 YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo();
395 if (union.getJavaFileInfo().getPackage() == null) { 390 if (union.getJavaFileInfo().getPackage() == null) {
396 - return getPackageFromParent(union.getParent()); 391 + return getPackageFromParent(union.getParent(), conflictResolver);
397 } 392 }
398 return union.getJavaFileInfo().getPackage(); 393 return union.getJavaFileInfo().getPackage();
399 } 394 }
...@@ -402,16 +397,17 @@ public final class AttributesJavaDataType { ...@@ -402,16 +397,17 @@ public final class AttributesJavaDataType {
402 * Returns YANG enumeration's java package. 397 * Returns YANG enumeration's java package.
403 * 398 *
404 * @param type YANG type 399 * @param type YANG type
400 + * @param conflictResolver object of YANG to java naming conflict util
405 * @return YANG enumeration's java package 401 * @return YANG enumeration's java package
406 */ 402 */
407 - private static String getEnumsPackage(YangType<?> type) { 403 + private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
408 404
409 if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) { 405 if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
410 throw new TranslatorException("type should have been enumeration."); 406 throw new TranslatorException("type should have been enumeration.");
411 } 407 }
412 YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo(); 408 YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo();
413 if (enumeration.getJavaFileInfo().getPackage() == null) { 409 if (enumeration.getJavaFileInfo().getPackage() == null) {
414 - return getPackageFromParent(enumeration.getParent()); 410 + return getPackageFromParent(enumeration.getParent(), conflictResolver);
415 } 411 }
416 return enumeration.getJavaFileInfo().getPackage(); 412 return enumeration.getJavaFileInfo().getPackage();
417 } 413 }
...@@ -420,9 +416,10 @@ public final class AttributesJavaDataType { ...@@ -420,9 +416,10 @@ public final class AttributesJavaDataType {
420 * Returns package from parent node. 416 * Returns package from parent node.
421 * 417 *
422 * @param parent parent YANG node 418 * @param parent parent YANG node
419 + * @param conflictResolver object of YANG to java naming conflict util
423 * @return java package from parent node 420 * @return java package from parent node
424 */ 421 */
425 - private static String getPackageFromParent(YangNode parent) { 422 + private static String getPackageFromParent(YangNode parent, YangToJavaNamingConflictUtil conflictResolver) {
426 if (!(parent instanceof JavaFileInfoContainer)) { 423 if (!(parent instanceof JavaFileInfoContainer)) {
427 throw new TranslatorException("invalid child node is being processed."); 424 throw new TranslatorException("invalid child node is being processed.");
428 } 425 }
...@@ -431,14 +428,14 @@ public final class AttributesJavaDataType { ...@@ -431,14 +428,14 @@ public final class AttributesJavaDataType {
431 if (parent instanceof YangJavaModule) { 428 if (parent instanceof YangJavaModule) {
432 YangJavaModule module = (YangJavaModule) parent; 429 YangJavaModule module = (YangJavaModule) parent;
433 String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module 430 String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
434 - .getRevision().getRevDate()); 431 + .getRevision().getRevDate(), conflictResolver);
435 - return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase(); 432 + return modulePkg + PERIOD + getCamelCase(module.getName(), conflictResolver).toLowerCase();
436 } else if (parent instanceof YangJavaSubModule) { 433 } else if (parent instanceof YangJavaSubModule) {
437 YangJavaSubModule submodule = (YangJavaSubModule) parent; 434 YangJavaSubModule submodule = (YangJavaSubModule) parent;
438 String subModulePkg = getRootPackage(submodule.getVersion(), 435 String subModulePkg = getRootPackage(submodule.getVersion(),
439 submodule.getNameSpaceFromModule(submodule.getBelongsTo()), 436 submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
440 - submodule.getRevision().getRevDate()); 437 + submodule.getRevision().getRevDate(), conflictResolver);
441 - return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase(); 438 + return subModulePkg + PERIOD + getCamelCase(submodule.getName(), conflictResolver).toLowerCase();
442 } 439 }
443 } 440 }
444 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); 441 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import org.onosproject.yangutils.datamodel.YangNode; 19 import org.onosproject.yangutils.datamodel.YangNode;
20 -import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
21 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 20 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
22 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 21 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
23 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; 22 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
...@@ -27,12 +26,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -27,12 +26,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
35 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
36 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 35 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
37 import static org.onosproject.yangutils.utils.UtilConstants.CLASS; 36 import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
38 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 37 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
...@@ -54,8 +53,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; ...@@ -54,8 +53,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
54 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; 53 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
55 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 54 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
56 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 55 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
56 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
57 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; 57 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
58 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 58 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
59 +import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
59 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
60 61
61 /** 62 /**
...@@ -95,8 +96,6 @@ public final class ClassDefinitionGenerator { ...@@ -95,8 +96,6 @@ public final class ClassDefinitionGenerator {
95 return getTypeClassDefinition(yangName); 96 return getTypeClassDefinition(yangName);
96 case GENERATE_ENUM_CLASS: 97 case GENERATE_ENUM_CLASS:
97 return getEnumClassDefinition(yangName); 98 return getEnumClassDefinition(yangName);
98 - case GENERATE_EVENT_LISTENER_INTERFACE:
99 - return getEventListenerDefinition(yangName);
100 default: 99 default:
101 return null; 100 return null;
102 } 101 }
...@@ -123,9 +122,12 @@ public final class ClassDefinitionGenerator { ...@@ -123,9 +122,12 @@ public final class ClassDefinitionGenerator {
123 case GENERATE_SERVICE_AND_MANAGER: 122 case GENERATE_SERVICE_AND_MANAGER:
124 return getRpcInterfaceDefinition(yangName, curNode); 123 return getRpcInterfaceDefinition(yangName, curNode);
125 case GENERATE_EVENT_CLASS: 124 case GENERATE_EVENT_CLASS:
126 - String eventName = getCapitalCase(((JavaFileInfoContainer) curNode) 125 + String eventName = yangName + SUBJECT;
127 - .getJavaFileInfo().getJavaName());
128 return getEventDefinition(yangName, eventName); 126 return getEventDefinition(yangName, eventName);
127 + case GENERATE_EVENT_LISTENER_INTERFACE:
128 + return getEventListenerDefinition(yangName);
129 + case GENERATE_EVENT_SUBJECT_CLASS:
130 + return getClassDefinition(yangName);
129 default: 131 default:
130 return null; 132 return null;
131 } 133 }
...@@ -183,7 +185,6 @@ public final class ClassDefinitionGenerator { ...@@ -183,7 +185,6 @@ public final class ClassDefinitionGenerator {
183 * Returns builder file class definition. 185 * Returns builder file class definition.
184 * 186 *
185 * @param yangName file name 187 * @param yangName file name
186 - * @param genFileTypes
187 * @return definition 188 * @return definition
188 */ 189 */
189 private static String getBuilderClassDefinition(String yangName) { 190 private static String getBuilderClassDefinition(String yangName) {
...@@ -198,8 +199,18 @@ public final class ClassDefinitionGenerator { ...@@ -198,8 +199,18 @@ public final class ClassDefinitionGenerator {
198 * @return definition 199 * @return definition
199 */ 200 */
200 private static String getImplClassDefinition(String yangName) { 201 private static String getImplClassDefinition(String yangName) {
201 - return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName 202 + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE
202 - + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 203 + + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
204 + }
205 +
206 + /**
207 + * Returns impl file class definition.
208 + *
209 + * @param yangName file name
210 + * @return definition
211 + */
212 + private static String getClassDefinition(String yangName) {
213 + return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
203 } 214 }
204 215
205 /** 216 /**
...@@ -231,27 +242,28 @@ public final class ClassDefinitionGenerator { ...@@ -231,27 +242,28 @@ public final class ClassDefinitionGenerator {
231 curNode = curNode.getNextSibling(); 242 curNode = curNode.getNextSibling();
232 } 243 }
233 } 244 }
234 - if (yangName.contains(SERVICE)) { 245 + if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
235 return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 246 return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
236 } 247 }
237 - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName 248 + return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + IMPLEMENTS + SPACE
238 - + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 249 + + yangName.substring(0, yangName.length() - 7) + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
239 } 250 }
240 251
241 /* Provides class definition when RPC interface needs to extends any event.*/ 252 /* Provides class definition when RPC interface needs to extends any event.*/
242 private static String getRpcInterfaceDefinitionWhenItExtends(String yangName, 253 private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
243 JavaExtendsListHolder holder) { 254 JavaExtendsListHolder holder) {
244 255
245 - if (yangName.contains(SERVICE)) { 256 + if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
246 String[] strArray = yangName.split(SERVICE); 257 String[] strArray = yangName.split(SERVICE);
247 - return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION 258 + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION
248 + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA 259 + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
249 + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE 260 + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
250 + OPEN_CURLY_BRACKET + NEW_LINE; 261 + OPEN_CURLY_BRACKET + NEW_LINE;
251 } 262 }
252 - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION 263 + yangName = yangName.substring(0, yangName.length() - 7);
264 + return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION
253 + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE 265 + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
254 - + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE 266 + + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE
255 + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET 267 + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
256 + NEW_LINE; 268 + NEW_LINE;
257 } 269 }
......
...@@ -115,7 +115,7 @@ public final class JavaCodeSnippetGen { ...@@ -115,7 +115,7 @@ public final class JavaCodeSnippetGen {
115 * @param type attribute type 115 * @param type attribute type
116 * @return list attribute string 116 * @return list attribute string
117 */ 117 */
118 - private static String getListAttribute(String type) { 118 + public static String getListAttribute(String type) {
119 return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; 119 return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
120 } 120 }
121 121
...@@ -145,10 +145,11 @@ public final class JavaCodeSnippetGen { ...@@ -145,10 +145,11 @@ public final class JavaCodeSnippetGen {
145 * 145 *
146 * @param name name of attribute 146 * @param name name of attribute
147 * @param value value of the enum 147 * @param value value of the enum
148 + * @param pluginConfig plugin configurations
148 * @return string for enum's attribute 149 * @return string for enum's attribute
149 */ 150 */
150 - public static String generateEnumAttributeString(String name, int value) { 151 + public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
151 - return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION 152 + return getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig) + FOUR_SPACE_INDENTATION
152 + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS 153 + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
153 + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; 154 + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
154 } 155 }
......
...@@ -27,18 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; ...@@ -27,18 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
27 import org.onosproject.yangutils.translator.tojava.JavaImportData; 27 import org.onosproject.yangutils.translator.tojava.JavaImportData;
28 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 28 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
29 29
30 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
31 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement; 30 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
32 -import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
33 -import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
34 -import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
35 -import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
36 -import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
37 -import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
38 -import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
39 -import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
40 -import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
41 -import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
42 31
43 /** 32 /**
44 * Represent the extends list for generated java classes. It holds the class details which needs 33 * Represent the extends list for generated java classes. It holds the class details which needs
...@@ -87,6 +76,7 @@ public class JavaExtendsListHolder { ...@@ -87,6 +76,7 @@ public class JavaExtendsListHolder {
87 if (!fileInfo.getPackage().equals(info.getPkgInfo())) { 76 if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
88 JavaImportData importData = getTempJavaFragement(node).getJavaImportData(); 77 JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
89 importData.addImportInfo(info); 78 importData.addImportInfo(info);
79 +
90 /*true means import should be added*/ 80 /*true means import should be added*/
91 getExtendedClassStore().put(info, true); 81 getExtendedClassStore().put(info, true);
92 } 82 }
...@@ -95,33 +85,6 @@ public class JavaExtendsListHolder { ...@@ -95,33 +85,6 @@ public class JavaExtendsListHolder {
95 } 85 }
96 86
97 /** 87 /**
98 - * Returns extends string for class.
99 - *
100 - * @param genFileType generated file type
101 - * @param className class name
102 - * @param isNotificationPresent if notification node is present
103 - * @return extends string
104 - */
105 - public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) {
106 - String extend = EXTEND + SPACE;
107 - if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) {
108 - extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE
109 - + className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE;
110 - } else {
111 - for (JavaQualifiedTypeInfo info : getExtendsList()) {
112 - if (info.getClassInfo().equals(className)) {
113 - if (!getExtendedClassStore().get(info)) {
114 - return extend + info.getClassInfo();
115 - } else {
116 - return extend + info.getPkgInfo() + PERIOD + info.getClassInfo();
117 - }
118 - }
119 - }
120 - }
121 - return null;
122 - }
123 -
124 - /**
125 * Returns extends list. 88 * Returns extends list.
126 * 89 *
127 * @return the extendsList 90 * @return the extendsList
......
...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; ...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
27 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 27 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
28 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 28 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
29 import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; 29 import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
30 +import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
30 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; 31 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
31 32
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
...@@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
38 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
...@@ -44,6 +46,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -44,6 +46,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
49 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
50 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
51 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
52 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
53 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; 54 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 55 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 56 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
...@@ -59,6 +66,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato ...@@ -59,6 +66,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
59 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute; 66 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
60 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; 67 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
61 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 68 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
69 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
70 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
62 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; 71 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
63 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; 72 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; 73 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
...@@ -75,6 +84,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -75,6 +84,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
75 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; 84 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl;
76 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; 85 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
77 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; 86 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
87 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getEventEnumTypeStart;
78 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; 88 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
79 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 89 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
80 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; 90 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
...@@ -82,20 +92,23 @@ import static org.onosproject.yangutils.utils.UtilConstants.COMMA; ...@@ -82,20 +92,23 @@ import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
82 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 92 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
83 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; 93 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
84 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; 94 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
95 +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
85 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 96 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
86 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 97 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
87 import static org.onosproject.yangutils.utils.UtilConstants.INT; 98 import static org.onosproject.yangutils.utils.UtilConstants.INT;
99 +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
100 +import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
88 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 101 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
89 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 102 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
90 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 103 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
91 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 104 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
92 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; 105 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
106 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
93 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 107 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
94 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 108 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
95 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
96 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 109 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
97 -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString;
98 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 110 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
111 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
99 112
100 /** 113 /**
101 * Representation of java file generator. 114 * Representation of java file generator.
...@@ -141,7 +154,7 @@ public final class JavaFileGenerator { ...@@ -141,7 +154,7 @@ public final class JavaFileGenerator {
141 + " while interface file generation"); 154 + " while interface file generation");
142 } 155 }
143 } 156 }
144 - return file; 157 + return validateLineLength(file);
145 } 158 }
146 159
147 /** 160 /**
...@@ -157,11 +170,12 @@ public final class JavaFileGenerator { ...@@ -157,11 +170,12 @@ public final class JavaFileGenerator {
157 throws IOException { 170 throws IOException {
158 171
159 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 172 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
173 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
160 174
161 String className = getCapitalCase(javaFileInfo.getJavaName()); 175 String className = getCapitalCase(javaFileInfo.getJavaName());
162 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 176 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
163 177
164 - initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path); 178 + initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path, pluginConfig);
165 List<String> methods = new ArrayList<>(); 179 List<String> methods = new ArrayList<>();
166 if (isAttrPresent) { 180 if (isAttrPresent) {
167 try { 181 try {
...@@ -188,7 +202,7 @@ public final class JavaFileGenerator { ...@@ -188,7 +202,7 @@ public final class JavaFileGenerator {
188 */ 202 */
189 methods.add( 203 methods.add(
190 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 204 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
191 - .addBuildMethodForInterface()); 205 + .addBuildMethodForInterface(pluginConfig));
192 206
193 /** 207 /**
194 * Add getters and setters in builder interface. 208 * Add getters and setters in builder interface.
...@@ -198,7 +212,7 @@ public final class JavaFileGenerator { ...@@ -198,7 +212,7 @@ public final class JavaFileGenerator {
198 } 212 }
199 213
200 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 214 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
201 - return file; 215 + return validateLineLength(file);
202 } 216 }
203 217
204 /** 218 /**
...@@ -216,11 +230,12 @@ public final class JavaFileGenerator { ...@@ -216,11 +230,12 @@ public final class JavaFileGenerator {
216 throws IOException { 230 throws IOException {
217 231
218 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 232 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
233 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
219 234
220 String className = getCapitalCase(javaFileInfo.getJavaName()); 235 String className = getCapitalCase(javaFileInfo.getJavaName());
221 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 236 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
222 237
223 - initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path); 238 + initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path, pluginConfig);
224 239
225 List<String> methods = new ArrayList<>(); 240 List<String> methods = new ArrayList<>();
226 241
...@@ -265,7 +280,7 @@ public final class JavaFileGenerator { ...@@ -265,7 +280,7 @@ public final class JavaFileGenerator {
265 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 280 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
266 .addBuildMethodImpl()); 281 .addBuildMethodImpl());
267 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 282 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
268 - .addDefaultConstructor(PUBLIC, BUILDER)); 283 + .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig));
269 284
270 /** 285 /**
271 * Add methods in builder class. 286 * Add methods in builder class.
...@@ -273,7 +288,7 @@ public final class JavaFileGenerator { ...@@ -273,7 +288,7 @@ public final class JavaFileGenerator {
273 for (String method : methods) { 288 for (String method : methods) {
274 insertDataIntoJavaFile(file, method); 289 insertDataIntoJavaFile(file, method);
275 } 290 }
276 - return file; 291 + return validateLineLength(file);
277 } 292 }
278 293
279 /** 294 /**
...@@ -292,12 +307,16 @@ public final class JavaFileGenerator { ...@@ -292,12 +307,16 @@ public final class JavaFileGenerator {
292 307
293 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 308 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
294 309
295 - String className = getCapitalCase(javaFileInfo.getJavaName()); 310 + String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER;
296 311
297 initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); 312 initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
298 313
299 List<String> methods = new ArrayList<>(); 314 List<String> methods = new ArrayList<>();
300 315
316 + insertDataIntoJavaFile(file, LOGGER_STATEMENT);
317 + methods.add(addActivateMethod());
318 + methods.add(addDeActivateMethod());
319 +
301 try { 320 try {
302 if (isAttrPresent) { 321 if (isAttrPresent) {
303 /** 322 /**
...@@ -338,7 +357,7 @@ public final class JavaFileGenerator { ...@@ -338,7 +357,7 @@ public final class JavaFileGenerator {
338 for (String method : methods) { 357 for (String method : methods) {
339 insertDataIntoJavaFile(file, method); 358 insertDataIntoJavaFile(file, method);
340 } 359 }
341 - return file; 360 + return validateLineLength(file);
342 } 361 }
343 362
344 /** 363 /**
...@@ -354,11 +373,12 @@ public final class JavaFileGenerator { ...@@ -354,11 +373,12 @@ public final class JavaFileGenerator {
354 throws IOException { 373 throws IOException {
355 374
356 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 375 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
376 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
357 377
358 String className = getCapitalCase(javaFileInfo.getJavaName()); 378 String className = getCapitalCase(javaFileInfo.getJavaName());
359 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 379 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
360 380
361 - initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); 381 + initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path, pluginConfig);
362 382
363 List<String> methods = new ArrayList<>(); 383 List<String> methods = new ArrayList<>();
364 384
...@@ -398,10 +418,10 @@ public final class JavaFileGenerator { ...@@ -398,10 +418,10 @@ public final class JavaFileGenerator {
398 /** 418 /**
399 * Hash code method. 419 * Hash code method.
400 */ 420 */
401 - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( 421 + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
402 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, 422 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
403 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 423 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
404 - .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)))); 424 + .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)));
405 /** 425 /**
406 * Equals method. 426 * Equals method.
407 */ 427 */
...@@ -429,9 +449,10 @@ public final class JavaFileGenerator { ...@@ -429,9 +449,10 @@ public final class JavaFileGenerator {
429 /** 449 /**
430 * Constructor. 450 * Constructor.
431 */ 451 */
432 - String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, 452 + String constructor =
433 - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 453 + getConstructorStart(className, pluginConfig) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
434 - .getBeanTempFiles()); 454 + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
455 + .getBeanTempFiles());
435 456
436 methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); 457 methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
437 } catch (IOException e) { 458 } catch (IOException e) {
...@@ -456,7 +477,7 @@ public final class JavaFileGenerator { ...@@ -456,7 +477,7 @@ public final class JavaFileGenerator {
456 } 477 }
457 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 478 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
458 479
459 - return file; 480 + return validateLineLength(file);
460 } 481 }
461 482
462 /** 483 /**
...@@ -472,11 +493,12 @@ public final class JavaFileGenerator { ...@@ -472,11 +493,12 @@ public final class JavaFileGenerator {
472 throws IOException { 493 throws IOException {
473 494
474 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 495 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
496 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
475 497
476 String className = getCapitalCase(javaFileInfo.getJavaName()); 498 String className = getCapitalCase(javaFileInfo.getJavaName());
477 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 499 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
478 500
479 - initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path); 501 + initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig);
480 502
481 List<String> methods = new ArrayList<>(); 503 List<String> methods = new ArrayList<>();
482 504
...@@ -497,7 +519,7 @@ public final class JavaFileGenerator { ...@@ -497,7 +519,7 @@ public final class JavaFileGenerator {
497 * Default constructor. 519 * Default constructor.
498 */ 520 */
499 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 521 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
500 - .addDefaultConstructor(PRIVATE, EMPTY_STRING)); 522 + .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
501 523
502 try { 524 try {
503 525
...@@ -522,11 +544,11 @@ public final class JavaFileGenerator { ...@@ -522,11 +544,11 @@ public final class JavaFileGenerator {
522 /** 544 /**
523 * Hash code method. 545 * Hash code method.
524 */ 546 */
525 - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( 547 + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
526 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, 548 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
527 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 549 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
528 .getTypeTempFiles()) 550 .getTypeTempFiles())
529 - .replace(NEW_LINE, EMPTY_STRING)))); 551 + .replace(NEW_LINE, EMPTY_STRING)));
530 552
531 /** 553 /**
532 * Equals method. 554 * Equals method.
...@@ -546,7 +568,7 @@ public final class JavaFileGenerator { ...@@ -546,7 +568,7 @@ public final class JavaFileGenerator {
546 /** 568 /**
547 * From string method. 569 * From string method.
548 */ 570 */
549 - methods.add(getFromStringMethodSignature(className) 571 + methods.add(getFromStringMethodSignature(className, pluginConfig)
550 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() 572 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
551 .getTypeTempFiles()) + getFromStringMethodClose()); 573 .getTypeTempFiles()) + getFromStringMethodClose());
552 574
...@@ -560,7 +582,7 @@ public final class JavaFileGenerator { ...@@ -560,7 +582,7 @@ public final class JavaFileGenerator {
560 } 582 }
561 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 583 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
562 584
563 - return file; 585 + return validateLineLength(file);
564 } 586 }
565 587
566 /** 588 /**
...@@ -576,11 +598,12 @@ public final class JavaFileGenerator { ...@@ -576,11 +598,12 @@ public final class JavaFileGenerator {
576 throws IOException { 598 throws IOException {
577 599
578 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 600 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
601 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
579 602
580 String className = getCapitalCase(javaFileInfo.getJavaName()); 603 String className = getCapitalCase(javaFileInfo.getJavaName());
581 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 604 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
582 605
583 - initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path); 606 + initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path, pluginConfig);
584 607
585 List<String> methods = new ArrayList<>(); 608 List<String> methods = new ArrayList<>();
586 609
...@@ -601,7 +624,7 @@ public final class JavaFileGenerator { ...@@ -601,7 +624,7 @@ public final class JavaFileGenerator {
601 * Default constructor. 624 * Default constructor.
602 */ 625 */
603 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 626 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
604 - .addDefaultConstructor(PRIVATE, EMPTY_STRING)); 627 + .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
605 628
606 try { 629 try {
607 630
...@@ -626,11 +649,11 @@ public final class JavaFileGenerator { ...@@ -626,11 +649,11 @@ public final class JavaFileGenerator {
626 /** 649 /**
627 * Hash code method. 650 * Hash code method.
628 */ 651 */
629 - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( 652 + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
630 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, 653 getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
631 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 654 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
632 .getTypeTempFiles()) 655 .getTypeTempFiles())
633 - .replace(NEW_LINE, EMPTY_STRING)))); 656 + .replace(NEW_LINE, EMPTY_STRING)));
634 657
635 /** 658 /**
636 * Equals method. 659 * Equals method.
...@@ -650,7 +673,7 @@ public final class JavaFileGenerator { ...@@ -650,7 +673,7 @@ public final class JavaFileGenerator {
650 /** 673 /**
651 * From string method. 674 * From string method.
652 */ 675 */
653 - methods.add(getFromStringMethodSignature(className) 676 + methods.add(getFromStringMethodSignature(className, pluginConfig)
654 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, 677 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
655 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()) 678 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
656 + getFromStringMethodClose()); 679 + getFromStringMethodClose());
...@@ -665,7 +688,7 @@ public final class JavaFileGenerator { ...@@ -665,7 +688,7 @@ public final class JavaFileGenerator {
665 } 688 }
666 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 689 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
667 690
668 - return file; 691 + return validateLineLength(file);
669 } 692 }
670 693
671 /** 694 /**
...@@ -680,11 +703,12 @@ public final class JavaFileGenerator { ...@@ -680,11 +703,12 @@ public final class JavaFileGenerator {
680 throws IOException { 703 throws IOException {
681 704
682 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 705 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
706 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
683 707
684 String className = javaFileInfo.getJavaName(); 708 String className = javaFileInfo.getJavaName();
685 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 709 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
686 710
687 - initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path); 711 + initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path, pluginConfig);
688 /** 712 /**
689 * Add attribute strings. 713 * Add attribute strings.
690 */ 714 */
...@@ -708,26 +732,26 @@ public final class JavaFileGenerator { ...@@ -708,26 +732,26 @@ public final class JavaFileGenerator {
708 /** 732 /**
709 * Add a constructor for enum. 733 * Add a constructor for enum.
710 */ 734 */
711 - insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false) 735 + insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig)
712 + getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE); 736 + getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE);
713 737
714 TempJavaEnumerationFragmentFiles enumFragFiles = 738 TempJavaEnumerationFragmentFiles enumFragFiles =
715 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 739 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
716 .getEnumerationTempFiles(); 740 .getEnumerationTempFiles();
717 insertDataIntoJavaFile(file, getEnumsOfMethod(className, 741 insertDataIntoJavaFile(file, getEnumsOfMethod(className,
718 - enumFragFiles.getJavaAttributeForEnum(), 742 + enumFragFiles.getJavaAttributeForEnum(pluginConfig),
719 enumFragFiles.getEnumSetJavaMap(), 743 enumFragFiles.getEnumSetJavaMap(),
720 - enumFragFiles.getEnumStringList()) 744 + enumFragFiles.getEnumStringList(), pluginConfig)
721 + NEW_LINE); 745 + NEW_LINE);
722 746
723 /** 747 /**
724 * Add a getter method for enum. 748 * Add a getter method for enum.
725 */ 749 */
726 - insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false) 750 + insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig)
727 + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); 751 + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
728 752
729 try { 753 try {
730 - insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className)) 754 + insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig)
731 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, 755 + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
732 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 756 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
733 .getEnumerationTempFiles()) 757 .getEnumerationTempFiles())
...@@ -739,7 +763,7 @@ public final class JavaFileGenerator { ...@@ -739,7 +763,7 @@ public final class JavaFileGenerator {
739 763
740 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 764 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
741 765
742 - return file; 766 + return validateLineLength(file);
743 } 767 }
744 768
745 /** 769 /**
...@@ -797,7 +821,7 @@ public final class JavaFileGenerator { ...@@ -797,7 +821,7 @@ public final class JavaFileGenerator {
797 } 821 }
798 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 822 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
799 823
800 - return file; 824 + return validateLineLength(file);
801 } 825 }
802 826
803 /** 827 /**
...@@ -810,49 +834,28 @@ public final class JavaFileGenerator { ...@@ -810,49 +834,28 @@ public final class JavaFileGenerator {
810 */ 834 */
811 public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { 835 public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
812 836
813 - YangNode parent = curNode.getParent();
814 - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
815 -
816 String className = 837 String className =
817 - getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) 838 + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
818 + EVENT_STRING; 839 + EVENT_STRING;
819 840
841 + TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
842 + .getTempJavaCodeFragmentFiles().getServiceTempFiles();
843 +
820 initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); 844 initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
821 - insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName())); 845 + try {
822 - insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 846 + insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() +
823 - } 847 + trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles), COMMA)
848 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
849 +
850 + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles));
851 +
852 + } catch (IOException e) {
853 + throw new IOException("No data found in temporary java code fragment files for " + className
854 + + " while event class file generation");
855 + }
824 856
825 - private static String getEventFileContents(String eventClassname, String classname) { 857 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
826 - return "\n" + 858 + validateLineLength(file);
827 - " public enum Type {\n" +
828 - " /**\n" +
829 - " * " + getCapitalCase(classname) + " notification.\n" +
830 - " */\n" +
831 - " " + classname.toUpperCase() + "_EVENT\n" +
832 - " }\n" +
833 - "\n" +
834 - " /**\n" +
835 - " * Creates " + classname + " event with type and subject.\n" +
836 - " *\n" +
837 - " * @param type event type\n" +
838 - " * @param subject subject " + classname + "\n" +
839 - " */\n" +
840 - " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
841 - " super(type, subject);\n" +
842 - " }\n" +
843 - "\n" +
844 - " /**\n" +
845 - " * Creates " + classname + " event with type, subject and time.\n" +
846 - " *\n" +
847 - " * @param type event type\n" +
848 - " * @param subject subject " + classname + "\n" +
849 - " * @param time time of event\n" +
850 - " */\n" +
851 - " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
852 - + " subject, long time) {\n" +
853 - " super(type, subject, time);\n" +
854 - " }\n" +
855 - "\n";
856 } 859 }
857 860
858 /** 861 /**
...@@ -865,15 +868,48 @@ public final class JavaFileGenerator { ...@@ -865,15 +868,48 @@ public final class JavaFileGenerator {
865 */ 868 */
866 public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) 869 public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
867 throws IOException { 870 throws IOException {
868 - YangNode parent = curNode.getParent();
869 - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
870 871
871 String className = 872 String className =
872 - getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) 873 + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
873 + EVENT_LISTENER_STRING; 874 + EVENT_LISTENER_STRING;
874 - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
875 875
876 - initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path); 876 + initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className);
877 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
878 + validateLineLength(file);
879 + }
880 +
881 + /**
882 + * Generates event subject's file.
883 + *
884 + * @param file file handle
885 + * @param curNode current YANG node
886 + * @throws IOException when fails to do IO exceptions
887 + */
888 + public static void generateEventSubjectFile(File file, YangNode curNode)
889 + throws IOException {
890 +
891 + String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
892 + + EVENT_SUBJECT_NAME_SUFFIX;
893 +
894 + initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className);
895 +
896 + TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
897 + .getTempJavaCodeFragmentFiles().getServiceTempFiles();
898 +
899 + insertDataIntoJavaFile(file, NEW_LINE);
900 + try {
901 + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles));
902 +
903 + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles));
904 +
905 + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles));
906 +
907 + } catch (IOException e) {
908 + throw new IOException("No data found in temporary java code fragment files for " + className
909 + + " while event class file generation");
910 + }
911 +
877 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 912 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
913 + validateLineLength(file);
878 } 914 }
879 } 915 }
......
...@@ -37,6 +37,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -37,6 +37,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
40 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
...@@ -47,6 +48,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -47,6 +48,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
51 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
52 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
53 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
54 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
55 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; 56 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 57 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 58 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
...@@ -60,28 +66,36 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -60,28 +66,36 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
60 import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; 66 import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
61 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; 67 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
62 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 68 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
69 +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
70 +import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
71 +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
63 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 72 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
73 +import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
64 import static org.onosproject.yangutils.utils.UtilConstants.INT; 74 import static org.onosproject.yangutils.utils.UtilConstants.INT;
65 -import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
66 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 75 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
67 -import static org.onosproject.yangutils.utils.UtilConstants.ORG; 76 +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
68 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; 77 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
78 +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
69 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 79 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
80 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
70 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 81 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
71 -import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; 82 +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION;
72 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 83 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
73 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 84 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
85 +import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
74 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; 86 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
75 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; 87 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
76 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; 88 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
77 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; 89 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
78 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT; 90 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
79 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER; 91 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
92 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
80 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 93 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
81 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 94 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
82 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; 95 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
83 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER; 96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER;
84 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 97 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
98 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg;
85 99
86 /** 100 /**
87 * Represents utilities for java file generator. 101 * Represents utilities for java file generator.
...@@ -136,6 +150,7 @@ public final class JavaFileGeneratorUtils { ...@@ -136,6 +150,7 @@ public final class JavaFileGeneratorUtils {
136 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { 150 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
137 serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; 151 serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
138 } 152 }
153 +
139 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { 154 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
140 return tempJavaFragmentFiles 155 return tempJavaFragmentFiles
141 .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle()); 156 .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
...@@ -201,6 +216,36 @@ public final class JavaFileGeneratorUtils { ...@@ -201,6 +216,36 @@ public final class JavaFileGeneratorUtils {
201 } 216 }
202 return serviceFragmentFiles 217 return serviceFragmentFiles
203 .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle()); 218 .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle());
219 + } else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) {
220 + if (serviceFragmentFiles == null) {
221 + throw new TranslatorException("Required rpc implementation info is missing.");
222 + }
223 + return serviceFragmentFiles
224 + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle());
225 + } else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) {
226 + if (serviceFragmentFiles == null) {
227 + throw new TranslatorException("Required rpc implementation info is missing.");
228 + }
229 + return serviceFragmentFiles
230 + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle());
231 + } else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
232 + if (serviceFragmentFiles == null) {
233 + throw new TranslatorException("Required rpc implementation info is missing.");
234 + }
235 + return serviceFragmentFiles
236 + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle());
237 + } else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
238 + if (serviceFragmentFiles == null) {
239 + throw new TranslatorException("Required rpc implementation info is missing.");
240 + }
241 + return serviceFragmentFiles
242 + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle());
243 + } else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
244 + if (serviceFragmentFiles == null) {
245 + throw new TranslatorException("Required rpc implementation info is missing.");
246 + }
247 + return serviceFragmentFiles
248 + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle());
204 } 249 }
205 return null; 250 return null;
206 } 251 }
...@@ -213,15 +258,16 @@ public final class JavaFileGeneratorUtils { ...@@ -213,15 +258,16 @@ public final class JavaFileGeneratorUtils {
213 * @param type generated file type 258 * @param type generated file type
214 * @param imports imports for the file 259 * @param imports imports for the file
215 * @param pkg generated file package 260 * @param pkg generated file package
261 + * @param pluginConfig plugin configurations
216 * @throws IOException when fails to generate a file 262 * @throws IOException when fails to generate a file
217 */ 263 */
218 public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports, 264 public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports,
219 - String pkg) 265 + String pkg, YangPluginConfig pluginConfig)
220 throws IOException { 266 throws IOException {
221 267
222 try { 268 try {
223 file.createNewFile(); 269 file.createNewFile();
224 - appendContents(file, className, type, imports, pkg); 270 + appendContents(file, className, type, imports, pkg, pluginConfig);
225 } catch (IOException e) { 271 } catch (IOException e) {
226 throw new IOException("Failed to create " + file.getName() + " class file."); 272 throw new IOException("Failed to create " + file.getName() + " class file.");
227 } 273 }
...@@ -263,9 +309,17 @@ public final class JavaFileGeneratorUtils { ...@@ -263,9 +309,17 @@ public final class JavaFileGeneratorUtils {
263 309
264 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 310 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
265 311
312 + String name = javaFileInfo.getJavaName();
266 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 313 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
267 - String pkgString = parsePackageString(path, importsList);
268 314
315 + String pkgString = null;
316 + if (type == GENERATE_EVENT_CLASS
317 + || type == GENERATE_EVENT_LISTENER_INTERFACE
318 + || type == GENERATE_EVENT_SUBJECT_CLASS) {
319 + pkgString = parsePackageString((path + PERIOD + name).toLowerCase(), importsList);
320 + } else {
321 + pkgString = parsePackageString(path, importsList);
322 + }
269 switch (type) { 323 switch (type) {
270 case INTERFACE_MASK: 324 case INTERFACE_MASK:
271 appendHeaderContents(file, pkgString, importsList); 325 appendHeaderContents(file, pkgString, importsList);
...@@ -279,6 +333,14 @@ public final class JavaFileGeneratorUtils { ...@@ -279,6 +333,14 @@ public final class JavaFileGeneratorUtils {
279 appendHeaderContents(file, pkgString, importsList); 333 appendHeaderContents(file, pkgString, importsList);
280 write(file, type, EVENT, curNode, className); 334 write(file, type, EVENT, curNode, className);
281 break; 335 break;
336 + case GENERATE_EVENT_LISTENER_INTERFACE:
337 + appendHeaderContents(file, pkgString, importsList);
338 + write(file, type, EVENT_LISTENER, curNode, className);
339 + break;
340 + case GENERATE_EVENT_SUBJECT_CLASS:
341 + appendHeaderContents(file, pkgString, importsList);
342 + write(file, type, EVENT_SUBJECT_CLASS, curNode, className);
343 + break;
282 default: 344 default:
283 break; 345 break;
284 } 346 }
...@@ -294,37 +356,34 @@ public final class JavaFileGeneratorUtils { ...@@ -294,37 +356,34 @@ public final class JavaFileGeneratorUtils {
294 * @param importsList list of java imports. 356 * @param importsList list of java imports.
295 * @throws IOException when fails to append contents 357 * @throws IOException when fails to append contents
296 */ 358 */
297 - private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg) 359 + private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg,
360 + YangPluginConfig pluginConfig)
298 throws IOException { 361 throws IOException {
299 362
300 String pkgString = parsePackageString(pkg, importsList); 363 String pkgString = parsePackageString(pkg, importsList);
301 364
302 switch (type) { 365 switch (type) {
303 case IMPL_CLASS_MASK: 366 case IMPL_CLASS_MASK:
304 - write(file, fileName, type, IMPL_CLASS); 367 + write(file, fileName, type, IMPL_CLASS, pluginConfig);
305 break; 368 break;
306 case BUILDER_INTERFACE_MASK: 369 case BUILDER_INTERFACE_MASK:
307 - write(file, fileName, type, BUILDER_INTERFACE); 370 + write(file, fileName, type, BUILDER_INTERFACE, pluginConfig);
308 break; 371 break;
309 case GENERATE_TYPEDEF_CLASS: 372 case GENERATE_TYPEDEF_CLASS:
310 appendHeaderContents(file, pkgString, importsList); 373 appendHeaderContents(file, pkgString, importsList);
311 - write(file, fileName, type, IMPL_CLASS); 374 + write(file, fileName, type, IMPL_CLASS, pluginConfig);
312 break; 375 break;
313 case BUILDER_CLASS_MASK: 376 case BUILDER_CLASS_MASK:
314 appendHeaderContents(file, pkgString, importsList); 377 appendHeaderContents(file, pkgString, importsList);
315 - write(file, fileName, type, BUILDER_CLASS); 378 + write(file, fileName, type, BUILDER_CLASS, pluginConfig);
316 break; 379 break;
317 case GENERATE_UNION_CLASS: 380 case GENERATE_UNION_CLASS:
318 appendHeaderContents(file, pkgString, importsList); 381 appendHeaderContents(file, pkgString, importsList);
319 - write(file, fileName, type, IMPL_CLASS); 382 + write(file, fileName, type, IMPL_CLASS, pluginConfig);
320 break; 383 break;
321 case GENERATE_ENUM_CLASS: 384 case GENERATE_ENUM_CLASS:
322 appendHeaderContents(file, pkgString, importsList); 385 appendHeaderContents(file, pkgString, importsList);
323 - write(file, fileName, type, ENUM_CLASS); 386 + write(file, fileName, type, ENUM_CLASS, pluginConfig);
324 - break;
325 - case GENERATE_EVENT_LISTENER_INTERFACE:
326 - appendHeaderContents(file, pkgString, importsList);
327 - write(file, fileName, type, EVENT_LISTENER);
328 break; 387 break;
329 default: 388 default:
330 break; 389 break;
...@@ -340,10 +399,7 @@ public final class JavaFileGeneratorUtils { ...@@ -340,10 +399,7 @@ public final class JavaFileGeneratorUtils {
340 */ 399 */
341 private static String parsePackageString(String javaPkg, List<String> importsList) { 400 private static String parsePackageString(String javaPkg, List<String> importsList) {
342 401
343 - if (javaPkg.contains(ORG)) { 402 + javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg));
344 - String[] strArray = javaPkg.split(ORG);
345 - javaPkg = ORG + getJavaPackageFromPackagePath(strArray[1]);
346 - }
347 if (importsList != null) { 403 if (importsList != null) {
348 if (!importsList.isEmpty()) { 404 if (!importsList.isEmpty()) {
349 return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE; 405 return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE;
...@@ -395,14 +451,16 @@ public final class JavaFileGeneratorUtils { ...@@ -395,14 +451,16 @@ public final class JavaFileGeneratorUtils {
395 private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName) 451 private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName)
396 throws IOException { 452 throws IOException {
397 453
454 + YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
398 if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { 455 if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
399 - if (!fileName.contains(SERVICE)) { 456 + if (!fileName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
400 - insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false)); 457 + insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName, false, pluginConfig));
458 + insertDataIntoJavaFile(file, addComponentString());
401 } else { 459 } else {
402 - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); 460 + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
403 } 461 }
404 } else { 462 } else {
405 - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); 463 + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
406 } 464 }
407 insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode)); 465 insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
408 } 466 }
...@@ -416,9 +474,10 @@ public final class JavaFileGeneratorUtils { ...@@ -416,9 +474,10 @@ public final class JavaFileGeneratorUtils {
416 * @param javaDocType java doc type 474 * @param javaDocType java doc type
417 * @throws IOException when fails to write into a file 475 * @throws IOException when fails to write into a file
418 */ 476 */
419 - private static void write(File file, String fileName, int genType, JavaDocType javaDocType) 477 + private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
478 + YangPluginConfig pluginConfig)
420 throws IOException { 479 throws IOException {
421 - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); 480 + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
422 insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName)); 481 insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
423 } 482 }
424 483
...@@ -433,4 +492,13 @@ public final class JavaFileGeneratorUtils { ...@@ -433,4 +492,13 @@ public final class JavaFileGeneratorUtils {
433 + SEMI_COLAN + NEW_LINE; 492 + SEMI_COLAN + NEW_LINE;
434 } 493 }
435 494
495 + /**
496 + * Returns component string.
497 + *
498 + * @return component string
499 + */
500 + public static String addComponentString() {
501 + return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
502 + + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
503 + }
436 } 504 }
......
...@@ -75,16 +75,18 @@ public final class JavaIdentifierSyntax { ...@@ -75,16 +75,18 @@ public final class JavaIdentifierSyntax {
75 * @param version YANG version 75 * @param version YANG version
76 * @param nameSpace name space of the module 76 * @param nameSpace name space of the module
77 * @param revision revision of the module defined 77 * @param revision revision of the module defined
78 - * @return returns the root package string 78 + * @param conflictResolver object of YANG to java naming conflict util
79 + * @return the root package string
79 */ 80 */
80 - public static String getRootPackage(byte version, String nameSpace, String revision) { 81 + public static String getRootPackage(byte version, String nameSpace, String revision,
82 + YangToJavaNamingConflictUtil conflictResolver) {
81 83
82 String pkg; 84 String pkg;
83 pkg = DEFAULT_BASE_PKG; 85 pkg = DEFAULT_BASE_PKG;
84 pkg = pkg + PERIOD; 86 pkg = pkg + PERIOD;
85 pkg = pkg + getYangVersion(version); 87 pkg = pkg + getYangVersion(version);
86 pkg = pkg + PERIOD; 88 pkg = pkg + PERIOD;
87 - pkg = pkg + getPkgFromNameSpace(nameSpace); 89 + pkg = pkg + getPkgFromNameSpace(nameSpace, conflictResolver);
88 pkg = pkg + PERIOD; 90 pkg = pkg + PERIOD;
89 pkg = pkg + getYangRevisionStr(revision); 91 pkg = pkg + getYangRevisionStr(revision);
90 92
...@@ -144,9 +146,10 @@ public final class JavaIdentifierSyntax { ...@@ -144,9 +146,10 @@ public final class JavaIdentifierSyntax {
144 * Returns package name from name space. 146 * Returns package name from name space.
145 * 147 *
146 * @param nameSpace name space of YANG module 148 * @param nameSpace name space of YANG module
149 + * @param conflictResolver object of YANG to java naming conflict util
147 * @return java package name as per java rules 150 * @return java package name as per java rules
148 */ 151 */
149 - private static String getPkgFromNameSpace(String nameSpace) { 152 + private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) {
150 153
151 ArrayList<String> pkgArr = new ArrayList<String>(); 154 ArrayList<String> pkgArr = new ArrayList<String>();
152 nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); 155 nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
...@@ -156,7 +159,7 @@ public final class JavaIdentifierSyntax { ...@@ -156,7 +159,7 @@ public final class JavaIdentifierSyntax {
156 for (String nameSpaceString : nameSpaceArr) { 159 for (String nameSpaceString : nameSpaceArr) {
157 pkgArr.add(nameSpaceString); 160 pkgArr.add(nameSpaceString);
158 } 161 }
159 - return getPkgFrmArr(pkgArr); 162 + return getPkgFrmArr(pkgArr, conflictResolver);
160 } 163 }
161 164
162 /** 165 /**
...@@ -194,17 +197,19 @@ public final class JavaIdentifierSyntax { ...@@ -194,17 +197,19 @@ public final class JavaIdentifierSyntax {
194 * Returns the package string. 197 * Returns the package string.
195 * 198 *
196 * @param pkgArr package array 199 * @param pkgArr package array
200 + * @param conflictResolver object of YANG to java naming conflict util
197 * @return package string 201 * @return package string
198 */ 202 */
199 - private static String getPkgFrmArr(ArrayList<String> pkgArr) { 203 + private static String getPkgFrmArr(ArrayList<String> pkgArr, YangToJavaNamingConflictUtil conflictResolver) {
200 204
201 String pkg = EMPTY_STRING; 205 String pkg = EMPTY_STRING;
202 int size = pkgArr.size(); 206 int size = pkgArr.size();
203 int i = 0; 207 int i = 0;
204 for (String member : pkgArr) { 208 for (String member : pkgArr) {
205 - boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member); 209 + boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
206 if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { 210 if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
207 - member = YANG_AUTO_PREFIX + member; 211 + String prefix = getPrefixForIdentifier(conflictResolver);
212 + member = prefix + member;
208 } 213 }
209 pkg = pkg + member; 214 pkg = pkg + member;
210 if (i != size - 1) { 215 if (i != size - 1) {
...@@ -216,20 +221,40 @@ public final class JavaIdentifierSyntax { ...@@ -216,20 +221,40 @@ public final class JavaIdentifierSyntax {
216 } 221 }
217 222
218 /** 223 /**
219 - * Returns package sub name from YANG identifier name. 224 + * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
220 * 225 *
221 - * @param name YANG identifier name 226 + * @param conflictResolver object of YANG to java naming conflict util
222 - * @return java package sub name as per java rules 227 + * @return prefix which needs to be added
223 */ 228 */
224 - public static String getSubPkgFromName(String name) { 229 + public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
225 -
226 - ArrayList<String> pkgArr = new ArrayList<String>();
227 - String[] nameArr = name.split(COLAN);
228 230
229 - for (String nameString : nameArr) { 231 + String prefixForIdentifier = null;
230 - pkgArr.add(nameString); 232 + if (conflictResolver != null) {
233 + prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
234 + }
235 + if (prefixForIdentifier != null) {
236 + prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
237 + String[] strArray = prefixForIdentifier.split(COLAN);
238 + try {
239 + if (strArray[0].isEmpty()) {
240 + List<String> stringArrangement = new ArrayList<String>();
241 + for (int i = 1; i < strArray.length; i++) {
242 + stringArrangement.add(strArray[i]);
243 + }
244 + strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
245 + }
246 + prefixForIdentifier = strArray[0];
247 + for (int j = 1; j < strArray.length; j++) {
248 + prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
249 + strArray[j].substring(1);
250 + }
251 + } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
252 + throw new TranslatorException("The given prefix in pom.xml is invalid.");
253 + }
254 + } else {
255 + prefixForIdentifier = YANG_AUTO_PREFIX;
231 } 256 }
232 - return getPkgFrmArr(pkgArr); 257 + return prefixForIdentifier;
233 } 258 }
234 259
235 /** 260 /**
...@@ -267,16 +292,18 @@ public final class JavaIdentifierSyntax { ...@@ -267,16 +292,18 @@ public final class JavaIdentifierSyntax {
267 } 292 }
268 strArray = stringArrangement.toArray(new String[stringArrangement.size()]); 293 strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
269 } 294 }
270 - return upperCaseConflictResolver(strArray); 295 + return upperCaseConflictResolver(strArray, conflictResolver);
271 } 296 }
272 297
273 /** 298 /**
274 - * Resolves the conflict when input has uppercase. 299 + * Resolves the conflict when input has upper case.
275 * 300 *
276 - * @param stringArray containing strings for uppercase conflict resolver 301 + * @param stringArray containing strings for upper case conflict resolver
302 + * @param conflictResolver object of YANG to java naming conflict util
277 * @return camel cased string 303 * @return camel cased string
278 */ 304 */
279 - private static String upperCaseConflictResolver(String[] stringArray) { 305 + private static String upperCaseConflictResolver(String[] stringArray,
306 + YangToJavaNamingConflictUtil conflictResolver) {
280 307
281 for (int l = 0; l < stringArray.length; l++) { 308 for (int l = 0; l < stringArray.length; l++) {
282 String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE); 309 String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
...@@ -317,7 +344,7 @@ public final class JavaIdentifierSyntax { ...@@ -317,7 +344,7 @@ public final class JavaIdentifierSyntax {
317 } 344 }
318 } 345 }
319 stringArray = result.toArray(new String[result.size()]); 346 stringArray = result.toArray(new String[result.size()]);
320 - return applyCamelCaseRule(stringArray); 347 + return applyCamelCaseRule(stringArray, conflictResolver);
321 } 348 }
322 349
323 /** 350 /**
...@@ -325,9 +352,10 @@ public final class JavaIdentifierSyntax { ...@@ -325,9 +352,10 @@ public final class JavaIdentifierSyntax {
325 * the letter next to a number in an array. 352 * the letter next to a number in an array.
326 * 353 *
327 * @param stringArray containing strings for camel case separation 354 * @param stringArray containing strings for camel case separation
355 + * @param conflictResolver object of YANG to java naming conflict util
328 * @return camel case rule checked string 356 * @return camel case rule checked string
329 */ 357 */
330 - private static String applyCamelCaseRule(String[] stringArray) { 358 + private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
331 359
332 String ruleChecker = stringArray[0].toLowerCase(); 360 String ruleChecker = stringArray[0].toLowerCase();
333 int i; 361 int i;
...@@ -338,7 +366,7 @@ public final class JavaIdentifierSyntax { ...@@ -338,7 +366,7 @@ public final class JavaIdentifierSyntax {
338 i = 1; 366 i = 1;
339 } 367 }
340 for (; i < stringArray.length; i++) { 368 for (; i < stringArray.length; i++) {
341 - if ((i + 1) == stringArray.length) { 369 + if (i + 1 == stringArray.length) {
342 if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER) 370 if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
343 || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) { 371 || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
344 ruleChecker = ruleChecker + stringArray[i].toLowerCase(); 372 ruleChecker = ruleChecker + stringArray[i].toLowerCase();
...@@ -359,23 +387,25 @@ public final class JavaIdentifierSyntax { ...@@ -359,23 +387,25 @@ public final class JavaIdentifierSyntax {
359 ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1); 387 ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
360 } 388 }
361 } 389 }
362 - String ruleCheckerWithPrefix = addPrefix(ruleChecker); 390 + String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
363 return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix); 391 return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
364 } 392 }
365 393
366 /** 394 /**
367 - * Adds prefix YANG auto prefix if the string begins with digit or is a java key word. 395 + * Adds prefix, if the string begins with digit or is a java key word.
368 * 396 *
369 * @param camelCasePrefix string for adding prefix 397 * @param camelCasePrefix string for adding prefix
398 + * @param conflictResolver object of YANG to java naming conflict util
370 * @return prefixed camel case string 399 * @return prefixed camel case string
371 */ 400 */
372 - private static String addPrefix(String camelCasePrefix) { 401 + private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
373 402
403 + String prefix = getPrefixForIdentifier(conflictResolver);
374 if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) { 404 if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
375 - camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix; 405 + camelCasePrefix = prefix + camelCasePrefix;
376 } 406 }
377 - if (JAVA_KEY_WORDS.contains(camelCasePrefix.toLowerCase())) { 407 + if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
378 - camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix.substring(0, 1).toUpperCase() 408 + camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
379 + camelCasePrefix.substring(1); 409 + camelCasePrefix.substring(1);
380 } 410 }
381 return camelCasePrefix; 411 return camelCasePrefix;
...@@ -444,13 +474,21 @@ public final class JavaIdentifierSyntax { ...@@ -444,13 +474,21 @@ public final class JavaIdentifierSyntax {
444 */ 474 */
445 public static String getEnumJavaAttribute(String name) { 475 public static String getEnumJavaAttribute(String name) {
446 476
447 - String[] strArray = name.split(HYPHEN); 477 + name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
478 + String[] strArray = name.split(COLAN);
448 String output = EMPTY_STRING; 479 String output = EMPTY_STRING;
480 + if (strArray[0].isEmpty()) {
481 + List<String> stringArrangement = new ArrayList<String>();
482 + for (int i = 1; i < strArray.length; i++) {
483 + stringArrangement.add(strArray[i]);
484 + }
485 + strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
486 + }
449 for (int i = 0; i < strArray.length; i++) { 487 for (int i = 0; i < strArray.length; i++) {
450 - output = output + strArray[i]; 488 + if (i > 0 && i < strArray.length) {
451 - if (i > 0 && i < strArray.length - 1) {
452 output = output + UNDER_SCORE; 489 output = output + UNDER_SCORE;
453 } 490 }
491 + output = output + strArray[i];
454 } 492 }
455 return output; 493 return output;
456 } 494 }
......
...@@ -26,11 +26,14 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; ...@@ -26,11 +26,14 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
26 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; 26 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
27 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 27 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
28 28
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
30 import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod; 31 import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod;
31 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 33 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
33 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 34 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
35 +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
36 +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
34 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; 37 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
35 import static org.onosproject.yangutils.utils.UtilConstants.AND; 38 import static org.onosproject.yangutils.utils.UtilConstants.AND;
36 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE; 39 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE;
...@@ -48,6 +51,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; ...@@ -48,6 +51,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
48 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 51 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
49 import static org.onosproject.yangutils.utils.UtilConstants.COLAN; 52 import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
50 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 53 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
54 +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
55 +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION;
51 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; 56 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
52 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; 57 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
53 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; 58 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
...@@ -93,7 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; ...@@ -93,7 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
93 import static org.onosproject.yangutils.utils.UtilConstants.SHORT; 98 import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
94 import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; 99 import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
95 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 100 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
101 +import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO;
96 import static org.onosproject.yangutils.utils.UtilConstants.STATIC; 102 import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
103 +import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO;
97 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 104 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
98 import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; 105 import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
99 import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; 106 import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
...@@ -106,6 +113,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA ...@@ -106,6 +113,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
106 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 113 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
107 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 114 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
108 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; 115 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
116 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
109 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; 117 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
110 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; 118 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
111 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; 119 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
...@@ -115,7 +123,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN ...@@ -115,7 +123,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN
115 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; 123 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
116 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; 124 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
117 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 125 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
118 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
119 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 126 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
120 127
121 /** 128 /**
...@@ -133,10 +140,11 @@ public final class MethodsGenerator { ...@@ -133,10 +140,11 @@ public final class MethodsGenerator {
133 * Returns the methods strings for builder interface. 140 * Returns the methods strings for builder interface.
134 * 141 *
135 * @param name attribute name 142 * @param name attribute name
143 + * @param pluginConfig plugin configurations
136 * @return method string for builder interface 144 * @return method string for builder interface
137 */ 145 */
138 - public static String parseBuilderInterfaceBuildMethodString(String name) { 146 + public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
139 - return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); 147 + return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name);
140 } 148 }
141 149
142 /** 150 /**
...@@ -144,14 +152,16 @@ public final class MethodsGenerator { ...@@ -144,14 +152,16 @@ public final class MethodsGenerator {
144 * 152 *
145 * @param attr attribute info 153 * @param attr attribute info
146 * @param generatedJavaFiles generated java files 154 * @param generatedJavaFiles generated java files
155 + * @param pluginConfig plugin configurations
147 * @return getter string 156 * @return getter string
148 */ 157 */
149 - public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles) { 158 + public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
159 + YangPluginConfig pluginConfig) {
150 160
151 String returnType = getReturnType(attr); 161 String returnType = getReturnType(attr);
152 String attributeName = attr.getAttributeName(); 162 String attributeName = attr.getAttributeName();
153 163
154 - return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) 164 + return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig)
155 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles); 165 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
156 } 166 }
157 167
...@@ -161,20 +171,22 @@ public final class MethodsGenerator { ...@@ -161,20 +171,22 @@ public final class MethodsGenerator {
161 * @param attr attribute info 171 * @param attr attribute info
162 * @param className java class name 172 * @param className java class name
163 * @param generatedJavaFiles generated java files 173 * @param generatedJavaFiles generated java files
174 + * @param pluginConfig plugin configurations
164 * @return setter string 175 * @return setter string
165 */ 176 */
166 - public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles) { 177 + public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
178 + YangPluginConfig pluginConfig) {
167 179
168 String attrType = getReturnType(attr); 180 String attrType = getReturnType(attr);
169 String attributeName = attr.getAttributeName(); 181 String attributeName = attr.getAttributeName();
170 JavaDocGen.JavaDocType type; 182 JavaDocGen.JavaDocType type;
171 - if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { 183 + if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
172 type = MANAGER_SETTER_METHOD; 184 type = MANAGER_SETTER_METHOD;
173 } else { 185 } else {
174 type = SETTER_METHOD; 186 type = SETTER_METHOD;
175 } 187 }
176 188
177 - return getJavaDoc(type, attributeName, attr.isListAttr()) 189 + return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig)
178 + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles); 190 + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
179 } 191 }
180 192
...@@ -182,10 +194,11 @@ public final class MethodsGenerator { ...@@ -182,10 +194,11 @@ public final class MethodsGenerator {
182 * Returns constructor method string. 194 * Returns constructor method string.
183 * 195 *
184 * @param name class name 196 * @param name class name
197 + * @param pluginConfig plugin configurations
185 * @return constructor string 198 * @return constructor string
186 */ 199 */
187 - public static String getConstructorString(String name) { 200 + public static String getConstructorString(String name, YangPluginConfig pluginConfig) {
188 - return getJavaDoc(CONSTRUCTOR, name, false); 201 + return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
189 } 202 }
190 203
191 /** 204 /**
...@@ -193,10 +206,13 @@ public final class MethodsGenerator { ...@@ -193,10 +206,13 @@ public final class MethodsGenerator {
193 * 206 *
194 * @param name class name 207 * @param name class name
195 * @param modifierType modifier type 208 * @param modifierType modifier type
209 + * @param pluginConfig plugin configurations
196 * @return default constructor string 210 * @return default constructor string
197 */ 211 */
198 - public static String getDefaultConstructorString(String name, String modifierType) { 212 + public static String getDefaultConstructorString(String name, String modifierType,
199 - return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType) 213 + YangPluginConfig pluginConfig) {
214 + return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig)
215 + + getDefaultConstructor(name, modifierType)
200 + NEW_LINE; 216 + NEW_LINE;
201 } 217 }
202 218
...@@ -249,7 +265,7 @@ public final class MethodsGenerator { ...@@ -249,7 +265,7 @@ public final class MethodsGenerator {
249 * @return getter for attribute 265 * @return getter for attribute
250 */ 266 */
251 public static String getGetter(String type, String name, int generatedJavaFiles) { 267 public static String getGetter(String type, String name, int generatedJavaFiles) {
252 - String ret = parseTypeForGetter(type); 268 + String ret = parseTypeForReturnValue(type);
253 if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { 269 if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
254 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) 270 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
255 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + 271 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
...@@ -265,7 +281,7 @@ public final class MethodsGenerator { ...@@ -265,7 +281,7 @@ public final class MethodsGenerator {
265 } 281 }
266 282
267 /*Provides string to return for type.*/ 283 /*Provides string to return for type.*/
268 - private static String parseTypeForGetter(String type) { 284 + private static String parseTypeForReturnValue(String type) {
269 switch (type) { 285 switch (type) {
270 case BYTE: 286 case BYTE:
271 case INT: 287 case INT:
...@@ -312,12 +328,17 @@ public final class MethodsGenerator { ...@@ -312,12 +328,17 @@ public final class MethodsGenerator {
312 + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE + 328 + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
313 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + 329 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
314 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 330 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
331 + } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
332 + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE
333 + + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
334 + + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
335 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
315 } else { 336 } else {
316 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + 337 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
317 name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE 338 name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
318 - + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + 339 + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE
319 - SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + 340 + + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
320 - SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 341 + + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
321 } 342 }
322 } 343 }
323 344
...@@ -474,14 +495,17 @@ public final class MethodsGenerator { ...@@ -474,14 +495,17 @@ public final class MethodsGenerator {
474 * Returns constructor string for impl class. 495 * Returns constructor string for impl class.
475 * 496 *
476 * @param yangName class name 497 * @param yangName class name
498 + * @param pluginConfig plugin configurations
477 * @return constructor string 499 * @return constructor string
478 */ 500 */
479 - public static String getConstructorStart(String yangName) { 501 + public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) {
480 - 502 +
481 - String javadoc = getConstructorString(yangName); 503 + String javadoc = getConstructorString(yangName, pluginConfig);
482 - String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName 504 + String constructor =
483 - + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET 505 + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName
484 - + NEW_LINE; 506 + + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
507 + + OPEN_CURLY_BRACKET
508 + + NEW_LINE;
485 return javadoc + constructor; 509 return javadoc + constructor;
486 } 510 }
487 511
...@@ -491,24 +515,29 @@ public final class MethodsGenerator { ...@@ -491,24 +515,29 @@ public final class MethodsGenerator {
491 * @param yangName name of the class 515 * @param yangName name of the class
492 * @param attr attribute info 516 * @param attr attribute info
493 * @param generatedJavaFiles generated java files 517 * @param generatedJavaFiles generated java files
518 + * @param pluginConfig plugin configurations
494 * @return constructor for class 519 * @return constructor for class
495 */ 520 */
496 - public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles) { 521 + public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles,
522 + YangPluginConfig pluginConfig) {
497 523
498 String attributeName = attr.getAttributeName(); 524 String attributeName = attr.getAttributeName();
499 String constructor; 525 String constructor;
500 526
501 if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { 527 if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
502 - constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL 528 + constructor =
503 - + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX 529 + EIGHT_SPACE_INDENTATION + THIS + PERIOD
504 - + getCapitalCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + 530 + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
505 - SEMI_COLAN 531 + + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
506 - + NEW_LINE; 532 + + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
533 + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
507 } else { 534 } else {
508 - constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL 535 + constructor =
509 - + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + getCamelCase(attributeName, null) + 536 + EIGHT_SPACE_INDENTATION + THIS + PERIOD
510 - OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN 537 + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
511 - + NEW_LINE; 538 + + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
539 + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
540 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
512 } 541 }
513 return constructor; 542 return constructor;
514 } 543 }
...@@ -519,17 +548,18 @@ public final class MethodsGenerator { ...@@ -519,17 +548,18 @@ public final class MethodsGenerator {
519 * @param rpcName name of the rpc 548 * @param rpcName name of the rpc
520 * @param inputName name of input 549 * @param inputName name of input
521 * @param outputName name of output 550 * @param outputName name of output
551 + * @param pluginConfig plugin configurations
522 * @return rpc method string 552 * @return rpc method string
523 */ 553 */
524 - public static String getRpcServiceMethod(String rpcName, String inputName, String outputName) { 554 + public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
555 + YangPluginConfig pluginConfig) {
525 556
526 - rpcName = getCamelCase(rpcName, null); 557 + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
527 - inputName = getCapitalCase(inputName); 558 + if (!inputName.equals(EMPTY_STRING)) {
528 - if (!outputName.equals(VOID)) { 559 + inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
529 - outputName = getCapitalCase(outputName);
530 } 560 }
531 - return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName + SPACE 561 + return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
532 - + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; 562 + + CLOSE_PARENTHESIS + SEMI_COLAN;
533 } 563 }
534 564
535 /** 565 /**
...@@ -538,21 +568,24 @@ public final class MethodsGenerator { ...@@ -538,21 +568,24 @@ public final class MethodsGenerator {
538 * @param rpcName name of the rpc 568 * @param rpcName name of the rpc
539 * @param inputName name of input 569 * @param inputName name of input
540 * @param outputName name of output 570 * @param outputName name of output
571 + * @param pluginConfig plugin configurations
541 * @return rpc method string 572 * @return rpc method string
542 */ 573 */
543 - public static String getRpcManagerMethod(String rpcName, String inputName, String outputName) { 574 + public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
575 + YangPluginConfig pluginConfig) {
544 576
545 - rpcName = getCamelCase(rpcName, null); 577 + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
546 - inputName = getCapitalCase(inputName); 578 + if (!inputName.equals(EMPTY_STRING)) {
547 - if (!outputName.equals(VOID)) { 579 + inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
548 - outputName = getCapitalCase(outputName);
549 } 580 }
550 581
551 - String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName 582 + String method =
552 - + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE 583 + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
553 - + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; 584 + + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
585 + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
554 if (!outputName.contentEquals(VOID)) { 586 if (!outputName.contentEquals(VOID)) {
555 - method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE; 587 + method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
588 + + NEW_LINE;
556 } 589 }
557 method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 590 method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
558 591
...@@ -631,12 +664,14 @@ public final class MethodsGenerator { ...@@ -631,12 +664,14 @@ public final class MethodsGenerator {
631 * Returns from string method's open string. 664 * Returns from string method's open string.
632 * 665 *
633 * @param className name of the class 666 * @param className name of the class
667 + * @param pluginConfig plugin configurations
634 * @return from string method's open string 668 * @return from string method's open string
635 */ 669 */
636 - public static String getFromStringMethodSignature(String className) { 670 + public static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
637 - return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE 671 + return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
638 - + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE 672 + + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
639 - + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 673 + + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
674 + + OPEN_CURLY_BRACKET + NEW_LINE;
640 } 675 }
641 676
642 /** 677 /**
...@@ -832,14 +867,16 @@ public final class MethodsGenerator { ...@@ -832,14 +867,16 @@ public final class MethodsGenerator {
832 * 867 *
833 * @param attr attribute info 868 * @param attr attribute info
834 * @param generatedJavaClassName class name 869 * @param generatedJavaClassName class name
870 + * @param pluginConfig plugin configurations
835 * @return of method's string and java doc for special type 871 * @return of method's string and java doc for special type
836 */ 872 */
837 - public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { 873 + public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
874 + YangPluginConfig pluginConfig) {
838 875
839 String attrType = getReturnType(attr); 876 String attrType = getReturnType(attr);
840 String attrName = attr.getAttributeName(); 877 String attrName = attr.getAttributeName();
841 878
842 - return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false) 879 + return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
843 + getOfMethodString(attrType, generatedJavaClassName); 880 + getOfMethodString(attrType, generatedJavaClassName);
844 } 881 }
845 882
...@@ -863,14 +900,16 @@ public final class MethodsGenerator { ...@@ -863,14 +900,16 @@ public final class MethodsGenerator {
863 * 900 *
864 * @param attr attribute info 901 * @param attr attribute info
865 * @param generatedJavaClassName class name 902 * @param generatedJavaClassName class name
903 + * @param pluginConfig plugin configurations
866 * @return string and java doc for constructor of type class 904 * @return string and java doc for constructor of type class
867 */ 905 */
868 - public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { 906 + public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
907 + String generatedJavaClassName, YangPluginConfig pluginConfig) {
869 908
870 String attrType = getReturnType(attr); 909 String attrType = getReturnType(attr);
871 String attrName = attr.getAttributeName(); 910 String attrName = attr.getAttributeName();
872 911
873 - return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false) 912 + return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
874 + getTypeConstructorString(attrType, attrName, generatedJavaClassName); 913 + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
875 } 914 }
876 915
...@@ -986,10 +1025,11 @@ public final class MethodsGenerator { ...@@ -986,10 +1025,11 @@ public final class MethodsGenerator {
986 * @param attr java attribute 1025 * @param attr java attribute
987 * @param enumMap enum's sets map 1026 * @param enumMap enum's sets map
988 * @param enumList enum's sets list 1027 * @param enumList enum's sets list
1028 + * @param pluginConfig plugin configurations
989 * @return of method 1029 * @return of method
990 */ 1030 */
991 public static String getEnumsOfMethod(String className, JavaAttributeInfo attr, 1031 public static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
992 - Map<String, Integer> enumMap, List<String> enumList) { 1032 + Map<String, Integer> enumMap, List<String> enumList, YangPluginConfig pluginConfig) {
993 String attrType = getReturnType(attr); 1033 String attrType = getReturnType(attr);
994 String attrName = attr.getAttributeName(); 1034 String attrName = attr.getAttributeName();
995 1035
...@@ -1010,6 +1050,37 @@ public final class MethodsGenerator { ...@@ -1010,6 +1050,37 @@ public final class MethodsGenerator {
1010 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET 1050 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1011 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 1051 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1012 1052
1013 - return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false) + method; 1053 + return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig)
1054 + + method;
1014 } 1055 }
1056 +
1057 + /**
1058 + * Returns activate method string.
1059 + *
1060 + * @return activate method string
1061 + */
1062 + public static String addActivateMethod() {
1063 + return FOUR_SPACE_INDENTATION + ACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
1064 + + PUBLIC + SPACE + VOID + SPACE + ACTIVATE + OPEN_PARENTHESIS
1065 + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
1066 + + NEW_LINE + EIGHT_SPACE_INDENTATION
1067 + + YANG_UTILS_TODO
1068 + + NEW_LINE + EIGHT_SPACE_INDENTATION
1069 + + STARTED_LOG_INFO + FOUR_SPACE_INDENTATION
1070 + + CLOSE_CURLY_BRACKET + NEW_LINE;
1071 + }
1072 +
1073 + /**
1074 + * Returns deactivate method string.
1075 + *
1076 + * @return deactivate method string
1077 + */
1078 + public static String addDeActivateMethod() {
1079 + return NEW_LINE + FOUR_SPACE_INDENTATION + DEACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
1080 + + PUBLIC + SPACE + VOID + SPACE + DEACTIVATE + OPEN_PARENTHESIS
1081 + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
1082 + + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION
1083 + + STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1084 + }
1085 +
1015 } 1086 }
......
...@@ -29,30 +29,44 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -29,30 +29,44 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
29 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 29 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
30 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; 30 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
31 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; 31 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
32 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
32 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; 33 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
34 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
35 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
33 36
34 import static java.util.Collections.sort; 37 import static java.util.Collections.sort;
35 38
36 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 39 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
37 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 40 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
41 +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
38 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; 42 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
39 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; 43 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
40 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; 44 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
41 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; 45 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
42 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 46 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
43 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 47 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
48 +import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
49 +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
44 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; 50 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
51 +import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
45 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; 52 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
53 +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
46 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 54 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
47 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; 55 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
48 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; 56 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
57 +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
58 +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
49 import static org.onosproject.yangutils.utils.UtilConstants.NEW; 59 import static org.onosproject.yangutils.utils.UtilConstants.NEW;
50 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 60 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
61 +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
51 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; 62 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
52 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 63 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
64 +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
53 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 65 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
66 +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
54 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 67 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
55 import static org.onosproject.yangutils.utils.UtilConstants.THIS; 68 import static org.onosproject.yangutils.utils.UtilConstants.THIS;
69 +import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
56 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; 70 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
57 71
58 /** 72 /**
...@@ -102,12 +116,6 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -102,12 +116,6 @@ public final class TempJavaCodeFragmentFilesUtils {
102 if (container.getBeanTempFiles() != null) { 116 if (container.getBeanTempFiles() != null) {
103 return container.getBeanTempFiles(); 117 return container.getBeanTempFiles();
104 } 118 }
105 - if (container.getEventTempFiles() != null) {
106 - return container.getEventTempFiles();
107 - }
108 - if (container.getEventListenerTempFiles() != null) {
109 - return container.getEventListenerTempFiles();
110 - }
111 if (container.getServiceTempFiles() != null) { 119 if (container.getServiceTempFiles() != null) {
112 return container.getServiceTempFiles(); 120 return container.getServiceTempFiles();
113 } 121 }
...@@ -234,6 +242,31 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -234,6 +242,31 @@ public final class TempJavaCodeFragmentFilesUtils {
234 } 242 }
235 243
236 /** 244 /**
245 + * Adds annotations imports.
246 + *
247 + * @param imports list if imports
248 + * @param operation to add or to delete
249 + */
250 + public static void addAnnotationsImports(List<String> imports, boolean operation) {
251 + if (operation) {
252 + imports.add(ACTIVATE_ANNOTATION_IMPORT);
253 + imports.add(DEACTIVATE_ANNOTATION_IMPORT);
254 + imports.add(COMPONENT_ANNOTATION_IMPORT);
255 + imports.add(SERVICE_ANNOTATION_IMPORT);
256 + imports.add(LOGGER_FACTORY_IMPORT);
257 + imports.add(LOGGER_IMPORT);
258 + } else {
259 + imports.remove(ACTIVATE_ANNOTATION_IMPORT);
260 + imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
261 + imports.remove(COMPONENT_ANNOTATION_IMPORT);
262 + imports.remove(SERVICE_ANNOTATION_IMPORT);
263 + imports.remove(LOGGER_FACTORY_IMPORT);
264 + imports.remove(LOGGER_IMPORT);
265 + }
266 + sortImports(imports);
267 + }
268 +
269 + /**
237 * Performs given operations on import list. 270 * Performs given operations on import list.
238 * 271 *
239 * @param imports list of imports 272 * @param imports list of imports
...@@ -309,6 +342,12 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -309,6 +342,12 @@ public final class TempJavaCodeFragmentFilesUtils {
309 JavaQualifiedTypeInfo qualifiedTypeInfo) { 342 JavaQualifiedTypeInfo qualifiedTypeInfo) {
310 343
311 YangNode parent = curNode.getParent(); 344 YangNode parent = curNode.getParent();
345 + if (parent instanceof YangJavaModule
346 + || parent instanceof YangJavaSubModule
347 + || parent instanceof YangJavaInput
348 + || parent instanceof YangJavaOutput) {
349 + return false;
350 + }
312 String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); 351 String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
313 String childsClassInfo = qualifiedTypeInfo.getClassInfo(); 352 String childsClassInfo = qualifiedTypeInfo.getClassInfo();
314 if (childsClassInfo.equals(parentsClassInfo)) { 353 if (childsClassInfo.equals(parentsClassInfo)) {
...@@ -328,4 +367,13 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -328,4 +367,13 @@ public final class TempJavaCodeFragmentFilesUtils {
328 return imports; 367 return imports;
329 } 368 }
330 369
370 + /**
371 + * Returns event enum start.
372 + *
373 + * @return event enum start
374 + */
375 + public static String getEventEnumTypeStart() {
376 + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
377 + + NEW_LINE;
378 + }
331 } 379 }
......
...@@ -32,11 +32,17 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; ...@@ -32,11 +32,17 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
32 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 32 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
33 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; 33 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
34 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; 34 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
35 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
36 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
35 37
36 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent; 38 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
39 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
40 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
41 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
38 import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; 43 import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
39 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 44 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
45 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
40 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; 46 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
41 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; 47 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
42 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; 48 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
...@@ -49,7 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATIO ...@@ -49,7 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATIO
49 public final class YangJavaModelUtils { 55 public final class YangJavaModelUtils {
50 56
51 /** 57 /**
52 - * Creates YANG java model utility. 58 + * Creates an instance of YANG java model utility.
53 */ 59 */
54 private YangJavaModelUtils() { 60 private YangJavaModelUtils() {
55 } 61 }
...@@ -64,6 +70,7 @@ public final class YangJavaModelUtils { ...@@ -64,6 +70,7 @@ public final class YangJavaModelUtils {
64 public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, 70 public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
65 YangPluginConfig yangPluginConfig) 71 YangPluginConfig yangPluginConfig)
66 throws IOException { 72 throws IOException {
73 +
67 javaCodeGeneratorInfo.getJavaFileInfo() 74 javaCodeGeneratorInfo.getJavaFileInfo()
68 .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), 75 .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
69 yangPluginConfig.getConflictResolver())); 76 yangPluginConfig.getConflictResolver()));
...@@ -71,6 +78,7 @@ public final class YangJavaModelUtils { ...@@ -71,6 +78,7 @@ public final class YangJavaModelUtils {
71 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( 78 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
72 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); 79 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
73 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); 80 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
81 + javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
74 } 82 }
75 83
76 /** 84 /**
...@@ -90,6 +98,7 @@ public final class YangJavaModelUtils { ...@@ -90,6 +98,7 @@ public final class YangJavaModelUtils {
90 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( 98 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
91 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); 99 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
92 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); 100 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
101 + javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
93 } 102 }
94 103
95 /** 104 /**
...@@ -120,6 +129,16 @@ public final class YangJavaModelUtils { ...@@ -120,6 +129,16 @@ public final class YangJavaModelUtils {
120 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 129 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
121 .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( 130 .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
122 (YangNode) javaCodeGeneratorInfo, yangPluginConfig); 131 (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
132 + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
133 + if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
134 + updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
135 + }
136 + } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
137 + if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
138 + updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
139 + }
140 + }
141 +
123 } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { 142 } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
124 /* 143 /*
125 * Container 144 * Container
...@@ -139,13 +158,14 @@ public final class YangJavaModelUtils { ...@@ -139,13 +158,14 @@ public final class YangJavaModelUtils {
139 * Union 158 * Union
140 */ 159 */
141 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 160 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
142 - .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo); 161 + .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
143 } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { 162 } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
144 /* 163 /*
145 * Enumeration 164 * Enumeration
146 */ 165 */
147 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() 166 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
148 - .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); 167 + .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
168 +
149 } else if (javaCodeGeneratorInfo instanceof YangChoice) { 169 } else if (javaCodeGeneratorInfo instanceof YangChoice) {
150 /*Do nothing, only the interface needs to be generated*/ 170 /*Do nothing, only the interface needs to be generated*/
151 } else { 171 } else {
...@@ -171,6 +191,32 @@ public final class YangJavaModelUtils { ...@@ -171,6 +191,32 @@ public final class YangJavaModelUtils {
171 } 191 }
172 192
173 /** 193 /**
194 + * Updates notification node info in service temporary file.
195 + *
196 + * @param javaCodeGeneratorInfo java code generator info
197 + * @param yangPluginConfig plugin configurations
198 + * @throws IOException when fails to do IO operations
199 + */
200 + private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
201 + YangPluginConfig yangPluginConfig) throws IOException {
202 + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
203 + for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
204 + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
205 + .getServiceTempFiles()
206 + .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
207 + }
208 + }
209 + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
210 + for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
211 + .getNotificationNodes()) {
212 + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
213 + .getServiceTempFiles()
214 + .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
215 + }
216 + }
217 + }
218 +
219 + /**
174 * Generates code for the current ata model node and adds itself as an attribute in the parent. 220 * Generates code for the current ata model node and adds itself as an attribute in the parent.
175 * 221 *
176 * @param javaCodeGeneratorInfo YANG java file info node 222 * @param javaCodeGeneratorInfo YANG java file info node
...@@ -193,7 +239,7 @@ public final class YangJavaModelUtils { ...@@ -193,7 +239,7 @@ public final class YangJavaModelUtils {
193 /* 239 /*
194 * Update the current nodes info in its parent nodes generated files. 240 * Update the current nodes info in its parent nodes generated files.
195 */ 241 */
196 - addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); 242 + addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
197 } 243 }
198 244
199 /** 245 /**
...@@ -234,7 +280,7 @@ public final class YangJavaModelUtils { ...@@ -234,7 +280,7 @@ public final class YangJavaModelUtils {
234 if (javaCodeGeneratorInfo instanceof YangCase) { 280 if (javaCodeGeneratorInfo instanceof YangCase) {
235 YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); 281 YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
236 JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo(); 282 JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
237 - String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); 283 + String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
238 String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); 284 String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
239 parentsInfo.setClassInfo(parentName); 285 parentsInfo.setClassInfo(parentName);
240 parentsInfo.setPkgInfo(parentPkg); 286 parentsInfo.setPkgInfo(parentPkg);
...@@ -242,7 +288,7 @@ public final class YangJavaModelUtils { ...@@ -242,7 +288,7 @@ public final class YangJavaModelUtils {
242 .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo); 288 .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
243 289
244 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() 290 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
245 - .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo); 291 + .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
246 292
247 } 293 }
248 } 294 }
...@@ -284,7 +330,26 @@ public final class YangJavaModelUtils { ...@@ -284,7 +330,26 @@ public final class YangJavaModelUtils {
284 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); 330 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
285 } 331 }
286 332
333 + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
334 + if (!((YangJavaModule) javaCodeGeneratorInfo)
335 + .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
336 + updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
337 + }
338 + } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
339 + if (!((YangJavaSubModule) javaCodeGeneratorInfo)
340 + .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
341 + updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
342 + }
343 + }
344 +
287 generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); 345 generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
288 } 346 }
289 347
348 + /*Updates java code generator info with events info.*/
349 + private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) {
350 + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS);
351 + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS);
352 + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
353 + }
354 +
290 } 355 }
......
...@@ -37,6 +37,11 @@ public final class YangToJavaNamingConflictUtil { ...@@ -37,6 +37,11 @@ public final class YangToJavaNamingConflictUtil {
37 private static String replacementForHyphenInIdentifier; 37 private static String replacementForHyphenInIdentifier;
38 38
39 /** 39 /**
40 + * Contains the prefix value for adding with the identifier.
41 + */
42 + private static String prefixForIdentifier;
43 +
44 + /**
40 * Creates an object for YANG to java naming conflict util. 45 * Creates an object for YANG to java naming conflict util.
41 */ 46 */
42 public YangToJavaNamingConflictUtil() { 47 public YangToJavaNamingConflictUtil() {
...@@ -95,4 +100,22 @@ public final class YangToJavaNamingConflictUtil { ...@@ -95,4 +100,22 @@ public final class YangToJavaNamingConflictUtil {
95 public String getReplacementForUnderscore() { 100 public String getReplacementForUnderscore() {
96 return replacementForUnderscoreInIdentifier; 101 return replacementForUnderscoreInIdentifier;
97 } 102 }
103 +
104 + /**
105 + * Sets the prefix value for adding with the identifier.
106 + *
107 + * @param prefix prefix for identifier
108 + */
109 + public void setPrefixForIdentifier(String prefix) {
110 + prefixForIdentifier = prefix;
111 + }
112 +
113 + /**
114 + * Returns the prefix for identifier.
115 + *
116 + * @return prefix for identifier
117 + */
118 + public String getPrefixForIdentifier() {
119 + return prefixForIdentifier;
120 + }
98 } 121 }
......
...@@ -99,11 +99,11 @@ public final class RestrictionResolver { ...@@ -99,11 +99,11 @@ public final class RestrictionResolver {
99 } 99 }
100 100
101 if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { 101 if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
102 - startInterval = rangeBoundary[0]; 102 + startInterval = rangeBoundary[0].trim();
103 - endInterval = rangeBoundary[0]; 103 + endInterval = rangeBoundary[0].trim();
104 } else { 104 } else {
105 - startInterval = rangeBoundary[0]; 105 + startInterval = rangeBoundary[0].trim();
106 - endInterval = rangeBoundary[1]; 106 + endInterval = rangeBoundary[1].trim();
107 } 107 }
108 108
109 try { 109 try {
...@@ -186,11 +186,11 @@ public final class RestrictionResolver { ...@@ -186,11 +186,11 @@ public final class RestrictionResolver {
186 } 186 }
187 187
188 if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { 188 if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
189 - startInterval = rangeBoundary[0]; 189 + startInterval = rangeBoundary[0].trim();
190 - endInterval = rangeBoundary[0]; 190 + endInterval = rangeBoundary[0].trim();
191 } else { 191 } else {
192 - startInterval = rangeBoundary[0]; 192 + startInterval = rangeBoundary[0].trim();
193 - endInterval = rangeBoundary[1]; 193 + endInterval = rangeBoundary[1].trim();
194 } 194 }
195 195
196 try { 196 try {
......
...@@ -197,6 +197,11 @@ public final class UtilConstants { ...@@ -197,6 +197,11 @@ public final class UtilConstants {
197 public static final String PARSE_BYTE = "parseByte"; 197 public static final String PARSE_BYTE = "parseByte";
198 198
199 /** 199 /**
200 + * Static attribute for parse boolean.
201 + */
202 + public static final String PARSE_BOOLEAN = "parseBoolean";
203 +
204 + /**
200 * Static attribute for parse short. 205 * Static attribute for parse short.
201 */ 206 */
202 public static final String PARSE_SHORT = "parseShort"; 207 public static final String PARSE_SHORT = "parseShort";
...@@ -242,6 +247,11 @@ public final class UtilConstants { ...@@ -242,6 +247,11 @@ public final class UtilConstants {
242 public static final String SPACE = " "; 247 public static final String SPACE = " ";
243 248
244 /** 249 /**
250 + * Static attribute for subject.
251 + */
252 + public static final String SUBJECT = "Subject";
253 +
254 + /**
245 * Static attribute for ListenerRegistry. 255 * Static attribute for ListenerRegistry.
246 */ 256 */
247 public static final String LISTENER_REG = "ListenerRegistry"; 257 public static final String LISTENER_REG = "ListenerRegistry";
...@@ -254,7 +264,7 @@ public final class UtilConstants { ...@@ -254,7 +264,7 @@ public final class UtilConstants {
254 /** 264 /**
255 * Static attribute for listener package. 265 * Static attribute for listener package.
256 */ 266 */
257 - public static final String LISTENER_PKG = "org.onosproject.event"; 267 + public static final String ONOS_EVENT_PKG = "org.onosproject.event";
258 268
259 /** 269 /**
260 * Static attribute for colon. 270 * Static attribute for colon.
...@@ -272,6 +282,21 @@ public final class UtilConstants { ...@@ -272,6 +282,21 @@ public final class UtilConstants {
272 public static final String INPUT = "input"; 282 public static final String INPUT = "input";
273 283
274 /** 284 /**
285 + * Static attribute for leafref string.
286 + */
287 + public static final String LEAFREF = "leafref";
288 +
289 + /**
290 + * Static attribute for identityref string.
291 + */
292 + public static final String IDENTITYREF = "identityref";
293 +
294 + /**
295 + * Static attribute for instance identifier string.
296 + */
297 + public static final String INSTANCE_IDENTIFIER = "instance-identifier";
298 +
299 + /**
275 * Static attribute for output variable of rpc. 300 * Static attribute for output variable of rpc.
276 */ 301 */
277 public static final String RPC_INPUT_VAR_NAME = "inputVar"; 302 public static final String RPC_INPUT_VAR_NAME = "inputVar";
...@@ -742,6 +767,11 @@ public final class UtilConstants { ...@@ -742,6 +767,11 @@ public final class UtilConstants {
742 public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+"; 767 public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+";
743 768
744 /** 769 /**
770 + * Static attribute for regex for any string ending with service.
771 + */
772 + public static final String REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE = ".+Service";
773 +
774 + /**
745 * Static attribute for class syntax. 775 * Static attribute for class syntax.
746 */ 776 */
747 public static final String CLASS = "class"; 777 public static final String CLASS = "class";
...@@ -772,6 +802,11 @@ public final class UtilConstants { ...@@ -772,6 +802,11 @@ public final class UtilConstants {
772 public static final String ENUM = "enum"; 802 public static final String ENUM = "enum";
773 803
774 /** 804 /**
805 + * Static attribute for type syntax.
806 + */
807 + public static final String TYPE = "Type";
808 +
809 + /**
775 * Static attribute for static syntax. 810 * Static attribute for static syntax.
776 */ 811 */
777 public static final String STATIC = "static"; 812 public static final String STATIC = "static";
...@@ -837,6 +872,11 @@ public final class UtilConstants { ...@@ -837,6 +872,11 @@ public final class UtilConstants {
837 public static final String EVENT_LISTENER_STRING = "Listener"; 872 public static final String EVENT_LISTENER_STRING = "Listener";
838 873
839 /** 874 /**
875 + * For event subject file generation.
876 + */
877 + public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
878 +
879 + /**
840 * Static attribute for impl syntax. 880 * Static attribute for impl syntax.
841 */ 881 */
842 public static final String IMPL = "Impl"; 882 public static final String IMPL = "Impl";
...@@ -942,6 +982,130 @@ public final class UtilConstants { ...@@ -942,6 +982,130 @@ public final class UtilConstants {
942 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; 982 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
943 983
944 /** 984 /**
985 + * Static attribute for activate annotation.
986 + */
987 + public static final String ACTIVATE_ANNOTATION = "@Activate\n";
988 +
989 + /**
990 + * Static attribute for activate.
991 + */
992 + public static final String ACTIVATE = "activate";
993 +
994 + /**
995 + * Static attribute for activate annotation import.
996 + */
997 + public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n";
998 +
999 + /**
1000 + * Static attribute for deactivate annotation.
1001 + */
1002 + public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n";
1003 +
1004 + /**
1005 + * Static attribute for deactivate.
1006 + */
1007 + public static final String DEACTIVATE = "deactivate";
1008 +
1009 + /**
1010 + * Static attribute for deactivate annotation import.
1011 + */
1012 + public static final String DEACTIVATE_ANNOTATION_IMPORT =
1013 + "import org.apache.felix.scr.annotations.Deactivate;\n";
1014 +
1015 + /**
1016 + * Static attribute for component annotation.
1017 + */
1018 + public static final String COMPONENT_ANNOTATION = "@Component";
1019 +
1020 + /**
1021 + * Static attribute for immediate.
1022 + */
1023 + public static final String IMMEDIATE = "immediate";
1024 +
1025 + /**
1026 + * Static attribute for component annotation import.
1027 + */
1028 + public static final String COMPONENT_ANNOTATION_IMPORT =
1029 + "import org.apache.felix.scr.annotations.Component;\n";
1030 +
1031 + /**
1032 + * Static attribute for service annotation.
1033 + */
1034 + public static final String SERVICE_ANNOTATION = "@Service\n";
1035 +
1036 + /**
1037 + * Static attribute for service annotation import.
1038 + */
1039 + public static final String SERVICE_ANNOTATION_IMPORT =
1040 + "import org.apache.felix.scr.annotations.Service;\n";
1041 +
1042 + /**
1043 + * Static attribute for logger factory import.
1044 + */
1045 + public static final String LOGGER_FACTORY_IMPORT =
1046 + "import static org.slf4j.LoggerFactory.getLogger;\n";
1047 +
1048 + /**
1049 + * Static attribute for logger import.
1050 + */
1051 + public static final String LOGGER_IMPORT =
1052 + "import org.slf4j.Logger;\n";
1053 +
1054 + /**
1055 + * Static attribute for logger statement.
1056 + */
1057 + public static final String LOGGER_STATEMENT =
1058 + "\n private final Logger log = getLogger(getClass());\n";
1059 +
1060 + /**
1061 + * Static attribute for logger statement for started.
1062 + */
1063 + public static final String STARTED_LOG_INFO =
1064 + "log.info(\"Started\");\n";
1065 +
1066 + /**
1067 + * Static attribute for logger statement for stopped.
1068 + */
1069 + public static final String STOPPED_LOG_INFO =
1070 + "log.info(\"Stopped\");\n";
1071 +
1072 + /**
1073 + * Static attribute for AbstractEvent.
1074 + */
1075 + public static final String ABSTRACT_EVENT = "AbstractEvent";
1076 +
1077 + /**
1078 + * Static attribute for EventListener.
1079 + */
1080 + public static final String EVENT_LISTENER = "EventListener";
1081 +
1082 + /**
1083 + * Static attribute for YangBinary class.
1084 + */
1085 + public static final String YANG_BINARY_CLASS = "YangBinary";
1086 +
1087 + /**
1088 + * Static attribute for YangBinary class.
1089 + */
1090 + public static final String YANG_BITS_CLASS = "YangBits";
1091 +
1092 + /**
1093 + * Static attribute for YANG types package.
1094 + */
1095 + public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.utils.builtindatatype";
1096 +
1097 + /**
1098 + * Static attribute for MathContext class.
1099 + */
1100 + public static final String MATH_CONTEXT = "MathContext";
1101 +
1102 + /**
1103 + * Static attribute for DECIMAL64 class.
1104 + */
1105 + public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
1106 +
1107 +
1108 + /**
945 * Static attribute for YANG file error. 1109 * Static attribute for YANG file error.
946 */ 1110 */
947 public static final String YANG_FILE_ERROR = "YANG file error : "; 1111 public static final String YANG_FILE_ERROR = "YANG file error : ";
...@@ -958,6 +1122,18 @@ public final class UtilConstants { ...@@ -958,6 +1122,18 @@ public final class UtilConstants {
958 " for YANG utils road map."; 1122 " for YANG utils road map.";
959 1123
960 /** 1124 /**
1125 + * Static attribute for typedef linker error information.
1126 + */
1127 + public static final String TYPEDEF_LINKER_ERROR = "YANG file error: Unable to find base "
1128 + + "typedef for given type";
1129 +
1130 + /**
1131 + * Static attribute for grouping linker error information.
1132 + */
1133 + public static final String GROUPING_LINKER_ERROR = "YANG file error: Unable to find base "
1134 + + "grouping for given uses";
1135 +
1136 + /**
961 * Creates an instance of util constants. 1137 * Creates an instance of util constants.
962 */ 1138 */
963 private UtilConstants() { 1139 private UtilConstants() {
......
...@@ -350,6 +350,21 @@ public enum YangConstructType { ...@@ -350,6 +350,21 @@ public enum YangConstructType {
350 REFINE_DATA, 350 REFINE_DATA,
351 351
352 /** 352 /**
353 + * Identifies the YANG leafref element parsed data.
354 + */
355 + LEAFREF_DATA,
356 +
357 + /**
358 + * Identifies the YANG identityref element parsed data.
359 + */
360 + IDENTITYREF_DATA,
361 +
362 + /**
363 + * Identifies the YANG instance identifier element parsed data.
364 + */
365 + INSTANCE_IDENTIFIER_DATA,
366 +
367 + /**
353 * Identifies the YANG deviation element parsed data. 368 * Identifies the YANG deviation element parsed data.
354 */ 369 */
355 DEVIATION_DATA, 370 DEVIATION_DATA,
...@@ -500,6 +515,12 @@ public enum YangConstructType { ...@@ -500,6 +515,12 @@ public enum YangConstructType {
500 return "unique"; 515 return "unique";
501 case REFINE_DATA: 516 case REFINE_DATA:
502 return "refine"; 517 return "refine";
518 + case LEAFREF_DATA:
519 + return "leafref";
520 + case IDENTITYREF_DATA:
521 + return "identityref";
522 + case INSTANCE_IDENTIFIER_DATA:
523 + return "instance-identifier";
503 case DEVIATION_DATA: 524 case DEVIATION_DATA:
504 return "deviation"; 525 return "deviation";
505 case ANYXML_DATA: 526 case ANYXML_DATA:
......
1 +/*
2 + * Copyright 2016-present 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.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents binary data type.
25 + */
26 +public final class YangBinary {
27 +
28 + private byte[] byteArray;
29 +
30 + /**
31 + * Creates an instance of YANG binary.
32 + */
33 + private YangBinary() {
34 + }
35 +
36 + /**
37 + * Creates an instance of YANG binary.
38 + *
39 + * @param bytes byte array
40 + */
41 + public YangBinary(byte[] bytes) {
42 + this.byteArray = bytes;
43 + }
44 +
45 + /**
46 + * Returns object of YANG binary.
47 + *
48 + * @param bytes byte array
49 + * @return object of YANG binary
50 + */
51 + public static YangBinary of(byte[] bytes) {
52 + return new YangBinary(bytes);
53 + }
54 +
55 + /**
56 + * Returns byte array.
57 + *
58 + * @return byte array
59 + */
60 + public byte[] byteArray() {
61 + return byteArray;
62 + }
63 +
64 + @Override
65 + public int hashCode() {
66 + return Objects.hash(byteArray);
67 + }
68 +
69 + @Override
70 + public boolean equals(Object obj) {
71 + if (this == obj) {
72 + return true;
73 + }
74 + if (obj instanceof YangBinary) {
75 + YangBinary other = (YangBinary) obj;
76 + return Objects.equals(byteArray, other.byteArray);
77 + }
78 + return false;
79 + }
80 +
81 + @Override
82 + public String toString() {
83 + return MoreObjects.toStringHelper(getClass())
84 + .omitNullValues()
85 + .add("byteArray", byteArray)
86 + .toString();
87 + }
88 +
89 + /**
90 + * Returns the object of YANG binary fromString input String.
91 + *
92 + * @param valInString input String
93 + * @return Object of YANG binary
94 + */
95 + public static YangBinary fromString(String valInString) {
96 + try {
97 + byte[] tmpVal = valInString.getBytes();
98 + return of(tmpVal);
99 + } catch (Exception e) {
100 + }
101 + return null;
102 + }
103 +
104 +}
1 +/*
2 + * Copyright 2016-present 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.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents bits data type.
25 + */
26 +public class YangBits {
27 +
28 + private byte[] byteArray;
29 +
30 + /**
31 + * Creates an instance of YANG bits.
32 + */
33 + private YangBits() {
34 + }
35 +
36 + /**
37 + * Creates an instance of YANG bits.
38 + *
39 + * @param bytes byte array
40 + */
41 + public YangBits(byte[] bytes) {
42 + this.byteArray = bytes;
43 + }
44 +
45 + /**
46 + * Returns object of YANG bits.
47 + *
48 + * @param bytes byte array
49 + * @return object of YANG bits
50 + */
51 + public static YangBits of(byte[] bytes) {
52 + return new YangBits(bytes);
53 + }
54 +
55 + /**
56 + * Returns byte array.
57 + *
58 + * @return byte array
59 + */
60 + public byte[] byteArray() {
61 + return byteArray;
62 + }
63 +
64 + @Override
65 + public int hashCode() {
66 + return Objects.hash(byteArray);
67 + }
68 +
69 + @Override
70 + public boolean equals(Object obj) {
71 + if (this == obj) {
72 + return true;
73 + }
74 + if (obj instanceof YangBits) {
75 + YangBits other = (YangBits) obj;
76 + return Objects.equals(byteArray, other.byteArray);
77 + }
78 + return false;
79 + }
80 +
81 + @Override
82 + public String toString() {
83 + return MoreObjects.toStringHelper(getClass())
84 + .omitNullValues()
85 + .add("byteArray", byteArray)
86 + .toString();
87 + }
88 +
89 + /**
90 + * Returns the object of YANG bits fromString input String.
91 + *
92 + * @param valInString input String
93 + * @return Object of YANG bits
94 + */
95 + public static YangBits fromString(String valInString) {
96 + try {
97 + byte[] tmpVal = valInString.getBytes();
98 + return of(tmpVal);
99 + } catch (Exception e) {
100 + }
101 + return null;
102 + }
103 +
104 +}
1 +/*
2 + * Copyright 2016-present 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.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents YANG decimal 64.
25 + */
26 +public class YangDecimal64 {
27 +
28 + private int fractionDigit;
29 +
30 + /**
31 + * Creates an instance of YANG decimal64.
32 + */
33 + public YangDecimal64() {
34 + }
35 +
36 + /**
37 + * Creates an instance of of YANG decimal64.
38 + *
39 + * @param fractionDigit fraction digit
40 + */
41 + public YangDecimal64(int fractionDigit) {
42 + this.setFractionDigit(fractionDigit);
43 + }
44 +
45 + /**
46 + * Returns fraction digit.
47 + *
48 + * @return the fractionDigit
49 + */
50 + public int getFractionDigit() {
51 + return fractionDigit;
52 + }
53 +
54 + /**
55 + * Sets fraction digit.
56 + *
57 + * @param fractionDigit fraction digits.
58 + */
59 + public void setFractionDigit(int fractionDigit) {
60 + this.fractionDigit = fractionDigit;
61 + }
62 +
63 + /**
64 + * Returns object of YANG decimal64.
65 + *
66 + * @param value fraction digit
67 + * @return YANG decimal64
68 + */
69 + public static YangDecimal64 of(int value) {
70 + return new YangDecimal64(value);
71 + }
72 +
73 + @Override
74 + public int hashCode() {
75 + return Objects.hash(fractionDigit);
76 + }
77 +
78 + @Override
79 + public boolean equals(Object obj) {
80 + if (this == obj) {
81 + return true;
82 + }
83 + if (obj instanceof YangDecimal64) {
84 + YangDecimal64 other = (YangDecimal64) obj;
85 + return Objects.equals(fractionDigit, other.fractionDigit);
86 + }
87 + return false;
88 + }
89 +
90 + @Override
91 + public String toString() {
92 + return MoreObjects.toStringHelper(getClass())
93 + .omitNullValues()
94 + .add("fractionDigit", fractionDigit)
95 + .toString();
96 + }
97 +
98 + /**
99 + * Returns the object of YANG decimal64 fromString input String.
100 + *
101 + * @param valInString input String
102 + * @return Object of YANG decimal64
103 + */
104 + public static YangDecimal64 fromString(String valInString) {
105 + try {
106 + int tmpVal = Integer.parseInt(valInString);
107 + return of(tmpVal);
108 + } catch (Exception e) {
109 + }
110 + return null;
111 + }
112 +}
...@@ -22,6 +22,8 @@ import java.io.FileReader; ...@@ -22,6 +22,8 @@ import java.io.FileReader;
22 import java.io.FileWriter; 22 import java.io.FileWriter;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.PrintWriter; 24 import java.io.PrintWriter;
25 +import java.util.ArrayList;
26 +import java.util.List;
25 27
26 import org.onosproject.yangutils.datamodel.YangNode; 28 import org.onosproject.yangutils.datamodel.YangNode;
27 import org.onosproject.yangutils.translator.exception.TranslatorException; 29 import org.onosproject.yangutils.translator.exception.TranslatorException;
...@@ -84,10 +86,12 @@ public final class FileSystemUtil { ...@@ -84,10 +86,12 @@ public final class FileSystemUtil {
84 YangNode parent = getParentNodeInGenCode(yangNode); 86 YangNode parent = getParentNodeInGenCode(yangNode);
85 if (parent != null) { 87 if (parent != null) {
86 pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); 88 pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
87 - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true); 89 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
90 + ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
88 } else { 91 } else {
89 pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName(); 92 pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
90 - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false); 93 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
94 + ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
91 } 95 }
92 } catch (IOException e) { 96 } catch (IOException e) {
93 throw new IOException("failed to create package-info file"); 97 throw new IOException("failed to create package-info file");
...@@ -120,6 +124,7 @@ public final class FileSystemUtil { ...@@ -120,6 +124,7 @@ public final class FileSystemUtil {
120 */ 124 */
121 public static String readAppendFile(String toAppend, String spaces) 125 public static String readAppendFile(String toAppend, String spaces)
122 throws IOException { 126 throws IOException {
127 +
123 FileReader fileReader = new FileReader(toAppend); 128 FileReader fileReader = new FileReader(toAppend);
124 BufferedReader bufferReader = new BufferedReader(fileReader); 129 BufferedReader bufferReader = new BufferedReader(fileReader);
125 try { 130 try {
...@@ -156,15 +161,22 @@ public final class FileSystemUtil { ...@@ -156,15 +161,22 @@ public final class FileSystemUtil {
156 */ 161 */
157 public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) 162 public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
158 throws IOException { 163 throws IOException {
164 +
165 + List<FileWriter> fileWriterStore = new ArrayList<>();
166 +
159 FileWriter fileWriter = new FileWriter(inputFile, true); 167 FileWriter fileWriter = new FileWriter(inputFile, true);
168 + fileWriterStore.add(fileWriter);
160 PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); 169 PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
161 if (!isClose) { 170 if (!isClose) {
162 outputPrintWriter.write(contentTobeAdded); 171 outputPrintWriter.write(contentTobeAdded);
163 outputPrintWriter.flush(); 172 outputPrintWriter.flush();
164 outputPrintWriter.close(); 173 outputPrintWriter.close();
165 } else { 174 } else {
166 - fileWriter.flush(); 175 + for (FileWriter curWriter : fileWriterStore) {
167 - fileWriter.close(); 176 + curWriter.flush();
177 + curWriter.close();
178 + curWriter = null;
179 + }
168 } 180 }
169 } 181 }
170 } 182 }
......
...@@ -17,12 +17,14 @@ ...@@ -17,12 +17,14 @@
17 package org.onosproject.yangutils.utils.io.impl; 17 package org.onosproject.yangutils.utils.io.impl;
18 18
19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
20 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
20 21
21 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 22 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 25 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
25 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; 26 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
27 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
26 import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC; 28 import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
27 import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC; 29 import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
28 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC; 30 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC;
...@@ -181,7 +183,12 @@ public final class JavaDocGen { ...@@ -181,7 +183,12 @@ public final class JavaDocGen {
181 /** 183 /**
182 * For manager setters. 184 * For manager setters.
183 */ 185 */
184 - MANAGER_SETTER_METHOD 186 + MANAGER_SETTER_METHOD,
187 +
188 + /**
189 + * For event subject.
190 + */
191 + EVENT_SUBJECT_CLASS
185 } 192 }
186 193
187 /** 194 /**
...@@ -190,14 +197,15 @@ public final class JavaDocGen { ...@@ -190,14 +197,15 @@ public final class JavaDocGen {
190 * @param type java doc type 197 * @param type java doc type
191 * @param name name of the YangNode 198 * @param name name of the YangNode
192 * @param isList is list attribute 199 * @param isList is list attribute
200 + * @param pluginConfig plugin configurations
193 * @return javadocs. 201 * @return javadocs.
194 */ 202 */
195 - public static String getJavaDoc(JavaDocType type, String name, boolean isList) { 203 + public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
196 204
197 - name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, null)); 205 + name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
198 switch (type) { 206 switch (type) {
199 case IMPL_CLASS: { 207 case IMPL_CLASS: {
200 - return generateForImplClass(name); 208 + return generateForClass(name);
201 } 209 }
202 case BUILDER_CLASS: { 210 case BUILDER_CLASS: {
203 return generateForBuilderClass(name); 211 return generateForBuilderClass(name);
...@@ -248,7 +256,7 @@ public final class JavaDocGen { ...@@ -248,7 +256,7 @@ public final class JavaDocGen {
248 return generateForRpcService(name); 256 return generateForRpcService(name);
249 } 257 }
250 case RPC_MANAGER: { 258 case RPC_MANAGER: {
251 - return generateForImplClass(name); 259 + return generateForClass(name);
252 } 260 }
253 case EVENT: { 261 case EVENT: {
254 return generateForEvent(name); 262 return generateForEvent(name);
...@@ -256,6 +264,9 @@ public final class JavaDocGen { ...@@ -256,6 +264,9 @@ public final class JavaDocGen {
256 case EVENT_LISTENER: { 264 case EVENT_LISTENER: {
257 return generateForEventListener(name); 265 return generateForEventListener(name);
258 } 266 }
267 + case EVENT_SUBJECT_CLASS: {
268 + return generateForClass(name);
269 + }
259 default: { 270 default: {
260 return generateForConstructors(name); 271 return generateForConstructors(name);
261 } 272 }
...@@ -279,14 +290,19 @@ public final class JavaDocGen { ...@@ -279,14 +290,19 @@ public final class JavaDocGen {
279 * @param rpcName name of the rpc 290 * @param rpcName name of the rpc
280 * @param inputName name of input 291 * @param inputName name of input
281 * @param outputName name of output 292 * @param outputName name of output
293 + * @param pluginConfig plugin configurations
282 * @return javaDocs of rpc method 294 * @return javaDocs of rpc method
283 */ 295 */
284 - public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) { 296 + public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName,
285 - rpcName = getCamelCase(rpcName, null); 297 + YangPluginConfig pluginConfig) {
286 - 298 + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
287 - String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC 299 +
288 - + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK 300 + String javadoc =
289 - + getInputString(inputName, rpcName); 301 + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
302 + + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK;
303 + if (!inputName.equals(EMPTY_STRING)) {
304 + javadoc = javadoc + getInputString(inputName, rpcName);
305 + }
290 if (!outputName.equals(VOID)) { 306 if (!outputName.equals(VOID)) {
291 javadoc = javadoc + getOutputString(outputName, rpcName); 307 javadoc = javadoc + getOutputString(outputName, rpcName);
292 } 308 }
...@@ -393,7 +409,8 @@ public final class JavaDocGen { ...@@ -393,7 +409,8 @@ public final class JavaDocGen {
393 } else { 409 } else {
394 setter = setter + VALUE + SPACE + OF + SPACE; 410 setter = setter + VALUE + SPACE + OF + SPACE;
395 } 411 }
396 - setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT + attribute 412 + setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT
413 + + attribute
397 + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; 414 + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
398 return setter; 415 return setter;
399 } 416 }
...@@ -470,7 +487,7 @@ public final class JavaDocGen { ...@@ -470,7 +487,7 @@ public final class JavaDocGen {
470 * @param className class name 487 * @param className class name
471 * @return javaDocs 488 * @return javaDocs
472 */ 489 */
473 - private static String generateForImplClass(String className) { 490 + private static String generateForClass(String className) {
474 return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; 491 return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
475 } 492 }
476 493
......
...@@ -60,8 +60,8 @@ public final class YangFileScanner { ...@@ -60,8 +60,8 @@ public final class YangFileScanner {
60 * operations 60 * operations
61 */ 61 */
62 public static List<String> getYangFiles(String root) throws IOException { 62 public static List<String> getYangFiles(String root) throws IOException {
63 - List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION); 63 +
64 - return yangFiles; 64 + return getFiles(root, YANG_FILE_EXTENTION);
65 } 65 }
66 66
67 /** 67 /**
......
...@@ -16,32 +16,38 @@ ...@@ -16,32 +16,38 @@
16 16
17 package org.onosproject.yangutils.utils.io.impl; 17 package org.onosproject.yangutils.utils.io.impl;
18 18
19 +import java.io.BufferedReader;
19 import java.io.BufferedWriter; 20 import java.io.BufferedWriter;
20 import java.io.File; 21 import java.io.File;
22 +import java.io.FileReader;
21 import java.io.FileWriter; 23 import java.io.FileWriter;
22 import java.io.IOException; 24 import java.io.IOException;
23 import java.nio.file.Files; 25 import java.nio.file.Files;
24 import java.nio.file.StandardCopyOption; 26 import java.nio.file.StandardCopyOption;
25 import java.util.ArrayList; 27 import java.util.ArrayList;
26 import java.util.Iterator; 28 import java.util.Iterator;
27 -import java.util.List;
28 import java.util.LinkedList; 29 import java.util.LinkedList;
29 -import java.util.Stack; 30 +import java.util.List;
30 import java.util.Set; 31 import java.util.Set;
32 +import java.util.Stack;
33 +import java.util.regex.Pattern;
31 34
32 import org.apache.commons.io.FileUtils; 35 import org.apache.commons.io.FileUtils;
33 import org.apache.maven.model.Resource; 36 import org.apache.maven.model.Resource;
34 import org.apache.maven.project.MavenProject; 37 import org.apache.maven.project.MavenProject;
35 import org.onosproject.yangutils.plugin.manager.YangFileInfo; 38 import org.onosproject.yangutils.plugin.manager.YangFileInfo;
36 - 39 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
37 import org.slf4j.Logger; 40 import org.slf4j.Logger;
38 import org.sonatype.plexus.build.incremental.BuildContext; 41 import org.sonatype.plexus.build.incremental.BuildContext;
39 42
40 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 43 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
41 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 44 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
45 +import static org.onosproject.yangutils.utils.UtilConstants.HASH;
42 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 46 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
47 +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
43 import static org.onosproject.yangutils.utils.UtilConstants.ORG; 48 import static org.onosproject.yangutils.utils.UtilConstants.ORG;
44 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; 49 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
50 +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
45 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 51 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
46 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 52 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
47 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 53 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
...@@ -61,6 +67,9 @@ public final class YangIoUtils { ...@@ -61,6 +67,9 @@ public final class YangIoUtils {
61 67
62 private static final Logger log = getLogger(YangIoUtils.class); 68 private static final Logger log = getLogger(YangIoUtils.class);
63 private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH; 69 private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
70 + private static final int LINE_SIZE = 116;
71 + private static final int SUB_LINE_SIZE = 112;
72 + private static final int ZERO = 0;
64 73
65 /** 74 /**
66 * Creates an instance of YANG io utils. 75 * Creates an instance of YANG io utils.
...@@ -83,19 +92,19 @@ public final class YangIoUtils { ...@@ -83,19 +92,19 @@ public final class YangIoUtils {
83 /** 92 /**
84 * Adds package info file for the created directory. 93 * Adds package info file for the created directory.
85 * 94 *
86 - * @param path directory path 95 + * @param path directory path
87 - * @param classInfo class info for the package 96 + * @param classInfo class info for the package
88 - * @param pack package of the directory 97 + * @param pack package of the directory
89 * @param isChildNode is it a child node 98 * @param isChildNode is it a child node
99 + * @param pluginConfig plugin configurations
90 * @throws IOException when fails to create package info file 100 * @throws IOException when fails to create package info file
91 */ 101 */
92 - public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode) 102 + public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode,
103 + YangPluginConfig pluginConfig)
93 throws IOException { 104 throws IOException {
94 105
95 - if (pack.contains(ORG)) { 106 + pack = parsePkg(pack);
96 - String[] strArray = pack.split(ORG); 107 +
97 - pack = ORG + strArray[1];
98 - }
99 try { 108 try {
100 109
101 File packageInfo = new File(path + SLASH + "package-info.java"); 110 File packageInfo = new File(path + SLASH + "package-info.java");
...@@ -105,9 +114,12 @@ public final class YangIoUtils { ...@@ -105,9 +114,12 @@ public final class YangIoUtils {
105 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); 114 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
106 115
107 bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); 116 bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
108 - bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode)); 117 + bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig));
109 - bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); 118 + String pkg = PACKAGE + SPACE + pack + SEMI_COLAN;
110 - 119 + if (pkg.length() > LINE_SIZE) {
120 + pkg = whenDelimiterIsPersent(pkg, LINE_SIZE);
121 + }
122 + bufferedWriter.write(pkg);
111 bufferedWriter.close(); 123 bufferedWriter.close();
112 fileWriter.close(); 124 fileWriter.close();
113 } catch (IOException e) { 125 } catch (IOException e) {
...@@ -116,6 +128,32 @@ public final class YangIoUtils { ...@@ -116,6 +128,32 @@ public final class YangIoUtils {
116 } 128 }
117 129
118 /** 130 /**
131 + * Parses package and returns updated package.
132 + *
133 + * @param pack package needs to be updated
134 + * @return updated package
135 + */
136 + public static String parsePkg(String pack) {
137 +
138 + if (pack.contains(ORG)) {
139 + String[] strArray = pack.split(ORG);
140 + if (strArray.length >= 3) {
141 + for (int i = 1; i < strArray.length; i++) {
142 + if (i == 1) {
143 + pack = ORG + strArray[1];
144 + } else {
145 + pack = pack + ORG + strArray[i];
146 + }
147 + }
148 + } else {
149 + pack = ORG + strArray[1];
150 + }
151 + }
152 +
153 + return pack;
154 + }
155 +
156 + /**
119 * Cleans the generated directory if already exist in source folder. 157 * Cleans the generated directory if already exist in source folder.
120 * 158 *
121 * @param dir generated directory in previous build 159 * @param dir generated directory in previous build
...@@ -169,7 +207,7 @@ public final class YangIoUtils { ...@@ -169,7 +207,7 @@ public final class YangIoUtils {
169 /** 207 /**
170 * Adds generated source directory to the compilation root. 208 * Adds generated source directory to the compilation root.
171 * 209 *
172 - * @param source directory 210 + * @param source directory
173 * @param project current maven project 211 * @param project current maven project
174 * @param context current build context 212 * @param context current build context
175 */ 213 */
...@@ -182,7 +220,7 @@ public final class YangIoUtils { ...@@ -182,7 +220,7 @@ public final class YangIoUtils {
182 /** 220 /**
183 * Removes extra char from the string. 221 * Removes extra char from the string.
184 * 222 *
185 - * @param valueString string to be trimmed 223 + * @param valueString string to be trimmed
186 * @param removealStirng extra chars 224 * @param removealStirng extra chars
187 * @return new string 225 * @return new string
188 */ 226 */
...@@ -217,8 +255,8 @@ public final class YangIoUtils { ...@@ -217,8 +255,8 @@ public final class YangIoUtils {
217 * Returns the directory path of the package in canonical form. 255 * Returns the directory path of the package in canonical form.
218 * 256 *
219 * @param baseCodeGenPath base path where the generated files needs to be 257 * @param baseCodeGenPath base path where the generated files needs to be
220 - * put 258 + * put
221 - * @param pathOfJavaPkg java package of the file being generated 259 + * @param pathOfJavaPkg java package of the file being generated
222 * @return absolute path of the package in canonical form 260 * @return absolute path of the package in canonical form
223 */ 261 */
224 public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { 262 public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
...@@ -238,8 +276,8 @@ public final class YangIoUtils { ...@@ -238,8 +276,8 @@ public final class YangIoUtils {
238 * Returns the absolute path of the package in canonical form. 276 * Returns the absolute path of the package in canonical form.
239 * 277 *
240 * @param baseCodeGenPath base path where the generated files needs to be 278 * @param baseCodeGenPath base path where the generated files needs to be
241 - * put 279 + * put
242 - * @param pathOfJavaPkg java package of the file being generated 280 + * @param pathOfJavaPkg java package of the file being generated
243 * @return absolute path of the package in canonical form 281 * @return absolute path of the package in canonical form
244 */ 282 */
245 public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) { 283 public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
...@@ -249,9 +287,9 @@ public final class YangIoUtils { ...@@ -249,9 +287,9 @@ public final class YangIoUtils {
249 /** 287 /**
250 * Copies YANG files to the current project's output directory. 288 * Copies YANG files to the current project's output directory.
251 * 289 *
252 - * @param yangFileInfo set of YANG files 290 + * @param yangFileInfo list of YANG files
253 - * @param outputDir project's output directory 291 + * @param outputDir project's output directory
254 - * @param project maven project 292 + * @param project maven project
255 * @throws IOException when fails to copy files to destination resource directory 293 * @throws IOException when fails to copy files to destination resource directory
256 */ 294 */
257 public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project) 295 public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
...@@ -318,4 +356,126 @@ public final class YangIoUtils { ...@@ -318,4 +356,126 @@ public final class YangIoUtils {
318 throw new IOException("Failed to insert in " + file + "file"); 356 throw new IOException("Failed to insert in " + file + "file");
319 } 357 }
320 } 358 }
359 +
360 + /**
361 + * Validates a line size in given file whether it is having more then 120 characters.
362 + * If yes it will update and give a new file.
363 + *
364 + * @param dataFile file in which need to verify all lines.
365 + * @return updated file
366 + * @throws IOException when fails to do IO operations.
367 + */
368 + public static File validateLineLength(File dataFile) throws IOException {
369 + File tempFile = dataFile;
370 + FileReader fileReader = new FileReader(dataFile);
371 + BufferedReader bufferReader = new BufferedReader(fileReader);
372 + try {
373 + StringBuilder stringBuilder = new StringBuilder();
374 + String line = bufferReader.readLine();
375 +
376 + while (line != null) {
377 + if (line.length() > LINE_SIZE) {
378 + if (line.contains(PERIOD)) {
379 + line = whenDelimiterIsPersent(line, LINE_SIZE);
380 + } else if (line.contains(SPACE)) {
381 + line = whenSpaceIsPresent(line, LINE_SIZE);
382 + }
383 + stringBuilder.append(line);
384 + } else {
385 + stringBuilder.append(line + NEW_LINE);
386 + }
387 + line = bufferReader.readLine();
388 + }
389 + FileWriter writer = new FileWriter(tempFile);
390 + writer.write(stringBuilder.toString());
391 + writer.close();
392 + return tempFile;
393 + } finally {
394 + fileReader.close();
395 + bufferReader.close();
396 + }
397 + }
398 +
399 + /*When delimiters are present in the given line.*/
400 + private static String whenDelimiterIsPersent(String line, int lineSize) {
401 + StringBuilder stringBuilder = new StringBuilder();
402 +
403 + if (line.length() > lineSize) {
404 + String[] strArray = line.split(Pattern.quote(PERIOD));
405 + stringBuilder = updateString(strArray, stringBuilder, PERIOD, lineSize);
406 + } else {
407 + stringBuilder.append(line + NEW_LINE);
408 + }
409 + String[] strArray = stringBuilder.toString().split(NEW_LINE);
410 + StringBuilder tempBuilder = new StringBuilder();
411 + for (String str : strArray) {
412 + if (str.length() > SUB_LINE_SIZE) {
413 + if (line.contains(PERIOD) && !line.contains(PERIOD + HASH + OPEN_PARENTHESIS)) {
414 + String[] strArr = str.split(Pattern.quote(PERIOD));
415 + tempBuilder = updateString(strArr, tempBuilder, PERIOD, SUB_LINE_SIZE);
416 + } else if (str.contains(SPACE)) {
417 + tempBuilder.append(whenSpaceIsPresent(str, SUB_LINE_SIZE));
418 + }
419 + } else {
420 + tempBuilder.append(str + NEW_LINE);
421 + }
422 + }
423 + return tempBuilder.toString();
424 +
425 + }
426 +
427 + /*When spaces are present in the given line.*/
428 + private static String whenSpaceIsPresent(String line, int lineSize) {
429 + StringBuilder stringBuilder = new StringBuilder();
430 + if (line.length() > lineSize) {
431 + String[] strArray = line.split(SPACE);
432 + stringBuilder = updateString(strArray, stringBuilder, SPACE, lineSize);
433 + } else {
434 + stringBuilder.append(line + NEW_LINE);
435 + }
436 +
437 + String[] strArray = stringBuilder.toString().split(NEW_LINE);
438 + StringBuilder tempBuilder = new StringBuilder();
439 + for (String str : strArray) {
440 + if (str.length() > SUB_LINE_SIZE) {
441 + if (str.contains(SPACE)) {
442 + String[] strArr = str.split(SPACE);
443 + tempBuilder = updateString(strArr, tempBuilder, SPACE, SUB_LINE_SIZE);
444 + }
445 + } else {
446 + tempBuilder.append(str + NEW_LINE);
447 + }
448 + }
449 + return tempBuilder.toString();
450 + }
451 +
452 + /*Updates the given line with the given size conditions.*/
453 + private static StringBuilder updateString(String[] strArray, StringBuilder stringBuilder, String string,
454 + int lineSize) {
455 +
456 + StringBuilder tempBuilder = new StringBuilder();
457 + for (String str : strArray) {
458 + tempBuilder.append(str + string);
459 + if (tempBuilder.length() > lineSize) {
460 + String tempString = stringBuilder.toString();
461 + stringBuilder.delete(ZERO, stringBuilder.length());
462 + tempString = trimAtLast(tempString, string);
463 + stringBuilder.append(tempString);
464 + if (string.equals(PERIOD)) {
465 + stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string);
466 + } else {
467 + stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + str + string);
468 + }
469 + tempBuilder.delete(ZERO, tempBuilder.length());
470 + tempBuilder.append(TWELVE_SPACE_INDENTATION);
471 + } else {
472 + stringBuilder.append(str + string);
473 + }
474 + }
475 + String tempString = stringBuilder.toString();
476 + tempString = trimAtLast(tempString, string);
477 + stringBuilder.delete(ZERO, stringBuilder.length());
478 + stringBuilder.append(tempString + NEW_LINE);
479 + return stringBuilder;
480 + }
321 } 481 }
......
...@@ -25,8 +25,8 @@ import YangLexer; ...@@ -25,8 +25,8 @@ import YangLexer;
25 package org.onosproject.yangutils.parser.antlrgencode; 25 package org.onosproject.yangutils.parser.antlrgencode;
26 } 26 }
27 27
28 - yangfile : moduleStatement 28 + yangfile : moduleStatement EOF
29 - | subModuleStatement; 29 + | subModuleStatement EOF;
30 30
31 /** 31 /**
32 * module-stmt = optsep module-keyword sep identifier-arg-str 32 * module-stmt = optsep module-keyword sep identifier-arg-str
......
...@@ -564,7 +564,7 @@ public class IntraFileUsesLinkingTest { ...@@ -564,7 +564,7 @@ public class IntraFileUsesLinkingTest {
564 564
565 thrown.expect(ParserException.class); 565 thrown.expect(ParserException.class);
566 thrown.expectMessage( 566 thrown.expectMessage(
567 - "YANG file error: Unable to find base typedef/grouping for given type/uses"); 567 + "YANG file error: Unable to find base grouping for given uses");
568 568
569 YangNode node = manager 569 YangNode node = manager
570 .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); 570 .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang");
......
...@@ -52,4 +52,34 @@ public class TreeWalkListenerTest { ...@@ -52,4 +52,34 @@ public class TreeWalkListenerTest {
52 thrown.expectMessage("YANG file error : \"anyxml\" is not supported."); 52 thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
53 manager.getDataModel("src/test/resources/AnyxmlStatement.yang"); 53 manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
54 } 54 }
55 +
56 + /**
57 + * Checks whether exception is thrown when extra brace is added in the EOF.
58 + */
59 + @Test
60 + public void processFileWithExtraBrace() throws IOException, ParserException {
61 + thrown.expect(ParserException.class);
62 + thrown.expectMessage("mismatched input '}' expecting <EOF>");
63 + manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang");
64 + }
65 +
66 + /**
67 + * Checks whether exception is thrown when leaf is given after module ends.
68 + */
69 + @Test
70 + public void processFileWithExtraLeaf() throws IOException, ParserException {
71 + thrown.expect(ParserException.class);
72 + thrown.expectMessage("mismatched input 'leaf' expecting <EOF>");
73 + manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang");
74 + }
75 +
76 + /**
77 + * Checks whether exception is thrown when extra brace is added in between the EOF.
78 + */
79 + @Test
80 + public void processFileWithExtraBraceInBetween() throws IOException, ParserException {
81 + thrown.expect(ParserException.class);
82 + thrown.expectMessage("mismatched input 'container' expecting <EOF>");
83 + manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang");
84 + }
55 } 85 }
......
...@@ -26,10 +26,14 @@ import org.onosproject.yangutils.datamodel.YangLeaf; ...@@ -26,10 +26,14 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
26 import org.onosproject.yangutils.datamodel.YangModule; 26 import org.onosproject.yangutils.datamodel.YangModule;
27 import org.onosproject.yangutils.datamodel.YangNode; 27 import org.onosproject.yangutils.datamodel.YangNode;
28 import org.onosproject.yangutils.datamodel.YangNodeType; 28 import org.onosproject.yangutils.datamodel.YangNodeType;
29 +import org.onosproject.yangutils.datamodel.YangType;
30 +import org.onosproject.yangutils.datamodel.YangTypeDef;
31 +import org.onosproject.yangutils.datamodel.YangUnion;
29 import org.onosproject.yangutils.parser.exceptions.ParserException; 32 import org.onosproject.yangutils.parser.exceptions.ParserException;
30 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 33 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 34
32 import java.io.IOException; 35 import java.io.IOException;
36 +import java.util.List;
33 import java.util.ListIterator; 37 import java.util.ListIterator;
34 import java.util.Set; 38 import java.util.Set;
35 39
...@@ -80,6 +84,84 @@ public class BitListenerTest { ...@@ -80,6 +84,84 @@ public class BitListenerTest {
80 } 84 }
81 85
82 /** 86 /**
87 + * Checks bit statement with typedef.
88 + */
89 + @Test
90 + public void processBitTypedefStatement() throws IOException, ParserException {
91 +
92 + YangNode node = manager.getDataModel("src/test/resources/BitTypedefStatement.yang");
93 +
94 + // Check whether the data model tree returned is of type module.
95 + assertThat((node instanceof YangModule), is(true));
96 +
97 + // Check whether the node type is set properly to module.
98 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
99 +
100 + // Check whether the module name is set correctly.
101 + YangModule yangNode = (YangModule) node;
102 + assertThat(yangNode.getName(), is("Test"));
103 +
104 + YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
105 + assertThat(typedef.getName(), is("type15"));
106 +
107 + YangType type = typedef.getTypeList().iterator().next();
108 + assertThat(type.getDataType(), is(YangDataTypes.BITS));
109 + assertThat(type.getDataTypeName(), is("bits"));
110 + Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet();
111 + for (YangBit tmp : bitSet) {
112 + if (tmp.getBitName().equals("disable-nagle")) {
113 + assertThat(tmp.getPosition(), is(0));
114 + } else if (tmp.getBitName().equals("auto-sense-speed")) {
115 + assertThat(tmp.getPosition(), is(1));
116 + }
117 + }
118 + }
119 +
120 + /**
121 + * Checks bit statement with union.
122 + */
123 + @Test
124 + public void processBitUnionStatement() throws IOException, ParserException {
125 +
126 + YangNode node = manager.getDataModel("src/test/resources/BitUnionStatement.yang");
127 +
128 + // Check whether the data model tree returned is of type module.
129 + assertThat((node instanceof YangModule), is(true));
130 +
131 + // Check whether the node type is set properly to module.
132 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
133 +
134 + // Check whether the module name is set correctly.
135 + YangModule yangNode = (YangModule) node;
136 + assertThat(yangNode.getName(), is("Test"));
137 +
138 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
139 + YangLeaf leafInfo = leafIterator.next();
140 +
141 + assertThat(leafInfo.getName(), is("type15"));
142 +
143 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UNION));
144 + assertThat(leafInfo.getDataType().getDataTypeName(), is("union"));
145 +
146 + YangUnion yangUnion = (YangUnion) leafInfo.getDataType().getDataTypeExtendedInfo();
147 +
148 + List<YangType<?>> typeList = yangUnion.getTypeList();
149 + ListIterator<YangType<?>> typeListIterator = typeList.listIterator();
150 + YangType<?> yangType = typeListIterator.next();
151 +
152 + assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
153 + assertThat(yangType.getDataTypeName(), is("bits"));
154 + Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet();
155 + for (YangBit tmp : bitSet) {
156 + if (tmp.getBitName().equals("disable-nagle")) {
157 + assertThat(tmp.getPosition(), is(0));
158 + } else if (tmp.getBitName().equals("auto-sense-speed")) {
159 + assertThat(tmp.getPosition(), is(1));
160 + }
161 + }
162 + }
163 +
164 + /**
83 * Checks if enum with same name is not allowed. 165 * Checks if enum with same name is not allowed.
84 */ 166 */
85 @Test(expected = ParserException.class) 167 @Test(expected = ParserException.class)
......
...@@ -33,8 +33,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -33,8 +33,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
33 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 33 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
34 34
35 import java.io.IOException; 35 import java.io.IOException;
36 +import java.util.Iterator;
36 import java.util.ListIterator; 37 import java.util.ListIterator;
37 -import java.util.Set; 38 +import java.util.SortedSet;
38 39
39 /** 40 /**
40 * Test cases for enum listener. 41 * Test cases for enum listener.
...@@ -73,7 +74,7 @@ public class EnumListenerTest { ...@@ -73,7 +74,7 @@ public class EnumListenerTest {
73 assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), 74 assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
74 is("speed_enum")); 75 is("speed_enum"));
75 76
76 - Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); 77 + SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
77 for (YangEnum tmp : enumSet) { 78 for (YangEnum tmp : enumSet) {
78 if (tmp.getNamedValue().equals("10m")) { 79 if (tmp.getNamedValue().equals("10m")) {
79 assertThat(tmp.getValue(), is(0)); 80 assertThat(tmp.getValue(), is(0));
...@@ -114,4 +115,34 @@ public class EnumListenerTest { ...@@ -114,4 +115,34 @@ public class EnumListenerTest {
114 + "with the current highest value"); 115 + "with the current highest value");
115 YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang"); 116 YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang");
116 } 117 }
118 +
119 + /**
120 + * Checks enum values stored are sorted.
121 + */
122 + @Test
123 + public void processEnumSorted() throws IOException, ParserException {
124 + YangNode node = manager.getDataModel("src/test/resources/EnumSorted.yang");
125 + // Check whether the data model tree returned is of type module.
126 + assertThat((node instanceof YangModule), is(true));
127 +
128 + // Check whether the node type is set properly to module.
129 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
130 +
131 + // Check whether the module name is set correctly.
132 + YangModule yangNode = (YangModule) node;
133 + assertThat(yangNode.getName(), is("Test"));
134 +
135 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
136 + YangLeaf leafInfo = leafIterator.next();
137 +
138 + assertThat(leafInfo.getName(), is("ifType"));
139 + assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
140 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
141 + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
142 + is("ifType_enum"));
143 +
144 + SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
145 + Iterator<YangEnum> enumIterator = enumSet.iterator();
146 + assertThat(enumIterator.next().getNamedValue(), is("five"));
147 + }
117 } 148 }
......
...@@ -267,4 +267,36 @@ public class LengthRestrictionListenerTest { ...@@ -267,4 +267,36 @@ public class LengthRestrictionListenerTest {
267 assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); 267 assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
268 assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); 268 assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
269 } 269 }
270 +
271 + /**
272 + * Checks whether space can be allowed when length statement is present.
273 + */
274 + @Test
275 + public void processLengthStatementWithSpace() throws IOException, ParserException {
276 +
277 + YangNode node = manager.getDataModel("src/test/resources/LengthStatementWithSpace.yang");
278 +
279 + assertThat((node instanceof YangModule), is(true));
280 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
281 + YangModule yangNode = (YangModule) node;
282 + assertThat(yangNode.getName(), is("Test"));
283 +
284 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
285 + YangLeaf leafInfo = leafIterator.next();
286 +
287 + assertThat(leafInfo.getName(), is("invalid-interval"));
288 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
289 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
290 + YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
291 + .getDataType().getDataTypeExtendedInfo();
292 + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
293 +
294 + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
295 + .listIterator();
296 +
297 + YangRangeInterval rangeInterval = lengthListIterator.next();
298 +
299 + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
300 + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
301 + }
270 } 302 }
......
...@@ -176,4 +176,15 @@ public class MaxElementsListenerTest { ...@@ -176,4 +176,15 @@ public class MaxElementsListenerTest {
176 assertThat(leafListInfo.getName(), is("invalid-interval")); 176 assertThat(leafListInfo.getName(), is("invalid-interval"));
177 assertThat(leafListInfo.getMaxElelements(), is(2147483647)); 177 assertThat(leafListInfo.getMaxElelements(), is(2147483647));
178 } 178 }
179 +
180 + /**
181 + * Checks whether exception is thrown when invalid min-elements value is
182 + * given as input.
183 + */
184 + @Test
185 + public void processMaxElementsMaxValue() throws IOException, ParserException {
186 + thrown.expect(ParserException.class);
187 + thrown.expectMessage("YANG file error : max-elements value 77777777777777777777777 is not valid.");
188 + YangNode node = manager.getDataModel("src/test/resources/MaxElementsMaxValue.yang");
189 + }
179 } 190 }
......
...@@ -116,6 +116,17 @@ public class MinElementsListenerTest { ...@@ -116,6 +116,17 @@ public class MinElementsListenerTest {
116 } 116 }
117 117
118 /** 118 /**
119 + * Checks whether exception is thrown when invalid min-elements value is
120 + * given as input.
121 + */
122 + @Test
123 + public void processMinElementsMaxValue() throws IOException, ParserException {
124 + thrown.expect(ParserException.class);
125 + thrown.expectMessage("YANG file error : min-elements value 77777777777777777777777 is not valid.");
126 + YangNode node = manager.getDataModel("src/test/resources/MinElementsMaxValue.yang");
127 + }
128 +
129 + /**
119 * Checks whether exception is thrown when min-elements statement without 130 * Checks whether exception is thrown when min-elements statement without
120 * statement end is given as input. 131 * statement end is given as input.
121 */ 132 */
......
...@@ -66,6 +66,6 @@ public class NotificationListenerTest { ...@@ -66,6 +66,6 @@ public class NotificationListenerTest {
66 YangLeaf leafInfo = leafIterator.next(); 66 YangLeaf leafInfo = leafIterator.next();
67 67
68 assertThat(leafInfo.getName(), is("if-name")); 68 assertThat(leafInfo.getName(), is("if-name"));
69 - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); 69 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
70 } 70 }
71 } 71 }
......
...@@ -207,4 +207,33 @@ public class RangeRestrictionListenerTest { ...@@ -207,4 +207,33 @@ public class RangeRestrictionListenerTest {
207 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); 207 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
208 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); 208 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
209 } 209 }
210 +
211 + /**
212 + * Checks whether space can be allowed when range statement is present.
213 + */
214 + @Test
215 + public void processRangeStatementWithSpace() throws IOException, ParserException {
216 +
217 + YangNode node = manager.getDataModel("src/test/resources/RangeStatementWithSpace.yang");
218 +
219 + assertThat((node instanceof YangModule), is(true));
220 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
221 + YangModule yangNode = (YangModule) node;
222 + assertThat(yangNode.getName(), is("Test"));
223 +
224 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
225 + YangLeaf leafInfo = leafIterator.next();
226 +
227 + assertThat(leafInfo.getName(), is("invalid-interval"));
228 + assertThat(leafInfo.getDataType().getDataTypeName(), is("int32"));
229 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32));
230 + YangRangeRestriction rangeRestriction = (YangRangeRestriction) leafInfo
231 + .getDataType().getDataTypeExtendedInfo();
232 +
233 + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
234 + .listIterator();
235 + YangRangeInterval rangeInterval = rangeListIterator.next();
236 + assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
237 + assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
238 + }
210 } 239 }
......
...@@ -17,7 +17,9 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -17,7 +17,9 @@ package org.onosproject.yangutils.parser.impl.listeners;
17 17
18 import java.io.IOException; 18 import java.io.IOException;
19 import java.util.ListIterator; 19 import java.util.ListIterator;
20 +import org.junit.Rule;
20 import org.junit.Test; 21 import org.junit.Test;
22 +import org.junit.rules.ExpectedException;
21 import org.onosproject.yangutils.datamodel.YangDataTypes; 23 import org.onosproject.yangutils.datamodel.YangDataTypes;
22 import org.onosproject.yangutils.datamodel.YangLeaf; 24 import org.onosproject.yangutils.datamodel.YangLeaf;
23 import org.onosproject.yangutils.datamodel.YangLeafList; 25 import org.onosproject.yangutils.datamodel.YangLeafList;
...@@ -35,6 +37,9 @@ import static org.hamcrest.core.Is.is; ...@@ -35,6 +37,9 @@ import static org.hamcrest.core.Is.is;
35 */ 37 */
36 public class TypeListenerTest { 38 public class TypeListenerTest {
37 39
40 + @Rule
41 + public ExpectedException thrown = ExpectedException.none();
42 +
38 private final YangUtilsParserManager manager = new YangUtilsParserManager(); 43 private final YangUtilsParserManager manager = new YangUtilsParserManager();
39 44
40 /** 45 /**
...@@ -114,4 +119,46 @@ public class TypeListenerTest { ...@@ -114,4 +119,46 @@ public class TypeListenerTest {
114 assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16")); 119 assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
115 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 120 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
116 } 121 }
122 +
123 + /**
124 + * Checks for unsupported type leafref.
125 + */
126 + @Test
127 + public void processLeafrefType() throws IOException, ParserException {
128 +
129 + thrown.expect(ParserException.class);
130 + thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version,"
131 + + " please check wiki for YANG utils road map.");
132 +
133 + YangNode node = manager
134 + .getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang");
135 + }
136 +
137 + /**
138 + * Checks for unsupported type identityref.
139 + */
140 + @Test
141 + public void processIdentityrefType() throws IOException, ParserException {
142 +
143 + thrown.expect(ParserException.class);
144 + thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
145 + + " please check wiki for YANG utils road map.");
146 +
147 + YangNode node = manager
148 + .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
149 + }
150 +
151 + /**
152 + * Checks for unsupported type instance identifier.
153 + */
154 + @Test
155 + public void processInstanceIdentifierType() throws IOException, ParserException {
156 +
157 + thrown.expect(ParserException.class);
158 + thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version,"
159 + + " please check wiki for YANG utils road map.");
160 +
161 + YangNode node = manager
162 + .getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang");
163 + }
117 } 164 }
......
1 +/*
2 + * Copyright 2016-present 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.parser.impl.parseutils;
18 +
19 +import java.io.IOException;
20 +import org.junit.Rule;
21 +import org.junit.Test;
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.parser.exceptions.ParserException;
24 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
25 +
26 +/**
27 + * Test case for testing listener util.
28 + */
29 +public class ListenerUtilTest {
30 +
31 + @Rule
32 + public ExpectedException thrown = ExpectedException.none();
33 +
34 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
35 +
36 + /**
37 + * Checks whether exception is thrown when identifier starts with xml.
38 + */
39 + @Test
40 + public void validateIdentifierStartsWithXml() throws IOException {
41 + thrown.expect(ParserException.class);
42 + thrown.expectMessage("YANG file error : module identifier xMlTest must not start" +
43 + " with (('X'|'x') ('M'|'m') ('L'|'l'))");
44 + manager.getDataModel("src/test/resources/InValidIdentifierXML.yang");
45 + }
46 +}
1 -/*
2 - * Copyright 2016-present 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.parser.parseutils;
18 -
19 -import org.junit.Test;
20 -
21 -import static org.hamcrest.core.Is.is;
22 -import static org.junit.Assert.assertThat;
23 -import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
24 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
25 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
26 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
27 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
28 -
29 -/**
30 - * Test case for testing listener error message construction util.
31 - */
32 -public class ListenerErrorMessageConstructionTest {
33 -
34 - /**
35 - * Checks for error message construction with parsable data type name.
36 - */
37 - @Test
38 - public void checkErrorMsgConstructionWithName() {
39 -
40 - // Create an test error message
41 - String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
42 -
43 - // Check message.
44 - assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
45 - + "\"Test Instance\" before processing."));
46 - }
47 -
48 - /**
49 - * Checks for error message construction without parsable data type name.
50 - */
51 - @Test
52 - public void checkErrorMsgConstructionWithoutName() {
53 -
54 - // Create an test error message
55 - String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
56 -
57 - // Check message.
58 - assertThat(testErrorMessage,
59 - is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
60 - + " before processing."));
61 - }
62 -
63 - /**
64 - * Checks for extended error message construction with parsable data type
65 - * name.
66 - */
67 - @Test
68 - public void checkExtendedErrorMsgConstructionWithName() {
69 -
70 - // Create an test error message
71 - String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
72 - "Test Instance", ENTRY,
73 - "Extended Information");
74 -
75 - // Check message.
76 - assertThat(testErrorMessage,
77 - is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
78 - + " before processing.\n" + "Error Information: Extended Information"));
79 - }
80 -
81 - /**
82 - * Checks for extended error message construction without parsable data type
83 - * name.
84 - */
85 - @Test
86 - public void checkExtendedErrorMsgConstructionWithoutName() {
87 -
88 - // Create an test error message
89 - String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
90 - "Extended Information");
91 -
92 - // Check message.
93 - assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
94 - + " before processing.\n" + "Error Information: Extended Information"));
95 - }
96 -}
1 -/*
2 - * Copyright 2016-present 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.parser.parseutils;
18 -
19 -import org.junit.Rule;
20 -import org.junit.Test;
21 -import org.junit.rules.ExpectedException;
22 -import org.onosproject.yangutils.datamodel.YangRevision;
23 -import org.onosproject.yangutils.parser.exceptions.ParserException;
24 -import org.onosproject.yangutils.parser.impl.TreeWalkListener;
25 -
26 -import static org.onosproject.yangutils.utils.YangConstructType.YANGBASE_DATA;
27 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
28 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
29 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
30 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
31 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
32 -
33 -/**
34 - * Test case for testing listener validation util.
35 - */
36 -public class ListenerValidationTest {
37 -
38 - @Rule
39 - public ExpectedException thrown = ExpectedException.none();
40 -
41 - /**
42 - * Checks for exception in case parsable stack is empty while validating for
43 - * not empty scenario.
44 - */
45 - @Test
46 - public void validateStackIsNotEmptyForEmptyStack() {
47 -
48 - String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
49 -
50 - // Get the exception occurred during parsing.
51 - thrown.expect(ParserException.class);
52 - thrown.expectMessage(expectedError);
53 -
54 - // Create test walker and assign test error to it.
55 - TreeWalkListener testWalker = new TreeWalkListener();
56 -
57 - checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
58 - }
59 -
60 - /**
61 - * Checks if there is no exception in case parsable stack is not empty while
62 - * validating for not empty scenario.
63 - */
64 - @Test
65 - public void validateStackIsNotEmptyForNonEmptyStack() {
66 -
67 - // Create test walker and assign test error to it.
68 - TreeWalkListener testWalker = new TreeWalkListener();
69 -
70 - // Create a temporary node of parsable.
71 - YangRevision tmpNode = new YangRevision();
72 - testWalker.getParsedDataStack().push(tmpNode);
73 -
74 - checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
75 - }
76 -
77 - /**
78 - * Checks for exception in case parsable stack is not empty while validating
79 - * for empty scenario.
80 - */
81 - @Test
82 - public void validateStackIsEmptyForNonEmptyStack() {
83 -
84 - String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
85 -
86 - // Get the exception occurred during parsing.
87 - thrown.expect(ParserException.class);
88 - thrown.expectMessage(expectedError);
89 -
90 - // Create test walker and assign test error to it.
91 - TreeWalkListener testWalker = new TreeWalkListener();
92 -
93 - // Create a temporary node of parsable.
94 - YangRevision tmpNode = new YangRevision();
95 - testWalker.getParsedDataStack().push(tmpNode);
96 -
97 - checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
98 - }
99 -
100 - /**
101 - * Checks if there is no exception in case parsable stack is empty while
102 - * validating for empty scenario.
103 - */
104 - @Test
105 - public void validateStackIsEmptyForEmptyStack() {
106 -
107 - // Create test walker and assign test error to it.
108 - TreeWalkListener testWalker = new TreeWalkListener();
109 -
110 - checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
111 - }
112 -}
1 -/*
2 - * Copyright 2016-present 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.parser.parseutils;
18 -
19 -import org.antlr.v4.runtime.ANTLRFileStream;
20 -import org.antlr.v4.runtime.ANTLRInputStream;
21 -import org.antlr.v4.runtime.CommonTokenStream;
22 -import org.antlr.v4.runtime.tree.ParseTree;
23 -import org.junit.Rule;
24 -import org.junit.Test;
25 -import org.junit.rules.ExpectedException;
26 -import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer;
27 -import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
28 -import org.onosproject.yangutils.parser.exceptions.ParserException;
29 -import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher;
30 -import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 -import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
32 -
33 -import java.io.BufferedWriter;
34 -import java.io.File;
35 -import java.io.IOException;
36 -
37 -/**
38 - * Test case for testing parse tree error listener.
39 - */
40 -public class ParseTreeErrorListenerTest {
41 -
42 - YangUtilsParserManager manager = new YangUtilsParserManager();
43 - File file;
44 - BufferedWriter out;
45 -
46 - @Rule
47 - public ExpectedException thrown = ExpectedException.none();
48 -
49 - /**
50 - * Checks that no exception is generated for YANG file with valid syntax.
51 - */
52 - @Test
53 - public void checkValidYangFileForNoSyntaxError() throws IOException {
54 -
55 - ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");
56 -
57 - // Create a lexer that feeds off of input char stream.
58 - GeneratedYangLexer lexer = new GeneratedYangLexer(input);
59 - // Create a buffer of tokens pulled from the lexer.
60 - CommonTokenStream tokens = new CommonTokenStream(lexer);
61 - // Create a parser that feeds off the tokens buffer.
62 - GeneratedYangParser parser = new GeneratedYangParser(tokens);
63 - // Remove console error listener.
64 - parser.removeErrorListeners();
65 - // Create instance of customized error listener.
66 - ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
67 - // Add customized error listener to catch errors during parsing.
68 - parser.addErrorListener(parseTreeErrorListener);
69 - // Begin parsing YANG file and generate parse tree.
70 - ParseTree tree = parser.yangfile();
71 - }
72 -
73 - /**
74 - * Checks that exception is generated for YANG file with invalid syntax.
75 - */
76 - @Test
77 - public void checkInvalidYangFileForSyntaxError() throws IOException {
78 -
79 - // Get the exception occurred during parsing.
80 - thrown.expect(ParserException.class);
81 - thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
82 - thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");
83 -
84 - ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");
85 -
86 - // Create a lexer that feeds off of input char stream.
87 - GeneratedYangLexer lexer = new GeneratedYangLexer(input);
88 - // Create a buffer of tokens pulled from the lexer.
89 - CommonTokenStream tokens = new CommonTokenStream(lexer);
90 - // Create a parser that feeds off the tokens buffer.
91 - GeneratedYangParser parser = new GeneratedYangParser(tokens);
92 - // Remove console error listener.
93 - parser.removeErrorListeners();
94 - // Create instance of customized error listener.
95 - ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
96 - // Add customized error listener to catch errors during parsing.
97 - parser.addErrorListener(parseTreeErrorListener);
98 - // Begin parsing YANG file and generate parse tree.
99 - ParseTree tree = parser.yangfile();
100 - }
101 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -59,6 +59,7 @@ public class AttributesJavaDataTypeTest { ...@@ -59,6 +59,7 @@ public class AttributesJavaDataTypeTest {
59 private static final String CLASS_INFO5 = "Integer"; 59 private static final String CLASS_INFO5 = "Integer";
60 private static final String TYPE_DEF_PKG = "target.test"; 60 private static final String TYPE_DEF_PKG = "target.test";
61 private static String test = ""; 61 private static String test = "";
62 + private static YangToJavaNamingConflictUtil pluginConfig = null;
62 63
63 /** 64 /**
64 * Unit test for private constructor. 65 * Unit test for private constructor.
...@@ -71,7 +72,8 @@ public class AttributesJavaDataTypeTest { ...@@ -71,7 +72,8 @@ public class AttributesJavaDataTypeTest {
71 * @throws InvocationTargetException when an exception occurs by the method or constructor 72 * @throws InvocationTargetException when an exception occurs by the method or constructor
72 */ 73 */
73 @Test 74 @Test
74 - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 75 + public void callPrivateConstructors()
76 + throws SecurityException, NoSuchMethodException, IllegalArgumentException,
75 InstantiationException, IllegalAccessException, InvocationTargetException { 77 InstantiationException, IllegalAccessException, InvocationTargetException {
76 78
77 Class<?>[] classesToConstruct = {AttributesJavaDataType.class }; 79 Class<?>[] classesToConstruct = {AttributesJavaDataType.class };
...@@ -87,16 +89,16 @@ public class AttributesJavaDataTypeTest { ...@@ -87,16 +89,16 @@ public class AttributesJavaDataTypeTest {
87 */ 89 */
88 @Test 90 @Test
89 public void testgetJavaClassInfo() { 91 public void testgetJavaClassInfo() {
90 - test = getJavaImportClass(getStubYangType(TYPE1), false); 92 + test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig);
91 assertThat(true, is(test.equals(CLASS_INFO1))); 93 assertThat(true, is(test.equals(CLASS_INFO1)));
92 94
93 - test = getJavaImportClass(getStubYangType(TYPE2), true); 95 + test = getJavaImportClass(getStubYangType(TYPE2), true, pluginConfig);
94 assertThat(true, is(test.equals(CLASS_INFO5))); 96 assertThat(true, is(test.equals(CLASS_INFO5)));
95 97
96 - test = getJavaImportClass(getStubYangType(TYPE3), false); 98 + test = getJavaImportClass(getStubYangType(TYPE3), false, pluginConfig);
97 assertThat(null, is(test)); 99 assertThat(null, is(test));
98 100
99 - test = getJavaImportClass(getStubYangType(TYPE4), false); 101 + test = getJavaImportClass(getStubYangType(TYPE4), false, pluginConfig);
100 assertThat(null, is(test)); 102 assertThat(null, is(test));
101 } 103 }
102 104
...@@ -123,16 +125,16 @@ public class AttributesJavaDataTypeTest { ...@@ -123,16 +125,16 @@ public class AttributesJavaDataTypeTest {
123 */ 125 */
124 @Test 126 @Test
125 public void testgetJavaPkgInfo() { 127 public void testgetJavaPkgInfo() {
126 - test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1); 128 + test = getJavaImportPackage(getStubYangType(TYPE1), false, pluginConfig);
127 assertThat(true, is(test.equals(JAVA_LANG))); 129 assertThat(true, is(test.equals(JAVA_LANG)));
128 130
129 - test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5); 131 + test = getJavaImportPackage(getStubYangType(TYPE2), true, pluginConfig);
130 assertThat(true, is(test.equals(JAVA_LANG))); 132 assertThat(true, is(test.equals(JAVA_LANG)));
131 133
132 - test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3); 134 + test = getJavaImportPackage(getStubYangType(TYPE3), false, pluginConfig);
133 assertThat(null, is(test)); 135 assertThat(null, is(test));
134 136
135 - test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4); 137 + test = getJavaImportPackage(getStubYangType(TYPE4), false, pluginConfig);
136 assertThat(null, is(test)); 138 assertThat(null, is(test));
137 } 139 }
138 140
...@@ -143,7 +145,7 @@ public class AttributesJavaDataTypeTest { ...@@ -143,7 +145,7 @@ public class AttributesJavaDataTypeTest {
143 */ 145 */
144 @Test 146 @Test
145 public void testForTypeDef() throws DataModelException { 147 public void testForTypeDef() throws DataModelException {
146 - test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG); 148 + test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, pluginConfig);
147 assertThat(true, is(test.equals(TYPE_DEF_PKG))); 149 assertThat(true, is(test.equals(TYPE_DEF_PKG)));
148 } 150 }
149 151
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 +
20 import org.junit.Test; 21 import org.junit.Test;
21 import org.onosproject.yangutils.datamodel.YangNode; 22 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.parser.exceptions.ParserException; 23 import org.onosproject.yangutils.parser.exceptions.ParserException;
...@@ -44,7 +45,7 @@ public final class ChoiceCaseTranslatorTest { ...@@ -44,7 +45,7 @@ public final class ChoiceCaseTranslatorTest {
44 YangPluginConfig yangPluginConfig = new YangPluginConfig(); 45 YangPluginConfig yangPluginConfig = new YangPluginConfig();
45 yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); 46 yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
46 47
47 - generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator"); 48 + generateJavaCode(node, yangPluginConfig);
48 49
49 deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/"); 50 deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
50 } 51 }
......
...@@ -46,7 +46,7 @@ public final class EnumTranslatorTest { ...@@ -46,7 +46,7 @@ public final class EnumTranslatorTest {
46 YangPluginConfig yangPluginConfig = new YangPluginConfig(); 46 YangPluginConfig yangPluginConfig = new YangPluginConfig();
47 yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); 47 yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
48 48
49 - generateJavaCode(node, yangPluginConfig, "EnumTranslator"); 49 + generateJavaCode(node, yangPluginConfig);
50 50
51 deleteDirectory(userDir + "/target/EnumTestGenFile/"); 51 deleteDirectory(userDir + "/target/EnumTestGenFile/");
52 } 52 }
......
...@@ -19,7 +19,10 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,7 +19,10 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import java.lang.reflect.Constructor; 19 import java.lang.reflect.Constructor;
20 import java.lang.reflect.InvocationTargetException; 20 import java.lang.reflect.InvocationTargetException;
21 21
22 +import org.junit.Rule;
22 import org.junit.Test; 23 import org.junit.Test;
24 +import org.junit.rules.ExpectedException;
25 +import org.onosproject.yangutils.translator.exception.TranslatorException;
23 26
24 import static org.hamcrest.core.Is.is; 27 import static org.hamcrest.core.Is.is;
25 import static org.hamcrest.core.IsNot.not; 28 import static org.hamcrest.core.IsNot.not;
...@@ -38,6 +41,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; ...@@ -38,6 +41,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
38 */ 41 */
39 public final class JavaIdentifierSyntaxTest { 42 public final class JavaIdentifierSyntaxTest {
40 43
44 + @Rule
45 + public ExpectedException thrown = ExpectedException.none();
46 +
41 private static final String PARENT_PACKAGE = "test5/test6/test7"; 47 private static final String PARENT_PACKAGE = "test5/test6/test7";
42 private static final String CHILD_PACKAGE = "test1:test2:test3"; 48 private static final String CHILD_PACKAGE = "test1:test2:test3";
43 private static final String DATE1 = "2000-1-5"; 49 private static final String DATE1 = "2000-1-5";
...@@ -47,10 +53,17 @@ public final class JavaIdentifierSyntaxTest { ...@@ -47,10 +53,17 @@ public final class JavaIdentifierSyntaxTest {
47 private static final String DATE_WITH_REV1 = "rev20000105"; 53 private static final String DATE_WITH_REV1 = "rev20000105";
48 private static final String DATE_WITH_REV2 = "rev19920125"; 54 private static final String DATE_WITH_REV2 = "rev19920125";
49 private static final String VERSION_NUMBER = "v1"; 55 private static final String VERSION_NUMBER = "v1";
56 + private static final String VALID_PREFIX = "123add-prefix";
57 + private static final String INVALID_PREFIX = "-*()&^&#$%";
58 + private static final String INVALID_PREFIX1 = "abc~!@#$%^&*()_+}{:<>?`1234567890-=[]''|,./SS";
59 + private static final String INVALID_NAME_SPACE_FOR_INVALID_PREFIX = "try:#test3:9case3";
50 private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; 60 private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
51 private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; 61 private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
52 - private static final String VALID_NAME_SPACE1 = "yangautoprefixbyte.test2.yangautoprefix9test3"; 62 + private static final String INVALID_NAME_SPACE3 = "CONST:TRY://9test3";
63 + private static final String VALID_NAME_SPACE1 = "123addprefixbyte.test2.123addprefix9test3";
53 private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3"; 64 private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3";
65 + private static final String VALID_NAME_SPACE3 = "abc1234567890ssconst.test2.abc1234567890ss9test3";
66 + private static final String VALID_NAME_SPACE4 = "yangautoprefixconst.yangautoprefixtry.yangautoprefix9test3";
54 private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; 67 private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
55 private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; 68 private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
56 private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123"; 69 private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123";
...@@ -77,9 +90,16 @@ public final class JavaIdentifierSyntaxTest { ...@@ -77,9 +90,16 @@ public final class JavaIdentifierSyntaxTest {
77 private static final String WITH_CAMEL_CASE11 = "test3Name"; 90 private static final String WITH_CAMEL_CASE11 = "test3Name";
78 private static final String WITHOUT_CAMEL_CASE12 = "TEST3name"; 91 private static final String WITHOUT_CAMEL_CASE12 = "TEST3name";
79 private static final String WITH_CAMEL_CASE12 = "test3Name"; 92 private static final String WITH_CAMEL_CASE12 = "test3Name";
93 + private static final String WITHOUT_CAMEL_CASE13 = "t-RY";
94 + private static final String WITH_CAMEL_CASE13 = "tRy";
95 + private static final String WITHOUT_CAMEL_CASE14 = "TRY";
96 + private static final String WITH_CAMEL_CASE14 = "yangAutoPrefixTry";
80 private static final String WITHOUT_CAPITAL = "test_this"; 97 private static final String WITHOUT_CAPITAL = "test_this";
81 private static final String WITH_CAPITAL = "Test_this"; 98 private static final String WITH_CAPITAL = "Test_this";
82 private static final String WITH_SMALL = "test_this"; 99 private static final String WITH_SMALL = "test_this";
100 + private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
101 + private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
102 + private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
83 103
84 /** 104 /**
85 * Unit test for private constructor. 105 * Unit test for private constructor.
...@@ -111,22 +131,44 @@ public final class JavaIdentifierSyntaxTest { ...@@ -111,22 +131,44 @@ public final class JavaIdentifierSyntaxTest {
111 */ 131 */
112 @Test 132 @Test
113 public void getRootPackageTest() { 133 public void getRootPackageTest() {
114 - String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1); 134 + conflictResolver.setPrefixForIdentifier(null);
135 + String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver);
115 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER 136 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
116 + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); 137 + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
117 } 138 }
118 139
119 /** 140 /**
141 + * Unit test for root package generation with invalid prefix.
142 + */
143 + @Test
144 + public void getRootPackageWithInvalidPrefix() throws TranslatorException {
145 + thrown.expect(TranslatorException.class);
146 + thrown.expectMessage("The given prefix in pom.xml is invalid.");
147 + conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
148 + String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver);
149 + }
150 +
151 + /**
120 * Unit test for root package generation with special characters presence. 152 * Unit test for root package generation with special characters presence.
121 */ 153 */
122 @Test 154 @Test
123 public void getRootPackageWithSpecialCharactersTest() { 155 public void getRootPackageWithSpecialCharactersTest() {
124 - String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1); 156 + conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
157 + String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver);
125 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER 158 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
126 + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); 159 + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
127 - String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1); 160 + conflictResolver.setPrefixForIdentifier(null);
161 + String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
128 assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER 162 assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
129 + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); 163 + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
164 + String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver);
165 + assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
166 + + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true));
167 + conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
168 + String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
169 + assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
170 + + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true));
171 +
130 } 172 }
131 173
132 /** 174 /**
...@@ -134,7 +176,7 @@ public final class JavaIdentifierSyntaxTest { ...@@ -134,7 +176,7 @@ public final class JavaIdentifierSyntaxTest {
134 */ 176 */
135 @Test 177 @Test
136 public void getRootPackageWithRevTest() { 178 public void getRootPackageWithRevTest() {
137 - String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2); 179 + String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null);
138 assertThat(rootPkgWithRev.equals( 180 assertThat(rootPkgWithRev.equals(
139 DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), 181 DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
140 is(true)); 182 is(true));
...@@ -154,32 +196,63 @@ public final class JavaIdentifierSyntaxTest { ...@@ -154,32 +196,63 @@ public final class JavaIdentifierSyntaxTest {
154 */ 196 */
155 @Test 197 @Test
156 public void getCamelCaseTest() { 198 public void getCamelCaseTest() {
157 - String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, null); 199 + conflictResolver.setPrefixForIdentifier(null);
200 + String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, conflictResolver);
158 assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); 201 assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
159 - String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, null); 202 + String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, conflictResolver);
160 assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true)); 203 assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true));
161 - String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, null); 204 + String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
162 assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true)); 205 assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true));
163 - String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, null); 206 + String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
164 assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true)); 207 assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
165 - String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, null); 208 + String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, conflictResolver);
166 assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true)); 209 assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
167 - String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, null); 210 + String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, conflictResolver);
168 assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true)); 211 assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true));
169 - String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, null); 212 + String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, conflictResolver);
170 assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true)); 213 assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true));
171 - String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, null); 214 + String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, conflictResolver);
172 assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true)); 215 assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true));
173 - String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, null); 216 + String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, conflictResolver);
174 assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true)); 217 assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true));
175 - String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, null); 218 + String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, conflictResolver);
176 assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true)); 219 assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true));
177 - String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, null); 220 + String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, conflictResolver);
178 assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true)); 221 assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true));
179 - String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, null); 222 + String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, conflictResolver);
180 assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true)); 223 assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true));
181 - String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, null); 224 + String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, conflictResolver);
182 assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true)); 225 assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true));
226 + String camelCase13 = getCamelCase(WITHOUT_CAMEL_CASE13, conflictResolver);
227 + assertThat(camelCase13.equals(WITH_CAMEL_CASE13), is(true));
228 + String camelCase14 = getCamelCase(WITHOUT_CAMEL_CASE14, conflictResolver);
229 + assertThat(camelCase14.equals(WITH_CAMEL_CASE14), is(true));
230 + }
231 +
232 + /**
233 + * Unit test for getting the camel case along with the prefix provided.
234 + */
235 + @Test
236 + public void getCamelCaseWithPrefixTest() {
237 +
238 + conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
239 + String camelCase = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
240 + assertThat(camelCase.equals(WITH_CAMEL_CASE_WITH_PREFIX), is(true));
241 + conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
242 + String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
243 + assertThat(camelCase2.equals(WITH_CAMEL_CASE_WITH_PREFIX1), is(true));
244 + }
245 +
246 + /**
247 + * Unit test for getting the camel case along with the invalid prefix provided.
248 + */
249 + @Test
250 + public void getCamelCaseWithInvalidPrefixTest() throws TranslatorException {
251 +
252 + thrown.expect(TranslatorException.class);
253 + thrown.expectMessage("The given prefix in pom.xml is invalid.");
254 + conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
255 + String camelCase = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
183 } 256 }
184 257
185 /** 258 /**
......
...@@ -29,6 +29,7 @@ import static org.hamcrest.core.IsNot.not; ...@@ -29,6 +29,7 @@ import static org.hamcrest.core.IsNot.not;
29 import static org.junit.Assert.assertThat; 29 import static org.junit.Assert.assertThat;
30 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; 30 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
32 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
32 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild; 33 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
33 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface; 34 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
34 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull; 35 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
...@@ -105,7 +106,7 @@ public final class MethodsGeneratorTest { ...@@ -105,7 +106,7 @@ public final class MethodsGeneratorTest {
105 throws SecurityException, NoSuchMethodException, IllegalArgumentException, 106 throws SecurityException, NoSuchMethodException, IllegalArgumentException,
106 InstantiationException, IllegalAccessException, InvocationTargetException { 107 InstantiationException, IllegalAccessException, InvocationTargetException {
107 108
108 - Class<?>[] classesToConstruct = {MethodsGenerator.class}; 109 + Class<?>[] classesToConstruct = {MethodsGenerator.class };
109 for (Class<?> clazz : classesToConstruct) { 110 for (Class<?> clazz : classesToConstruct) {
110 Constructor<?> constructor = clazz.getDeclaredConstructor(); 111 Constructor<?> constructor = clazz.getDeclaredConstructor();
111 constructor.setAccessible(true); 112 constructor.setAccessible(true);
...@@ -118,8 +119,10 @@ public final class MethodsGeneratorTest { ...@@ -118,8 +119,10 @@ public final class MethodsGeneratorTest {
118 */ 119 */
119 @Test 120 @Test
120 public void getTypeConstructorTest() { 121 public void getTypeConstructorTest() {
122 +
123 + YangPluginConfig pluginConfig = new YangPluginConfig();
121 JavaAttributeInfo testAttr = getTestAttribute(); 124 JavaAttributeInfo testAttr = getTestAttribute();
122 - String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME); 125 + String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME, pluginConfig);
123 assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); 126 assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
124 } 127 }
125 128
...@@ -162,7 +165,8 @@ public final class MethodsGeneratorTest { ...@@ -162,7 +165,8 @@ public final class MethodsGeneratorTest {
162 @Test 165 @Test
163 public void getConstructorTest() { 166 public void getConstructorTest() {
164 JavaAttributeInfo testAttr = getTestAttribute(); 167 JavaAttributeInfo testAttr = getTestAttribute();
165 - String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER); 168 + YangPluginConfig pluginConfig = new YangPluginConfig();
169 + String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
166 assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT 170 assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
167 + PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN))); 171 + PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
168 } 172 }
...@@ -172,7 +176,8 @@ public final class MethodsGeneratorTest { ...@@ -172,7 +176,8 @@ public final class MethodsGeneratorTest {
172 */ 176 */
173 @Test 177 @Test
174 public void getConstructorStartTest() { 178 public void getConstructorStartTest() {
175 - String method = getConstructorStart(CLASS_NAME); 179 + YangPluginConfig pluginConfig = new YangPluginConfig();
180 + String method = getConstructorStart(CLASS_NAME, pluginConfig);
176 assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME 181 assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
177 + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE 182 + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
178 + OPEN_CURLY_BRACKET + NEW_LINE))); 183 + OPEN_CURLY_BRACKET + NEW_LINE)));
...@@ -227,10 +232,10 @@ public final class MethodsGeneratorTest { ...@@ -227,10 +232,10 @@ public final class MethodsGeneratorTest {
227 public void getSetterForClassTest() { 232 public void getSetterForClassTest() {
228 JavaAttributeInfo testAttr = getTestAttribute(); 233 JavaAttributeInfo testAttr = getTestAttribute();
229 String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER); 234 String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
230 -// assertThat(true, is( 235 + assertThat(true, is(
231 -// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX 236 + method.contains(PUBLIC + SPACE + VOID + SPACE +
232 -// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE 237 + SET_METHOD_PREFIX + getCapitalCase(CLASS_NAME) + OPEN_PARENTHESIS +
233 -// + ATTRIBUTE_NAME))); 238 + STRING_DATA_TYPE + SPACE + ATTRIBUTE_NAME)));
234 } 239 }
235 240
236 /** 241 /**
...@@ -240,7 +245,8 @@ public final class MethodsGeneratorTest { ...@@ -240,7 +245,8 @@ public final class MethodsGeneratorTest {
240 public void getSetterForInterfaceTest() { 245 public void getSetterForInterfaceTest() {
241 String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false, 246 String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
242 GENERATE_SERVICE_AND_MANAGER); 247 GENERATE_SERVICE_AND_MANAGER);
243 -// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname"))); 248 + assertThat(true, is(method.contains(VOID + SPACE +
249 + SET_METHOD_PREFIX + "Testname")));
244 } 250 }
245 251
246 /** 252 /**
......
...@@ -46,7 +46,7 @@ public final class NotificationTranslatorTest { ...@@ -46,7 +46,7 @@ public final class NotificationTranslatorTest {
46 YangPluginConfig yangPluginConfig = new YangPluginConfig(); 46 YangPluginConfig yangPluginConfig = new YangPluginConfig();
47 yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/"); 47 yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
48 48
49 - generateJavaCode(node, yangPluginConfig, "NotificationTest"); 49 + generateJavaCode(node, yangPluginConfig);
50 50
51 deleteDirectory(userDir + "/target/NotificationTest/"); 51 deleteDirectory(userDir + "/target/NotificationTest/");
52 } 52 }
......
...@@ -46,7 +46,7 @@ public final class RpcTranslatorTest { ...@@ -46,7 +46,7 @@ public final class RpcTranslatorTest {
46 YangPluginConfig yangPluginConfig = new YangPluginConfig(); 46 YangPluginConfig yangPluginConfig = new YangPluginConfig();
47 yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/"); 47 yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
48 48
49 - generateJavaCode(node, yangPluginConfig, "RpcTranslator"); 49 + generateJavaCode(node, yangPluginConfig);
50 50
51 deleteDirectory(userDir + "/target/RpcTestGenFile/"); 51 deleteDirectory(userDir + "/target/RpcTestGenFile/");
52 } 52 }
......
...@@ -46,7 +46,7 @@ public final class UnionTranslatorTest { ...@@ -46,7 +46,7 @@ public final class UnionTranslatorTest {
46 YangPluginConfig yangPluginConfig = new YangPluginConfig(); 46 YangPluginConfig yangPluginConfig = new YangPluginConfig();
47 yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); 47 yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
48 48
49 - generateJavaCode(node, yangPluginConfig, "UnionTranslator"); 49 + generateJavaCode(node, yangPluginConfig);
50 50
51 deleteDirectory(userDir + "/target/UnionTestGenFile/"); 51 deleteDirectory(userDir + "/target/UnionTestGenFile/");
52 } 52 }
......
...@@ -25,6 +25,7 @@ import org.junit.Test; ...@@ -25,6 +25,7 @@ import org.junit.Test;
25 import org.onosproject.yangutils.datamodel.YangNode; 25 import org.onosproject.yangutils.datamodel.YangNode;
26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; 27 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
28 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 29
29 import static org.hamcrest.core.Is.is; 30 import static org.hamcrest.core.Is.is;
30 import static org.hamcrest.core.IsNot.not; 31 import static org.hamcrest.core.IsNot.not;
...@@ -125,7 +126,20 @@ public final class FileSystemUtilTest { ...@@ -125,7 +126,20 @@ public final class FileSystemUtilTest {
125 javafileInfo.setJavaName(TEST_DATA_1); 126 javafileInfo.setJavaName(TEST_DATA_1);
126 javafileInfo.setBaseCodeGenPath(""); 127 javafileInfo.setBaseCodeGenPath("");
127 javafileInfo.setPackageFilePath(BASE_PKG); 128 javafileInfo.setPackageFilePath(BASE_PKG);
129 + javafileInfo.setPluginConfig(getStubPluginConfig());
128 module.setJavaFileInfo(javafileInfo); 130 module.setJavaFileInfo(javafileInfo);
129 return module; 131 return module;
130 } 132 }
133 +
134 + /**
135 + * Returns stub pluginConfig.
136 + *
137 + * @return stub pluginConfig
138 + */
139 + private YangPluginConfig getStubPluginConfig() {
140 + YangPluginConfig pluginConfig = new YangPluginConfig();
141 + pluginConfig.setConflictResolver(null);
142 + return pluginConfig;
143 + }
144 +
131 } 145 }
......
...@@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException; ...@@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
22 import org.junit.Rule; 22 import org.junit.Rule;
23 import org.junit.Test; 23 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 24 import org.junit.rules.ExpectedException;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.hamcrest.core.Is.is; 27 import static org.hamcrest.core.Is.is;
27 import static org.hamcrest.core.IsNot.not; 28 import static org.hamcrest.core.IsNot.not;
...@@ -55,7 +56,7 @@ public final class JavaDocGenTest { ...@@ -55,7 +56,7 @@ public final class JavaDocGenTest {
55 */ 56 */
56 @Test 57 @Test
57 public void builderClassGenerationTest() { 58 public void builderClassGenerationTest() {
58 - String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false); 59 + String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig());
59 assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of") 60 assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
60 && builderClassJavaDoc.contains(END_STRING))); 61 && builderClassJavaDoc.contains(END_STRING)));
61 } 62 }
...@@ -65,9 +66,10 @@ public final class JavaDocGenTest { ...@@ -65,9 +66,10 @@ public final class JavaDocGenTest {
65 */ 66 */
66 @Test 67 @Test
67 public void builderInterfaceGenerationTest() { 68 public void builderInterfaceGenerationTest() {
68 - String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false); 69 + String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig());
69 assertThat(true, 70 assertThat(true,
70 - is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING))); 71 + is(builderInterfaceJavaDoc.contains("Builder for")
72 + && builderInterfaceJavaDoc.contains(END_STRING)));
71 } 73 }
72 74
73 /** 75 /**
...@@ -75,7 +77,7 @@ public final class JavaDocGenTest { ...@@ -75,7 +77,7 @@ public final class JavaDocGenTest {
75 */ 77 */
76 @Test 78 @Test
77 public void buildGenerationTest() { 79 public void buildGenerationTest() {
78 - String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false); 80 + String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig());
79 assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING))); 81 assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
80 } 82 }
81 83
...@@ -90,7 +92,8 @@ public final class JavaDocGenTest { ...@@ -90,7 +92,8 @@ public final class JavaDocGenTest {
90 * @throws InvocationTargetException when an exception occurs by the method or constructor 92 * @throws InvocationTargetException when an exception occurs by the method or constructor
91 */ 93 */
92 @Test 94 @Test
93 - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 95 + public void callPrivateConstructors()
96 + throws SecurityException, NoSuchMethodException, IllegalArgumentException,
94 InstantiationException, IllegalAccessException, InvocationTargetException { 97 InstantiationException, IllegalAccessException, InvocationTargetException {
95 98
96 Class<?>[] classesToConstruct = {JavaDocGen.class }; 99 Class<?>[] classesToConstruct = {JavaDocGen.class };
...@@ -106,9 +109,10 @@ public final class JavaDocGenTest { ...@@ -106,9 +109,10 @@ public final class JavaDocGenTest {
106 */ 109 */
107 @Test 110 @Test
108 public void constructorGenerationTest() { 111 public void constructorGenerationTest() {
109 - String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false); 112 + String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
110 assertThat(true, 113 assertThat(true,
111 - is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of") 114 + is(constructorDoc.contains("Creates an instance of ")
115 + && constructorDoc.contains("builder object of")
112 && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"))); 116 && constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
113 } 117 }
114 118
...@@ -117,7 +121,7 @@ public final class JavaDocGenTest { ...@@ -117,7 +121,7 @@ public final class JavaDocGenTest {
117 */ 121 */
118 @Test 122 @Test
119 public void defaultConstructorGenerationTest() { 123 public void defaultConstructorGenerationTest() {
120 - String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false); 124 + String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
121 assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ") 125 assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
122 && defaultConstructorDoc.contains(END_STRING))); 126 && defaultConstructorDoc.contains(END_STRING)));
123 } 127 }
...@@ -127,8 +131,9 @@ public final class JavaDocGenTest { ...@@ -127,8 +131,9 @@ public final class JavaDocGenTest {
127 */ 131 */
128 @Test 132 @Test
129 public void getterGenerationTest() { 133 public void getterGenerationTest() {
130 - String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false); 134 + String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
131 - assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING))); 135 + assertThat(true,
136 + is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
132 } 137 }
133 138
134 /** 139 /**
...@@ -136,7 +141,7 @@ public final class JavaDocGenTest { ...@@ -136,7 +141,7 @@ public final class JavaDocGenTest {
136 */ 141 */
137 @Test 142 @Test
138 public void implClassGenerationTest() { 143 public void implClassGenerationTest() {
139 - String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false); 144 + String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig());
140 assertThat(true, 145 assertThat(true,
141 is(implClassJavaDoc.contains("Represents the implementation of") 146 is(implClassJavaDoc.contains("Represents the implementation of")
142 && implClassJavaDoc.contains(END_STRING))); 147 && implClassJavaDoc.contains(END_STRING)));
...@@ -147,7 +152,7 @@ public final class JavaDocGenTest { ...@@ -147,7 +152,7 @@ public final class JavaDocGenTest {
147 */ 152 */
148 @Test 153 @Test
149 public void interfaceGenerationTest() { 154 public void interfaceGenerationTest() {
150 - String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false); 155 + String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig());
151 assertThat(true, 156 assertThat(true,
152 is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of") 157 is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
153 && interfaceJavaDoc.contains(END_STRING))); 158 && interfaceJavaDoc.contains(END_STRING)));
...@@ -158,8 +163,9 @@ public final class JavaDocGenTest { ...@@ -158,8 +163,9 @@ public final class JavaDocGenTest {
158 */ 163 */
159 @Test 164 @Test
160 public void packageInfoGenerationTest() { 165 public void packageInfoGenerationTest() {
161 - String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); 166 + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig());
162 - assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING))); 167 + assertThat(true,
168 + is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
163 } 169 }
164 170
165 /** 171 /**
...@@ -167,7 +173,7 @@ public final class JavaDocGenTest { ...@@ -167,7 +173,7 @@ public final class JavaDocGenTest {
167 */ 173 */
168 @Test 174 @Test
169 public void packageInfoGenerationForChildNodeTest() { 175 public void packageInfoGenerationForChildNodeTest() {
170 - String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true); 176 + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig());
171 assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes") 177 assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
172 && packageInfo.contains(END_STRING))); 178 && packageInfo.contains(END_STRING)));
173 } 179 }
...@@ -177,7 +183,7 @@ public final class JavaDocGenTest { ...@@ -177,7 +183,7 @@ public final class JavaDocGenTest {
177 */ 183 */
178 @Test 184 @Test
179 public void setterGenerationTest() { 185 public void setterGenerationTest() {
180 - String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false); 186 + String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
181 assertThat(true, 187 assertThat(true,
182 is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING))); 188 is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
183 } 189 }
...@@ -187,7 +193,18 @@ public final class JavaDocGenTest { ...@@ -187,7 +193,18 @@ public final class JavaDocGenTest {
187 */ 193 */
188 @Test 194 @Test
189 public void typeDefSetterGenerationTest() { 195 public void typeDefSetterGenerationTest() {
190 - String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false); 196 + String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
191 assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING))); 197 assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
192 } 198 }
199 +
200 + /**
201 + * Returns stub pluginConfig.
202 + *
203 + * @return stub pluginConfig
204 + */
205 + private YangPluginConfig getStubPluginConfig() {
206 + YangPluginConfig pluginConfig = new YangPluginConfig();
207 + pluginConfig.setConflictResolver(null);
208 + return pluginConfig;
209 + }
193 } 210 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -25,6 +25,7 @@ import org.apache.maven.project.MavenProject; ...@@ -25,6 +25,7 @@ import org.apache.maven.project.MavenProject;
25 import org.junit.Rule; 25 import org.junit.Rule;
26 import org.junit.Test; 26 import org.junit.Test;
27 import org.junit.rules.ExpectedException; 27 import org.junit.rules.ExpectedException;
28 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 import org.onosproject.yangutils.utils.UtilConstants; 29 import org.onosproject.yangutils.utils.UtilConstants;
29 import org.sonatype.plexus.build.incremental.BuildContext; 30 import org.sonatype.plexus.build.incremental.BuildContext;
30 import org.sonatype.plexus.build.incremental.DefaultBuildContext; 31 import org.sonatype.plexus.build.incremental.DefaultBuildContext;
...@@ -68,7 +69,7 @@ public final class YangIoUtilsTest { ...@@ -68,7 +69,7 @@ public final class YangIoUtilsTest {
68 69
69 File dirPath = new File(CREATE_PATH); 70 File dirPath = new File(CREATE_PATH);
70 dirPath.mkdirs(); 71 dirPath.mkdirs();
71 - addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); 72 + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
72 File filePath = new File(dirPath + File.separator + PKG_INFO); 73 File filePath = new File(dirPath + File.separator + PKG_INFO);
73 assertThat(filePath.isFile(), is(true)); 74 assertThat(filePath.isFile(), is(true));
74 } 75 }
...@@ -83,7 +84,7 @@ public final class YangIoUtilsTest { ...@@ -83,7 +84,7 @@ public final class YangIoUtilsTest {
83 84
84 File dirPath = new File(CREATE_PATH); 85 File dirPath = new File(CREATE_PATH);
85 dirPath.mkdirs(); 86 dirPath.mkdirs();
86 - addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false); 87 + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
87 File filePath = new File(dirPath + File.separator + PKG_INFO); 88 File filePath = new File(dirPath + File.separator + PKG_INFO);
88 assertThat(filePath.isFile(), is(true)); 89 assertThat(filePath.isFile(), is(true));
89 } 90 }
...@@ -98,7 +99,7 @@ public final class YangIoUtilsTest { ...@@ -98,7 +99,7 @@ public final class YangIoUtilsTest {
98 99
99 File dirPath = new File(CREATE_PATH); 100 File dirPath = new File(CREATE_PATH);
100 dirPath.mkdirs(); 101 dirPath.mkdirs();
101 - addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true); 102 + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
102 File filePath = new File(dirPath + File.separator + PKG_INFO); 103 File filePath = new File(dirPath + File.separator + PKG_INFO);
103 assertThat(filePath.isFile(), is(true)); 104 assertThat(filePath.isFile(), is(true));
104 } 105 }
...@@ -114,7 +115,7 @@ public final class YangIoUtilsTest { ...@@ -114,7 +115,7 @@ public final class YangIoUtilsTest {
114 File dirPath = new File("invalid/check"); 115 File dirPath = new File("invalid/check");
115 thrown.expect(IOException.class); 116 thrown.expect(IOException.class);
116 thrown.expectMessage(MSG); 117 thrown.expectMessage(MSG);
117 - addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); 118 + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
118 File filePath1 = new File(dirPath + File.separator + PKG_INFO); 119 File filePath1 = new File(dirPath + File.separator + PKG_INFO);
119 assertThat(filePath1.isFile(), is(false)); 120 assertThat(filePath1.isFile(), is(false));
120 } 121 }
...@@ -130,7 +131,8 @@ public final class YangIoUtilsTest { ...@@ -130,7 +131,8 @@ public final class YangIoUtilsTest {
130 * @throws InvocationTargetException when an exception occurs by the method or constructor 131 * @throws InvocationTargetException when an exception occurs by the method or constructor
131 */ 132 */
132 @Test 133 @Test
133 - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 134 + public void callPrivateConstructors()
135 + throws SecurityException, NoSuchMethodException, IllegalArgumentException,
134 InstantiationException, IllegalAccessException, InvocationTargetException { 136 InstantiationException, IllegalAccessException, InvocationTargetException {
135 137
136 Class<?>[] classesToConstruct = {YangIoUtils.class }; 138 Class<?>[] classesToConstruct = {YangIoUtils.class };
...@@ -192,7 +194,7 @@ public final class YangIoUtilsTest { ...@@ -192,7 +194,7 @@ public final class YangIoUtilsTest {
192 addToSource(sourceDir.toString(), project, context); 194 addToSource(sourceDir.toString(), project, context);
193 } 195 }
194 196
195 - /* 197 + /**
196 * Unit test case for trim at last method. 198 * Unit test case for trim at last method.
197 */ 199 */
198 @Test 200 @Test
...@@ -202,4 +204,14 @@ public final class YangIoUtilsTest { ...@@ -202,4 +204,14 @@ public final class YangIoUtilsTest {
202 assertThat(test.contains(TRIM_STRING), is(true)); 204 assertThat(test.contains(TRIM_STRING), is(true));
203 } 205 }
204 206
207 + /**
208 + * Returns stub pluginConfig.
209 + *
210 + * @return stub pluginConfig
211 + */
212 + private YangPluginConfig getStubPluginConfig() {
213 + YangPluginConfig pluginConfig = new YangPluginConfig();
214 + pluginConfig.setConflictResolver(null);
215 + return pluginConfig;
216 + }
205 } 217 }
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef type15 {
6 + type bits {
7 + bit disable-nagle {
8 + position 0;
9 + }
10 + bit auto-sense-speed {
11 + position 1;
12 + }
13 + bit Mb-only {
14 + position 2;
15 + }
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf type15 {
6 + type union {
7 + type bits {
8 + bit disable-nagle {
9 + position 0;
10 + }
11 + bit auto-sense-speed {
12 + position 1;
13 + }
14 + bit Mb-only {
15 + position 2;
16 + }
17 + }
18 + }
19 + }
20 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf ifType {
6 + type enumeration {
7 + enum four{
8 + value 7;
9 + }
10 + enum seven {
11 + value 2147483647;
12 + }
13 + enum five {
14 + value 5;
15 + }
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + grouping currentcheck {
6 + leaf invalid-interval {
7 + type identityref {
8 + }
9 + }
10 + }
11 +}
1 +module xMlTest {
2 +yang-version 1;
3 +namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
4 +prefix On;
5 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container currentcheck {
6 + leaf invalid-interval {
7 + type instance-identifier;
8 + }
9 + }
10 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type leafref;
7 + }
8 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type string {
7 + length " 0 .. 100 ";
8 + }
9 + }
10 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + max-elements 77777777777777777777777;
8 + }
9 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + min-elements 77777777777777777777777;
8 + }
9 +}
...@@ -2,14 +2,14 @@ module Test { ...@@ -2,14 +2,14 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - leaf mybits { 5 + leaf mybits {
6 - type bits { 6 + type bits {
7 - bit disable-nagle; 7 + bit disable-nagle;
8 - bit auto-sense-speed { 8 + bit auto-sense-speed {
9 - position 1; 9 + position 1;
10 - } 10 + }
11 - bit Ten-Mb-only; 11 + bit Ten-Mb-only;
12 - } 12 + }
13 - }
14 } 13 }
15 } 14 }
15 +
......
...@@ -2,17 +2,17 @@ module Test { ...@@ -2,17 +2,17 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - leaf mybits { 5 + leaf mybits {
6 - type bits { 6 + type bits {
7 - bit disable-nagle { 7 + bit disable-nagle {
8 - position 0; 8 + position 0;
9 - } 9 + }
10 - bit auto-sense-speed { 10 + bit auto-sense-speed {
11 - position 1; 11 + position 1;
12 - } 12 + }
13 - bit Ten-Mb-only { 13 + bit Ten-Mb-only {
14 - position 2; 14 + position 2;
15 - } 15 + }
16 - } 16 + }
17 } 17 }
18 } 18 }
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container food {
6 + choice snack {
7 + list sports-arena {
8 + }
9 + }
10 + }
11 + }
12 +}
13 +}
14 +}
15 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import ietf-yang-types {
6 + prefix "P";
7 + }
8 + grouping Percentage {
9 + leaf hello{
10 + type string;
11 + }
12 + leaf invalid1{
13 + type string;
14 + }
15 + }
16 + leaf invalid2{
17 + type string;
18 + }
19 + }
20 + container ospf {
21 + list valid {
22 + key "invalid";
23 + leaf invalid{
24 + type string;
25 + }
26 + uses Ant:FirstClass;
27 + grouping FirstClass {
28 + uses P:PassingClass;
29 + }
30 + }
31 + grouping PassingClass {
32 + uses Ant:Percentage;
33 + }
34 + }
35 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container food {
6 + choice snack {
7 + list sports-arena {
8 + }
9 + }
10 + }
11 +}
12 +leaf invalid {
13 +
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type int32 {
7 + range " 1 .. 4 | 10 .. 20 ";
8 + }
9 + }
10 +}
11 +
...@@ -2,12 +2,11 @@ module Test { ...@@ -2,12 +2,11 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - container food { 5 + container food {
6 - choice snack { 6 + choice snack {
7 - container sports-arena { 7 + container sports-arena {
8 - leaf pretzel { 8 + leaf pretzel {
9 - type empty; 9 + type empty;
10 - }
11 } 10 }
12 } 11 }
13 } 12 }
......
...@@ -2,15 +2,15 @@ module Test { ...@@ -2,15 +2,15 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - container food { 5 + container food {
6 - choice snack { 6 + choice snack {
7 - list sports-arena { 7 + list sports-arena {
8 - key "pretzel"; 8 + key "pretzel";
9 - leaf pretzel { 9 + leaf pretzel {
10 - type int32; 10 + type int32;
11 - }
12 } 11 }
13 } 12 }
14 } 13 }
15 } 14 }
16 } 15 }
16 +
......
...@@ -14,7 +14,7 @@ module rock { ...@@ -14,7 +14,7 @@ module rock {
14 type int32; 14 type int32;
15 } 15 }
16 leaf if-name { 16 leaf if-name {
17 - type leafref; 17 + type string;
18 } 18 }
19 leaf if-admin-status { 19 leaf if-admin-status {
20 type P:admin-status; 20 type P:admin-status;
......