Bharat saraswal

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

Change-Id: I1b23f9ed0293edbc2d551efe82982559eb916ede
Showing 109 changed files with 2164 additions and 742 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 + try {
109 maxElementsValue = Integer.parseInt(value); 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) {
82 setCurNode(codeGenNode); 80 setCurNode(codeGenNode);
83 - generateCodeEntry(codeGenNode, yangPlugin, fileName); 81 + generateCodeEntry(codeGenNode, yangPlugin);
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,6 +140,7 @@ public final class JavaCodeGeneratorUtil { ...@@ -162,6 +140,7 @@ public final class JavaCodeGeneratorUtil {
162 private static void freeRestResources() { 140 private static void freeRestResources() {
163 141
164 YangNode freedNode = getCurNode(); 142 YangNode freedNode = getCurNode();
143 + if (getCurNode() != null) {
165 YangNode tempNode = freedNode; 144 YangNode tempNode = freedNode;
166 TraversalType curTraversal = ROOT; 145 TraversalType curTraversal = ROOT;
167 146
...@@ -185,6 +164,7 @@ public final class JavaCodeGeneratorUtil { ...@@ -185,6 +164,7 @@ public final class JavaCodeGeneratorUtil {
185 } 164 }
186 } 165 }
187 } 166 }
167 + }
188 168
189 /** 169 /**
190 * Free the current node. 170 * Free the current node.
...@@ -213,6 +193,7 @@ public final class JavaCodeGeneratorUtil { ...@@ -213,6 +193,7 @@ 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
196 + if (rootNode != null) {
216 /** 197 /**
217 * Free other resources where translator has failed. 198 * Free other resources where translator has failed.
218 */ 199 */
...@@ -244,6 +225,7 @@ public final class JavaCodeGeneratorUtil { ...@@ -244,6 +225,7 @@ public final class JavaCodeGeneratorUtil {
244 225
245 freeRestResources(); 226 freeRestResources();
246 } 227 }
228 + }
247 229
248 /** 230 /**
249 * Closes all the current open file handles of node and delete all generated 231 * Closes all the current open file handles of node and delete all generated
...@@ -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 -}
...@@ -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);
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;
31 } 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 {
128 + if (isCodeGenFlag()) {
126 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 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 {
129 + if (isCodeGenFlag()) {
127 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 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 }
......
...@@ -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;
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;
31 } 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 }
......
...@@ -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
......
...@@ -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);
231 } 250 }
232 - return getPkgFrmArr(pkgArr); 251 + } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
252 + throw new TranslatorException("The given prefix in pom.xml is invalid.");
253 + }
254 + } else {
255 + prefixForIdentifier = YANG_AUTO_PREFIX;
256 + }
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 }
......
...@@ -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) {
298 + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
286 299
287 - String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC 300 + String javadoc =
288 - + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK 301 + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
289 - + getInputString(inputName, rpcName); 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.
...@@ -87,15 +96,15 @@ public final class YangIoUtils { ...@@ -87,15 +96,15 @@ public final class YangIoUtils {
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
...@@ -249,7 +287,7 @@ public final class YangIoUtils { ...@@ -249,7 +287,7 @@ 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
...@@ -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 -}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.