Committed by
Patrick Liu
[ONOS-4947][ONOS-4954][ONOS-4952]Defect Fixed: Invalid name in case of qualified…
… info for child nodes Change-Id: I0b94455333afd9322c1e583a5c3ec311dbe99991
Showing
11 changed files
with
333 additions
and
13 deletions
... | @@ -302,8 +302,11 @@ public class YangType<T> | ... | @@ -302,8 +302,11 @@ public class YangType<T> |
302 | break; | 302 | break; |
303 | } | 303 | } |
304 | case STRING: { | 304 | case STRING: { |
305 | - if (!(((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnLengthRestriction(value) && | 305 | + if (getDataTypeExtendedInfo() == null) { |
306 | - ((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnPatternRestriction(value))) { | 306 | + break; |
307 | + } else if (!(((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnLengthRestriction(value) | ||
308 | + && ((YangStringRestriction) getDataTypeExtendedInfo()) | ||
309 | + .isValidStringOnPatternRestriction(value))) { | ||
307 | throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + | 310 | throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + |
308 | "string"); | 311 | "string"); |
309 | } | 312 | } |
... | @@ -319,7 +322,7 @@ public class YangType<T> | ... | @@ -319,7 +322,7 @@ public class YangType<T> |
319 | Iterator<YangEnum> iterator = ((YangEnumeration) getDataTypeExtendedInfo()).getEnumSet().iterator(); | 322 | Iterator<YangEnum> iterator = ((YangEnumeration) getDataTypeExtendedInfo()).getEnumSet().iterator(); |
320 | boolean isValidated = false; | 323 | boolean isValidated = false; |
321 | while (iterator.hasNext()) { | 324 | while (iterator.hasNext()) { |
322 | - YangEnum enumTemp = (YangEnum) iterator.next(); | 325 | + YangEnum enumTemp = iterator.next(); |
323 | if (enumTemp.getNamedValue().equals(value)) { | 326 | if (enumTemp.getNamedValue().equals(value)) { |
324 | isValidated = true; | 327 | isValidated = true; |
325 | break; | 328 | break; | ... | ... |
... | @@ -19,12 +19,14 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -19,12 +19,14 @@ package org.onosproject.yangutils.translator.tojava; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.TraversalType; | 21 | import org.onosproject.yangutils.datamodel.TraversalType; |
22 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
22 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
23 | -import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo; | 24 | +import org.onosproject.yangutils.datamodel.YangNodeType; |
25 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
24 | import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException; | 26 | import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException; |
25 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 27 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
26 | import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; | 28 | import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; |
27 | - | 29 | +import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo; |
28 | import static org.onosproject.yangutils.datamodel.TraversalType.CHILD; | 30 | import static org.onosproject.yangutils.datamodel.TraversalType.CHILD; |
29 | import static org.onosproject.yangutils.datamodel.TraversalType.PARENT; | 31 | import static org.onosproject.yangutils.datamodel.TraversalType.PARENT; |
30 | import static org.onosproject.yangutils.datamodel.TraversalType.ROOT; | 32 | import static org.onosproject.yangutils.datamodel.TraversalType.ROOT; |
... | @@ -305,4 +307,43 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -305,4 +307,43 @@ public final class JavaCodeGeneratorUtil { |
305 | private static void setRootNode(YangNode rootNode) { | 307 | private static void setRootNode(YangNode rootNode) { |
306 | JavaCodeGeneratorUtil.rootNode = rootNode; | 308 | JavaCodeGeneratorUtil.rootNode = rootNode; |
307 | } | 309 | } |
310 | + | ||
311 | + /** | ||
312 | + * Searches child node in data model tree. | ||
313 | + * | ||
314 | + * @param parentNode parent node | ||
315 | + * @param nodeType node type | ||
316 | + * @param nodeName node name | ||
317 | + * @return child node | ||
318 | + */ | ||
319 | + public static YangNode searchYangNode(YangNode parentNode, YangNodeType nodeType, String nodeName) { | ||
320 | + YangNode child = parentNode.getChild(); | ||
321 | + TraversalType curTraversal = ROOT; | ||
322 | + if (child == null) { | ||
323 | + throw new IllegalArgumentException("given parent node does not contain any child nodes"); | ||
324 | + } | ||
325 | + | ||
326 | + while (child != null) { | ||
327 | + if (curTraversal != PARENT) { | ||
328 | + if (child instanceof YangInput || child instanceof YangOutput) { | ||
329 | + if (child.getNodeType().equals(nodeType)) { | ||
330 | + return child; | ||
331 | + } | ||
332 | + } else if (child.getName().equals(nodeName) && child.getNodeType().equals(nodeType)) { | ||
333 | + return child; | ||
334 | + } | ||
335 | + } | ||
336 | + if (curTraversal != PARENT && child.getChild() != null) { | ||
337 | + curTraversal = CHILD; | ||
338 | + child = child.getChild(); | ||
339 | + } else if (child.getNextSibling() != null) { | ||
340 | + curTraversal = SIBILING; | ||
341 | + child = child.getNextSibling(); | ||
342 | + } else { | ||
343 | + curTraversal = PARENT; | ||
344 | + child = child.getParent(); | ||
345 | + } | ||
346 | + } | ||
347 | + return null; | ||
348 | + } | ||
308 | } | 349 | } | ... | ... |
... | @@ -100,7 +100,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -100,7 +100,7 @@ public class TempJavaEventFragmentFiles |
100 | /** | 100 | /** |
101 | * File name for generated class file for special type like union, typedef suffix. | 101 | * File name for generated class file for special type like union, typedef suffix. |
102 | */ | 102 | */ |
103 | - private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener"; | 103 | + private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "EventListener"; |
104 | 104 | ||
105 | private static final String JAVA_FILE_EXTENSION = ".java"; | 105 | private static final String JAVA_FILE_EXTENSION = ".java"; |
106 | 106 | ... | ... |
... | @@ -33,8 +33,6 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; | ... | @@ -33,8 +33,6 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; |
33 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 33 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
34 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; | 34 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator; | 35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator; |
36 | -import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator; | ||
37 | -import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator; | ||
38 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | 36 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
39 | 37 | ||
40 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; | 38 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; |
... | @@ -494,7 +492,7 @@ public class TempJavaFragmentFiles { | ... | @@ -494,7 +492,7 @@ public class TempJavaFragmentFiles { |
494 | JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo(); | 492 | JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo(); |
495 | 493 | ||
496 | boolean isQualified; | 494 | boolean isQualified; |
497 | - if ((targetNode instanceof YangJavaModuleTranslator || targetNode instanceof YangJavaSubModuleTranslator) | 495 | + if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) |
498 | && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE) | 496 | && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE) |
499 | || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT) | 497 | || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT) |
500 | || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE)) | 498 | || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE)) |
... | @@ -507,7 +505,7 @@ public class TempJavaFragmentFiles { | ... | @@ -507,7 +505,7 @@ public class TempJavaFragmentFiles { |
507 | isQualified = true; | 505 | isQualified = true; |
508 | } else { | 506 | } else { |
509 | String className; | 507 | String className; |
510 | - if (targetNode instanceof YangJavaModuleTranslator || targetNode instanceof YangJavaSubModuleTranslator) { | 508 | + if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
511 | className = getCapitalCase(fileInfo.getJavaName()) + "Service"; | 509 | className = getCapitalCase(fileInfo.getJavaName()) + "Service"; |
512 | } else { | 510 | } else { |
513 | className = getCapitalCase(fileInfo.getJavaName()); | 511 | className = getCapitalCase(fileInfo.getJavaName()); | ... | ... |
... | @@ -386,7 +386,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -386,7 +386,7 @@ public final class ClassDefinitionGenerator { |
386 | throw new RuntimeException("Event listener interface name is error"); | 386 | throw new RuntimeException("Event listener interface name is error"); |
387 | } | 387 | } |
388 | intfDef = intfDef.substring(0, intfDef.length() - 8); | 388 | intfDef = intfDef.substring(0, intfDef.length() - 8); |
389 | - intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 389 | + intfDef = intfDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
390 | 390 | ||
391 | return intfDef; | 391 | return intfDef; |
392 | } | 392 | } | ... | ... |
... | @@ -1191,7 +1191,7 @@ public final class UtilConstants { | ... | @@ -1191,7 +1191,7 @@ public final class UtilConstants { |
1191 | /** | 1191 | /** |
1192 | * For event listener file generation. | 1192 | * For event listener file generation. |
1193 | */ | 1193 | */ |
1194 | - public static final String EVENT_LISTENER_STRING = "Listener"; | 1194 | + public static final String EVENT_LISTENER_STRING = "EventListener"; |
1195 | 1195 | ||
1196 | /** | 1196 | /** |
1197 | * For event subject file generation. | 1197 | * For event subject file generation. | ... | ... |
... | @@ -41,7 +41,7 @@ public class TypeDefTranslatorTest { | ... | @@ -41,7 +41,7 @@ public class TypeDefTranslatorTest { |
41 | @Test | 41 | @Test |
42 | public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException { | 42 | public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException { |
43 | 43 | ||
44 | - String searchDir = "src/test/resources/typedefTranslator"; | 44 | + String searchDir = "src/test/resources/typedefTranslator/without"; |
45 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | 45 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
46 | utilManager.parseYangFileInfoSet(); | 46 | utilManager.parseYangFileInfoSet(); |
47 | utilManager.createYangNodeSet(); | 47 | utilManager.createYangNodeSet(); |
... | @@ -55,4 +55,27 @@ public class TypeDefTranslatorTest { | ... | @@ -55,4 +55,27 @@ public class TypeDefTranslatorTest { |
55 | deleteDirectory("target/typedefTranslator/"); | 55 | deleteDirectory("target/typedefTranslator/"); |
56 | } | 56 | } |
57 | 57 | ||
58 | + /** | ||
59 | + * Checks typedef translation should not result in any exception. | ||
60 | + * | ||
61 | + * @throws MojoExecutionException | ||
62 | + */ | ||
63 | + @Test | ||
64 | + public void processTypeDefWithRestrictionsTranslator() throws IOException, ParserException, MojoExecutionException { | ||
65 | + | ||
66 | + /*FIXME: After typedef with leafref is fixed. | ||
67 | + String searchDir = "src/test/resources/typedefTranslator/with"; | ||
68 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
69 | + utilManager.parseYangFileInfoSet(); | ||
70 | + utilManager.createYangNodeSet(); | ||
71 | + utilManager.resolveDependenciesUsingLinker(); | ||
72 | + | ||
73 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
74 | + yangPluginConfig.setCodeGenDir("target/typedefTranslator/"); | ||
75 | + yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/"); | ||
76 | + utilManager.translateToJava(yangPluginConfig); | ||
77 | + | ||
78 | + deleteDirectory("target/typedefTranslator/"); | ||
79 | + */ | ||
80 | + } | ||
58 | } | 81 | } | ... | ... |
1 | +module typedef { | ||
2 | + | ||
3 | + yang-version "1"; | ||
4 | + namespace "http://rob.sh/yang/test/list"; | ||
5 | + prefix "foo"; | ||
6 | + | ||
7 | + import remote { prefix defn; } | ||
8 | + | ||
9 | + organization "BugReports Inc"; | ||
10 | + contact "A bug reporter"; | ||
11 | + | ||
12 | + description | ||
13 | + "A test module"; | ||
14 | + revision 2014-01-01 { | ||
15 | + description "april-fools"; | ||
16 | + reference "fooled-you"; | ||
17 | + } | ||
18 | + | ||
19 | + typedef derived-string-type { | ||
20 | + type string; | ||
21 | + } | ||
22 | + | ||
23 | + typedef restricted-integer-type { | ||
24 | + type uint16 { | ||
25 | + range 0..64; | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + typedef bgp-session-direction { | ||
30 | + type enumeration { | ||
31 | + enum INBOUND; | ||
32 | + enum OUTBOUND; | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + typedef new-string-type { | ||
37 | + type string; | ||
38 | + default "defaultValue"; | ||
39 | + } | ||
40 | + | ||
41 | + typedef restricted-inherit { | ||
42 | + type string { | ||
43 | + pattern "^a.*"; | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + typedef restricted-int-inherit { | ||
48 | + type int8 { | ||
49 | + range 0..100; | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + typedef parent-union { | ||
54 | + type union { | ||
55 | + type string { | ||
56 | + pattern "a.*"; | ||
57 | + } | ||
58 | + type string { | ||
59 | + pattern "b.*"; | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + typedef child-union { | ||
65 | + type union { | ||
66 | + type parent-union; | ||
67 | + type string { | ||
68 | + pattern "z.*"; | ||
69 | + } | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + typedef union-included { | ||
74 | + type union { | ||
75 | + type string { | ||
76 | + pattern "a.*"; | ||
77 | + } | ||
78 | + type string { | ||
79 | + pattern "b.*"; | ||
80 | + } | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + identity identity_base; | ||
85 | + identity IDONE { | ||
86 | + base "identity_base"; | ||
87 | + } | ||
88 | + | ||
89 | + identity IDTWO { | ||
90 | + base "identity_base"; | ||
91 | + } | ||
92 | + | ||
93 | + typedef identity_one { | ||
94 | + type identityref { | ||
95 | + base identity_base; | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + typedef referenced-leaf { | ||
100 | + type leafref { | ||
101 | + path "/container/target"; | ||
102 | + require-instance false; | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + grouping scoped-typedef { | ||
107 | + typedef scoped-type { | ||
108 | + type string { | ||
109 | + pattern "a.*"; | ||
110 | + } | ||
111 | + } | ||
112 | + | ||
113 | + leaf scoped-leaf { | ||
114 | + type scoped-type; | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + container container { | ||
119 | + description | ||
120 | + "A container"; | ||
121 | + | ||
122 | + leaf-list target { | ||
123 | + type string; | ||
124 | + description | ||
125 | + "A target leaf for leafref checks"; | ||
126 | + } | ||
127 | + | ||
128 | + leaf string { | ||
129 | + type derived-string-type; | ||
130 | + } | ||
131 | + | ||
132 | + leaf integer { | ||
133 | + type restricted-integer-type; | ||
134 | + } | ||
135 | + | ||
136 | + leaf stringdefault { | ||
137 | + type derived-string-type; | ||
138 | + default "aDefaultValue"; | ||
139 | + } | ||
140 | + | ||
141 | + leaf integerdefault { | ||
142 | + type restricted-integer-type; | ||
143 | + default 10; | ||
144 | + } | ||
145 | + | ||
146 | + leaf new-string { | ||
147 | + type new-string-type; | ||
148 | + } | ||
149 | + | ||
150 | + leaf remote-new-type { | ||
151 | + type defn:remote-definition; | ||
152 | + } | ||
153 | + | ||
154 | + leaf session-dir { | ||
155 | + type bgp-session-direction; | ||
156 | + } | ||
157 | + | ||
158 | + leaf remote-local-type { | ||
159 | + type defn:remote-local-definition; | ||
160 | + } | ||
161 | + | ||
162 | + leaf inheritance { | ||
163 | + type restricted-inherit { | ||
164 | + pattern ".*k"; | ||
165 | + } | ||
166 | + } | ||
167 | + | ||
168 | + leaf int-inheritance { | ||
169 | + type restricted-int-inherit { | ||
170 | + range 2..5; | ||
171 | + } | ||
172 | + } | ||
173 | + | ||
174 | + leaf-list stacked-union { | ||
175 | + type child-union; | ||
176 | + } | ||
177 | + | ||
178 | + leaf include-of-include-definition { | ||
179 | + type defn:hybrid-definition; | ||
180 | + } | ||
181 | + | ||
182 | + leaf identity-one-typedef { | ||
183 | + type identity_one; | ||
184 | + } | ||
185 | + | ||
186 | + leaf union-with-union { | ||
187 | + type union { | ||
188 | + type union-included; | ||
189 | + type string { | ||
190 | + pattern "q.*"; | ||
191 | + } | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
195 | + leaf reference { | ||
196 | + type referenced-leaf; | ||
197 | + } | ||
198 | + | ||
199 | + uses scoped-typedef; | ||
200 | + } | ||
201 | +} |
1 | +module remote { | ||
2 | + yang-version "1"; | ||
3 | + namespace "http://rob.sh/yang/test/typedef/remote"; | ||
4 | + prefix "remote"; | ||
5 | + | ||
6 | + import second-remote { prefix sr; } | ||
7 | + | ||
8 | + organization "BugReports Inc"; | ||
9 | + contact "A bug reporter"; | ||
10 | + | ||
11 | + description | ||
12 | + "A test module"; | ||
13 | + revision 2014-01-01 { | ||
14 | + description "april-fools"; | ||
15 | + reference "fooled-you"; | ||
16 | + } | ||
17 | + | ||
18 | + typedef remote-definition { | ||
19 | + type string; | ||
20 | + } | ||
21 | + | ||
22 | + typedef remote-local-definition { | ||
23 | + type local-definition; | ||
24 | + } | ||
25 | + | ||
26 | + typedef local-definition { | ||
27 | + type string; | ||
28 | + } | ||
29 | + | ||
30 | + typedef hybrid-definition { | ||
31 | + type sr:second-remote-definition; | ||
32 | + } | ||
33 | +} |
1 | +module second-remote { | ||
2 | + yang-version "1"; | ||
3 | + namespace "http://rob.sh/yang/test/typedef/second-remote"; | ||
4 | + prefix "second-remote"; | ||
5 | + | ||
6 | + organization "BugReports Inc"; | ||
7 | + contact "A bug reporter"; | ||
8 | + | ||
9 | + description | ||
10 | + "A test module"; | ||
11 | + revision 2014-01-01 { | ||
12 | + description "april-fools"; | ||
13 | + reference "fooled-you"; | ||
14 | + } | ||
15 | + | ||
16 | + typedef second-remote-definition { | ||
17 | + type string { | ||
18 | + pattern "z.*"; | ||
19 | + } | ||
20 | + } | ||
21 | +} |
-
Please register or login to post a comment