Committed by
Gerrit Code Review
[ONOS-4527,ONOS-4524,ONOS-4536,ONOS-4541,ONOS-4549,ONOS-4550,ONOS-4557
,ONOS-4558,ONOS-4545,ONOS-4543,ONOS-4546] Checkstyle error in generated code handled and defect fixed. Change-Id: Ifef5a22f91d4ee21767f1e2c6d0dd5b5b0b8cfcc
Showing
53 changed files
with
2214 additions
and
800 deletions
... | @@ -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(); | ... | ... |
... | @@ -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. | ... | ... |
... | @@ -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 | ||
... | @@ -161,7 +162,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -161,7 +162,7 @@ public class YangUtilManager extends AbstractMojo { |
161 | return; | 162 | return; |
162 | } | 163 | } |
163 | 164 | ||
164 | - //Carry out the parsing for all the YANG files. | 165 | + // Carry out the parsing for all the YANG files. |
165 | parseYangFileInfoSet(); | 166 | parseYangFileInfoSet(); |
166 | 167 | ||
167 | // Resolve dependencies using linker. | 168 | // Resolve dependencies using linker. |
... | @@ -170,13 +171,13 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -170,13 +171,13 @@ public class YangUtilManager extends AbstractMojo { |
170 | // Perform translation to JAVA. | 171 | // Perform translation to JAVA. |
171 | translateToJava(getYangFileInfoSet(), yangPlugin); | 172 | translateToJava(getYangFileInfoSet(), yangPlugin); |
172 | 173 | ||
173 | - addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); | 174 | + addToSource(getDirectory(baseDir, genFilesDir), project, context); |
174 | 175 | ||
175 | copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); | 176 | copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); |
176 | } catch (Exception e) { | 177 | } catch (Exception e) { |
177 | String fileName = ""; | 178 | String fileName = ""; |
178 | - if (e instanceof TranslatorException) { | 179 | + if (getCurYangFileInfo() != null) { |
179 | - fileName = ((TranslatorException) e).getFileName(); | 180 | + fileName = getCurYangFileInfo().getYangFileName(); |
180 | } | 181 | } |
181 | try { | 182 | try { |
182 | translatorErrorHandler(getRootNode()); | 183 | translatorErrorHandler(getRootNode()); |
... | @@ -198,6 +199,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -198,6 +199,7 @@ public class YangUtilManager extends AbstractMojo { |
198 | */ | 199 | */ |
199 | public void resolveDependenciesUsingLinker() throws MojoExecutionException { | 200 | public void resolveDependenciesUsingLinker() throws MojoExecutionException { |
200 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { | 201 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { |
202 | + setCurYangFileInfo(yangFileInfo); | ||
201 | try { | 203 | try { |
202 | yangLinker.resolveDependencies(getYangFileInfoSet()); | 204 | yangLinker.resolveDependencies(getYangFileInfoSet()); |
203 | } catch (LinkerException e) { | 205 | } catch (LinkerException e) { |
... | @@ -213,6 +215,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -213,6 +215,7 @@ public class YangUtilManager extends AbstractMojo { |
213 | */ | 215 | */ |
214 | public void parseYangFileInfoSet() throws IOException { | 216 | public void parseYangFileInfoSet() throws IOException { |
215 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { | 217 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { |
218 | + setCurYangFileInfo(yangFileInfo); | ||
216 | try { | 219 | try { |
217 | YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName()); | 220 | YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName()); |
218 | yangFileInfo.setRootNode(yangNode); | 221 | yangFileInfo.setRootNode(yangNode); |
... | @@ -264,7 +267,8 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -264,7 +267,8 @@ public class YangUtilManager extends AbstractMojo { |
264 | Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator(); | 267 | Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator(); |
265 | while (yangFileIterator.hasNext()) { | 268 | while (yangFileIterator.hasNext()) { |
266 | YangFileInfo yangFileInfo = yangFileIterator.next(); | 269 | YangFileInfo yangFileInfo = yangFileIterator.next(); |
267 | - generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName()); | 270 | + setCurYangFileInfo(yangFileInfo); |
271 | + generateJavaCode(yangFileInfo.getRootNode(), yangPlugin); | ||
268 | } | 272 | } |
269 | } | 273 | } |
270 | 274 | ||
... | @@ -298,4 +302,22 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -298,4 +302,22 @@ public class YangUtilManager extends AbstractMojo { |
298 | public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) { | 302 | public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) { |
299 | this.yangFileInfoSet = yangFileInfoSet; | 303 | this.yangFileInfoSet = yangFileInfoSet; |
300 | } | 304 | } |
305 | + | ||
306 | + /** | ||
307 | + * Returns current YANG file's info. | ||
308 | + * | ||
309 | + * @return the yangFileInfo | ||
310 | + */ | ||
311 | + public YangFileInfo getCurYangFileInfo() { | ||
312 | + return curYangFileInfo; | ||
313 | + } | ||
314 | + | ||
315 | + /** | ||
316 | + * Sets current YANG file's info. | ||
317 | + * | ||
318 | + * @param yangFileInfo the yangFileInfo to set | ||
319 | + */ | ||
320 | + public void setCurYangFileInfo(YangFileInfo yangFileInfo) { | ||
321 | + this.curYangFileInfo = yangFileInfo; | ||
322 | + } | ||
301 | } | 323 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
... | @@ -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() { | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
... | @@ -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() { | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
... | @@ -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; |
... | @@ -80,7 +79,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -80,7 +79,7 @@ public final class JavaCodeGeneratorUtil { |
80 | if (curTraversal != PARENT) { | 79 | if (curTraversal != PARENT) { |
81 | if (codeGenNode instanceof JavaCodeGenerator) { | 80 | if (codeGenNode instanceof JavaCodeGenerator) { |
82 | setCurNode(codeGenNode); | 81 | setCurNode(codeGenNode); |
83 | - generateCodeEntry(codeGenNode, yangPlugin, fileName); | 82 | + generateCodeEntry(codeGenNode, yangPlugin); |
84 | } else { | 83 | } else { |
85 | /* | 84 | /* |
86 | * For grouping and uses, there is no code generation, skip the generation for the child. | 85 | * For grouping and uses, there is no code generation, skip the generation for the child. |
... | @@ -100,11 +99,11 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -100,11 +99,11 @@ public final class JavaCodeGeneratorUtil { |
100 | curTraversal = CHILD; | 99 | curTraversal = CHILD; |
101 | codeGenNode = codeGenNode.getChild(); | 100 | codeGenNode = codeGenNode.getChild(); |
102 | } else if (codeGenNode.getNextSibling() != null) { | 101 | } else if (codeGenNode.getNextSibling() != null) { |
103 | - generateCodeExit(codeGenNode, fileName); | 102 | + generateCodeExit(codeGenNode); |
104 | curTraversal = SIBILING; | 103 | curTraversal = SIBILING; |
105 | codeGenNode = codeGenNode.getNextSibling(); | 104 | codeGenNode = codeGenNode.getNextSibling(); |
106 | } else { | 105 | } else { |
107 | - generateCodeExit(codeGenNode, fileName); | 106 | + generateCodeExit(codeGenNode); |
108 | curTraversal = PARENT; | 107 | curTraversal = PARENT; |
109 | codeGenNode = codeGenNode.getParent(); | 108 | codeGenNode = codeGenNode.getParent(); |
110 | } | 109 | } |
... | @@ -117,20 +116,17 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -117,20 +116,17 @@ public final class JavaCodeGeneratorUtil { |
117 | * @param codeGenNode current data model node for which the code needs to be | 116 | * @param codeGenNode current data model node for which the code needs to be |
118 | * generated | 117 | * generated |
119 | * @param yangPlugin YANG plugin config | 118 | * @param yangPlugin YANG plugin config |
120 | - * @param fileName YANG file name | ||
121 | * @throws TranslatorException when fails to generate java code file the current | 119 | * @throws TranslatorException when fails to generate java code file the current |
122 | * node | 120 | * node |
123 | */ | 121 | */ |
124 | - private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName) | 122 | + private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin) |
125 | throws TranslatorException { | 123 | throws TranslatorException { |
126 | 124 | ||
127 | if (codeGenNode instanceof JavaCodeGenerator) { | 125 | if (codeGenNode instanceof JavaCodeGenerator) { |
128 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); | 126 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); |
129 | } else { | 127 | } else { |
130 | - TranslatorException ex = new TranslatorException( | 128 | + throw new TranslatorException( |
131 | "Generated data model node cannot be translated to target language code"); | 129 | "Generated data model node cannot be translated to target language code"); |
132 | - ex.setFileName(fileName); | ||
133 | - throw ex; | ||
134 | } | 130 | } |
135 | } | 131 | } |
136 | 132 | ||
... | @@ -139,19 +135,16 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -139,19 +135,16 @@ public final class JavaCodeGeneratorUtil { |
139 | * | 135 | * |
140 | * @param codeGenNode current data model node for which the code needs to be | 136 | * @param codeGenNode current data model node for which the code needs to be |
141 | * generated | 137 | * generated |
142 | - * @param fileName YANG file name | ||
143 | * @throws TranslatorException when fails to generate java code file the current | 138 | * @throws TranslatorException when fails to generate java code file the current |
144 | * node | 139 | * node |
145 | */ | 140 | */ |
146 | - private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException { | 141 | + private static void generateCodeExit(YangNode codeGenNode) throws TranslatorException { |
147 | 142 | ||
148 | if (codeGenNode instanceof JavaCodeGenerator) { | 143 | if (codeGenNode instanceof JavaCodeGenerator) { |
149 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); | 144 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); |
150 | } else { | 145 | } else { |
151 | - TranslatorException ex = new TranslatorException( | 146 | + throw new TranslatorException( |
152 | "Generated data model node cannot be translated to target language code"); | 147 | "Generated data model node cannot be translated to target language code"); |
153 | - ex.setFileName(fileName); | ||
154 | - throw ex; | ||
155 | } | 148 | } |
156 | } | 149 | } |
157 | 150 | ||
... | @@ -162,6 +155,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -162,6 +155,7 @@ public final class JavaCodeGeneratorUtil { |
162 | private static void freeRestResources() { | 155 | private static void freeRestResources() { |
163 | 156 | ||
164 | YangNode freedNode = getCurNode(); | 157 | YangNode freedNode = getCurNode(); |
158 | + if (getCurNode() != null) { | ||
165 | YangNode tempNode = freedNode; | 159 | YangNode tempNode = freedNode; |
166 | TraversalType curTraversal = ROOT; | 160 | TraversalType curTraversal = ROOT; |
167 | 161 | ||
... | @@ -185,6 +179,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -185,6 +179,7 @@ public final class JavaCodeGeneratorUtil { |
185 | } | 179 | } |
186 | } | 180 | } |
187 | } | 181 | } |
182 | + } | ||
188 | 183 | ||
189 | /** | 184 | /** |
190 | * Free the current node. | 185 | * Free the current node. |
... | @@ -213,6 +208,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -213,6 +208,7 @@ public final class JavaCodeGeneratorUtil { |
213 | public static void translatorErrorHandler(YangNode rootNode) | 208 | public static void translatorErrorHandler(YangNode rootNode) |
214 | throws IOException { | 209 | throws IOException { |
215 | 210 | ||
211 | + if (rootNode != null) { | ||
216 | /** | 212 | /** |
217 | * Free other resources where translator has failed. | 213 | * Free other resources where translator has failed. |
218 | */ | 214 | */ |
... | @@ -244,6 +240,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -244,6 +240,7 @@ public final class JavaCodeGeneratorUtil { |
244 | 240 | ||
245 | freeRestResources(); | 241 | freeRestResources(); |
246 | } | 242 | } |
243 | + } | ||
247 | 244 | ||
248 | /** | 245 | /** |
249 | * Closes all the current open file handles of node and delete all generated | 246 | * Closes all the current open file handles of node and delete all generated | ... | ... |
... | @@ -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 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -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,9 @@ public class JavaQualifiedTypeInfo | ... | @@ -102,7 +103,9 @@ 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 = |
107 | + AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(), | ||
108 | + leaf.getConflictResolveConfig()); | ||
106 | if (className != null) { | 109 | if (className != null) { |
107 | /* | 110 | /* |
108 | * Corresponding to the attribute type a class needs to be imported, | 111 | * Corresponding to the attribute type a class needs to be imported, |
... | @@ -163,17 +166,20 @@ public class JavaQualifiedTypeInfo | ... | @@ -163,17 +166,20 @@ public class JavaQualifiedTypeInfo |
163 | * Returns the java qualified type information for the wrapper classes. | 166 | * Returns the java qualified type information for the wrapper classes. |
164 | * | 167 | * |
165 | * @param referredTypesAttrInfo attribute of referred type | 168 | * @param referredTypesAttrInfo attribute of referred type |
169 | + * @param confilictResolver plugin configurations | ||
166 | * @return return the import info for this attribute | 170 | * @return return the import info for this attribute |
167 | */ | 171 | */ |
168 | - public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) { | 172 | + public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo, |
173 | + YangToJavaNamingConflictUtil confilictResolver) { | ||
169 | 174 | ||
170 | /* | 175 | /* |
171 | * Get the java qualified type information for the wrapper classes and | 176 | * Get the java qualified type information for the wrapper classes and |
172 | * set it in new java attribute information. | 177 | * set it in new java attribute information. |
173 | */ | 178 | */ |
174 | JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo(); | 179 | JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo(); |
180 | + | ||
175 | qualifiedInfoOfFromString.setClassInfo( | 181 | qualifiedInfoOfFromString.setClassInfo( |
176 | - getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true)); | 182 | + getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, confilictResolver)); |
177 | qualifiedInfoOfFromString.setPkgInfo( | 183 | qualifiedInfoOfFromString.setPkgInfo( |
178 | getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null)); | 184 | getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null)); |
179 | return qualifiedInfoOfFromString; | 185 | return qualifiedInfoOfFromString; | ... | ... |
... | @@ -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,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangEnumeration; | ... | @@ -28,6 +28,7 @@ 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; |
... | @@ -175,26 +176,28 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -175,26 +176,28 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
175 | * @param curEnumInfo current YANG enum | 176 | * @param curEnumInfo current YANG enum |
176 | * @throws IOException when fails to do IO operations. | 177 | * @throws IOException when fails to do IO operations. |
177 | */ | 178 | */ |
178 | - private void addAttributesForEnumClass(String curEnumName) throws IOException { | 179 | + private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException { |
179 | - appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue())); | 180 | + appendToFile(getEnumClassTempFileHandle(), |
181 | + generateEnumAttributeString(curEnumName, getEnumValue(), pluginConfig)); | ||
180 | } | 182 | } |
181 | 183 | ||
182 | /** | 184 | /** |
183 | * Adds enum attributes to temporary files. | 185 | * Adds enum attributes to temporary files. |
184 | * | 186 | * |
185 | * @param curNode current YANG node | 187 | * @param curNode current YANG node |
188 | + * @param pluginConfig plugin configurations | ||
186 | * @throws IOException when fails to do IO operations | 189 | * @throws IOException when fails to do IO operations |
187 | */ | 190 | */ |
188 | - public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException { | 191 | + public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException { |
189 | 192 | ||
190 | - super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum()); | 193 | + super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig); |
191 | if (curNode instanceof YangEnumeration) { | 194 | if (curNode instanceof YangEnumeration) { |
192 | YangEnumeration enumeration = (YangEnumeration) curNode; | 195 | YangEnumeration enumeration = (YangEnumeration) curNode; |
193 | for (YangEnum curEnum : enumeration.getEnumSet()) { | 196 | for (YangEnum curEnum : enumeration.getEnumSet()) { |
194 | setEnumValue(curEnum.getValue()); | 197 | setEnumValue(curEnum.getValue()); |
195 | addToEnumStringList(curEnum.getNamedValue()); | 198 | addToEnumStringList(curEnum.getNamedValue()); |
196 | addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); | 199 | addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); |
197 | - addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue()); | 200 | + addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue(), pluginConfig); |
198 | } | 201 | } |
199 | } else { | 202 | } else { |
200 | throw new TranslatorException("current node should be of enumeration type."); | 203 | throw new TranslatorException("current node should be of enumeration type."); |
... | @@ -204,13 +207,14 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -204,13 +207,14 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
204 | /** | 207 | /** |
205 | * Returns java attribute for enum class. | 208 | * Returns java attribute for enum class. |
206 | * | 209 | * |
210 | + * @param pluginConfig plugin configurations | ||
207 | * @return java attribute | 211 | * @return java attribute |
208 | */ | 212 | */ |
209 | - public JavaAttributeInfo getJavaAttributeForEnum() { | 213 | + public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) { |
210 | YangJavaType<?> javaType = new YangJavaType<>(); | 214 | YangJavaType<?> javaType = new YangJavaType<>(); |
211 | javaType.setDataType(YangDataTypes.INT32); | 215 | javaType.setDataType(YangDataTypes.INT32); |
212 | javaType.setDataTypeName("int"); | 216 | javaType.setDataTypeName("int"); |
213 | - javaType.updateJavaQualifiedInfo(); | 217 | + javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver()); |
214 | return getAttributeInfoForTheData( | 218 | return getAttributeInfoForTheData( |
215 | javaType.getJavaQualifiedInfo(), | 219 | javaType.getJavaQualifiedInfo(), |
216 | javaType.getDataTypeName(), javaType, | 220 | javaType.getDataTypeName(), javaType, |
... | @@ -234,8 +238,9 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -234,8 +238,9 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
234 | * files | 238 | * files |
235 | * @throws IOException IO operation fail | 239 | * @throws IOException IO operation fail |
236 | */ | 240 | */ |
237 | - void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException { | 241 | + void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig) |
238 | - addAttributesForEnumClass(curEnumName); | 242 | + throws IOException { |
243 | + addAttributesForEnumClass(curEnumName, pluginConfig); | ||
239 | } | 244 | } |
240 | 245 | ||
241 | /** | 246 | /** | ... | ... |
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 | -} |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
... | @@ -795,35 +795,40 @@ public class TempJavaFragmentFiles { | ... | @@ -795,35 +795,40 @@ public class TempJavaFragmentFiles { |
795 | * Adds attribute for class. | 795 | * Adds attribute for class. |
796 | * | 796 | * |
797 | * @param attr attribute info | 797 | * @param attr attribute info |
798 | + * @param pluginConfig plugin configurations | ||
798 | * @throws IOException when fails to append to temporary file | 799 | * @throws IOException when fails to append to temporary file |
799 | */ | 800 | */ |
800 | - private void addAttribute(JavaAttributeInfo attr) | 801 | + private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig) |
801 | throws IOException { | 802 | throws IOException { |
802 | - appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); | 803 | + appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig) |
804 | + + FOUR_SPACE_INDENTATION); | ||
803 | } | 805 | } |
804 | 806 | ||
805 | /** | 807 | /** |
806 | * Adds getter for interface. | 808 | * Adds getter for interface. |
807 | * | 809 | * |
808 | * @param attr attribute info | 810 | * @param attr attribute info |
811 | + * @param pluginConfig plugin configurations | ||
809 | * @throws IOException when fails to append to temporary file | 812 | * @throws IOException when fails to append to temporary file |
810 | */ | 813 | */ |
811 | - private void addGetterForInterface(JavaAttributeInfo attr) | 814 | + private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
812 | throws IOException { | 815 | throws IOException { |
813 | appendToFile(getGetterInterfaceTempFileHandle(), | 816 | appendToFile(getGetterInterfaceTempFileHandle(), |
814 | - getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE); | 817 | + getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE); |
815 | } | 818 | } |
816 | 819 | ||
817 | /** | 820 | /** |
818 | * Adds setter for interface. | 821 | * Adds setter for interface. |
819 | * | 822 | * |
820 | * @param attr attribute info | 823 | * @param attr attribute info |
824 | + * @param pluginConfig plugin configurations | ||
821 | * @throws IOException when fails to append to temporary file | 825 | * @throws IOException when fails to append to temporary file |
822 | */ | 826 | */ |
823 | - private void addSetterForInterface(JavaAttributeInfo attr) | 827 | + private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
824 | throws IOException { | 828 | throws IOException { |
825 | appendToFile(getSetterInterfaceTempFileHandle(), | 829 | appendToFile(getSetterInterfaceTempFileHandle(), |
826 | - getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE); | 830 | + getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig) |
831 | + + NEW_LINE); | ||
827 | } | 832 | } |
828 | 833 | ||
829 | /** | 834 | /** |
... | @@ -844,9 +849,10 @@ public class TempJavaFragmentFiles { | ... | @@ -844,9 +849,10 @@ public class TempJavaFragmentFiles { |
844 | * Adds getter method's impl for class. | 849 | * Adds getter method's impl for class. |
845 | * | 850 | * |
846 | * @param attr attribute info | 851 | * @param attr attribute info |
852 | + * @param pluginConfig plugin configurations | ||
847 | * @throws IOException when fails to append to temporary file | 853 | * @throws IOException when fails to append to temporary file |
848 | */ | 854 | */ |
849 | - private void addGetterImpl(JavaAttributeInfo attr) | 855 | + private void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
850 | throws IOException { | 856 | throws IOException { |
851 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 | 857 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 |
852 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { | 858 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
... | @@ -854,7 +860,7 @@ public class TempJavaFragmentFiles { | ... | @@ -854,7 +860,7 @@ public class TempJavaFragmentFiles { |
854 | getGeneratedJavaFiles()) + NEW_LINE); | 860 | getGeneratedJavaFiles()) + NEW_LINE); |
855 | } else { | 861 | } else { |
856 | appendToFile(getGetterImplTempFileHandle(), | 862 | appendToFile(getGetterImplTempFileHandle(), |
857 | - getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false) | 863 | + getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
858 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); | 864 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); |
859 | } | 865 | } |
860 | } | 866 | } |
... | @@ -863,11 +869,12 @@ public class TempJavaFragmentFiles { | ... | @@ -863,11 +869,12 @@ public class TempJavaFragmentFiles { |
863 | * Adds build method for interface. | 869 | * Adds build method for interface. |
864 | * | 870 | * |
865 | * @return build method for interface | 871 | * @return build method for interface |
872 | + * @param pluginConfig plugin configurations | ||
866 | * @throws IOException when fails to append to temporary file | 873 | * @throws IOException when fails to append to temporary file |
867 | */ | 874 | */ |
868 | - String addBuildMethodForInterface() | 875 | + String addBuildMethodForInterface(YangPluginConfig pluginConfig) |
869 | throws IOException { | 876 | throws IOException { |
870 | - return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName()); | 877 | + return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig); |
871 | } | 878 | } |
872 | 879 | ||
873 | /** | 880 | /** |
... | @@ -886,23 +893,26 @@ public class TempJavaFragmentFiles { | ... | @@ -886,23 +893,26 @@ public class TempJavaFragmentFiles { |
886 | * | 893 | * |
887 | * @param modifier modifier for constructor. | 894 | * @param modifier modifier for constructor. |
888 | * @param toAppend string which need to be appended with the class name | 895 | * @param toAppend string which need to be appended with the class name |
896 | + * @param pluginConfig plugin configurations | ||
889 | * @return default constructor for class | 897 | * @return default constructor for class |
890 | * @throws IOException when fails to append to file | 898 | * @throws IOException when fails to append to file |
891 | */ | 899 | */ |
892 | - String addDefaultConstructor(String modifier, String toAppend) | 900 | + String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig) |
893 | throws IOException { | 901 | throws IOException { |
894 | - return NEW_LINE + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier); | 902 | + return NEW_LINE |
903 | + + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig); | ||
895 | } | 904 | } |
896 | 905 | ||
897 | /** | 906 | /** |
898 | * Adds default constructor for class. | 907 | * Adds default constructor for class. |
899 | * | 908 | * |
909 | + * @param pluginCnfig plugin configurations | ||
900 | * @return default constructor for class | 910 | * @return default constructor for class |
901 | * @throws IOException when fails to append to file | 911 | * @throws IOException when fails to append to file |
902 | */ | 912 | */ |
903 | - public String addOfMethod() | 913 | + public String addOfMethod(YangPluginConfig pluginCnfig) |
904 | throws IOException { | 914 | throws IOException { |
905 | - return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false) | 915 | + return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig) |
906 | + getOfMethod(getGeneratedJavaClassName(), null); | 916 | + getOfMethod(getGeneratedJavaClassName(), null); |
907 | } | 917 | } |
908 | 918 | ||
... | @@ -994,6 +1004,7 @@ public class TempJavaFragmentFiles { | ... | @@ -994,6 +1004,7 @@ public class TempJavaFragmentFiles { |
994 | */ | 1004 | */ |
995 | public String getTemporaryDataFromFileHandle(File file) | 1005 | public String getTemporaryDataFromFileHandle(File file) |
996 | throws IOException { | 1006 | throws IOException { |
1007 | + | ||
997 | String path = getTempDirPath(); | 1008 | String path = getTempDirPath(); |
998 | if (new File(path + file.getName()).exists()) { | 1009 | if (new File(path + file.getName()).exists()) { |
999 | return readAppendFile(path + file.getName(), EMPTY_STRING); | 1010 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
... | @@ -1017,13 +1028,14 @@ public class TempJavaFragmentFiles { | ... | @@ -1017,13 +1028,14 @@ public class TempJavaFragmentFiles { |
1017 | * Parses attribute to get the attribute string. | 1028 | * Parses attribute to get the attribute string. |
1018 | * | 1029 | * |
1019 | * @param attr attribute info | 1030 | * @param attr attribute info |
1031 | + * @param pluginConfig plugin configurations | ||
1020 | * @return attribute string | 1032 | * @return attribute string |
1021 | */ | 1033 | */ |
1022 | - private String parseAttribute(JavaAttributeInfo attr) { | 1034 | + public String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) { |
1023 | /* | 1035 | /* |
1024 | * TODO: check if this utility needs to be called or move to the caller | 1036 | * TODO: check if this utility needs to be called or move to the caller |
1025 | */ | 1037 | */ |
1026 | - String attributeName = getCamelCase(attr.getAttributeName(), null); | 1038 | + String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver()); |
1027 | if (attr.isQualifiedName()) { | 1039 | if (attr.isQualifiedName()) { |
1028 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), | 1040 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), |
1029 | attr.getImportInfo().getClassInfo(), | 1041 | attr.getImportInfo().getClassInfo(), |
... | @@ -1056,10 +1068,11 @@ public class TempJavaFragmentFiles { | ... | @@ -1056,10 +1068,11 @@ public class TempJavaFragmentFiles { |
1056 | * @param curNode current node which needs to be added as an attribute in | 1068 | * @param curNode current node which needs to be added as an attribute in |
1057 | * the parent generated code | 1069 | * the parent generated code |
1058 | * @param isList is list construct | 1070 | * @param isList is list construct |
1071 | + * @param pluginConfig plugin configurations | ||
1059 | * @throws IOException IO operation exception | 1072 | * @throws IOException IO operation exception |
1060 | */ | 1073 | */ |
1061 | public static void addCurNodeInfoInParentTempFile(YangNode curNode, | 1074 | public static void addCurNodeInfoInParentTempFile(YangNode curNode, |
1062 | - boolean isList) | 1075 | + boolean isList, YangPluginConfig pluginConfig) |
1063 | throws IOException { | 1076 | throws IOException { |
1064 | YangNode parent = getParentNodeInGenCode(curNode); | 1077 | YangNode parent = getParentNodeInGenCode(curNode); |
1065 | if (!(parent instanceof JavaCodeGenerator)) { | 1078 | if (!(parent instanceof JavaCodeGenerator)) { |
... | @@ -1071,7 +1084,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1071,7 +1084,7 @@ public class TempJavaFragmentFiles { |
1071 | throw new TranslatorException("missing parent temp file handle"); | 1084 | throw new TranslatorException("missing parent temp file handle"); |
1072 | } | 1085 | } |
1073 | getNodesInterfaceFragmentFiles(parent) | 1086 | getNodesInterfaceFragmentFiles(parent) |
1074 | - .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | 1087 | + .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig); |
1075 | } | 1088 | } |
1076 | 1089 | ||
1077 | /** | 1090 | /** |
... | @@ -1134,8 +1147,9 @@ public class TempJavaFragmentFiles { | ... | @@ -1134,8 +1147,9 @@ public class TempJavaFragmentFiles { |
1134 | * Adds parent's info to current node import list. | 1147 | * Adds parent's info to current node import list. |
1135 | * | 1148 | * |
1136 | * @param curNode current node for which import list needs to be updated | 1149 | * @param curNode current node for which import list needs to be updated |
1150 | + * @param pluginConfig plugin configurations | ||
1137 | */ | 1151 | */ |
1138 | - public void addParentInfoInCurNodeTempFile(YangNode curNode) { | 1152 | + public void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) { |
1139 | caseImportInfo = new JavaQualifiedTypeInfo(); | 1153 | caseImportInfo = new JavaQualifiedTypeInfo(); |
1140 | YangNode parent = getParentNodeInGenCode(curNode); | 1154 | YangNode parent = getParentNodeInGenCode(curNode); |
1141 | if (!(parent instanceof JavaCodeGenerator)) { | 1155 | if (!(parent instanceof JavaCodeGenerator)) { |
... | @@ -1145,7 +1159,8 @@ public class TempJavaFragmentFiles { | ... | @@ -1145,7 +1159,8 @@ public class TempJavaFragmentFiles { |
1145 | throw new TranslatorException("missing java file information to get the package details " | 1159 | throw new TranslatorException("missing java file information to get the package details " |
1146 | + "of attribute corresponding to child node"); | 1160 | + "of attribute corresponding to child node"); |
1147 | } | 1161 | } |
1148 | - caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), null))); | 1162 | + caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), |
1163 | + pluginConfig.getConflictResolver()))); | ||
1149 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); | 1164 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); |
1150 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 1165 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
1151 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo); | 1166 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo); |
... | @@ -1167,6 +1182,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1167,6 +1182,7 @@ public class TempJavaFragmentFiles { |
1167 | throw new TranslatorException("Leaf does not have java information"); | 1182 | throw new TranslatorException("Leaf does not have java information"); |
1168 | } | 1183 | } |
1169 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; | 1184 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; |
1185 | + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); | ||
1170 | javaLeaf.updateJavaQualifiedInfo(); | 1186 | javaLeaf.updateJavaQualifiedInfo(); |
1171 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 1187 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
1172 | javaLeaf.getJavaQualifiedInfo(), | 1188 | javaLeaf.getJavaQualifiedInfo(), |
... | @@ -1174,7 +1190,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1174,7 +1190,7 @@ public class TempJavaFragmentFiles { |
1174 | javaLeaf.getDataType(), | 1190 | javaLeaf.getDataType(), |
1175 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), | 1191 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
1176 | false); | 1192 | false); |
1177 | - addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | 1193 | + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig); |
1178 | } | 1194 | } |
1179 | } | 1195 | } |
1180 | } | 1196 | } |
... | @@ -1194,6 +1210,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1194,6 +1210,7 @@ public class TempJavaFragmentFiles { |
1194 | throw new TranslatorException("Leaf-list does not have java information"); | 1210 | throw new TranslatorException("Leaf-list does not have java information"); |
1195 | } | 1211 | } |
1196 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; | 1212 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; |
1213 | + javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); | ||
1197 | javaLeaf.updateJavaQualifiedInfo(); | 1214 | javaLeaf.updateJavaQualifiedInfo(); |
1198 | getJavaImportData().setIfListImported(true); | 1215 | getJavaImportData().setIfListImported(true); |
1199 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 1216 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
... | @@ -1202,7 +1219,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1202,7 +1219,7 @@ public class TempJavaFragmentFiles { |
1202 | javaLeaf.getDataType(), | 1219 | javaLeaf.getDataType(), |
1203 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), | 1220 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
1204 | true); | 1221 | true); |
1205 | - addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | 1222 | + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig); |
1206 | } | 1223 | } |
1207 | } | 1224 | } |
1208 | } | 1225 | } |
... | @@ -1231,21 +1248,22 @@ public class TempJavaFragmentFiles { | ... | @@ -1231,21 +1248,22 @@ public class TempJavaFragmentFiles { |
1231 | * | 1248 | * |
1232 | * @param newAttrInfo the attribute info that needs to be added to temporary | 1249 | * @param newAttrInfo the attribute info that needs to be added to temporary |
1233 | * files | 1250 | * files |
1251 | + * @param pluginConfig plugin configurations | ||
1234 | * @throws IOException IO operation fail | 1252 | * @throws IOException IO operation fail |
1235 | */ | 1253 | */ |
1236 | - void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) | 1254 | + void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig) |
1237 | throws IOException { | 1255 | throws IOException { |
1238 | setAttributePresent(true); | 1256 | setAttributePresent(true); |
1239 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { | 1257 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
1240 | - addAttribute(newAttrInfo); | 1258 | + addAttribute(newAttrInfo, pluginConfig); |
1241 | } | 1259 | } |
1242 | 1260 | ||
1243 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { | 1261 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
1244 | - addGetterForInterface(newAttrInfo); | 1262 | + addGetterForInterface(newAttrInfo, pluginConfig); |
1245 | } | 1263 | } |
1246 | 1264 | ||
1247 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { | 1265 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
1248 | - addSetterForInterface(newAttrInfo); | 1266 | + addSetterForInterface(newAttrInfo, pluginConfig); |
1249 | } | 1267 | } |
1250 | 1268 | ||
1251 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { | 1269 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
... | @@ -1253,7 +1271,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1253,7 +1271,7 @@ public class TempJavaFragmentFiles { |
1253 | } | 1271 | } |
1254 | 1272 | ||
1255 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { | 1273 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
1256 | - addGetterImpl(newAttrInfo); | 1274 | + addGetterImpl(newAttrInfo, pluginConfig); |
1257 | } | 1275 | } |
1258 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { | 1276 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
1259 | addHashCodeMethod(newAttrInfo); | 1277 | addHashCodeMethod(newAttrInfo); |
... | @@ -1266,7 +1284,8 @@ public class TempJavaFragmentFiles { | ... | @@ -1266,7 +1284,8 @@ public class TempJavaFragmentFiles { |
1266 | } | 1284 | } |
1267 | 1285 | ||
1268 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { | 1286 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
1269 | - JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo); | 1287 | + JavaQualifiedTypeInfo qualifiedInfoOfFromString = |
1288 | + getQualifiedInfoOfFromString(newAttrInfo, pluginConfig.getConflictResolver()); | ||
1270 | /* | 1289 | /* |
1271 | * Create a new java attribute info with qualified information of | 1290 | * Create a new java attribute info with qualified information of |
1272 | * wrapper classes. | 1291 | * wrapper classes. |
... | @@ -1309,9 +1328,8 @@ public class TempJavaFragmentFiles { | ... | @@ -1309,9 +1328,8 @@ public class TempJavaFragmentFiles { |
1309 | public void generateJavaFile(int fileType, YangNode curNode) | 1328 | public void generateJavaFile(int fileType, YangNode curNode) |
1310 | throws IOException { | 1329 | throws IOException { |
1311 | List<String> imports = new ArrayList<>(); | 1330 | List<String> imports = new ArrayList<>(); |
1312 | - if (isAttributePresent()) { | ||
1313 | imports = getJavaImportData().getImports(); | 1331 | imports = getJavaImportData().getImports(); |
1314 | - } | 1332 | + |
1315 | createPackage(curNode); | 1333 | createPackage(curNode); |
1316 | 1334 | ||
1317 | /* | 1335 | /* | ... | ... |
... | @@ -22,26 +22,56 @@ import java.util.ArrayList; | ... | @@ -22,26 +22,56 @@ import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | 23 | ||
24 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
25 | -import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; | 25 | +import org.onosproject.yangutils.datamodel.YangNotification; |
26 | - | 26 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
27 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; | ||
28 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
29 | + | ||
30 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; | ||
32 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; | ||
33 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; | ||
34 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; | ||
35 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; | ||
36 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; | ||
37 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; | ||
27 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
40 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | ||
41 | +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | ||
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | 42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
43 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; | ||
44 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; | ||
45 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile; | ||
30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile; |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile; | 47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile; |
48 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; | ||
49 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
51 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | ||
52 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; | ||
33 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; |
34 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; |
55 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; | ||
56 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAnnotationsImports; | ||
35 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport; | 57 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport; |
36 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 58 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
59 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
37 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
61 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ||
62 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
38 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | 63 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | 64 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; | 66 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
67 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
42 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; | 68 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
43 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 69 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
44 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; | 70 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; |
71 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
72 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; | ||
73 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | ||
74 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD; | ||
45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 75 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
46 | 76 | ||
47 | /** | 77 | /** |
... | @@ -62,6 +92,30 @@ public class TempJavaServiceFragmentFiles | ... | @@ -62,6 +92,30 @@ public class TempJavaServiceFragmentFiles |
62 | private static final String RPC_IMPL_FILE_NAME = "RpcImpl"; | 92 | private static final String RPC_IMPL_FILE_NAME = "RpcImpl"; |
63 | 93 | ||
64 | /** | 94 | /** |
95 | + * File name for event enum temp file. | ||
96 | + */ | ||
97 | + private static final String EVENT_ENUM_FILE_NAME = "EventEnum"; | ||
98 | + | ||
99 | + /** | ||
100 | + * File name for event method temp file. | ||
101 | + */ | ||
102 | + private static final String EVENT_METHOD_FILE_NAME = "EventMethod"; | ||
103 | + | ||
104 | + /** | ||
105 | + * File name for event subject attribute temp file. | ||
106 | + */ | ||
107 | + private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute"; | ||
108 | + | ||
109 | + /** | ||
110 | + * File name for event subject getter temp file. | ||
111 | + */ | ||
112 | + private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter"; | ||
113 | + | ||
114 | + /** | ||
115 | + * File name for event subject setter temp file. | ||
116 | + */ | ||
117 | + private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter"; | ||
118 | + /** | ||
65 | * File name for generated class file for service | 119 | * File name for generated class file for service |
66 | * suffix. | 120 | * suffix. |
67 | */ | 121 | */ |
... | @@ -74,6 +128,41 @@ public class TempJavaServiceFragmentFiles | ... | @@ -74,6 +128,41 @@ public class TempJavaServiceFragmentFiles |
74 | private static final String MANAGER_FILE_NAME_SUFFIX = "Manager"; | 128 | private static final String MANAGER_FILE_NAME_SUFFIX = "Manager"; |
75 | 129 | ||
76 | /** | 130 | /** |
131 | + * File name for generated class file for special type like union, typedef | ||
132 | + * suffix. | ||
133 | + */ | ||
134 | + private static final String EVENT_FILE_NAME_SUFFIX = "Event"; | ||
135 | + | ||
136 | + /** | ||
137 | + * File name for generated class file for special type like union, typedef | ||
138 | + * suffix. | ||
139 | + */ | ||
140 | + private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener"; | ||
141 | + | ||
142 | + /** | ||
143 | + * File name for generated class file for special type like union, typedef | ||
144 | + * suffix. | ||
145 | + */ | ||
146 | + public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject"; | ||
147 | + | ||
148 | + private static final String JAVA_FILE_EXTENSION = ".java"; | ||
149 | + | ||
150 | + /** | ||
151 | + * Java file handle for event subject file. | ||
152 | + */ | ||
153 | + private File eventSubjectJavaFileHandle; | ||
154 | + | ||
155 | + /** | ||
156 | + * Java file handle for event listener file. | ||
157 | + */ | ||
158 | + private File eventListenerJavaFileHandle; | ||
159 | + | ||
160 | + /** | ||
161 | + * Java file handle for event file. | ||
162 | + */ | ||
163 | + private File eventJavaFileHandle; | ||
164 | + | ||
165 | + /** | ||
77 | * Temporary file handle for rpc interface. | 166 | * Temporary file handle for rpc interface. |
78 | */ | 167 | */ |
79 | private File rpcInterfaceTempFileHandle; | 168 | private File rpcInterfaceTempFileHandle; |
... | @@ -94,6 +183,31 @@ public class TempJavaServiceFragmentFiles | ... | @@ -94,6 +183,31 @@ public class TempJavaServiceFragmentFiles |
94 | private File managerJavaFileHandle; | 183 | private File managerJavaFileHandle; |
95 | 184 | ||
96 | /** | 185 | /** |
186 | + * Java file handle for event enum impl file. | ||
187 | + */ | ||
188 | + private File eventEnumTempFileHandle; | ||
189 | + | ||
190 | + /** | ||
191 | + * Java file handle for event method impl file. | ||
192 | + */ | ||
193 | + private File eventMethodTempFileHandle; | ||
194 | + | ||
195 | + /** | ||
196 | + * Java file handle for event subject attribute file. | ||
197 | + */ | ||
198 | + private File eventSubjectAttributeTempFileHandle; | ||
199 | + | ||
200 | + /** | ||
201 | + * Java file handle for event subject getter impl file. | ||
202 | + */ | ||
203 | + private File eventSubjectGetterTempFileHandle; | ||
204 | + | ||
205 | + /** | ||
206 | + * Java file handle for event subject setter impl file. | ||
207 | + */ | ||
208 | + private File eventSubjectSetterTempFileHandle; | ||
209 | + | ||
210 | + /** | ||
97 | * Returns rpc method's java file handle. | 211 | * Returns rpc method's java file handle. |
98 | * | 212 | * |
99 | * @return java file handle | 213 | * @return java file handle |
... | @@ -166,6 +280,60 @@ public class TempJavaServiceFragmentFiles | ... | @@ -166,6 +280,60 @@ public class TempJavaServiceFragmentFiles |
166 | } | 280 | } |
167 | 281 | ||
168 | /** | 282 | /** |
283 | + * Returns event's java file handle. | ||
284 | + * | ||
285 | + * @return java file handle | ||
286 | + */ | ||
287 | + private File getEventJavaFileHandle() { | ||
288 | + return eventJavaFileHandle; | ||
289 | + } | ||
290 | + | ||
291 | + /** | ||
292 | + * Sets event's java file handle. | ||
293 | + * | ||
294 | + * @param eventJavaFileHandle file handle for event | ||
295 | + */ | ||
296 | + private void setEventJavaFileHandle(File eventJavaFileHandle) { | ||
297 | + this.eventJavaFileHandle = eventJavaFileHandle; | ||
298 | + } | ||
299 | + | ||
300 | + /** | ||
301 | + * Returns event listeners's java file handle. | ||
302 | + * | ||
303 | + * @return java file handle | ||
304 | + */ | ||
305 | + private File getEventListenerJavaFileHandle() { | ||
306 | + return eventListenerJavaFileHandle; | ||
307 | + } | ||
308 | + | ||
309 | + /** | ||
310 | + * Sets event's java file handle. | ||
311 | + * | ||
312 | + * @param eventListenerJavaFileHandle file handle for event | ||
313 | + */ | ||
314 | + private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) { | ||
315 | + this.eventListenerJavaFileHandle = eventListenerJavaFileHandle; | ||
316 | + } | ||
317 | + | ||
318 | + /** | ||
319 | + * Returns event subject's java file handle. | ||
320 | + * | ||
321 | + * @return java file handle | ||
322 | + */ | ||
323 | + private File getEventSubjectJavaFileHandle() { | ||
324 | + return eventSubjectJavaFileHandle; | ||
325 | + } | ||
326 | + | ||
327 | + /** | ||
328 | + * Sets event's subject java file handle. | ||
329 | + * | ||
330 | + * @param eventSubjectJavaFileHandle file handle for event's subject | ||
331 | + */ | ||
332 | + private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) { | ||
333 | + this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle; | ||
334 | + } | ||
335 | + | ||
336 | + /** | ||
169 | * Creates an instance of temporary java code fragment. | 337 | * Creates an instance of temporary java code fragment. |
170 | * | 338 | * |
171 | * @param javaFileInfo generated file information | 339 | * @param javaFileInfo generated file information |
... | @@ -176,11 +344,22 @@ public class TempJavaServiceFragmentFiles | ... | @@ -176,11 +344,22 @@ public class TempJavaServiceFragmentFiles |
176 | super(javaFileInfo); | 344 | super(javaFileInfo); |
177 | 345 | ||
178 | addGeneratedTempFile(RPC_INTERFACE_MASK); | 346 | addGeneratedTempFile(RPC_INTERFACE_MASK); |
179 | - | ||
180 | addGeneratedTempFile(RPC_IMPL_MASK); | 347 | addGeneratedTempFile(RPC_IMPL_MASK); |
181 | 348 | ||
349 | + addGeneratedTempFile(EVENT_ENUM_MASK); | ||
350 | + addGeneratedTempFile(EVENT_METHOD_MASK); | ||
351 | + addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK); | ||
352 | + addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK); | ||
353 | + addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK); | ||
354 | + | ||
182 | setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME)); | 355 | setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME)); |
183 | setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME)); | 356 | setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME)); |
357 | + | ||
358 | + setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME)); | ||
359 | + setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME)); | ||
360 | + setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME)); | ||
361 | + setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME)); | ||
362 | + setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME)); | ||
184 | } | 363 | } |
185 | 364 | ||
186 | /** | 365 | /** |
... | @@ -199,13 +378,14 @@ public class TempJavaServiceFragmentFiles | ... | @@ -199,13 +378,14 @@ public class TempJavaServiceFragmentFiles |
199 | createPackage(curNode); | 378 | createPackage(curNode); |
200 | 379 | ||
201 | boolean isNotification = false; | 380 | boolean isNotification = false; |
202 | - YangNode tempNode = curNode.getChild(); | 381 | + if (curNode instanceof YangJavaModule) { |
203 | - while (tempNode != null) { | 382 | + if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) { |
204 | - if (tempNode instanceof YangJavaNotification) { | 383 | + isNotification = true; |
384 | + } | ||
385 | + } else if (curNode instanceof YangJavaSubModule) { | ||
386 | + if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) { | ||
205 | isNotification = true; | 387 | isNotification = true; |
206 | - break; | ||
207 | } | 388 | } |
208 | - tempNode = tempNode.getNextSibling(); | ||
209 | } | 389 | } |
210 | 390 | ||
211 | if (isNotification) { | 391 | if (isNotification) { |
... | @@ -221,6 +401,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -221,6 +401,7 @@ public class TempJavaServiceFragmentFiles |
221 | addListnersImport(curNode, imports, false, LISTENER_SERVICE); | 401 | addListnersImport(curNode, imports, false, LISTENER_SERVICE); |
222 | addListnersImport(curNode, imports, true, LISTENER_REG); | 402 | addListnersImport(curNode, imports, true, LISTENER_REG); |
223 | } | 403 | } |
404 | + addAnnotationsImports(imports, true); | ||
224 | /** | 405 | /** |
225 | * Create builder class file. | 406 | * Create builder class file. |
226 | */ | 407 | */ |
... | @@ -231,6 +412,14 @@ public class TempJavaServiceFragmentFiles | ... | @@ -231,6 +412,14 @@ public class TempJavaServiceFragmentFiles |
231 | if (isNotification) { | 412 | if (isNotification) { |
232 | addListnersImport(curNode, imports, false, LISTENER_REG); | 413 | addListnersImport(curNode, imports, false, LISTENER_REG); |
233 | } | 414 | } |
415 | + addAnnotationsImports(imports, false); | ||
416 | + | ||
417 | + if (isNotification) { | ||
418 | + generateEventJavaFile(GENERATE_EVENT_CLASS, curNode); | ||
419 | + generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode); | ||
420 | + generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode); | ||
421 | + } | ||
422 | + | ||
234 | /** | 423 | /** |
235 | * Close all the file handles. | 424 | * Close all the file handles. |
236 | */ | 425 | */ |
... | @@ -243,10 +432,11 @@ public class TempJavaServiceFragmentFiles | ... | @@ -243,10 +432,11 @@ public class TempJavaServiceFragmentFiles |
243 | * @param javaAttributeInfoOfInput rpc's input node attribute info | 432 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
244 | * @param javaAttributeInfoOfOutput rpc's output node attribute info | 433 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
245 | * @param rpcName name of the rpc function | 434 | * @param rpcName name of the rpc function |
435 | + * @param pluginConfig plugin configurations | ||
246 | * @throws IOException IO operation fail | 436 | * @throws IOException IO operation fail |
247 | */ | 437 | */ |
248 | private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, | 438 | private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, |
249 | - JavaAttributeInfo javaAttributeInfoOfOutput, | 439 | + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
250 | String rpcName) throws IOException { | 440 | String rpcName) throws IOException { |
251 | String rpcInput = EMPTY_STRING; | 441 | String rpcInput = EMPTY_STRING; |
252 | String rpcOutput = VOID; | 442 | String rpcOutput = VOID; |
... | @@ -256,9 +446,11 @@ public class TempJavaServiceFragmentFiles | ... | @@ -256,9 +446,11 @@ public class TempJavaServiceFragmentFiles |
256 | if (javaAttributeInfoOfOutput != null) { | 446 | if (javaAttributeInfoOfOutput != null) { |
257 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); | 447 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); |
258 | } | 448 | } |
259 | - appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput) | 449 | + appendToFile(getRpcInterfaceTempFileHandle(), |
260 | - + getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); | 450 | + generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput, pluginConfig) |
261 | - appendToFile(getRpcImplTempFileHandle(), getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); | 451 | + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
452 | + appendToFile(getRpcImplTempFileHandle(), | ||
453 | + getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); | ||
262 | } | 454 | } |
263 | 455 | ||
264 | /** | 456 | /** |
... | @@ -266,14 +458,99 @@ public class TempJavaServiceFragmentFiles | ... | @@ -266,14 +458,99 @@ public class TempJavaServiceFragmentFiles |
266 | * | 458 | * |
267 | * @param javaAttributeInfoOfInput rpc's input node attribute info | 459 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
268 | * @param javaAttributeInfoOfOutput rpc's output node attribute info | 460 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
461 | + * @param pluginConfig plugin configurations | ||
269 | * @param rpcName name of the rpc function | 462 | * @param rpcName name of the rpc function |
270 | * @throws IOException IO operation fail | 463 | * @throws IOException IO operation fail |
271 | */ | 464 | */ |
272 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, | 465 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, |
273 | - JavaAttributeInfo javaAttributeInfoOfOutput, | 466 | + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
274 | String rpcName) | 467 | String rpcName) |
275 | throws IOException { | 468 | throws IOException { |
276 | - addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName); | 469 | + addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName); |
470 | + } | ||
471 | + | ||
472 | + /** | ||
473 | + * Constructs java code exit. | ||
474 | + * | ||
475 | + * @param fileType generated file type | ||
476 | + * @param curNode current YANG node | ||
477 | + * @throws IOException when fails to generate java files | ||
478 | + */ | ||
479 | + public void generateEventJavaFile(int fileType, YangNode curNode) | ||
480 | + throws IOException { | ||
481 | + | ||
482 | + List<String> imports = new ArrayList<>(); | ||
483 | + | ||
484 | + imports.add(getJavaImportData().getAbstractEventsImport()); | ||
485 | + String curNodeInfo = | ||
486 | + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()); | ||
487 | + String nodeName = curNodeInfo + EVENT_STRING; | ||
488 | + | ||
489 | + addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX); | ||
490 | + | ||
491 | + /** | ||
492 | + * Creates event interface file. | ||
493 | + */ | ||
494 | + setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX)); | ||
495 | + generateEventFile(getEventJavaFileHandle(), curNode, imports); | ||
496 | + | ||
497 | + /** | ||
498 | + * Close all the file handles. | ||
499 | + */ | ||
500 | + freeTemporaryResources(false); | ||
501 | + } | ||
502 | + | ||
503 | + /** | ||
504 | + * Constructs java code exit. | ||
505 | + * | ||
506 | + * @param fileType generated file type | ||
507 | + * @param curNode current YANG node | ||
508 | + * @throws IOException when fails to generate java files | ||
509 | + */ | ||
510 | + public void generateEventListenerJavaFile(int fileType, YangNode curNode) | ||
511 | + throws IOException { | ||
512 | + | ||
513 | + List<String> imports = new ArrayList<>(); | ||
514 | + | ||
515 | + imports.add(getJavaImportData().getEventListenerImport()); | ||
516 | + String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) | ||
517 | + .getJavaFileInfo().getJavaName()); | ||
518 | + /** | ||
519 | + * Creates event listener interface file. | ||
520 | + */ | ||
521 | + setEventListenerJavaFileHandle( | ||
522 | + getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX)); | ||
523 | + generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports); | ||
524 | + | ||
525 | + /** | ||
526 | + * Close all the file handles. | ||
527 | + */ | ||
528 | + freeTemporaryResources(false); | ||
529 | + } | ||
530 | + | ||
531 | + /** | ||
532 | + * Constructs java code exit. | ||
533 | + * | ||
534 | + * @param fileType generated file type | ||
535 | + * @param curNode current YANG node | ||
536 | + * @throws IOException when fails to generate java files | ||
537 | + */ | ||
538 | + public void generateEventSubjectJavaFile(int fileType, YangNode curNode) | ||
539 | + throws IOException { | ||
540 | + | ||
541 | + String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) | ||
542 | + .getJavaFileInfo().getJavaName()); | ||
543 | + /** | ||
544 | + * Creates event interface file. | ||
545 | + */ | ||
546 | + setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + | ||
547 | + EVENT_SUBJECT_NAME_SUFFIX)); | ||
548 | + generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode); | ||
549 | + | ||
550 | + /** | ||
551 | + * Close all the file handles. | ||
552 | + */ | ||
553 | + freeTemporaryResources(false); | ||
277 | } | 554 | } |
278 | 555 | ||
279 | /** | 556 | /** |
... | @@ -290,6 +567,18 @@ public class TempJavaServiceFragmentFiles | ... | @@ -290,6 +567,18 @@ public class TempJavaServiceFragmentFiles |
290 | boolean isError = isErrorOccurred; | 567 | boolean isError = isErrorOccurred; |
291 | 568 | ||
292 | closeFile(getServiceInterfaceJavaFileHandle(), isError); | 569 | closeFile(getServiceInterfaceJavaFileHandle(), isError); |
570 | + closeFile(getManagerJavaFileHandle(), isError); | ||
571 | + | ||
572 | + if (getEventJavaFileHandle() != null) { | ||
573 | + closeFile(getEventJavaFileHandle(), isError); | ||
574 | + } | ||
575 | + if (getEventListenerJavaFileHandle() != null) { | ||
576 | + closeFile(getEventListenerJavaFileHandle(), isError); | ||
577 | + } | ||
578 | + if (getEventSubjectJavaFileHandle() != null) { | ||
579 | + closeFile(getEventSubjectJavaFileHandle(), isError); | ||
580 | + } | ||
581 | + | ||
293 | closeFile(getRpcInterfaceTempFileHandle(), true); | 582 | closeFile(getRpcInterfaceTempFileHandle(), true); |
294 | closeFile(getRpcImplTempFileHandle(), true); | 583 | closeFile(getRpcImplTempFileHandle(), true); |
295 | closeFile(getGetterInterfaceTempFileHandle(), true); | 584 | closeFile(getGetterInterfaceTempFileHandle(), true); |
... | @@ -299,4 +588,206 @@ public class TempJavaServiceFragmentFiles | ... | @@ -299,4 +588,206 @@ public class TempJavaServiceFragmentFiles |
299 | super.freeTemporaryResources(isErrorOccurred); | 588 | super.freeTemporaryResources(isErrorOccurred); |
300 | 589 | ||
301 | } | 590 | } |
591 | + | ||
592 | + /** | ||
593 | + * Returns event enum temp file. | ||
594 | + * | ||
595 | + * @return event enum temp file | ||
596 | + */ | ||
597 | + public File getEventEnumTempFileHandle() { | ||
598 | + return eventEnumTempFileHandle; | ||
599 | + } | ||
600 | + | ||
601 | + /** | ||
602 | + * Sets event enum temp file. | ||
603 | + * | ||
604 | + * @param eventEnumTempFileHandle event enum temp file | ||
605 | + */ | ||
606 | + public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) { | ||
607 | + this.eventEnumTempFileHandle = eventEnumTempFileHandle; | ||
608 | + } | ||
609 | + | ||
610 | + /** | ||
611 | + * Returns event method temp file. | ||
612 | + * | ||
613 | + * @return event method temp file | ||
614 | + */ | ||
615 | + public File getEventMethodTempFileHandle() { | ||
616 | + return eventMethodTempFileHandle; | ||
617 | + } | ||
618 | + | ||
619 | + /** | ||
620 | + * Sets event method temp file. | ||
621 | + * | ||
622 | + * @param eventMethodTempFileHandle event method temp file | ||
623 | + */ | ||
624 | + public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) { | ||
625 | + this.eventMethodTempFileHandle = eventMethodTempFileHandle; | ||
626 | + } | ||
627 | + | ||
628 | + /** | ||
629 | + * Returns event subject attribute temp file. | ||
630 | + * | ||
631 | + * @return event subject attribute temp file | ||
632 | + */ | ||
633 | + public File getEventSubjectAttributeTempFileHandle() { | ||
634 | + return eventSubjectAttributeTempFileHandle; | ||
635 | + } | ||
636 | + | ||
637 | + /** | ||
638 | + * Sets event subject attribute temp file. | ||
639 | + * | ||
640 | + * @param eventSubjectAttributeTempFileHandle event subject attribute temp file | ||
641 | + */ | ||
642 | + public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) { | ||
643 | + this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle; | ||
644 | + } | ||
645 | + | ||
646 | + /** | ||
647 | + * Returns event subject getter temp file. | ||
648 | + * | ||
649 | + * @return event subject getter temp file | ||
650 | + */ | ||
651 | + public File getEventSubjectGetterTempFileHandle() { | ||
652 | + return eventSubjectGetterTempFileHandle; | ||
653 | + } | ||
654 | + | ||
655 | + /** | ||
656 | + * Sets event subject getter temp file. | ||
657 | + * | ||
658 | + * @param eventSubjectGetterTempFileHandle event subject getter temp file | ||
659 | + */ | ||
660 | + public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) { | ||
661 | + this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle; | ||
662 | + } | ||
663 | + | ||
664 | + /** | ||
665 | + * Returns event subject setter temp file. | ||
666 | + * | ||
667 | + * @return event subject setter temp file | ||
668 | + */ | ||
669 | + public File getEventSubjectSetterTempFileHandle() { | ||
670 | + return eventSubjectSetterTempFileHandle; | ||
671 | + } | ||
672 | + | ||
673 | + /** | ||
674 | + * Sets event subject setter temp file. | ||
675 | + * | ||
676 | + * @param eventSubjectSetterTempFileHandle event subject setter temp file | ||
677 | + */ | ||
678 | + public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) { | ||
679 | + this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle; | ||
680 | + } | ||
681 | + | ||
682 | + /** | ||
683 | + * Adds java snippet for events to event subject file. | ||
684 | + * | ||
685 | + * @param curNode current node | ||
686 | + * @param pluginConfig plugin configurations | ||
687 | + * @throws IOException when fails to do IO operations | ||
688 | + */ | ||
689 | + public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) throws IOException { | ||
690 | + | ||
691 | + String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(), | ||
692 | + pluginConfig.getConflictResolver())); | ||
693 | + | ||
694 | + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(), | ||
695 | + getCapitalCase(currentInfo)); | ||
696 | + | ||
697 | + JavaAttributeInfo javaAttributeInfo = | ||
698 | + getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo), | ||
699 | + null, false, false); | ||
700 | + | ||
701 | + /*Adds java info for event in respective temp files.*/ | ||
702 | + addEventEnum(currentInfo, pluginConfig); | ||
703 | + addEventSubjectAttribute(javaAttributeInfo, pluginConfig); | ||
704 | + addEventSubjectGetter(javaAttributeInfo, pluginConfig); | ||
705 | + addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo); | ||
706 | + } | ||
707 | + | ||
708 | + /*Adds event to enum temp file.*/ | ||
709 | + private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException { | ||
710 | + appendToFile(getEventEnumTempFileHandle(), | ||
711 | + getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION | ||
712 | + + notificationName.toUpperCase() + COMMA + NEW_LINE); | ||
713 | + } | ||
714 | + | ||
715 | + /*Adds event method in event class*/ | ||
716 | + private void addEnumMethod(String eventClassname, String className) throws IOException { | ||
717 | + appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className)); | ||
718 | + } | ||
719 | + | ||
720 | + /*Adds event method contents to event file.*/ | ||
721 | + private static String getEventFileContents(String eventClassname, String classname) { | ||
722 | + return "\n" + | ||
723 | + " /**\n" + | ||
724 | + " * Creates " + classname + " event with type and subject.\n" + | ||
725 | + " *\n" + | ||
726 | + " * @param type event type\n" + | ||
727 | + " * @param subject subject " + classname + "\n" + | ||
728 | + " */\n" + | ||
729 | + " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" + | ||
730 | + " super(type, subject);\n" + | ||
731 | + " }\n" + | ||
732 | + "\n" + | ||
733 | + " /**\n" + | ||
734 | + " * Creates " + classname + " event with type, subject and time.\n" + | ||
735 | + " *\n" + | ||
736 | + " * @param type event type\n" + | ||
737 | + " * @param subject subject " + classname + "\n" + | ||
738 | + " * @param time time of event\n" + | ||
739 | + " */\n" + | ||
740 | + " public " + eventClassname + "(Type type, " + getCapitalCase(classname) | ||
741 | + + " subject, long time) {\n" + | ||
742 | + " super(type, subject, time);\n" + | ||
743 | + " }\n" + | ||
744 | + "\n"; | ||
745 | + } | ||
746 | + | ||
747 | + /*Adds events to event subject file.*/ | ||
748 | + private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) | ||
749 | + throws IOException { | ||
750 | + appendToFile(getEventSubjectAttributeTempFileHandle(), | ||
751 | + FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig)); | ||
752 | + } | ||
753 | + | ||
754 | + /*Adds getter method for event in event subject class.*/ | ||
755 | + private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException { | ||
756 | + appendToFile(getEventSubjectGetterTempFileHandle(), | ||
757 | + getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) | ||
758 | + + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE); | ||
759 | + } | ||
760 | + | ||
761 | + /*Adds setter method for event in event subject class.*/ | ||
762 | + private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className) | ||
763 | + throws IOException { | ||
764 | + appendToFile(getEventSubjectSetterTempFileHandle(), | ||
765 | + getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) | ||
766 | + + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE); | ||
767 | + } | ||
768 | + | ||
769 | + /** | ||
770 | + * Returns a temporary file handle for the event's file type. | ||
771 | + * | ||
772 | + * @param fileName file name | ||
773 | + * @return temporary file handle | ||
774 | + * @throws IOException when fails to create new file handle | ||
775 | + */ | ||
776 | + private File getJavaFileHandle(YangNode curNode, String name) | ||
777 | + throws IOException { | ||
778 | + | ||
779 | + JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | ||
780 | + | ||
781 | + return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION, | ||
782 | + parentInfo); | ||
783 | + } | ||
784 | + | ||
785 | + /** | ||
786 | + * Returns the directory path. | ||
787 | + * | ||
788 | + * @return directory path | ||
789 | + */ | ||
790 | + private String getDirPath(JavaFileInfo parentInfo) { | ||
791 | + return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase(); | ||
792 | + } | ||
302 | } | 793 | } | ... | ... |
... | @@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangType; | ... | @@ -26,6 +26,7 @@ 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.datamodel.YangDataTypes.DERIVED; |
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
... | @@ -196,9 +197,10 @@ public class TempJavaTypeFragmentFiles | ... | @@ -196,9 +197,10 @@ public class TempJavaTypeFragmentFiles |
196 | * | 197 | * |
197 | * @param yangTypeHolder YANG java data model node which has type info, eg union / | 198 | * @param yangTypeHolder YANG java data model node which has type info, eg union / |
198 | * typedef | 199 | * typedef |
200 | + * @param pluginConfig plugin configurations for naming conventions | ||
199 | * @throws IOException IO operation fail | 201 | * @throws IOException IO operation fail |
200 | */ | 202 | */ |
201 | - public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder) | 203 | + public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig) |
202 | throws IOException { | 204 | throws IOException { |
203 | 205 | ||
204 | List<YangType<?>> typeList = yangTypeHolder.getTypeList(); | 206 | List<YangType<?>> typeList = yangTypeHolder.getTypeList(); |
... | @@ -208,18 +210,19 @@ public class TempJavaTypeFragmentFiles | ... | @@ -208,18 +210,19 @@ public class TempJavaTypeFragmentFiles |
208 | throw new TranslatorException("Type does not have Java info"); | 210 | throw new TranslatorException("Type does not have Java info"); |
209 | } | 211 | } |
210 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; | 212 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; |
211 | - javaType.updateJavaQualifiedInfo(); | 213 | + javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver()); |
212 | String typeName = javaType.getDataTypeName(); | 214 | String typeName = javaType.getDataTypeName(); |
213 | 215 | ||
214 | if (javaType.getDataType().equals(DERIVED)) { | 216 | if (javaType.getDataType().equals(DERIVED)) { |
215 | - typeName = getCamelCase(typeName, null); | 217 | + typeName = getCamelCase(typeName, pluginConfig.getConflictResolver()); |
216 | } | 218 | } |
217 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 219 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
218 | javaType.getJavaQualifiedInfo(), | 220 | javaType.getJavaQualifiedInfo(), |
219 | typeName, javaType, | 221 | typeName, javaType, |
220 | getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), | 222 | getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), |
221 | false); | 223 | false); |
222 | - addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo); | 224 | + addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo, |
225 | + pluginConfig); | ||
223 | } | 226 | } |
224 | } | 227 | } |
225 | } | 228 | } |
... | @@ -231,18 +234,20 @@ public class TempJavaTypeFragmentFiles | ... | @@ -231,18 +234,20 @@ public class TempJavaTypeFragmentFiles |
231 | * @param hasType the node for which the type is being added as an attribute | 234 | * @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 | 235 | * @param javaAttributeInfo the attribute info that needs to be added to |
233 | * temporary files | 236 | * temporary files |
237 | + * @param pluginConfig plugin configurations | ||
234 | * @throws IOException IO operation fail | 238 | * @throws IOException IO operation fail |
235 | */ | 239 | */ |
236 | - private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo) | 240 | + private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo, |
241 | + YangPluginConfig pluginConfig) | ||
237 | throws IOException { | 242 | throws IOException { |
238 | 243 | ||
239 | - super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | 244 | + super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig); |
240 | 245 | ||
241 | if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) { | 246 | if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) { |
242 | - addOfStringMethod(javaAttributeInfo); | 247 | + addOfStringMethod(javaAttributeInfo, pluginConfig); |
243 | } | 248 | } |
244 | if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { | 249 | if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
245 | - addTypeConstructor(javaAttributeInfo); | 250 | + addTypeConstructor(javaAttributeInfo, pluginConfig); |
246 | } | 251 | } |
247 | } | 252 | } |
248 | 253 | ||
... | @@ -250,24 +255,26 @@ public class TempJavaTypeFragmentFiles | ... | @@ -250,24 +255,26 @@ public class TempJavaTypeFragmentFiles |
250 | * Adds type constructor. | 255 | * Adds type constructor. |
251 | * | 256 | * |
252 | * @param attr attribute info | 257 | * @param attr attribute info |
258 | + * @param pluginConfig plugin configurations | ||
253 | * @throws IOException when fails to append to temporary file | 259 | * @throws IOException when fails to append to temporary file |
254 | */ | 260 | */ |
255 | - private void addTypeConstructor(JavaAttributeInfo attr) | 261 | + private void addTypeConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
256 | throws IOException { | 262 | throws IOException { |
257 | appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr, | 263 | appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr, |
258 | - getGeneratedJavaClassName()) + NEW_LINE); | 264 | + getGeneratedJavaClassName(), pluginConfig) + NEW_LINE); |
259 | } | 265 | } |
260 | 266 | ||
261 | /** | 267 | /** |
262 | * Adds of string for type. | 268 | * Adds of string for type. |
263 | * | 269 | * |
264 | * @param attr attribute info | 270 | * @param attr attribute info |
271 | + * @param pluginConfig plugin configurations | ||
265 | * @throws IOException when fails to append to temporary file | 272 | * @throws IOException when fails to append to temporary file |
266 | */ | 273 | */ |
267 | - private void addOfStringMethod(JavaAttributeInfo attr) | 274 | + private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
268 | throws IOException { | 275 | throws IOException { |
269 | appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, | 276 | appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, |
270 | - getGeneratedJavaClassName()) | 277 | + getGeneratedJavaClassName(), pluginConfig) |
271 | + NEW_LINE); | 278 | + NEW_LINE); |
272 | } | 279 | } |
273 | 280 | ... | ... |
... | @@ -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 | } | ... | ... |
... | @@ -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,23 @@ public class YangJavaLeaf | ... | @@ -63,4 +65,23 @@ 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 | + public YangToJavaNamingConflictUtil getConflictResolveConfig() { | ||
75 | + return conflictResolveConfig; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Sets java naming conflict resolve configurations. | ||
80 | + * | ||
81 | + * @param conflictResolveConfig java naming conflict resolve configurations | ||
82 | + */ | ||
83 | + public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) { | ||
84 | + this.conflictResolveConfig = conflictResolveConfig; | ||
85 | + } | ||
86 | + | ||
66 | } | 87 | } | ... | ... |
... | @@ -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 | /** |
... | @@ -121,6 +140,15 @@ public class YangJavaModule | ... | @@ -121,6 +140,15 @@ public class YangJavaModule |
121 | */ | 140 | */ |
122 | @Override | 141 | @Override |
123 | public void generateCodeExit() throws TranslatorException { | 142 | public void generateCodeExit() throws TranslatorException { |
143 | + /** | ||
144 | + * As part of the notification support the following files needs to be generated. | ||
145 | + * 1) Subject of the notification(event), this is simple interface with builder class. | ||
146 | + * 2) Event class extending "AbstractEvent" and defining event type enum. | ||
147 | + * 3) Event listener interface extending "EventListener". | ||
148 | + * 4) Event subject class. | ||
149 | + * | ||
150 | + * The manager class needs to extend the "ListenerRegistry". | ||
151 | + */ | ||
124 | try { | 152 | try { |
125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); | 153 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); |
126 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + | 154 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + |
... | @@ -129,4 +157,53 @@ public class YangJavaModule | ... | @@ -129,4 +157,53 @@ public class YangJavaModule |
129 | throw new TranslatorException("Failed to generate code for module node " + this.getName()); | 157 | throw new TranslatorException("Failed to generate code for module node " + this.getName()); |
130 | } | 158 | } |
131 | } | 159 | } |
160 | + | ||
161 | + /** | ||
162 | + * Returns notifications node list. | ||
163 | + * | ||
164 | + * @return notification nodes | ||
165 | + */ | ||
166 | + public List<YangNode> getNotificationNodes() { | ||
167 | + return notificationNodes; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Sets notifications list. | ||
172 | + * | ||
173 | + * @param notificationNodes notification list | ||
174 | + */ | ||
175 | + private void setNotificationNodes(List<YangNode> notificationNodes) { | ||
176 | + this.notificationNodes = notificationNodes; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Adds to notification node list. | ||
181 | + * | ||
182 | + * @param curNode notification node | ||
183 | + */ | ||
184 | + private void addToNotificaitonList(YangNode curNode) { | ||
185 | + getNotificationNodes().add(curNode); | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Checks if there is any rpc defined in the module or sub-module. | ||
190 | + * | ||
191 | + * @param rootNode root node of the data model | ||
192 | + * @return status of rpc's existence | ||
193 | + */ | ||
194 | + public boolean isNotificationChildNodePresent(YangNode rootNode) { | ||
195 | + YangNode childNode = rootNode.getChild(); | ||
196 | + | ||
197 | + while (childNode != null) { | ||
198 | + if (childNode instanceof YangNotification) { | ||
199 | + addToNotificaitonList(childNode); | ||
200 | + } | ||
201 | + childNode = childNode.getNextSibling(); | ||
202 | + } | ||
203 | + | ||
204 | + if (!getNotificationNodes().isEmpty()) { | ||
205 | + return true; | ||
206 | + } | ||
207 | + return false; | ||
208 | + } | ||
132 | } | 209 | } | ... | ... |
... | @@ -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 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
... | @@ -135,6 +135,7 @@ public class YangJavaRpc | ... | @@ -135,6 +135,7 @@ public class YangJavaRpc |
135 | try { | 135 | try { |
136 | ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() | 136 | ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() |
137 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, | 137 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, |
138 | + ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(), | ||
138 | ((YangNode) this).getName()); | 139 | ((YangNode) this).getName()); |
139 | } catch (IOException e) { | 140 | } catch (IOException e) { |
140 | throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); | 141 | throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); | ... | ... |
... | @@ -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 | /** |
... | @@ -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 confilictResolver) { |
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, confilictResolver); |
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, | ... | ... |
... | @@ -49,6 +49,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; | ... | @@ -49,6 +49,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; |
49 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
50 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; | 50 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
51 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
52 | +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN; | ||
52 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; | 55 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; |
... | @@ -58,6 +59,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SHORT; | ... | @@ -58,6 +59,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
58 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; |
59 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
60 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 61 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
62 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS; | ||
63 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS; | ||
64 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS; | ||
65 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG; | ||
61 | 66 | ||
62 | /** | 67 | /** |
63 | * Represents java data types info corresponding to YANG type. | 68 | * Represents java data types info corresponding to YANG type. |
... | @@ -97,8 +102,10 @@ public final class AttributesJavaDataType { | ... | @@ -97,8 +102,10 @@ public final class AttributesJavaDataType { |
97 | return LONG; | 102 | return LONG; |
98 | case UINT64: | 103 | case UINT64: |
99 | return BIG_INTEGER; | 104 | return BIG_INTEGER; |
105 | + case BINARY: | ||
106 | + return YANG_BINARY_CLASS; | ||
100 | case DECIMAL64: | 107 | case DECIMAL64: |
101 | - //TODO: DECIMAL64. | 108 | + return YANG_DECIMAL64_CLASS; |
102 | case STRING: | 109 | case STRING: |
103 | return STRING_DATA_TYPE; | 110 | return STRING_DATA_TYPE; |
104 | case BOOLEAN: | 111 | case BOOLEAN: |
... | @@ -136,18 +143,16 @@ public final class AttributesJavaDataType { | ... | @@ -136,18 +143,16 @@ public final class AttributesJavaDataType { |
136 | return LONG_WRAPPER + PERIOD + PARSE_LONG; | 143 | return LONG_WRAPPER + PERIOD + PARSE_LONG; |
137 | case UINT64: | 144 | case UINT64: |
138 | return NEW + SPACE + BIG_INTEGER; | 145 | return NEW + SPACE + BIG_INTEGER; |
139 | - case DECIMAL64: | ||
140 | - //TODO: DECIMAL64. | ||
141 | case STRING: | 146 | case STRING: |
142 | return EMPTY_STRING; | 147 | return EMPTY_STRING; |
148 | + case EMPTY: | ||
143 | case BOOLEAN: | 149 | case BOOLEAN: |
144 | - return BOOLEAN_DATA_TYPE; | 150 | + return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN; |
145 | - case ENUMERATION: | 151 | + case DECIMAL64: |
146 | - //TODO:ENUMERATION. | ||
147 | case BITS: | 152 | case BITS: |
148 | - //TODO:BITS | ||
149 | case BINARY: | 153 | case BINARY: |
150 | - //TODO:BINARY | 154 | + case UNION: |
155 | + case ENUMERATION: | ||
151 | case DERIVED: | 156 | case DERIVED: |
152 | return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; | 157 | return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; |
153 | default: | 158 | default: |
... | @@ -160,9 +165,11 @@ public final class AttributesJavaDataType { | ... | @@ -160,9 +165,11 @@ public final class AttributesJavaDataType { |
160 | * | 165 | * |
161 | * @param yangType YANG type | 166 | * @param yangType YANG type |
162 | * @param isListAttr if the attribute need to be a list | 167 | * @param isListAttr if the attribute need to be a list |
168 | + * @param pluginConfig plugin configurations | ||
163 | * @return java import class | 169 | * @return java import class |
164 | */ | 170 | */ |
165 | - public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) { | 171 | + public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr, |
172 | + YangToJavaNamingConflictUtil pluginConfig) { | ||
166 | 173 | ||
167 | YangDataTypes type = yangType.getDataType(); | 174 | YangDataTypes type = yangType.getDataType(); |
168 | 175 | ||
... | @@ -185,21 +192,19 @@ public final class AttributesJavaDataType { | ... | @@ -185,21 +192,19 @@ public final class AttributesJavaDataType { |
185 | case UINT64: | 192 | case UINT64: |
186 | return BIG_INTEGER; | 193 | return BIG_INTEGER; |
187 | case DECIMAL64: | 194 | case DECIMAL64: |
188 | - //TODO: DECIMAL64. | 195 | + return YANG_DECIMAL64_CLASS; |
189 | - break; | ||
190 | case STRING: | 196 | case STRING: |
191 | return STRING_DATA_TYPE; | 197 | return STRING_DATA_TYPE; |
192 | case BOOLEAN: | 198 | case BOOLEAN: |
193 | return BOOLEAN_WRAPPER; | 199 | return BOOLEAN_WRAPPER; |
194 | case ENUMERATION: | 200 | case ENUMERATION: |
195 | return getCapitalCase( | 201 | return getCapitalCase( |
196 | - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); | 202 | + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), |
203 | + pluginConfig)); | ||
197 | case BITS: | 204 | case BITS: |
198 | - //TODO:BITS | 205 | + return YANG_BITS_CLASS; |
199 | - break; | ||
200 | case BINARY: | 206 | case BINARY: |
201 | - //TODO:BINARY | 207 | + return YANG_BINARY_CLASS; |
202 | - break; | ||
203 | case LEAFREF: | 208 | case LEAFREF: |
204 | //TODO:LEAFREF | 209 | //TODO:LEAFREF |
205 | break; | 210 | break; |
... | @@ -210,11 +215,13 @@ public final class AttributesJavaDataType { | ... | @@ -210,11 +215,13 @@ public final class AttributesJavaDataType { |
210 | return BOOLEAN_WRAPPER; | 215 | return BOOLEAN_WRAPPER; |
211 | case UNION: | 216 | case UNION: |
212 | return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), | 217 | return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), |
213 | - null)); | 218 | + pluginConfig)); |
214 | case INSTANCE_IDENTIFIER: | 219 | case INSTANCE_IDENTIFIER: |
215 | //TODO:INSTANCE_IDENTIFIER | 220 | //TODO:INSTANCE_IDENTIFIER |
221 | + break; | ||
216 | case DERIVED: | 222 | case DERIVED: |
217 | - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); | 223 | + return getCapitalCase( |
224 | + getCamelCase(yangType.getDataTypeName(), pluginConfig)); | ||
218 | default: | 225 | default: |
219 | throw new TranslatorException("given data type is not supported."); | 226 | throw new TranslatorException("given data type is not supported."); |
220 | } | 227 | } |
... | @@ -223,19 +230,17 @@ public final class AttributesJavaDataType { | ... | @@ -223,19 +230,17 @@ public final class AttributesJavaDataType { |
223 | case UINT64: | 230 | case UINT64: |
224 | return BIG_INTEGER; | 231 | return BIG_INTEGER; |
225 | case DECIMAL64: | 232 | case DECIMAL64: |
226 | - //TODO: DECIMAL64. | 233 | + return YANG_DECIMAL64_CLASS; |
227 | - break; | ||
228 | case STRING: | 234 | case STRING: |
229 | return STRING_DATA_TYPE; | 235 | return STRING_DATA_TYPE; |
230 | case ENUMERATION: | 236 | case ENUMERATION: |
231 | return getCapitalCase( | 237 | return getCapitalCase( |
232 | - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); | 238 | + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), |
239 | + pluginConfig)); | ||
233 | case BITS: | 240 | case BITS: |
234 | - //TODO:BITS | 241 | + return YANG_BITS_CLASS; |
235 | - break; | ||
236 | case BINARY: | 242 | case BINARY: |
237 | - //TODO:BINARY | 243 | + return YANG_BINARY_CLASS; |
238 | - break; | ||
239 | case LEAFREF: | 244 | case LEAFREF: |
240 | //TODO:LEAFREF | 245 | //TODO:LEAFREF |
241 | break; | 246 | break; |
... | @@ -243,16 +248,16 @@ public final class AttributesJavaDataType { | ... | @@ -243,16 +248,16 @@ public final class AttributesJavaDataType { |
243 | //TODO:IDENTITYREF | 248 | //TODO:IDENTITYREF |
244 | break; | 249 | break; |
245 | case EMPTY: | 250 | case EMPTY: |
246 | - //TODO:EMPTY | 251 | + return BOOLEAN_DATA_TYPE; |
247 | - break; | ||
248 | case UNION: | 252 | case UNION: |
249 | return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), | 253 | return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), |
250 | - null)); | 254 | + pluginConfig)); |
251 | case INSTANCE_IDENTIFIER: | 255 | case INSTANCE_IDENTIFIER: |
252 | //TODO:INSTANCE_IDENTIFIER | 256 | //TODO:INSTANCE_IDENTIFIER |
253 | break; | 257 | break; |
254 | case DERIVED: | 258 | case DERIVED: |
255 | - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); | 259 | + return getCapitalCase( |
260 | + getCamelCase(yangType.getDataTypeName(), pluginConfig)); | ||
256 | default: | 261 | default: |
257 | return null; | 262 | return null; |
258 | } | 263 | } |
... | @@ -283,29 +288,22 @@ public final class AttributesJavaDataType { | ... | @@ -283,29 +288,22 @@ public final class AttributesJavaDataType { |
283 | case UINT32: | 288 | case UINT32: |
284 | case STRING: | 289 | case STRING: |
285 | case BOOLEAN: | 290 | case BOOLEAN: |
291 | + case EMPTY: | ||
286 | return JAVA_LANG; | 292 | return JAVA_LANG; |
287 | case UINT64: | 293 | case UINT64: |
288 | return JAVA_MATH; | 294 | return JAVA_MATH; |
289 | - case DECIMAL64: | ||
290 | - //TODO: DECIMAL64. | ||
291 | - break; | ||
292 | case ENUMERATION: | 295 | case ENUMERATION: |
293 | return getEnumsPackage(yangType); | 296 | return getEnumsPackage(yangType); |
297 | + case DECIMAL64: | ||
294 | case BITS: | 298 | case BITS: |
295 | - //TODO:BITS | ||
296 | - break; | ||
297 | case BINARY: | 299 | case BINARY: |
298 | - //TODO:BINARY | 300 | + return YANG_TYPES_PKG; |
299 | - break; | ||
300 | case LEAFREF: | 301 | case LEAFREF: |
301 | //TODO:LEAFREF | 302 | //TODO:LEAFREF |
302 | break; | 303 | break; |
303 | case IDENTITYREF: | 304 | case IDENTITYREF: |
304 | //TODO:IDENTITYREF | 305 | //TODO:IDENTITYREF |
305 | break; | 306 | break; |
306 | - case EMPTY: | ||
307 | - //TODO:EMPTY | ||
308 | - break; | ||
309 | case UNION: | 307 | case UNION: |
310 | return getUnionPackage(yangType); | 308 | return getUnionPackage(yangType); |
311 | case INSTANCE_IDENTIFIER: | 309 | case INSTANCE_IDENTIFIER: |
... | @@ -320,19 +318,14 @@ public final class AttributesJavaDataType { | ... | @@ -320,19 +318,14 @@ public final class AttributesJavaDataType { |
320 | switch (type) { | 318 | switch (type) { |
321 | case UINT64: | 319 | case UINT64: |
322 | return JAVA_MATH; | 320 | return JAVA_MATH; |
323 | - case DECIMAL64: | ||
324 | - //TODO: DECIMAL64 | ||
325 | - break; | ||
326 | case STRING: | 321 | case STRING: |
327 | return JAVA_LANG; | 322 | return JAVA_LANG; |
328 | case ENUMERATION: | 323 | case ENUMERATION: |
329 | return getEnumsPackage(yangType); | 324 | return getEnumsPackage(yangType); |
325 | + case DECIMAL64: | ||
330 | case BITS: | 326 | case BITS: |
331 | - //TODO:BITS | ||
332 | - break; | ||
333 | case BINARY: | 327 | case BINARY: |
334 | - //TODO:BINARY | 328 | + return YANG_TYPES_PKG; |
335 | - break; | ||
336 | case LEAFREF: | 329 | case LEAFREF: |
337 | //TODO:LEAFREF | 330 | //TODO:LEAFREF |
338 | break; | 331 | break; |
... | @@ -340,8 +333,7 @@ public final class AttributesJavaDataType { | ... | @@ -340,8 +333,7 @@ public final class AttributesJavaDataType { |
340 | //TODO:IDENTITYREF | 333 | //TODO:IDENTITYREF |
341 | break; | 334 | break; |
342 | case EMPTY: | 335 | case EMPTY: |
343 | - //TODO:EMPTY | 336 | + return JAVA_LANG; |
344 | - break; | ||
345 | case UNION: | 337 | case UNION: |
346 | return getUnionPackage(yangType); | 338 | return getUnionPackage(yangType); |
347 | case INSTANCE_IDENTIFIER: | 339 | case INSTANCE_IDENTIFIER: | ... | ... |
... | @@ -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; |
... | @@ -56,6 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ... | @@ -56,6 +55,7 @@ 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; |
57 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | 56 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
58 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
58 | +import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT; | ||
59 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 59 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
60 | 60 | ||
61 | /** | 61 | /** |
... | @@ -95,8 +95,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -95,8 +95,6 @@ public final class ClassDefinitionGenerator { |
95 | return getTypeClassDefinition(yangName); | 95 | return getTypeClassDefinition(yangName); |
96 | case GENERATE_ENUM_CLASS: | 96 | case GENERATE_ENUM_CLASS: |
97 | return getEnumClassDefinition(yangName); | 97 | return getEnumClassDefinition(yangName); |
98 | - case GENERATE_EVENT_LISTENER_INTERFACE: | ||
99 | - return getEventListenerDefinition(yangName); | ||
100 | default: | 98 | default: |
101 | return null; | 99 | return null; |
102 | } | 100 | } |
... | @@ -123,9 +121,12 @@ public final class ClassDefinitionGenerator { | ... | @@ -123,9 +121,12 @@ public final class ClassDefinitionGenerator { |
123 | case GENERATE_SERVICE_AND_MANAGER: | 121 | case GENERATE_SERVICE_AND_MANAGER: |
124 | return getRpcInterfaceDefinition(yangName, curNode); | 122 | return getRpcInterfaceDefinition(yangName, curNode); |
125 | case GENERATE_EVENT_CLASS: | 123 | case GENERATE_EVENT_CLASS: |
126 | - String eventName = getCapitalCase(((JavaFileInfoContainer) curNode) | 124 | + String eventName = yangName + SUBJECT; |
127 | - .getJavaFileInfo().getJavaName()); | ||
128 | return getEventDefinition(yangName, eventName); | 125 | return getEventDefinition(yangName, eventName); |
126 | + case GENERATE_EVENT_LISTENER_INTERFACE: | ||
127 | + return getEventListenerDefinition(yangName); | ||
128 | + case GENERATE_EVENT_SUBJECT_CLASS: | ||
129 | + return getClassDefinition(yangName); | ||
129 | default: | 130 | default: |
130 | return null; | 131 | return null; |
131 | } | 132 | } |
... | @@ -183,7 +184,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -183,7 +184,6 @@ public final class ClassDefinitionGenerator { |
183 | * Returns builder file class definition. | 184 | * Returns builder file class definition. |
184 | * | 185 | * |
185 | * @param yangName file name | 186 | * @param yangName file name |
186 | - * @param genFileTypes | ||
187 | * @return definition | 187 | * @return definition |
188 | */ | 188 | */ |
189 | private static String getBuilderClassDefinition(String yangName) { | 189 | private static String getBuilderClassDefinition(String yangName) { |
... | @@ -198,8 +198,18 @@ public final class ClassDefinitionGenerator { | ... | @@ -198,8 +198,18 @@ public final class ClassDefinitionGenerator { |
198 | * @return definition | 198 | * @return definition |
199 | */ | 199 | */ |
200 | private static String getImplClassDefinition(String yangName) { | 200 | private static String getImplClassDefinition(String yangName) { |
201 | - return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName | 201 | + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE |
202 | - + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 202 | + + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Returns impl file class definition. | ||
207 | + * | ||
208 | + * @param yangName file name | ||
209 | + * @return definition | ||
210 | + */ | ||
211 | + private static String getClassDefinition(String yangName) { | ||
212 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
203 | } | 213 | } |
204 | 214 | ||
205 | /** | 215 | /** |
... | @@ -244,14 +254,14 @@ public final class ClassDefinitionGenerator { | ... | @@ -244,14 +254,14 @@ public final class ClassDefinitionGenerator { |
244 | 254 | ||
245 | if (yangName.contains(SERVICE)) { | 255 | if (yangName.contains(SERVICE)) { |
246 | String[] strArray = yangName.split(SERVICE); | 256 | String[] strArray = yangName.split(SERVICE); |
247 | - return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION | 257 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION |
248 | + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA | 258 | + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA |
249 | + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE | 259 | + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE |
250 | + OPEN_CURLY_BRACKET + NEW_LINE; | 260 | + OPEN_CURLY_BRACKET + NEW_LINE; |
251 | } | 261 | } |
252 | - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION | 262 | + 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 | 263 | + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE |
254 | - + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE | 264 | + + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE |
255 | + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET | 265 | + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET |
256 | + NEW_LINE; | 266 | + NEW_LINE; |
257 | } | 267 | } | ... | ... |
... | @@ -145,10 +145,11 @@ public final class JavaCodeSnippetGen { | ... | @@ -145,10 +145,11 @@ public final class JavaCodeSnippetGen { |
145 | * | 145 | * |
146 | * @param name name of attribute | 146 | * @param name name of attribute |
147 | * @param value value of the enum | 147 | * @param value value of the enum |
148 | + * @param pluginConfig plugin configurations | ||
148 | * @return string for enum's attribute | 149 | * @return string for enum's attribute |
149 | */ | 150 | */ |
150 | - public static String generateEnumAttributeString(String name, int value) { | 151 | + public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) { |
151 | - return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION | 152 | + return getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig) + FOUR_SPACE_INDENTATION |
152 | + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS | 153 | + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS |
153 | + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; | 154 | + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; |
154 | } | 155 | } | ... | ... |
... | @@ -27,18 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ... | @@ -27,18 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 28 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
29 | 29 | ||
30 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement; |
32 | -import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
33 | -import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
34 | -import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
35 | -import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; | ||
36 | -import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ||
37 | -import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; | ||
38 | -import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | ||
39 | -import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
40 | -import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
41 | -import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
42 | 31 | ||
43 | /** | 32 | /** |
44 | * Represent the extends list for generated java classes. It holds the class details which needs | 33 | * Represent the extends list for generated java classes. It holds the class details which needs |
... | @@ -87,6 +76,7 @@ public class JavaExtendsListHolder { | ... | @@ -87,6 +76,7 @@ public class JavaExtendsListHolder { |
87 | if (!fileInfo.getPackage().equals(info.getPkgInfo())) { | 76 | if (!fileInfo.getPackage().equals(info.getPkgInfo())) { |
88 | JavaImportData importData = getTempJavaFragement(node).getJavaImportData(); | 77 | JavaImportData importData = getTempJavaFragement(node).getJavaImportData(); |
89 | importData.addImportInfo(info); | 78 | importData.addImportInfo(info); |
79 | + | ||
90 | /*true means import should be added*/ | 80 | /*true means import should be added*/ |
91 | getExtendedClassStore().put(info, true); | 81 | getExtendedClassStore().put(info, true); |
92 | } | 82 | } |
... | @@ -95,33 +85,6 @@ public class JavaExtendsListHolder { | ... | @@ -95,33 +85,6 @@ public class JavaExtendsListHolder { |
95 | } | 85 | } |
96 | 86 | ||
97 | /** | 87 | /** |
98 | - * Returns extends string for class. | ||
99 | - * | ||
100 | - * @param genFileType generated file type | ||
101 | - * @param className class name | ||
102 | - * @param isNotificationPresent if notification node is present | ||
103 | - * @return extends string | ||
104 | - */ | ||
105 | - public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) { | ||
106 | - String extend = EXTEND + SPACE; | ||
107 | - if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) { | ||
108 | - extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE | ||
109 | - + className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE; | ||
110 | - } else { | ||
111 | - for (JavaQualifiedTypeInfo info : getExtendsList()) { | ||
112 | - if (info.getClassInfo().equals(className)) { | ||
113 | - if (!getExtendedClassStore().get(info)) { | ||
114 | - return extend + info.getClassInfo(); | ||
115 | - } else { | ||
116 | - return extend + info.getPkgInfo() + PERIOD + info.getClassInfo(); | ||
117 | - } | ||
118 | - } | ||
119 | - } | ||
120 | - } | ||
121 | - return null; | ||
122 | - } | ||
123 | - | ||
124 | - /** | ||
125 | * Returns extends list. | 88 | * Returns extends list. |
126 | * | 89 | * |
127 | * @return the extendsList | 90 | * @return the extendsList | ... | ... |
... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
29 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
30 | +import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; | ||
30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 31 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
31 | 32 | ||
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
... | @@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
38 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; | ||
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
... | @@ -44,6 +46,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -44,6 +46,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
49 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; | ||
50 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; | ||
51 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; | ||
52 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; | ||
53 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; | ||
47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; | 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
... | @@ -59,6 +66,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato | ... | @@ -59,6 +66,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato |
59 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute; | 66 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute; |
60 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; | 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
69 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod; | ||
70 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod; | ||
62 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; | 71 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; |
63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; | 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; |
64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
... | @@ -75,6 +84,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -75,6 +84,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; | 84 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; |
76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; | 85 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; | 86 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
87 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getEventEnumTypeStart; | ||
78 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; | 88 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; |
79 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
80 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 90 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
... | @@ -82,20 +92,22 @@ import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ... | @@ -82,20 +92,22 @@ import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
82 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 92 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
83 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; | 93 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; |
84 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | 94 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
95 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; | ||
85 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 96 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
86 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 97 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
87 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 98 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
99 | +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; | ||
88 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 100 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
89 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 101 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
90 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 102 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
91 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 103 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
92 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; | 104 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; |
105 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
93 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 106 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
94 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | 107 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
95 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
96 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 108 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
97 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; | ||
98 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 109 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
110 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; | ||
99 | 111 | ||
100 | /** | 112 | /** |
101 | * Representation of java file generator. | 113 | * Representation of java file generator. |
... | @@ -141,7 +153,7 @@ public final class JavaFileGenerator { | ... | @@ -141,7 +153,7 @@ public final class JavaFileGenerator { |
141 | + " while interface file generation"); | 153 | + " while interface file generation"); |
142 | } | 154 | } |
143 | } | 155 | } |
144 | - return file; | 156 | + return validateLineLength(file); |
145 | } | 157 | } |
146 | 158 | ||
147 | /** | 159 | /** |
... | @@ -157,11 +169,12 @@ public final class JavaFileGenerator { | ... | @@ -157,11 +169,12 @@ public final class JavaFileGenerator { |
157 | throws IOException { | 169 | throws IOException { |
158 | 170 | ||
159 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 171 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
172 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
160 | 173 | ||
161 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 174 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
162 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 175 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
163 | 176 | ||
164 | - initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path); | 177 | + initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path, pluginConfig); |
165 | List<String> methods = new ArrayList<>(); | 178 | List<String> methods = new ArrayList<>(); |
166 | if (isAttrPresent) { | 179 | if (isAttrPresent) { |
167 | try { | 180 | try { |
... | @@ -188,7 +201,7 @@ public final class JavaFileGenerator { | ... | @@ -188,7 +201,7 @@ public final class JavaFileGenerator { |
188 | */ | 201 | */ |
189 | methods.add( | 202 | methods.add( |
190 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 203 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
191 | - .addBuildMethodForInterface()); | 204 | + .addBuildMethodForInterface(pluginConfig)); |
192 | 205 | ||
193 | /** | 206 | /** |
194 | * Add getters and setters in builder interface. | 207 | * Add getters and setters in builder interface. |
... | @@ -198,7 +211,7 @@ public final class JavaFileGenerator { | ... | @@ -198,7 +211,7 @@ public final class JavaFileGenerator { |
198 | } | 211 | } |
199 | 212 | ||
200 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 213 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
201 | - return file; | 214 | + return validateLineLength(file); |
202 | } | 215 | } |
203 | 216 | ||
204 | /** | 217 | /** |
... | @@ -216,11 +229,12 @@ public final class JavaFileGenerator { | ... | @@ -216,11 +229,12 @@ public final class JavaFileGenerator { |
216 | throws IOException { | 229 | throws IOException { |
217 | 230 | ||
218 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 231 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
232 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
219 | 233 | ||
220 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 234 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
221 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 235 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
222 | 236 | ||
223 | - initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path); | 237 | + initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path, pluginConfig); |
224 | 238 | ||
225 | List<String> methods = new ArrayList<>(); | 239 | List<String> methods = new ArrayList<>(); |
226 | 240 | ||
... | @@ -265,7 +279,7 @@ public final class JavaFileGenerator { | ... | @@ -265,7 +279,7 @@ public final class JavaFileGenerator { |
265 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 279 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
266 | .addBuildMethodImpl()); | 280 | .addBuildMethodImpl()); |
267 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 281 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
268 | - .addDefaultConstructor(PUBLIC, BUILDER)); | 282 | + .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig)); |
269 | 283 | ||
270 | /** | 284 | /** |
271 | * Add methods in builder class. | 285 | * Add methods in builder class. |
... | @@ -273,7 +287,7 @@ public final class JavaFileGenerator { | ... | @@ -273,7 +287,7 @@ public final class JavaFileGenerator { |
273 | for (String method : methods) { | 287 | for (String method : methods) { |
274 | insertDataIntoJavaFile(file, method); | 288 | insertDataIntoJavaFile(file, method); |
275 | } | 289 | } |
276 | - return file; | 290 | + return validateLineLength(file); |
277 | } | 291 | } |
278 | 292 | ||
279 | /** | 293 | /** |
... | @@ -298,6 +312,10 @@ public final class JavaFileGenerator { | ... | @@ -298,6 +312,10 @@ public final class JavaFileGenerator { |
298 | 312 | ||
299 | List<String> methods = new ArrayList<>(); | 313 | List<String> methods = new ArrayList<>(); |
300 | 314 | ||
315 | + insertDataIntoJavaFile(file, LOGGER_STATEMENT); | ||
316 | + methods.add(addActivateMethod()); | ||
317 | + methods.add(addDeActivateMethod()); | ||
318 | + | ||
301 | try { | 319 | try { |
302 | if (isAttrPresent) { | 320 | if (isAttrPresent) { |
303 | /** | 321 | /** |
... | @@ -338,7 +356,7 @@ public final class JavaFileGenerator { | ... | @@ -338,7 +356,7 @@ public final class JavaFileGenerator { |
338 | for (String method : methods) { | 356 | for (String method : methods) { |
339 | insertDataIntoJavaFile(file, method); | 357 | insertDataIntoJavaFile(file, method); |
340 | } | 358 | } |
341 | - return file; | 359 | + return validateLineLength(file); |
342 | } | 360 | } |
343 | 361 | ||
344 | /** | 362 | /** |
... | @@ -354,11 +372,12 @@ public final class JavaFileGenerator { | ... | @@ -354,11 +372,12 @@ public final class JavaFileGenerator { |
354 | throws IOException { | 372 | throws IOException { |
355 | 373 | ||
356 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 374 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
375 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
357 | 376 | ||
358 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 377 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
359 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 378 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
360 | 379 | ||
361 | - initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); | 380 | + initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path, pluginConfig); |
362 | 381 | ||
363 | List<String> methods = new ArrayList<>(); | 382 | List<String> methods = new ArrayList<>(); |
364 | 383 | ||
... | @@ -398,10 +417,10 @@ public final class JavaFileGenerator { | ... | @@ -398,10 +417,10 @@ public final class JavaFileGenerator { |
398 | /** | 417 | /** |
399 | * Hash code method. | 418 | * Hash code method. |
400 | */ | 419 | */ |
401 | - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | 420 | + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
402 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, | 421 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
403 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 422 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
404 | - .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)))); | 423 | + .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING))); |
405 | /** | 424 | /** |
406 | * Equals method. | 425 | * Equals method. |
407 | */ | 426 | */ |
... | @@ -429,7 +448,8 @@ public final class JavaFileGenerator { | ... | @@ -429,7 +448,8 @@ public final class JavaFileGenerator { |
429 | /** | 448 | /** |
430 | * Constructor. | 449 | * Constructor. |
431 | */ | 450 | */ |
432 | - String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, | 451 | + String constructor = |
452 | + getConstructorStart(className, pluginConfig) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, | ||
433 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 453 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
434 | .getBeanTempFiles()); | 454 | .getBeanTempFiles()); |
435 | 455 | ||
... | @@ -456,7 +476,7 @@ public final class JavaFileGenerator { | ... | @@ -456,7 +476,7 @@ public final class JavaFileGenerator { |
456 | } | 476 | } |
457 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 477 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
458 | 478 | ||
459 | - return file; | 479 | + return validateLineLength(file); |
460 | } | 480 | } |
461 | 481 | ||
462 | /** | 482 | /** |
... | @@ -472,11 +492,12 @@ public final class JavaFileGenerator { | ... | @@ -472,11 +492,12 @@ public final class JavaFileGenerator { |
472 | throws IOException { | 492 | throws IOException { |
473 | 493 | ||
474 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 494 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
495 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
475 | 496 | ||
476 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 497 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
477 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 498 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
478 | 499 | ||
479 | - initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path); | 500 | + initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig); |
480 | 501 | ||
481 | List<String> methods = new ArrayList<>(); | 502 | List<String> methods = new ArrayList<>(); |
482 | 503 | ||
... | @@ -497,7 +518,7 @@ public final class JavaFileGenerator { | ... | @@ -497,7 +518,7 @@ public final class JavaFileGenerator { |
497 | * Default constructor. | 518 | * Default constructor. |
498 | */ | 519 | */ |
499 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 520 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
500 | - .addDefaultConstructor(PRIVATE, EMPTY_STRING)); | 521 | + .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
501 | 522 | ||
502 | try { | 523 | try { |
503 | 524 | ||
... | @@ -522,11 +543,11 @@ public final class JavaFileGenerator { | ... | @@ -522,11 +543,11 @@ public final class JavaFileGenerator { |
522 | /** | 543 | /** |
523 | * Hash code method. | 544 | * Hash code method. |
524 | */ | 545 | */ |
525 | - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | 546 | + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
526 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, | 547 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
527 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 548 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
528 | .getTypeTempFiles()) | 549 | .getTypeTempFiles()) |
529 | - .replace(NEW_LINE, EMPTY_STRING)))); | 550 | + .replace(NEW_LINE, EMPTY_STRING))); |
530 | 551 | ||
531 | /** | 552 | /** |
532 | * Equals method. | 553 | * Equals method. |
... | @@ -546,7 +567,7 @@ public final class JavaFileGenerator { | ... | @@ -546,7 +567,7 @@ public final class JavaFileGenerator { |
546 | /** | 567 | /** |
547 | * From string method. | 568 | * From string method. |
548 | */ | 569 | */ |
549 | - methods.add(getFromStringMethodSignature(className) | 570 | + methods.add(getFromStringMethodSignature(className, pluginConfig) |
550 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() | 571 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() |
551 | .getTypeTempFiles()) + getFromStringMethodClose()); | 572 | .getTypeTempFiles()) + getFromStringMethodClose()); |
552 | 573 | ||
... | @@ -560,7 +581,7 @@ public final class JavaFileGenerator { | ... | @@ -560,7 +581,7 @@ public final class JavaFileGenerator { |
560 | } | 581 | } |
561 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 582 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
562 | 583 | ||
563 | - return file; | 584 | + return validateLineLength(file); |
564 | } | 585 | } |
565 | 586 | ||
566 | /** | 587 | /** |
... | @@ -576,11 +597,12 @@ public final class JavaFileGenerator { | ... | @@ -576,11 +597,12 @@ public final class JavaFileGenerator { |
576 | throws IOException { | 597 | throws IOException { |
577 | 598 | ||
578 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 599 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
600 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
579 | 601 | ||
580 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 602 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
581 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 603 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
582 | 604 | ||
583 | - initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path); | 605 | + initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path, pluginConfig); |
584 | 606 | ||
585 | List<String> methods = new ArrayList<>(); | 607 | List<String> methods = new ArrayList<>(); |
586 | 608 | ||
... | @@ -601,7 +623,7 @@ public final class JavaFileGenerator { | ... | @@ -601,7 +623,7 @@ public final class JavaFileGenerator { |
601 | * Default constructor. | 623 | * Default constructor. |
602 | */ | 624 | */ |
603 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 625 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
604 | - .addDefaultConstructor(PRIVATE, EMPTY_STRING)); | 626 | + .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
605 | 627 | ||
606 | try { | 628 | try { |
607 | 629 | ||
... | @@ -626,11 +648,11 @@ public final class JavaFileGenerator { | ... | @@ -626,11 +648,11 @@ public final class JavaFileGenerator { |
626 | /** | 648 | /** |
627 | * Hash code method. | 649 | * Hash code method. |
628 | */ | 650 | */ |
629 | - methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | 651 | + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
630 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, | 652 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
631 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 653 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
632 | .getTypeTempFiles()) | 654 | .getTypeTempFiles()) |
633 | - .replace(NEW_LINE, EMPTY_STRING)))); | 655 | + .replace(NEW_LINE, EMPTY_STRING))); |
634 | 656 | ||
635 | /** | 657 | /** |
636 | * Equals method. | 658 | * Equals method. |
... | @@ -650,7 +672,7 @@ public final class JavaFileGenerator { | ... | @@ -650,7 +672,7 @@ public final class JavaFileGenerator { |
650 | /** | 672 | /** |
651 | * From string method. | 673 | * From string method. |
652 | */ | 674 | */ |
653 | - methods.add(getFromStringMethodSignature(className) | 675 | + methods.add(getFromStringMethodSignature(className, pluginConfig) |
654 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, | 676 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
655 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()) | 677 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()) |
656 | + getFromStringMethodClose()); | 678 | + getFromStringMethodClose()); |
... | @@ -665,7 +687,7 @@ public final class JavaFileGenerator { | ... | @@ -665,7 +687,7 @@ public final class JavaFileGenerator { |
665 | } | 687 | } |
666 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 688 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
667 | 689 | ||
668 | - return file; | 690 | + return validateLineLength(file); |
669 | } | 691 | } |
670 | 692 | ||
671 | /** | 693 | /** |
... | @@ -680,11 +702,12 @@ public final class JavaFileGenerator { | ... | @@ -680,11 +702,12 @@ public final class JavaFileGenerator { |
680 | throws IOException { | 702 | throws IOException { |
681 | 703 | ||
682 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 704 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
705 | + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | ||
683 | 706 | ||
684 | String className = javaFileInfo.getJavaName(); | 707 | String className = javaFileInfo.getJavaName(); |
685 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 708 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
686 | 709 | ||
687 | - initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path); | 710 | + initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path, pluginConfig); |
688 | /** | 711 | /** |
689 | * Add attribute strings. | 712 | * Add attribute strings. |
690 | */ | 713 | */ |
... | @@ -708,26 +731,26 @@ public final class JavaFileGenerator { | ... | @@ -708,26 +731,26 @@ public final class JavaFileGenerator { |
708 | /** | 731 | /** |
709 | * Add a constructor for enum. | 732 | * Add a constructor for enum. |
710 | */ | 733 | */ |
711 | - insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false) | 734 | + insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig) |
712 | + getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE); | 735 | + getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE); |
713 | 736 | ||
714 | TempJavaEnumerationFragmentFiles enumFragFiles = | 737 | TempJavaEnumerationFragmentFiles enumFragFiles = |
715 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 738 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
716 | .getEnumerationTempFiles(); | 739 | .getEnumerationTempFiles(); |
717 | insertDataIntoJavaFile(file, getEnumsOfMethod(className, | 740 | insertDataIntoJavaFile(file, getEnumsOfMethod(className, |
718 | - enumFragFiles.getJavaAttributeForEnum(), | 741 | + enumFragFiles.getJavaAttributeForEnum(pluginConfig), |
719 | enumFragFiles.getEnumSetJavaMap(), | 742 | enumFragFiles.getEnumSetJavaMap(), |
720 | - enumFragFiles.getEnumStringList()) | 743 | + enumFragFiles.getEnumStringList(), pluginConfig) |
721 | + NEW_LINE); | 744 | + NEW_LINE); |
722 | 745 | ||
723 | /** | 746 | /** |
724 | * Add a getter method for enum. | 747 | * Add a getter method for enum. |
725 | */ | 748 | */ |
726 | - insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false) | 749 | + insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig) |
727 | + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); | 750 | + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); |
728 | 751 | ||
729 | try { | 752 | try { |
730 | - insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className)) | 753 | + insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig) |
731 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, | 754 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
732 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 755 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
733 | .getEnumerationTempFiles()) | 756 | .getEnumerationTempFiles()) |
... | @@ -739,7 +762,7 @@ public final class JavaFileGenerator { | ... | @@ -739,7 +762,7 @@ public final class JavaFileGenerator { |
739 | 762 | ||
740 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 763 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
741 | 764 | ||
742 | - return file; | 765 | + return validateLineLength(file); |
743 | } | 766 | } |
744 | 767 | ||
745 | /** | 768 | /** |
... | @@ -797,7 +820,7 @@ public final class JavaFileGenerator { | ... | @@ -797,7 +820,7 @@ public final class JavaFileGenerator { |
797 | } | 820 | } |
798 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 821 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
799 | 822 | ||
800 | - return file; | 823 | + return validateLineLength(file); |
801 | } | 824 | } |
802 | 825 | ||
803 | /** | 826 | /** |
... | @@ -810,49 +833,28 @@ public final class JavaFileGenerator { | ... | @@ -810,49 +833,28 @@ public final class JavaFileGenerator { |
810 | */ | 833 | */ |
811 | public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { | 834 | public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { |
812 | 835 | ||
813 | - YangNode parent = curNode.getParent(); | ||
814 | - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | ||
815 | - | ||
816 | String className = | 836 | String className = |
817 | - getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) | 837 | + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
818 | + EVENT_STRING; | 838 | + EVENT_STRING; |
819 | 839 | ||
840 | + TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) | ||
841 | + .getTempJavaCodeFragmentFiles().getServiceTempFiles(); | ||
842 | + | ||
820 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); | 843 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); |
821 | - insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName())); | 844 | + try { |
822 | - insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 845 | + insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() + |
846 | + trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles), COMMA) | ||
847 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE); | ||
848 | + | ||
849 | + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles)); | ||
850 | + | ||
851 | + } catch (IOException e) { | ||
852 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
853 | + + " while event class file generation"); | ||
823 | } | 854 | } |
824 | 855 | ||
825 | - private static String getEventFileContents(String eventClassname, String classname) { | 856 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
826 | - return "\n" + | 857 | + validateLineLength(file); |
827 | - " public enum Type {\n" + | ||
828 | - " /**\n" + | ||
829 | - " * " + getCapitalCase(classname) + " notification.\n" + | ||
830 | - " */\n" + | ||
831 | - " " + classname.toUpperCase() + "_EVENT\n" + | ||
832 | - " }\n" + | ||
833 | - "\n" + | ||
834 | - " /**\n" + | ||
835 | - " * Creates " + classname + " event with type and subject.\n" + | ||
836 | - " *\n" + | ||
837 | - " * @param type event type\n" + | ||
838 | - " * @param subject subject " + classname + "\n" + | ||
839 | - " */\n" + | ||
840 | - " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" + | ||
841 | - " super(type, subject);\n" + | ||
842 | - " }\n" + | ||
843 | - "\n" + | ||
844 | - " /**\n" + | ||
845 | - " * Creates " + classname + " event with type, subject and time.\n" + | ||
846 | - " *\n" + | ||
847 | - " * @param type event type\n" + | ||
848 | - " * @param subject subject " + classname + "\n" + | ||
849 | - " * @param time time of event\n" + | ||
850 | - " */\n" + | ||
851 | - " public " + eventClassname + "(Type type, " + getCapitalCase(classname) | ||
852 | - + " subject, long time) {\n" + | ||
853 | - " super(type, subject, time);\n" + | ||
854 | - " }\n" + | ||
855 | - "\n"; | ||
856 | } | 858 | } |
857 | 859 | ||
858 | /** | 860 | /** |
... | @@ -865,15 +867,48 @@ public final class JavaFileGenerator { | ... | @@ -865,15 +867,48 @@ public final class JavaFileGenerator { |
865 | */ | 867 | */ |
866 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) | 868 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) |
867 | throws IOException { | 869 | throws IOException { |
868 | - YangNode parent = curNode.getParent(); | ||
869 | - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | ||
870 | 870 | ||
871 | String className = | 871 | String className = |
872 | - getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) | 872 | + getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
873 | + EVENT_LISTENER_STRING; | 873 | + EVENT_LISTENER_STRING; |
874 | - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
875 | 874 | ||
876 | - initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path); | 875 | + initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className); |
876 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | ||
877 | + validateLineLength(file); | ||
878 | + } | ||
879 | + | ||
880 | + /** | ||
881 | + * Generates event subject's file. | ||
882 | + * | ||
883 | + * @param file file handle | ||
884 | + * @param curNode current YANG node | ||
885 | + * @throws IOException when fails to do IO exceptions | ||
886 | + */ | ||
887 | + public static void generateEventSubjectFile(File file, YangNode curNode) | ||
888 | + throws IOException { | ||
889 | + | ||
890 | + String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) | ||
891 | + + EVENT_SUBJECT_NAME_SUFFIX; | ||
892 | + | ||
893 | + initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className); | ||
894 | + | ||
895 | + TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) | ||
896 | + .getTempJavaCodeFragmentFiles().getServiceTempFiles(); | ||
897 | + | ||
898 | + insertDataIntoJavaFile(file, NEW_LINE); | ||
899 | + try { | ||
900 | + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles)); | ||
901 | + | ||
902 | + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles)); | ||
903 | + | ||
904 | + insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles)); | ||
905 | + | ||
906 | + } catch (IOException e) { | ||
907 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
908 | + + " while event class file generation"); | ||
909 | + } | ||
910 | + | ||
877 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 911 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
912 | + validateLineLength(file); | ||
878 | } | 913 | } |
879 | } | 914 | } | ... | ... |
... | @@ -37,6 +37,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -37,6 +37,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
40 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; | ||
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
... | @@ -47,6 +48,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -47,6 +48,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
51 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; | ||
52 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; | ||
53 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; | ||
54 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; | ||
55 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; | ||
50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; | 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
52 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
... | @@ -60,28 +66,37 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -60,28 +66,37 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
60 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | 66 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; |
62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
69 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | ||
70 | +import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION; | ||
71 | +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | ||
63 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 72 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
73 | +import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; | ||
64 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 74 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
65 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | 75 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
66 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 76 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
67 | -import static org.onosproject.yangutils.utils.UtilConstants.ORG; | 77 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
68 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 78 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
79 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
69 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 80 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
70 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 81 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
71 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | 82 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
83 | +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION; | ||
72 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
73 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
86 | +import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | ||
74 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | 87 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
75 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; | 88 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; |
76 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | 89 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; |
77 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; | 90 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; |
78 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT; | 91 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT; |
79 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER; | 92 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER; |
93 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS; | ||
80 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | 94 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; |
81 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | 95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; |
82 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; | 96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; |
83 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER; | 97 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER; |
84 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 98 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
99 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg; | ||
85 | 100 | ||
86 | /** | 101 | /** |
87 | * Represents utilities for java file generator. | 102 | * Represents utilities for java file generator. |
... | @@ -136,6 +151,7 @@ public final class JavaFileGeneratorUtils { | ... | @@ -136,6 +151,7 @@ public final class JavaFileGeneratorUtils { |
136 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { | 151 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
137 | serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; | 152 | serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; |
138 | } | 153 | } |
154 | + | ||
139 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | 155 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
140 | return tempJavaFragmentFiles | 156 | return tempJavaFragmentFiles |
141 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle()); | 157 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle()); |
... | @@ -201,6 +217,36 @@ public final class JavaFileGeneratorUtils { | ... | @@ -201,6 +217,36 @@ public final class JavaFileGeneratorUtils { |
201 | } | 217 | } |
202 | return serviceFragmentFiles | 218 | return serviceFragmentFiles |
203 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle()); | 219 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle()); |
220 | + } else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) { | ||
221 | + if (serviceFragmentFiles == null) { | ||
222 | + throw new TranslatorException("Required rpc implementation info is missing."); | ||
223 | + } | ||
224 | + return serviceFragmentFiles | ||
225 | + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle()); | ||
226 | + } else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) { | ||
227 | + if (serviceFragmentFiles == null) { | ||
228 | + throw new TranslatorException("Required rpc implementation info is missing."); | ||
229 | + } | ||
230 | + return serviceFragmentFiles | ||
231 | + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle()); | ||
232 | + } else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) { | ||
233 | + if (serviceFragmentFiles == null) { | ||
234 | + throw new TranslatorException("Required rpc implementation info is missing."); | ||
235 | + } | ||
236 | + return serviceFragmentFiles | ||
237 | + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle()); | ||
238 | + } else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) { | ||
239 | + if (serviceFragmentFiles == null) { | ||
240 | + throw new TranslatorException("Required rpc implementation info is missing."); | ||
241 | + } | ||
242 | + return serviceFragmentFiles | ||
243 | + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle()); | ||
244 | + } else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) { | ||
245 | + if (serviceFragmentFiles == null) { | ||
246 | + throw new TranslatorException("Required rpc implementation info is missing."); | ||
247 | + } | ||
248 | + return serviceFragmentFiles | ||
249 | + .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle()); | ||
204 | } | 250 | } |
205 | return null; | 251 | return null; |
206 | } | 252 | } |
... | @@ -213,15 +259,16 @@ public final class JavaFileGeneratorUtils { | ... | @@ -213,15 +259,16 @@ public final class JavaFileGeneratorUtils { |
213 | * @param type generated file type | 259 | * @param type generated file type |
214 | * @param imports imports for the file | 260 | * @param imports imports for the file |
215 | * @param pkg generated file package | 261 | * @param pkg generated file package |
262 | + * @param pluginConfig plugin configurations | ||
216 | * @throws IOException when fails to generate a file | 263 | * @throws IOException when fails to generate a file |
217 | */ | 264 | */ |
218 | public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports, | 265 | public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports, |
219 | - String pkg) | 266 | + String pkg, YangPluginConfig pluginConfig) |
220 | throws IOException { | 267 | throws IOException { |
221 | 268 | ||
222 | try { | 269 | try { |
223 | file.createNewFile(); | 270 | file.createNewFile(); |
224 | - appendContents(file, className, type, imports, pkg); | 271 | + appendContents(file, className, type, imports, pkg, pluginConfig); |
225 | } catch (IOException e) { | 272 | } catch (IOException e) { |
226 | throw new IOException("Failed to create " + file.getName() + " class file."); | 273 | throw new IOException("Failed to create " + file.getName() + " class file."); |
227 | } | 274 | } |
... | @@ -263,9 +310,17 @@ public final class JavaFileGeneratorUtils { | ... | @@ -263,9 +310,17 @@ public final class JavaFileGeneratorUtils { |
263 | 310 | ||
264 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 311 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
265 | 312 | ||
313 | + String name = javaFileInfo.getJavaName(); | ||
266 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 314 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
267 | - String pkgString = parsePackageString(path, importsList); | ||
268 | 315 | ||
316 | + String pkgString = null; | ||
317 | + if (type == GENERATE_EVENT_CLASS | ||
318 | + || type == GENERATE_EVENT_LISTENER_INTERFACE | ||
319 | + || type == GENERATE_EVENT_SUBJECT_CLASS) { | ||
320 | + pkgString = parsePackageString(path + PERIOD + name, importsList); | ||
321 | + } else { | ||
322 | + pkgString = parsePackageString(path, importsList); | ||
323 | + } | ||
269 | switch (type) { | 324 | switch (type) { |
270 | case INTERFACE_MASK: | 325 | case INTERFACE_MASK: |
271 | appendHeaderContents(file, pkgString, importsList); | 326 | appendHeaderContents(file, pkgString, importsList); |
... | @@ -279,6 +334,14 @@ public final class JavaFileGeneratorUtils { | ... | @@ -279,6 +334,14 @@ public final class JavaFileGeneratorUtils { |
279 | appendHeaderContents(file, pkgString, importsList); | 334 | appendHeaderContents(file, pkgString, importsList); |
280 | write(file, type, EVENT, curNode, className); | 335 | write(file, type, EVENT, curNode, className); |
281 | break; | 336 | break; |
337 | + case GENERATE_EVENT_LISTENER_INTERFACE: | ||
338 | + appendHeaderContents(file, pkgString, importsList); | ||
339 | + write(file, type, EVENT_LISTENER, curNode, className); | ||
340 | + break; | ||
341 | + case GENERATE_EVENT_SUBJECT_CLASS: | ||
342 | + appendHeaderContents(file, pkgString, importsList); | ||
343 | + write(file, type, EVENT_SUBJECT_CLASS, curNode, className); | ||
344 | + break; | ||
282 | default: | 345 | default: |
283 | break; | 346 | break; |
284 | } | 347 | } |
... | @@ -294,37 +357,34 @@ public final class JavaFileGeneratorUtils { | ... | @@ -294,37 +357,34 @@ public final class JavaFileGeneratorUtils { |
294 | * @param importsList list of java imports. | 357 | * @param importsList list of java imports. |
295 | * @throws IOException when fails to append contents | 358 | * @throws IOException when fails to append contents |
296 | */ | 359 | */ |
297 | - private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg) | 360 | + private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg, |
361 | + YangPluginConfig pluginConfig) | ||
298 | throws IOException { | 362 | throws IOException { |
299 | 363 | ||
300 | String pkgString = parsePackageString(pkg, importsList); | 364 | String pkgString = parsePackageString(pkg, importsList); |
301 | 365 | ||
302 | switch (type) { | 366 | switch (type) { |
303 | case IMPL_CLASS_MASK: | 367 | case IMPL_CLASS_MASK: |
304 | - write(file, fileName, type, IMPL_CLASS); | 368 | + write(file, fileName, type, IMPL_CLASS, pluginConfig); |
305 | break; | 369 | break; |
306 | case BUILDER_INTERFACE_MASK: | 370 | case BUILDER_INTERFACE_MASK: |
307 | - write(file, fileName, type, BUILDER_INTERFACE); | 371 | + write(file, fileName, type, BUILDER_INTERFACE, pluginConfig); |
308 | break; | 372 | break; |
309 | case GENERATE_TYPEDEF_CLASS: | 373 | case GENERATE_TYPEDEF_CLASS: |
310 | appendHeaderContents(file, pkgString, importsList); | 374 | appendHeaderContents(file, pkgString, importsList); |
311 | - write(file, fileName, type, IMPL_CLASS); | 375 | + write(file, fileName, type, IMPL_CLASS, pluginConfig); |
312 | break; | 376 | break; |
313 | case BUILDER_CLASS_MASK: | 377 | case BUILDER_CLASS_MASK: |
314 | appendHeaderContents(file, pkgString, importsList); | 378 | appendHeaderContents(file, pkgString, importsList); |
315 | - write(file, fileName, type, BUILDER_CLASS); | 379 | + write(file, fileName, type, BUILDER_CLASS, pluginConfig); |
316 | break; | 380 | break; |
317 | case GENERATE_UNION_CLASS: | 381 | case GENERATE_UNION_CLASS: |
318 | appendHeaderContents(file, pkgString, importsList); | 382 | appendHeaderContents(file, pkgString, importsList); |
319 | - write(file, fileName, type, IMPL_CLASS); | 383 | + write(file, fileName, type, IMPL_CLASS, pluginConfig); |
320 | break; | 384 | break; |
321 | case GENERATE_ENUM_CLASS: | 385 | case GENERATE_ENUM_CLASS: |
322 | appendHeaderContents(file, pkgString, importsList); | 386 | appendHeaderContents(file, pkgString, importsList); |
323 | - write(file, fileName, type, ENUM_CLASS); | 387 | + write(file, fileName, type, ENUM_CLASS, pluginConfig); |
324 | - break; | ||
325 | - case GENERATE_EVENT_LISTENER_INTERFACE: | ||
326 | - appendHeaderContents(file, pkgString, importsList); | ||
327 | - write(file, fileName, type, EVENT_LISTENER); | ||
328 | break; | 388 | break; |
329 | default: | 389 | default: |
330 | break; | 390 | break; |
... | @@ -340,10 +400,7 @@ public final class JavaFileGeneratorUtils { | ... | @@ -340,10 +400,7 @@ public final class JavaFileGeneratorUtils { |
340 | */ | 400 | */ |
341 | private static String parsePackageString(String javaPkg, List<String> importsList) { | 401 | private static String parsePackageString(String javaPkg, List<String> importsList) { |
342 | 402 | ||
343 | - if (javaPkg.contains(ORG)) { | 403 | + javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg)); |
344 | - String[] strArray = javaPkg.split(ORG); | ||
345 | - javaPkg = ORG + getJavaPackageFromPackagePath(strArray[1]); | ||
346 | - } | ||
347 | if (importsList != null) { | 404 | if (importsList != null) { |
348 | if (!importsList.isEmpty()) { | 405 | if (!importsList.isEmpty()) { |
349 | return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE; | 406 | return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE; |
... | @@ -395,14 +452,16 @@ public final class JavaFileGeneratorUtils { | ... | @@ -395,14 +452,16 @@ public final class JavaFileGeneratorUtils { |
395 | private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName) | 452 | private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName) |
396 | throws IOException { | 453 | throws IOException { |
397 | 454 | ||
455 | + YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig(); | ||
398 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { | 456 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { |
399 | if (!fileName.contains(SERVICE)) { | 457 | if (!fileName.contains(SERVICE)) { |
400 | - insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false)); | 458 | + insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false, pluginConfig)); |
459 | + insertDataIntoJavaFile(file, addComponentString()); | ||
401 | } else { | 460 | } else { |
402 | - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | 461 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
403 | } | 462 | } |
404 | } else { | 463 | } else { |
405 | - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | 464 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
406 | } | 465 | } |
407 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode)); | 466 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode)); |
408 | } | 467 | } |
... | @@ -416,9 +475,10 @@ public final class JavaFileGeneratorUtils { | ... | @@ -416,9 +475,10 @@ public final class JavaFileGeneratorUtils { |
416 | * @param javaDocType java doc type | 475 | * @param javaDocType java doc type |
417 | * @throws IOException when fails to write into a file | 476 | * @throws IOException when fails to write into a file |
418 | */ | 477 | */ |
419 | - private static void write(File file, String fileName, int genType, JavaDocType javaDocType) | 478 | + private static void write(File file, String fileName, int genType, JavaDocType javaDocType, |
479 | + YangPluginConfig pluginConfig) | ||
420 | throws IOException { | 480 | throws IOException { |
421 | - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | 481 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
422 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName)); | 482 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName)); |
423 | } | 483 | } |
424 | 484 | ||
... | @@ -433,4 +493,13 @@ public final class JavaFileGeneratorUtils { | ... | @@ -433,4 +493,13 @@ public final class JavaFileGeneratorUtils { |
433 | + SEMI_COLAN + NEW_LINE; | 493 | + SEMI_COLAN + NEW_LINE; |
434 | } | 494 | } |
435 | 495 | ||
496 | + /** | ||
497 | + * Returns component string. | ||
498 | + * | ||
499 | + * @return component string | ||
500 | + */ | ||
501 | + public static String addComponentString() { | ||
502 | + return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE | ||
503 | + + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION; | ||
504 | + } | ||
436 | } | 505 | } | ... | ... |
... | @@ -26,11 +26,14 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | ... | @@ -26,11 +26,14 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
26 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; | 26 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; |
27 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | 27 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; |
28 | 28 | ||
29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
30 | import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod; |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
35 | +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.AND; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE; |
... | @@ -48,6 +51,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ... | @@ -48,6 +51,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
48 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
49 | import static org.onosproject.yangutils.utils.UtilConstants.COLAN; | 52 | import static org.onosproject.yangutils.utils.UtilConstants.COLAN; |
50 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
54 | +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION; | ||
51 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; | 56 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
52 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
... | @@ -93,7 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; | ... | @@ -93,7 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; |
93 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; | 98 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
94 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; | 99 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; |
95 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 100 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
101 | +import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO; | ||
96 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; | 102 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
103 | +import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO; | ||
97 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 104 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
98 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; | 105 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
99 | import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; | 106 | import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; |
... | @@ -106,6 +113,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA | ... | @@ -106,6 +113,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA |
106 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | 113 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
107 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; | 114 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
108 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; | 115 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; |
116 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
109 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | 117 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
110 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | 118 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
111 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | 119 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
... | @@ -115,7 +123,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN | ... | @@ -115,7 +123,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN |
115 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; | 123 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
116 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; | 124 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
117 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | 125 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
118 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
119 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 126 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
120 | 127 | ||
121 | /** | 128 | /** |
... | @@ -133,10 +140,11 @@ public final class MethodsGenerator { | ... | @@ -133,10 +140,11 @@ public final class MethodsGenerator { |
133 | * Returns the methods strings for builder interface. | 140 | * Returns the methods strings for builder interface. |
134 | * | 141 | * |
135 | * @param name attribute name | 142 | * @param name attribute name |
143 | + * @param pluginConfig plugin configurations | ||
136 | * @return method string for builder interface | 144 | * @return method string for builder interface |
137 | */ | 145 | */ |
138 | - public static String parseBuilderInterfaceBuildMethodString(String name) { | 146 | + public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) { |
139 | - return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); | 147 | + return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name); |
140 | } | 148 | } |
141 | 149 | ||
142 | /** | 150 | /** |
... | @@ -144,14 +152,16 @@ public final class MethodsGenerator { | ... | @@ -144,14 +152,16 @@ public final class MethodsGenerator { |
144 | * | 152 | * |
145 | * @param attr attribute info | 153 | * @param attr attribute info |
146 | * @param generatedJavaFiles generated java files | 154 | * @param generatedJavaFiles generated java files |
155 | + * @param pluginConfig plugin configurations | ||
147 | * @return getter string | 156 | * @return getter string |
148 | */ | 157 | */ |
149 | - public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles) { | 158 | + public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles, |
159 | + YangPluginConfig pluginConfig) { | ||
150 | 160 | ||
151 | String returnType = getReturnType(attr); | 161 | String returnType = getReturnType(attr); |
152 | String attributeName = attr.getAttributeName(); | 162 | String attributeName = attr.getAttributeName(); |
153 | 163 | ||
154 | - return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) | 164 | + return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig) |
155 | + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles); | 165 | + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles); |
156 | } | 166 | } |
157 | 167 | ||
... | @@ -161,20 +171,22 @@ public final class MethodsGenerator { | ... | @@ -161,20 +171,22 @@ public final class MethodsGenerator { |
161 | * @param attr attribute info | 171 | * @param attr attribute info |
162 | * @param className java class name | 172 | * @param className java class name |
163 | * @param generatedJavaFiles generated java files | 173 | * @param generatedJavaFiles generated java files |
174 | + * @param pluginConfig plugin configurations | ||
164 | * @return setter string | 175 | * @return setter string |
165 | */ | 176 | */ |
166 | - public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles) { | 177 | + public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles, |
178 | + YangPluginConfig pluginConfig) { | ||
167 | 179 | ||
168 | String attrType = getReturnType(attr); | 180 | String attrType = getReturnType(attr); |
169 | String attributeName = attr.getAttributeName(); | 181 | String attributeName = attr.getAttributeName(); |
170 | JavaDocGen.JavaDocType type; | 182 | JavaDocGen.JavaDocType type; |
171 | - if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { | 183 | + if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
172 | type = MANAGER_SETTER_METHOD; | 184 | type = MANAGER_SETTER_METHOD; |
173 | } else { | 185 | } else { |
174 | type = SETTER_METHOD; | 186 | type = SETTER_METHOD; |
175 | } | 187 | } |
176 | 188 | ||
177 | - return getJavaDoc(type, attributeName, attr.isListAttr()) | 189 | + return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig) |
178 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles); | 190 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles); |
179 | } | 191 | } |
180 | 192 | ||
... | @@ -182,10 +194,11 @@ public final class MethodsGenerator { | ... | @@ -182,10 +194,11 @@ public final class MethodsGenerator { |
182 | * Returns constructor method string. | 194 | * Returns constructor method string. |
183 | * | 195 | * |
184 | * @param name class name | 196 | * @param name class name |
197 | + * @param pluginConfig plugin configurations | ||
185 | * @return constructor string | 198 | * @return constructor string |
186 | */ | 199 | */ |
187 | - public static String getConstructorString(String name) { | 200 | + public static String getConstructorString(String name, YangPluginConfig pluginConfig) { |
188 | - return getJavaDoc(CONSTRUCTOR, name, false); | 201 | + return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig); |
189 | } | 202 | } |
190 | 203 | ||
191 | /** | 204 | /** |
... | @@ -193,10 +206,13 @@ public final class MethodsGenerator { | ... | @@ -193,10 +206,13 @@ public final class MethodsGenerator { |
193 | * | 206 | * |
194 | * @param name class name | 207 | * @param name class name |
195 | * @param modifierType modifier type | 208 | * @param modifierType modifier type |
209 | + * @param pluginConfig plugin configurations | ||
196 | * @return default constructor string | 210 | * @return default constructor string |
197 | */ | 211 | */ |
198 | - public static String getDefaultConstructorString(String name, String modifierType) { | 212 | + public static String getDefaultConstructorString(String name, String modifierType, |
199 | - return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType) | 213 | + YangPluginConfig pluginConfig) { |
214 | + return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig) | ||
215 | + + getDefaultConstructor(name, modifierType) | ||
200 | + NEW_LINE; | 216 | + NEW_LINE; |
201 | } | 217 | } |
202 | 218 | ||
... | @@ -312,12 +328,17 @@ public final class MethodsGenerator { | ... | @@ -312,12 +328,17 @@ public final class MethodsGenerator { |
312 | + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE + | 328 | + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE + |
313 | OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + | 329 | OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + |
314 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 330 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
331 | + } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) { | ||
332 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE | ||
333 | + + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
334 | + + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE | ||
335 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
315 | } else { | 336 | } else { |
316 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + | 337 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + |
317 | name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE | 338 | name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
318 | - + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + | 339 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE |
319 | - SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + | 340 | + + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE |
320 | - SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 341 | + + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
321 | } | 342 | } |
322 | } | 343 | } |
323 | 344 | ||
... | @@ -474,13 +495,16 @@ public final class MethodsGenerator { | ... | @@ -474,13 +495,16 @@ public final class MethodsGenerator { |
474 | * Returns constructor string for impl class. | 495 | * Returns constructor string for impl class. |
475 | * | 496 | * |
476 | * @param yangName class name | 497 | * @param yangName class name |
498 | + * @param pluginConfig plugin configurations | ||
477 | * @return constructor string | 499 | * @return constructor string |
478 | */ | 500 | */ |
479 | - public static String getConstructorStart(String yangName) { | 501 | + public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) { |
480 | 502 | ||
481 | - String javadoc = getConstructorString(yangName); | 503 | + String javadoc = getConstructorString(yangName, pluginConfig); |
482 | - String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName | 504 | + String constructor = |
483 | - + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET | 505 | + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName |
506 | + + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE | ||
507 | + + OPEN_CURLY_BRACKET | ||
484 | + NEW_LINE; | 508 | + NEW_LINE; |
485 | return javadoc + constructor; | 509 | return javadoc + constructor; |
486 | } | 510 | } |
... | @@ -491,24 +515,29 @@ public final class MethodsGenerator { | ... | @@ -491,24 +515,29 @@ public final class MethodsGenerator { |
491 | * @param yangName name of the class | 515 | * @param yangName name of the class |
492 | * @param attr attribute info | 516 | * @param attr attribute info |
493 | * @param generatedJavaFiles generated java files | 517 | * @param generatedJavaFiles generated java files |
518 | + * @param pluginConfig plugin configurations | ||
494 | * @return constructor for class | 519 | * @return constructor for class |
495 | */ | 520 | */ |
496 | - public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles) { | 521 | + public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles, |
522 | + YangPluginConfig pluginConfig) { | ||
497 | 523 | ||
498 | String attributeName = attr.getAttributeName(); | 524 | String attributeName = attr.getAttributeName(); |
499 | String constructor; | 525 | String constructor; |
500 | 526 | ||
501 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { | 527 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
502 | - constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL | 528 | + constructor = |
529 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD | ||
530 | + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL | ||
503 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX | 531 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
504 | - + getCapitalCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + | 532 | + + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver())) |
505 | - SEMI_COLAN | 533 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
506 | - + NEW_LINE; | ||
507 | } else { | 534 | } else { |
508 | - constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL | 535 | + constructor = |
509 | - + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + getCamelCase(attributeName, null) + | 536 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
510 | - OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN | 537 | + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL |
511 | - + NEW_LINE; | 538 | + + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD |
539 | + + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + | ||
540 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
512 | } | 541 | } |
513 | return constructor; | 542 | return constructor; |
514 | } | 543 | } |
... | @@ -519,11 +548,13 @@ public final class MethodsGenerator { | ... | @@ -519,11 +548,13 @@ public final class MethodsGenerator { |
519 | * @param rpcName name of the rpc | 548 | * @param rpcName name of the rpc |
520 | * @param inputName name of input | 549 | * @param inputName name of input |
521 | * @param outputName name of output | 550 | * @param outputName name of output |
551 | + * @param pluginConfig plugin configurations | ||
522 | * @return rpc method string | 552 | * @return rpc method string |
523 | */ | 553 | */ |
524 | - public static String getRpcServiceMethod(String rpcName, String inputName, String outputName) { | 554 | + public static String getRpcServiceMethod(String rpcName, String inputName, String outputName, |
555 | + YangPluginConfig pluginConfig) { | ||
525 | 556 | ||
526 | - rpcName = getCamelCase(rpcName, null); | 557 | + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
527 | inputName = getCapitalCase(inputName); | 558 | inputName = getCapitalCase(inputName); |
528 | if (!outputName.equals(VOID)) { | 559 | if (!outputName.equals(VOID)) { |
529 | outputName = getCapitalCase(outputName); | 560 | outputName = getCapitalCase(outputName); |
... | @@ -538,11 +569,13 @@ public final class MethodsGenerator { | ... | @@ -538,11 +569,13 @@ public final class MethodsGenerator { |
538 | * @param rpcName name of the rpc | 569 | * @param rpcName name of the rpc |
539 | * @param inputName name of input | 570 | * @param inputName name of input |
540 | * @param outputName name of output | 571 | * @param outputName name of output |
572 | + * @param pluginConfig plugin configurations | ||
541 | * @return rpc method string | 573 | * @return rpc method string |
542 | */ | 574 | */ |
543 | - public static String getRpcManagerMethod(String rpcName, String inputName, String outputName) { | 575 | + public static String getRpcManagerMethod(String rpcName, String inputName, String outputName, |
576 | + YangPluginConfig pluginConfig) { | ||
544 | 577 | ||
545 | - rpcName = getCamelCase(rpcName, null); | 578 | + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
546 | inputName = getCapitalCase(inputName); | 579 | inputName = getCapitalCase(inputName); |
547 | if (!outputName.equals(VOID)) { | 580 | if (!outputName.equals(VOID)) { |
548 | outputName = getCapitalCase(outputName); | 581 | outputName = getCapitalCase(outputName); |
... | @@ -631,12 +664,14 @@ public final class MethodsGenerator { | ... | @@ -631,12 +664,14 @@ public final class MethodsGenerator { |
631 | * Returns from string method's open string. | 664 | * Returns from string method's open string. |
632 | * | 665 | * |
633 | * @param className name of the class | 666 | * @param className name of the class |
667 | + * @param pluginConfig plugin configurations | ||
634 | * @return from string method's open string | 668 | * @return from string method's open string |
635 | */ | 669 | */ |
636 | - public static String getFromStringMethodSignature(String className) { | 670 | + public static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) { |
637 | - return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE | 671 | + return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE |
638 | - + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE | 672 | + + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS |
639 | - + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 673 | + + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE |
674 | + + OPEN_CURLY_BRACKET + NEW_LINE; | ||
640 | } | 675 | } |
641 | 676 | ||
642 | /** | 677 | /** |
... | @@ -832,14 +867,16 @@ public final class MethodsGenerator { | ... | @@ -832,14 +867,16 @@ public final class MethodsGenerator { |
832 | * | 867 | * |
833 | * @param attr attribute info | 868 | * @param attr attribute info |
834 | * @param generatedJavaClassName class name | 869 | * @param generatedJavaClassName class name |
870 | + * @param pluginConfig plugin configurations | ||
835 | * @return of method's string and java doc for special type | 871 | * @return of method's string and java doc for special type |
836 | */ | 872 | */ |
837 | - public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { | 873 | + public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName, |
874 | + YangPluginConfig pluginConfig) { | ||
838 | 875 | ||
839 | String attrType = getReturnType(attr); | 876 | String attrType = getReturnType(attr); |
840 | String attrName = attr.getAttributeName(); | 877 | String attrName = attr.getAttributeName(); |
841 | 878 | ||
842 | - return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false) | 879 | + return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig) |
843 | + getOfMethodString(attrType, generatedJavaClassName); | 880 | + getOfMethodString(attrType, generatedJavaClassName); |
844 | } | 881 | } |
845 | 882 | ||
... | @@ -863,14 +900,16 @@ public final class MethodsGenerator { | ... | @@ -863,14 +900,16 @@ public final class MethodsGenerator { |
863 | * | 900 | * |
864 | * @param attr attribute info | 901 | * @param attr attribute info |
865 | * @param generatedJavaClassName class name | 902 | * @param generatedJavaClassName class name |
903 | + * @param pluginConfig plugin configurations | ||
866 | * @return string and java doc for constructor of type class | 904 | * @return string and java doc for constructor of type class |
867 | */ | 905 | */ |
868 | - public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { | 906 | + public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, |
907 | + String generatedJavaClassName, YangPluginConfig pluginConfig) { | ||
869 | 908 | ||
870 | String attrType = getReturnType(attr); | 909 | String attrType = getReturnType(attr); |
871 | String attrName = attr.getAttributeName(); | 910 | String attrName = attr.getAttributeName(); |
872 | 911 | ||
873 | - return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false) | 912 | + return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig) |
874 | + getTypeConstructorString(attrType, attrName, generatedJavaClassName); | 913 | + getTypeConstructorString(attrType, attrName, generatedJavaClassName); |
875 | } | 914 | } |
876 | 915 | ||
... | @@ -986,10 +1025,11 @@ public final class MethodsGenerator { | ... | @@ -986,10 +1025,11 @@ public final class MethodsGenerator { |
986 | * @param attr java attribute | 1025 | * @param attr java attribute |
987 | * @param enumMap enum's sets map | 1026 | * @param enumMap enum's sets map |
988 | * @param enumList enum's sets list | 1027 | * @param enumList enum's sets list |
1028 | + * @param pluginConfig plugin configurations | ||
989 | * @return of method | 1029 | * @return of method |
990 | */ | 1030 | */ |
991 | public static String getEnumsOfMethod(String className, JavaAttributeInfo attr, | 1031 | public static String getEnumsOfMethod(String className, JavaAttributeInfo attr, |
992 | - Map<String, Integer> enumMap, List<String> enumList) { | 1032 | + Map<String, Integer> enumMap, List<String> enumList, YangPluginConfig pluginConfig) { |
993 | String attrType = getReturnType(attr); | 1033 | String attrType = getReturnType(attr); |
994 | String attrName = attr.getAttributeName(); | 1034 | String attrName = attr.getAttributeName(); |
995 | 1035 | ||
... | @@ -1010,6 +1050,37 @@ public final class MethodsGenerator { | ... | @@ -1010,6 +1050,37 @@ public final class MethodsGenerator { |
1010 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET | 1050 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
1011 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 1051 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
1012 | 1052 | ||
1013 | - return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false) + method; | 1053 | + return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig) |
1054 | + + method; | ||
1014 | } | 1055 | } |
1056 | + | ||
1057 | + /** | ||
1058 | + * Returns activate method string. | ||
1059 | + * | ||
1060 | + * @return activate method string | ||
1061 | + */ | ||
1062 | + public static String addActivateMethod() { | ||
1063 | + return FOUR_SPACE_INDENTATION + ACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION | ||
1064 | + + PUBLIC + SPACE + VOID + SPACE + ACTIVATE + OPEN_PARENTHESIS | ||
1065 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET | ||
1066 | + + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
1067 | + + YANG_UTILS_TODO | ||
1068 | + + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
1069 | + + STARTED_LOG_INFO + FOUR_SPACE_INDENTATION | ||
1070 | + + CLOSE_CURLY_BRACKET + NEW_LINE; | ||
1071 | + } | ||
1072 | + | ||
1073 | + /** | ||
1074 | + * Returns deactivate method string. | ||
1075 | + * | ||
1076 | + * @return deactivate method string | ||
1077 | + */ | ||
1078 | + public static String addDeActivateMethod() { | ||
1079 | + return NEW_LINE + FOUR_SPACE_INDENTATION + DEACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION | ||
1080 | + + PUBLIC + SPACE + VOID + SPACE + DEACTIVATE + OPEN_PARENTHESIS | ||
1081 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
1082 | + + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
1083 | + + STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | ||
1084 | + } | ||
1085 | + | ||
1015 | } | 1086 | } | ... | ... |
... | @@ -35,24 +35,35 @@ import static java.util.Collections.sort; | ... | @@ -35,24 +35,35 @@ import static java.util.Collections.sort; |
35 | 35 | ||
36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
38 | +import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT; | ||
38 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
43 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
45 | +import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT; | ||
44 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
48 | +import static org.onosproject.yangutils.utils.UtilConstants.ENUM; | ||
45 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
50 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
46 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
47 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 52 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
48 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
54 | +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT; | ||
49 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 56 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
50 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
58 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
51 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
52 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
61 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
53 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 62 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
63 | +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT; | ||
54 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 64 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
55 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
66 | +import static org.onosproject.yangutils.utils.UtilConstants.TYPE; | ||
56 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | 67 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; |
57 | 68 | ||
58 | /** | 69 | /** |
... | @@ -102,12 +113,6 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -102,12 +113,6 @@ public final class TempJavaCodeFragmentFilesUtils { |
102 | if (container.getBeanTempFiles() != null) { | 113 | if (container.getBeanTempFiles() != null) { |
103 | return container.getBeanTempFiles(); | 114 | return container.getBeanTempFiles(); |
104 | } | 115 | } |
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) { | 116 | if (container.getServiceTempFiles() != null) { |
112 | return container.getServiceTempFiles(); | 117 | return container.getServiceTempFiles(); |
113 | } | 118 | } |
... | @@ -234,6 +239,31 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -234,6 +239,31 @@ public final class TempJavaCodeFragmentFilesUtils { |
234 | } | 239 | } |
235 | 240 | ||
236 | /** | 241 | /** |
242 | + * Adds annotations imports. | ||
243 | + * | ||
244 | + * @param imports list if imports | ||
245 | + * @param operation to add or to delete | ||
246 | + */ | ||
247 | + public static void addAnnotationsImports(List<String> imports, boolean operation) { | ||
248 | + if (operation) { | ||
249 | + imports.add(ACTIVATE_ANNOTATION_IMPORT); | ||
250 | + imports.add(DEACTIVATE_ANNOTATION_IMPORT); | ||
251 | + imports.add(COMPONENT_ANNOTATION_IMPORT); | ||
252 | + imports.add(SERVICE_ANNOTATION_IMPORT); | ||
253 | + imports.add(LOGGER_FACTORY_IMPORT); | ||
254 | + imports.add(LOGGER_IMPORT); | ||
255 | + } else { | ||
256 | + imports.remove(ACTIVATE_ANNOTATION_IMPORT); | ||
257 | + imports.remove(DEACTIVATE_ANNOTATION_IMPORT); | ||
258 | + imports.remove(COMPONENT_ANNOTATION_IMPORT); | ||
259 | + imports.remove(SERVICE_ANNOTATION_IMPORT); | ||
260 | + imports.remove(LOGGER_FACTORY_IMPORT); | ||
261 | + imports.remove(LOGGER_IMPORT); | ||
262 | + } | ||
263 | + sortImports(imports); | ||
264 | + } | ||
265 | + | ||
266 | + /** | ||
237 | * Performs given operations on import list. | 267 | * Performs given operations on import list. |
238 | * | 268 | * |
239 | * @param imports list of imports | 269 | * @param imports list of imports |
... | @@ -328,4 +358,13 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -328,4 +358,13 @@ public final class TempJavaCodeFragmentFilesUtils { |
328 | return imports; | 358 | return imports; |
329 | } | 359 | } |
330 | 360 | ||
361 | + /** | ||
362 | + * Returns event enum start. | ||
363 | + * | ||
364 | + * @return event enum start | ||
365 | + */ | ||
366 | + public static String getEventEnumTypeStart() { | ||
367 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET | ||
368 | + + NEW_LINE; | ||
369 | + } | ||
331 | } | 370 | } | ... | ... |
... | @@ -32,8 +32,13 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ... | @@ -32,8 +32,13 @@ 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; |
... | @@ -49,7 +54,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATIO | ... | @@ -49,7 +54,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATIO |
49 | public final class YangJavaModelUtils { | 54 | public final class YangJavaModelUtils { |
50 | 55 | ||
51 | /** | 56 | /** |
52 | - * Creates YANG java model utility. | 57 | + * Creates an instance of YANG java model utility. |
53 | */ | 58 | */ |
54 | private YangJavaModelUtils() { | 59 | private YangJavaModelUtils() { |
55 | } | 60 | } |
... | @@ -64,6 +69,7 @@ public final class YangJavaModelUtils { | ... | @@ -64,6 +69,7 @@ public final class YangJavaModelUtils { |
64 | public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, | 69 | public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
65 | YangPluginConfig yangPluginConfig) | 70 | YangPluginConfig yangPluginConfig) |
66 | throws IOException { | 71 | throws IOException { |
72 | + | ||
67 | javaCodeGeneratorInfo.getJavaFileInfo() | 73 | javaCodeGeneratorInfo.getJavaFileInfo() |
68 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), | 74 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), |
69 | yangPluginConfig.getConflictResolver())); | 75 | yangPluginConfig.getConflictResolver())); |
... | @@ -71,6 +77,7 @@ public final class YangJavaModelUtils { | ... | @@ -71,6 +77,7 @@ public final class YangJavaModelUtils { |
71 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( | 77 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
72 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); | 78 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
73 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); | 79 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); |
80 | + javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig); | ||
74 | } | 81 | } |
75 | 82 | ||
76 | /** | 83 | /** |
... | @@ -90,6 +97,7 @@ public final class YangJavaModelUtils { | ... | @@ -90,6 +97,7 @@ public final class YangJavaModelUtils { |
90 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( | 97 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
91 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); | 98 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
92 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); | 99 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); |
100 | + javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin); | ||
93 | } | 101 | } |
94 | 102 | ||
95 | /** | 103 | /** |
... | @@ -120,6 +128,16 @@ public final class YangJavaModelUtils { | ... | @@ -120,6 +128,16 @@ public final class YangJavaModelUtils { |
120 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 128 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
121 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( | 129 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( |
122 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); | 130 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
131 | + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { | ||
132 | + if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { | ||
133 | + updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); | ||
134 | + } | ||
135 | + } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { | ||
136 | + if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { | ||
137 | + updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
123 | } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { | 141 | } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { |
124 | /* | 142 | /* |
125 | * Container | 143 | * Container |
... | @@ -139,13 +157,14 @@ public final class YangJavaModelUtils { | ... | @@ -139,13 +157,14 @@ public final class YangJavaModelUtils { |
139 | * Union | 157 | * Union |
140 | */ | 158 | */ |
141 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 159 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
142 | - .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo); | 160 | + .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig); |
143 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { | 161 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { |
144 | /* | 162 | /* |
145 | * Enumeration | 163 | * Enumeration |
146 | */ | 164 | */ |
147 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() | 165 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() |
148 | - .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); | 166 | + .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
167 | + | ||
149 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { | 168 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { |
150 | /*Do nothing, only the interface needs to be generated*/ | 169 | /*Do nothing, only the interface needs to be generated*/ |
151 | } else { | 170 | } else { |
... | @@ -171,6 +190,32 @@ public final class YangJavaModelUtils { | ... | @@ -171,6 +190,32 @@ public final class YangJavaModelUtils { |
171 | } | 190 | } |
172 | 191 | ||
173 | /** | 192 | /** |
193 | + * Updates notification node info in service temporary file. | ||
194 | + * | ||
195 | + * @param javaCodeGeneratorInfo java code generator info | ||
196 | + * @param yangPluginConfig plugin configurations | ||
197 | + * @throws IOException when fails to do IO operations | ||
198 | + */ | ||
199 | + private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, | ||
200 | + YangPluginConfig yangPluginConfig) throws IOException { | ||
201 | + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { | ||
202 | + for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) { | ||
203 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | ||
204 | + .getServiceTempFiles() | ||
205 | + .addJavaSnippetOfEvent(notificaiton, yangPluginConfig); | ||
206 | + } | ||
207 | + } | ||
208 | + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { | ||
209 | + for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo) | ||
210 | + .getNotificationNodes()) { | ||
211 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | ||
212 | + .getServiceTempFiles() | ||
213 | + .addJavaSnippetOfEvent(notificaiton, yangPluginConfig); | ||
214 | + } | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + /** | ||
174 | * Generates code for the current ata model node and adds itself as an attribute in the parent. | 219 | * Generates code for the current ata model node and adds itself as an attribute in the parent. |
175 | * | 220 | * |
176 | * @param javaCodeGeneratorInfo YANG java file info node | 221 | * @param javaCodeGeneratorInfo YANG java file info node |
... | @@ -193,7 +238,7 @@ public final class YangJavaModelUtils { | ... | @@ -193,7 +238,7 @@ public final class YangJavaModelUtils { |
193 | /* | 238 | /* |
194 | * Update the current nodes info in its parent nodes generated files. | 239 | * Update the current nodes info in its parent nodes generated files. |
195 | */ | 240 | */ |
196 | - addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | 241 | + addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin); |
197 | } | 242 | } |
198 | 243 | ||
199 | /** | 244 | /** |
... | @@ -242,7 +287,7 @@ public final class YangJavaModelUtils { | ... | @@ -242,7 +287,7 @@ public final class YangJavaModelUtils { |
242 | .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo); | 287 | .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo); |
243 | 288 | ||
244 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() | 289 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() |
245 | - .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo); | 290 | + .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin); |
246 | 291 | ||
247 | } | 292 | } |
248 | } | 293 | } |
... | @@ -284,7 +329,26 @@ public final class YangJavaModelUtils { | ... | @@ -284,7 +329,26 @@ public final class YangJavaModelUtils { |
284 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); | 329 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); |
285 | } | 330 | } |
286 | 331 | ||
332 | + if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { | ||
333 | + if (!((YangJavaModule) javaCodeGeneratorInfo) | ||
334 | + .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) { | ||
335 | + updateCodeGenInfoForEvent(javaCodeGeneratorInfo); | ||
336 | + } | ||
337 | + } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { | ||
338 | + if (!((YangJavaSubModule) javaCodeGeneratorInfo) | ||
339 | + .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) { | ||
340 | + updateCodeGenInfoForEvent(javaCodeGeneratorInfo); | ||
341 | + } | ||
342 | + } | ||
343 | + | ||
287 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); | 344 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); |
288 | } | 345 | } |
289 | 346 | ||
347 | + /*Updates java code generator info with events info.*/ | ||
348 | + private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) { | ||
349 | + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS); | ||
350 | + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS); | ||
351 | + javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE); | ||
352 | + } | ||
353 | + | ||
290 | } | 354 | } | ... | ... |
... | @@ -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. |
... | @@ -787,6 +797,11 @@ public final class UtilConstants { | ... | @@ -787,6 +797,11 @@ public final class UtilConstants { |
787 | public static final String ENUM = "enum"; | 797 | public static final String ENUM = "enum"; |
788 | 798 | ||
789 | /** | 799 | /** |
800 | + * Static attribute for type syntax. | ||
801 | + */ | ||
802 | + public static final String TYPE = "Type"; | ||
803 | + | ||
804 | + /** | ||
790 | * Static attribute for static syntax. | 805 | * Static attribute for static syntax. |
791 | */ | 806 | */ |
792 | public static final String STATIC = "static"; | 807 | public static final String STATIC = "static"; |
... | @@ -852,6 +867,11 @@ public final class UtilConstants { | ... | @@ -852,6 +867,11 @@ public final class UtilConstants { |
852 | public static final String EVENT_LISTENER_STRING = "Listener"; | 867 | public static final String EVENT_LISTENER_STRING = "Listener"; |
853 | 868 | ||
854 | /** | 869 | /** |
870 | + * For event subject file generation. | ||
871 | + */ | ||
872 | + public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject"; | ||
873 | + | ||
874 | + /** | ||
855 | * Static attribute for impl syntax. | 875 | * Static attribute for impl syntax. |
856 | */ | 876 | */ |
857 | public static final String IMPL = "Impl"; | 877 | public static final String IMPL = "Impl"; |
... | @@ -957,6 +977,130 @@ public final class UtilConstants { | ... | @@ -957,6 +977,130 @@ public final class UtilConstants { |
957 | public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; | 977 | public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; |
958 | 978 | ||
959 | /** | 979 | /** |
980 | + * Static attribute for activate annotation. | ||
981 | + */ | ||
982 | + public static final String ACTIVATE_ANNOTATION = "@Activate\n"; | ||
983 | + | ||
984 | + /** | ||
985 | + * Static attribute for activate. | ||
986 | + */ | ||
987 | + public static final String ACTIVATE = "activate"; | ||
988 | + | ||
989 | + /** | ||
990 | + * Static attribute for activate annotation import. | ||
991 | + */ | ||
992 | + public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n"; | ||
993 | + | ||
994 | + /** | ||
995 | + * Static attribute for deactivate annotation. | ||
996 | + */ | ||
997 | + public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n"; | ||
998 | + | ||
999 | + /** | ||
1000 | + * Static attribute for deactivate. | ||
1001 | + */ | ||
1002 | + public static final String DEACTIVATE = "deactivate"; | ||
1003 | + | ||
1004 | + /** | ||
1005 | + * Static attribute for deactivate annotation import. | ||
1006 | + */ | ||
1007 | + public static final String DEACTIVATE_ANNOTATION_IMPORT = | ||
1008 | + "import org.apache.felix.scr.annotations.Deactivate;\n"; | ||
1009 | + | ||
1010 | + /** | ||
1011 | + * Static attribute for component annotation. | ||
1012 | + */ | ||
1013 | + public static final String COMPONENT_ANNOTATION = "@Component"; | ||
1014 | + | ||
1015 | + /** | ||
1016 | + * Static attribute for immediate. | ||
1017 | + */ | ||
1018 | + public static final String IMMEDIATE = "immediate"; | ||
1019 | + | ||
1020 | + /** | ||
1021 | + * Static attribute for component annotation import. | ||
1022 | + */ | ||
1023 | + public static final String COMPONENT_ANNOTATION_IMPORT = | ||
1024 | + "import org.apache.felix.scr.annotations.Component;\n"; | ||
1025 | + | ||
1026 | + /** | ||
1027 | + * Static attribute for service annotation. | ||
1028 | + */ | ||
1029 | + public static final String SERVICE_ANNOTATION = "@Service\n"; | ||
1030 | + | ||
1031 | + /** | ||
1032 | + * Static attribute for service annotation import. | ||
1033 | + */ | ||
1034 | + public static final String SERVICE_ANNOTATION_IMPORT = | ||
1035 | + "import org.apache.felix.scr.annotations.Service;\n"; | ||
1036 | + | ||
1037 | + /** | ||
1038 | + * Static attribute for logger factory import. | ||
1039 | + */ | ||
1040 | + public static final String LOGGER_FACTORY_IMPORT = | ||
1041 | + "import static org.slf4j.LoggerFactory.getLogger;\n"; | ||
1042 | + | ||
1043 | + /** | ||
1044 | + * Static attribute for logger import. | ||
1045 | + */ | ||
1046 | + public static final String LOGGER_IMPORT = | ||
1047 | + "import org.slf4j.Logger;\n"; | ||
1048 | + | ||
1049 | + /** | ||
1050 | + * Static attribute for logger statement. | ||
1051 | + */ | ||
1052 | + public static final String LOGGER_STATEMENT = | ||
1053 | + "\n private final Logger log = getLogger(getClass());\n"; | ||
1054 | + | ||
1055 | + /** | ||
1056 | + * Static attribute for logger statement for started. | ||
1057 | + */ | ||
1058 | + public static final String STARTED_LOG_INFO = | ||
1059 | + "log.info(\"Started\");\n"; | ||
1060 | + | ||
1061 | + /** | ||
1062 | + * Static attribute for logger statement for stopped. | ||
1063 | + */ | ||
1064 | + public static final String STOPPED_LOG_INFO = | ||
1065 | + "log.info(\"Stopped\");\n"; | ||
1066 | + | ||
1067 | + /** | ||
1068 | + * Static attribute for AbstractEvent. | ||
1069 | + */ | ||
1070 | + public static final String ABSTRACT_EVENT = "AbstractEvent"; | ||
1071 | + | ||
1072 | + /** | ||
1073 | + * Static attribute for EventListener. | ||
1074 | + */ | ||
1075 | + public static final String EVENT_LISTENER = "EventListener"; | ||
1076 | + | ||
1077 | + /** | ||
1078 | + * Static attribute for YangBinary class. | ||
1079 | + */ | ||
1080 | + public static final String YANG_BINARY_CLASS = "YangBinary"; | ||
1081 | + | ||
1082 | + /** | ||
1083 | + * Static attribute for YangBinary class. | ||
1084 | + */ | ||
1085 | + public static final String YANG_BITS_CLASS = "YangBits"; | ||
1086 | + | ||
1087 | + /** | ||
1088 | + * Static attribute for YANG types package. | ||
1089 | + */ | ||
1090 | + public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.utils.builtindatatype"; | ||
1091 | + | ||
1092 | + /** | ||
1093 | + * Static attribute for MathContext class. | ||
1094 | + */ | ||
1095 | + public static final String MATH_CONTEXT = "MathContext"; | ||
1096 | + | ||
1097 | + /** | ||
1098 | + * Static attribute for DECIMAL64 class. | ||
1099 | + */ | ||
1100 | + public static final String YANG_DECIMAL64_CLASS = "YangDecimal64"; | ||
1101 | + | ||
1102 | + | ||
1103 | + /** | ||
960 | * Static attribute for YANG file error. | 1104 | * Static attribute for YANG file error. |
961 | */ | 1105 | */ |
962 | public static final String YANG_FILE_ERROR = "YANG file error : "; | 1106 | public static final String YANG_FILE_ERROR = "YANG file error : "; | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBinary.java
0 → 100644
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 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBits.java
0 → 100644
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 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangDecimal64.java
0 → 100644
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,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
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; |
... | @@ -181,7 +182,12 @@ public final class JavaDocGen { | ... | @@ -181,7 +182,12 @@ public final class JavaDocGen { |
181 | /** | 182 | /** |
182 | * For manager setters. | 183 | * For manager setters. |
183 | */ | 184 | */ |
184 | - MANAGER_SETTER_METHOD | 185 | + MANAGER_SETTER_METHOD, |
186 | + | ||
187 | + /** | ||
188 | + * For event subject. | ||
189 | + */ | ||
190 | + EVENT_SUBJECT_CLASS | ||
185 | } | 191 | } |
186 | 192 | ||
187 | /** | 193 | /** |
... | @@ -190,14 +196,15 @@ public final class JavaDocGen { | ... | @@ -190,14 +196,15 @@ public final class JavaDocGen { |
190 | * @param type java doc type | 196 | * @param type java doc type |
191 | * @param name name of the YangNode | 197 | * @param name name of the YangNode |
192 | * @param isList is list attribute | 198 | * @param isList is list attribute |
199 | + * @param pluginConfig plugin configurations | ||
193 | * @return javadocs. | 200 | * @return javadocs. |
194 | */ | 201 | */ |
195 | - public static String getJavaDoc(JavaDocType type, String name, boolean isList) { | 202 | + public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) { |
196 | 203 | ||
197 | - name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, null)); | 204 | + name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver())); |
198 | switch (type) { | 205 | switch (type) { |
199 | case IMPL_CLASS: { | 206 | case IMPL_CLASS: { |
200 | - return generateForImplClass(name); | 207 | + return generateForClass(name); |
201 | } | 208 | } |
202 | case BUILDER_CLASS: { | 209 | case BUILDER_CLASS: { |
203 | return generateForBuilderClass(name); | 210 | return generateForBuilderClass(name); |
... | @@ -248,7 +255,7 @@ public final class JavaDocGen { | ... | @@ -248,7 +255,7 @@ public final class JavaDocGen { |
248 | return generateForRpcService(name); | 255 | return generateForRpcService(name); |
249 | } | 256 | } |
250 | case RPC_MANAGER: { | 257 | case RPC_MANAGER: { |
251 | - return generateForImplClass(name); | 258 | + return generateForClass(name); |
252 | } | 259 | } |
253 | case EVENT: { | 260 | case EVENT: { |
254 | return generateForEvent(name); | 261 | return generateForEvent(name); |
... | @@ -256,6 +263,9 @@ public final class JavaDocGen { | ... | @@ -256,6 +263,9 @@ public final class JavaDocGen { |
256 | case EVENT_LISTENER: { | 263 | case EVENT_LISTENER: { |
257 | return generateForEventListener(name); | 264 | return generateForEventListener(name); |
258 | } | 265 | } |
266 | + case EVENT_SUBJECT_CLASS: { | ||
267 | + return generateForClass(name); | ||
268 | + } | ||
259 | default: { | 269 | default: { |
260 | return generateForConstructors(name); | 270 | return generateForConstructors(name); |
261 | } | 271 | } |
... | @@ -279,12 +289,15 @@ public final class JavaDocGen { | ... | @@ -279,12 +289,15 @@ public final class JavaDocGen { |
279 | * @param rpcName name of the rpc | 289 | * @param rpcName name of the rpc |
280 | * @param inputName name of input | 290 | * @param inputName name of input |
281 | * @param outputName name of output | 291 | * @param outputName name of output |
292 | + * @param pluginConfig plugin configurations | ||
282 | * @return javaDocs of rpc method | 293 | * @return javaDocs of rpc method |
283 | */ | 294 | */ |
284 | - public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) { | 295 | + public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName, |
285 | - rpcName = getCamelCase(rpcName, null); | 296 | + YangPluginConfig pluginConfig) { |
297 | + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); | ||
286 | 298 | ||
287 | - String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC | 299 | + String javadoc = |
300 | + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC | ||
288 | + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK | 301 | + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
289 | + getInputString(inputName, rpcName); | 302 | + getInputString(inputName, rpcName); |
290 | if (!outputName.equals(VOID)) { | 303 | if (!outputName.equals(VOID)) { |
... | @@ -470,7 +483,7 @@ public final class JavaDocGen { | ... | @@ -470,7 +483,7 @@ public final class JavaDocGen { |
470 | * @param className class name | 483 | * @param className class name |
471 | * @return javaDocs | 484 | * @return javaDocs |
472 | */ | 485 | */ |
473 | - private static String generateForImplClass(String className) { | 486 | + 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; | 487 | return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
475 | } | 488 | } |
476 | 489 | ... | ... |
... | @@ -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,113 @@ public final class YangIoUtils { | ... | @@ -318,4 +356,113 @@ 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 | + return stringBuilder.toString(); | ||
437 | + } | ||
438 | + | ||
439 | + /*Updates the given line with the given size conditions.*/ | ||
440 | + private static StringBuilder updateString(String[] strArray, StringBuilder stringBuilder, String string, | ||
441 | + int lineSize) { | ||
442 | + | ||
443 | + StringBuilder tempBuilder = new StringBuilder(); | ||
444 | + for (String str : strArray) { | ||
445 | + tempBuilder.append(str + string); | ||
446 | + if (tempBuilder.length() > lineSize) { | ||
447 | + String tempString = stringBuilder.toString(); | ||
448 | + stringBuilder.delete(ZERO, stringBuilder.length()); | ||
449 | + tempString = trimAtLast(tempString, string); | ||
450 | + stringBuilder.append(tempString); | ||
451 | + if (string.equals(PERIOD)) { | ||
452 | + stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string); | ||
453 | + } else { | ||
454 | + stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + str + string); | ||
455 | + } | ||
456 | + tempBuilder.delete(ZERO, tempBuilder.length()); | ||
457 | + tempBuilder.append(TWELVE_SPACE_INDENTATION); | ||
458 | + } else { | ||
459 | + stringBuilder.append(str + string); | ||
460 | + } | ||
461 | + } | ||
462 | + String tempString = stringBuilder.toString(); | ||
463 | + tempString = trimAtLast(tempString, string); | ||
464 | + stringBuilder.delete(ZERO, stringBuilder.length()); | ||
465 | + stringBuilder.append(tempString + NEW_LINE); | ||
466 | + return stringBuilder; | ||
467 | + } | ||
321 | } | 468 | } | ... | ... |
... | @@ -71,7 +71,8 @@ public class AttributesJavaDataTypeTest { | ... | @@ -71,7 +71,8 @@ public class AttributesJavaDataTypeTest { |
71 | * @throws InvocationTargetException when an exception occurs by the method or constructor | 71 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
72 | */ | 72 | */ |
73 | @Test | 73 | @Test |
74 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 74 | + public void callPrivateConstructors() |
75 | + throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
75 | InstantiationException, IllegalAccessException, InvocationTargetException { | 76 | InstantiationException, IllegalAccessException, InvocationTargetException { |
76 | 77 | ||
77 | Class<?>[] classesToConstruct = {AttributesJavaDataType.class }; | 78 | Class<?>[] classesToConstruct = {AttributesJavaDataType.class }; |
... | @@ -87,16 +88,17 @@ public class AttributesJavaDataTypeTest { | ... | @@ -87,16 +88,17 @@ public class AttributesJavaDataTypeTest { |
87 | */ | 88 | */ |
88 | @Test | 89 | @Test |
89 | public void testgetJavaClassInfo() { | 90 | public void testgetJavaClassInfo() { |
90 | - test = getJavaImportClass(getStubYangType(TYPE1), false); | 91 | + YangToJavaNamingConflictUtil pluginConfig = null; |
92 | + test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig); | ||
91 | assertThat(true, is(test.equals(CLASS_INFO1))); | 93 | assertThat(true, is(test.equals(CLASS_INFO1))); |
92 | 94 | ||
93 | - test = getJavaImportClass(getStubYangType(TYPE2), true); | 95 | + test = getJavaImportClass(getStubYangType(TYPE2), true, pluginConfig); |
94 | assertThat(true, is(test.equals(CLASS_INFO5))); | 96 | assertThat(true, is(test.equals(CLASS_INFO5))); |
95 | 97 | ||
96 | - test = getJavaImportClass(getStubYangType(TYPE3), false); | 98 | + test = getJavaImportClass(getStubYangType(TYPE3), false, pluginConfig); |
97 | assertThat(null, is(test)); | 99 | assertThat(null, is(test)); |
98 | 100 | ||
99 | - test = getJavaImportClass(getStubYangType(TYPE4), false); | 101 | + test = getJavaImportClass(getStubYangType(TYPE4), false, pluginConfig); |
100 | assertThat(null, is(test)); | 102 | assertThat(null, is(test)); |
101 | } | 103 | } |
102 | 104 | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | + | ||
20 | import org.junit.Test; | 21 | import org.junit.Test; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 23 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
... | @@ -44,7 +45,7 @@ public final class ChoiceCaseTranslatorTest { | ... | @@ -44,7 +45,7 @@ public final class ChoiceCaseTranslatorTest { |
44 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 45 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
45 | yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); | 46 | yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); |
46 | 47 | ||
47 | - generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator"); | 48 | + generateJavaCode(node, yangPluginConfig); |
48 | 49 | ||
49 | deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/"); | 50 | deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/"); |
50 | } | 51 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public final class EnumTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class EnumTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig, "EnumTranslator"); | 49 | + generateJavaCode(node, yangPluginConfig); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/EnumTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/EnumTestGenFile/"); |
52 | } | 52 | } | ... | ... |
... | @@ -29,6 +29,7 @@ import static org.hamcrest.core.IsNot.not; | ... | @@ -29,6 +29,7 @@ import static org.hamcrest.core.IsNot.not; |
29 | import static org.junit.Assert.assertThat; | 29 | import static org.junit.Assert.assertThat; |
30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | 30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; |
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
32 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
32 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface; | 34 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface; |
34 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull; | 35 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull; |
... | @@ -105,7 +106,7 @@ public final class MethodsGeneratorTest { | ... | @@ -105,7 +106,7 @@ public final class MethodsGeneratorTest { |
105 | throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 106 | throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
106 | InstantiationException, IllegalAccessException, InvocationTargetException { | 107 | InstantiationException, IllegalAccessException, InvocationTargetException { |
107 | 108 | ||
108 | - Class<?>[] classesToConstruct = {MethodsGenerator.class}; | 109 | + Class<?>[] classesToConstruct = {MethodsGenerator.class }; |
109 | for (Class<?> clazz : classesToConstruct) { | 110 | for (Class<?> clazz : classesToConstruct) { |
110 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 111 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
111 | constructor.setAccessible(true); | 112 | constructor.setAccessible(true); |
... | @@ -118,8 +119,10 @@ public final class MethodsGeneratorTest { | ... | @@ -118,8 +119,10 @@ public final class MethodsGeneratorTest { |
118 | */ | 119 | */ |
119 | @Test | 120 | @Test |
120 | public void getTypeConstructorTest() { | 121 | public void getTypeConstructorTest() { |
122 | + | ||
123 | + YangPluginConfig pluginConfig = new YangPluginConfig(); | ||
121 | JavaAttributeInfo testAttr = getTestAttribute(); | 124 | JavaAttributeInfo testAttr = getTestAttribute(); |
122 | - String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME); | 125 | + String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME, pluginConfig); |
123 | assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); | 126 | assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); |
124 | } | 127 | } |
125 | 128 | ||
... | @@ -162,7 +165,8 @@ public final class MethodsGeneratorTest { | ... | @@ -162,7 +165,8 @@ public final class MethodsGeneratorTest { |
162 | @Test | 165 | @Test |
163 | public void getConstructorTest() { | 166 | public void getConstructorTest() { |
164 | JavaAttributeInfo testAttr = getTestAttribute(); | 167 | JavaAttributeInfo testAttr = getTestAttribute(); |
165 | - String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER); | 168 | + YangPluginConfig pluginConfig = new YangPluginConfig(); |
169 | + String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig); | ||
166 | assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT | 170 | assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT |
167 | + PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN))); | 171 | + PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN))); |
168 | } | 172 | } |
... | @@ -172,7 +176,8 @@ public final class MethodsGeneratorTest { | ... | @@ -172,7 +176,8 @@ public final class MethodsGeneratorTest { |
172 | */ | 176 | */ |
173 | @Test | 177 | @Test |
174 | public void getConstructorStartTest() { | 178 | public void getConstructorStartTest() { |
175 | - String method = getConstructorStart(CLASS_NAME); | 179 | + YangPluginConfig pluginConfig = new YangPluginConfig(); |
180 | + String method = getConstructorStart(CLASS_NAME, pluginConfig); | ||
176 | assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME | 181 | assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME |
177 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE | 182 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE |
178 | + OPEN_CURLY_BRACKET + NEW_LINE))); | 183 | + OPEN_CURLY_BRACKET + NEW_LINE))); |
... | @@ -227,10 +232,10 @@ public final class MethodsGeneratorTest { | ... | @@ -227,10 +232,10 @@ public final class MethodsGeneratorTest { |
227 | public void getSetterForClassTest() { | 232 | public void getSetterForClassTest() { |
228 | JavaAttributeInfo testAttr = getTestAttribute(); | 233 | JavaAttributeInfo testAttr = getTestAttribute(); |
229 | String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER); | 234 | String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER); |
230 | -// assertThat(true, is( | 235 | + assertThat(true, is( |
231 | -// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX | 236 | + method.contains(PUBLIC + SPACE + VOID + SPACE + |
232 | -// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE | 237 | + SET_METHOD_PREFIX + getCapitalCase(CLASS_NAME) + OPEN_PARENTHESIS + |
233 | -// + ATTRIBUTE_NAME))); | 238 | + STRING_DATA_TYPE + SPACE + ATTRIBUTE_NAME))); |
234 | } | 239 | } |
235 | 240 | ||
236 | /** | 241 | /** |
... | @@ -240,7 +245,8 @@ public final class MethodsGeneratorTest { | ... | @@ -240,7 +245,8 @@ public final class MethodsGeneratorTest { |
240 | public void getSetterForInterfaceTest() { | 245 | public void getSetterForInterfaceTest() { |
241 | String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false, | 246 | String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false, |
242 | GENERATE_SERVICE_AND_MANAGER); | 247 | GENERATE_SERVICE_AND_MANAGER); |
243 | -// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname"))); | 248 | + assertThat(true, is(method.contains(VOID + SPACE + |
249 | + SET_METHOD_PREFIX + "Testname"))); | ||
244 | } | 250 | } |
245 | 251 | ||
246 | /** | 252 | /** | ... | ... |
... | @@ -46,7 +46,7 @@ public final class NotificationTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class NotificationTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig, "NotificationTest"); | 49 | + generateJavaCode(node, yangPluginConfig); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/NotificationTest/"); | 51 | deleteDirectory(userDir + "/target/NotificationTest/"); |
52 | } | 52 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public final class RpcTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class RpcTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig, "RpcTranslator"); | 49 | + generateJavaCode(node, yangPluginConfig); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/RpcTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/RpcTestGenFile/"); |
52 | } | 52 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public final class UnionTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class UnionTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig, "UnionTranslator"); | 49 | + generateJavaCode(node, yangPluginConfig); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/UnionTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/UnionTestGenFile/"); |
52 | } | 52 | } | ... | ... |
... | @@ -25,6 +25,7 @@ import org.junit.Test; | ... | @@ -25,6 +25,7 @@ import org.junit.Test; |
25 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | 27 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
28 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
28 | 29 | ||
29 | import static org.hamcrest.core.Is.is; | 30 | import static org.hamcrest.core.Is.is; |
30 | import static org.hamcrest.core.IsNot.not; | 31 | import static org.hamcrest.core.IsNot.not; |
... | @@ -125,7 +126,20 @@ public final class FileSystemUtilTest { | ... | @@ -125,7 +126,20 @@ public final class FileSystemUtilTest { |
125 | javafileInfo.setJavaName(TEST_DATA_1); | 126 | javafileInfo.setJavaName(TEST_DATA_1); |
126 | javafileInfo.setBaseCodeGenPath(""); | 127 | javafileInfo.setBaseCodeGenPath(""); |
127 | javafileInfo.setPackageFilePath(BASE_PKG); | 128 | javafileInfo.setPackageFilePath(BASE_PKG); |
129 | + javafileInfo.setPluginConfig(getStubPluginConfig()); | ||
128 | module.setJavaFileInfo(javafileInfo); | 130 | module.setJavaFileInfo(javafileInfo); |
129 | return module; | 131 | return module; |
130 | } | 132 | } |
133 | + | ||
134 | + /** | ||
135 | + * Returns stub pluginConfig. | ||
136 | + * | ||
137 | + * @return stub pluginConfig | ||
138 | + */ | ||
139 | + private YangPluginConfig getStubPluginConfig() { | ||
140 | + YangPluginConfig pluginConfig = new YangPluginConfig(); | ||
141 | + pluginConfig.setConflictResolver(null); | ||
142 | + return pluginConfig; | ||
143 | + } | ||
144 | + | ||
131 | } | 145 | } | ... | ... |
... | @@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException; | ... | @@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException; |
22 | import org.junit.Rule; | 22 | import org.junit.Rule; |
23 | import org.junit.Test; | 23 | import org.junit.Test; |
24 | import org.junit.rules.ExpectedException; | 24 | import org.junit.rules.ExpectedException; |
25 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
25 | 26 | ||
26 | import static org.hamcrest.core.Is.is; | 27 | import static org.hamcrest.core.Is.is; |
27 | import static org.hamcrest.core.IsNot.not; | 28 | import static org.hamcrest.core.IsNot.not; |
... | @@ -55,7 +56,7 @@ public final class JavaDocGenTest { | ... | @@ -55,7 +56,7 @@ public final class JavaDocGenTest { |
55 | */ | 56 | */ |
56 | @Test | 57 | @Test |
57 | public void builderClassGenerationTest() { | 58 | public void builderClassGenerationTest() { |
58 | - String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false); | 59 | + String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig()); |
59 | assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of") | 60 | assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of") |
60 | && builderClassJavaDoc.contains(END_STRING))); | 61 | && builderClassJavaDoc.contains(END_STRING))); |
61 | } | 62 | } |
... | @@ -65,9 +66,10 @@ public final class JavaDocGenTest { | ... | @@ -65,9 +66,10 @@ public final class JavaDocGenTest { |
65 | */ | 66 | */ |
66 | @Test | 67 | @Test |
67 | public void builderInterfaceGenerationTest() { | 68 | public void builderInterfaceGenerationTest() { |
68 | - String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false); | 69 | + String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig()); |
69 | assertThat(true, | 70 | assertThat(true, |
70 | - is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING))); | 71 | + is(builderInterfaceJavaDoc.contains("Builder for") |
72 | + && builderInterfaceJavaDoc.contains(END_STRING))); | ||
71 | } | 73 | } |
72 | 74 | ||
73 | /** | 75 | /** |
... | @@ -75,7 +77,7 @@ public final class JavaDocGenTest { | ... | @@ -75,7 +77,7 @@ public final class JavaDocGenTest { |
75 | */ | 77 | */ |
76 | @Test | 78 | @Test |
77 | public void buildGenerationTest() { | 79 | public void buildGenerationTest() { |
78 | - String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false); | 80 | + String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig()); |
79 | assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING))); | 81 | assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING))); |
80 | } | 82 | } |
81 | 83 | ||
... | @@ -90,7 +92,8 @@ public final class JavaDocGenTest { | ... | @@ -90,7 +92,8 @@ public final class JavaDocGenTest { |
90 | * @throws InvocationTargetException when an exception occurs by the method or constructor | 92 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
91 | */ | 93 | */ |
92 | @Test | 94 | @Test |
93 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 95 | + public void callPrivateConstructors() |
96 | + throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
94 | InstantiationException, IllegalAccessException, InvocationTargetException { | 97 | InstantiationException, IllegalAccessException, InvocationTargetException { |
95 | 98 | ||
96 | Class<?>[] classesToConstruct = {JavaDocGen.class }; | 99 | Class<?>[] classesToConstruct = {JavaDocGen.class }; |
... | @@ -106,9 +109,10 @@ public final class JavaDocGenTest { | ... | @@ -106,9 +109,10 @@ public final class JavaDocGenTest { |
106 | */ | 109 | */ |
107 | @Test | 110 | @Test |
108 | public void constructorGenerationTest() { | 111 | public void constructorGenerationTest() { |
109 | - String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false); | 112 | + String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig()); |
110 | assertThat(true, | 113 | assertThat(true, |
111 | - is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of") | 114 | + is(constructorDoc.contains("Creates an instance of ") |
115 | + && constructorDoc.contains("builder object of") | ||
112 | && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"))); | 116 | && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"))); |
113 | } | 117 | } |
114 | 118 | ||
... | @@ -117,7 +121,7 @@ public final class JavaDocGenTest { | ... | @@ -117,7 +121,7 @@ public final class JavaDocGenTest { |
117 | */ | 121 | */ |
118 | @Test | 122 | @Test |
119 | public void defaultConstructorGenerationTest() { | 123 | public void defaultConstructorGenerationTest() { |
120 | - String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false); | 124 | + String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig()); |
121 | assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ") | 125 | assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ") |
122 | && defaultConstructorDoc.contains(END_STRING))); | 126 | && defaultConstructorDoc.contains(END_STRING))); |
123 | } | 127 | } |
... | @@ -127,8 +131,9 @@ public final class JavaDocGenTest { | ... | @@ -127,8 +131,9 @@ public final class JavaDocGenTest { |
127 | */ | 131 | */ |
128 | @Test | 132 | @Test |
129 | public void getterGenerationTest() { | 133 | public void getterGenerationTest() { |
130 | - String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false); | 134 | + String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig()); |
131 | - assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING))); | 135 | + assertThat(true, |
136 | + is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING))); | ||
132 | } | 137 | } |
133 | 138 | ||
134 | /** | 139 | /** |
... | @@ -136,7 +141,7 @@ public final class JavaDocGenTest { | ... | @@ -136,7 +141,7 @@ public final class JavaDocGenTest { |
136 | */ | 141 | */ |
137 | @Test | 142 | @Test |
138 | public void implClassGenerationTest() { | 143 | public void implClassGenerationTest() { |
139 | - String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false); | 144 | + String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig()); |
140 | assertThat(true, | 145 | assertThat(true, |
141 | is(implClassJavaDoc.contains("Represents the implementation of") | 146 | is(implClassJavaDoc.contains("Represents the implementation of") |
142 | && implClassJavaDoc.contains(END_STRING))); | 147 | && implClassJavaDoc.contains(END_STRING))); |
... | @@ -147,7 +152,7 @@ public final class JavaDocGenTest { | ... | @@ -147,7 +152,7 @@ public final class JavaDocGenTest { |
147 | */ | 152 | */ |
148 | @Test | 153 | @Test |
149 | public void interfaceGenerationTest() { | 154 | public void interfaceGenerationTest() { |
150 | - String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false); | 155 | + String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig()); |
151 | assertThat(true, | 156 | assertThat(true, |
152 | is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of") | 157 | is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of") |
153 | && interfaceJavaDoc.contains(END_STRING))); | 158 | && interfaceJavaDoc.contains(END_STRING))); |
... | @@ -158,8 +163,9 @@ public final class JavaDocGenTest { | ... | @@ -158,8 +163,9 @@ public final class JavaDocGenTest { |
158 | */ | 163 | */ |
159 | @Test | 164 | @Test |
160 | public void packageInfoGenerationTest() { | 165 | public void packageInfoGenerationTest() { |
161 | - String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); | 166 | + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig()); |
162 | - assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING))); | 167 | + assertThat(true, |
168 | + is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING))); | ||
163 | } | 169 | } |
164 | 170 | ||
165 | /** | 171 | /** |
... | @@ -167,7 +173,7 @@ public final class JavaDocGenTest { | ... | @@ -167,7 +173,7 @@ public final class JavaDocGenTest { |
167 | */ | 173 | */ |
168 | @Test | 174 | @Test |
169 | public void packageInfoGenerationForChildNodeTest() { | 175 | public void packageInfoGenerationForChildNodeTest() { |
170 | - String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true); | 176 | + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig()); |
171 | assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes") | 177 | assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes") |
172 | && packageInfo.contains(END_STRING))); | 178 | && packageInfo.contains(END_STRING))); |
173 | } | 179 | } |
... | @@ -177,7 +183,7 @@ public final class JavaDocGenTest { | ... | @@ -177,7 +183,7 @@ public final class JavaDocGenTest { |
177 | */ | 183 | */ |
178 | @Test | 184 | @Test |
179 | public void setterGenerationTest() { | 185 | public void setterGenerationTest() { |
180 | - String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false); | 186 | + String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig()); |
181 | assertThat(true, | 187 | assertThat(true, |
182 | is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING))); | 188 | is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING))); |
183 | } | 189 | } |
... | @@ -187,7 +193,18 @@ public final class JavaDocGenTest { | ... | @@ -187,7 +193,18 @@ public final class JavaDocGenTest { |
187 | */ | 193 | */ |
188 | @Test | 194 | @Test |
189 | public void typeDefSetterGenerationTest() { | 195 | public void typeDefSetterGenerationTest() { |
190 | - String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false); | 196 | + String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig()); |
191 | assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING))); | 197 | assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING))); |
192 | } | 198 | } |
199 | + | ||
200 | + /** | ||
201 | + * Returns stub pluginConfig. | ||
202 | + * | ||
203 | + * @return stub pluginConfig | ||
204 | + */ | ||
205 | + private YangPluginConfig getStubPluginConfig() { | ||
206 | + YangPluginConfig pluginConfig = new YangPluginConfig(); | ||
207 | + pluginConfig.setConflictResolver(null); | ||
208 | + return pluginConfig; | ||
209 | + } | ||
193 | } | 210 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -25,6 +25,7 @@ import org.apache.maven.project.MavenProject; | ... | @@ -25,6 +25,7 @@ import org.apache.maven.project.MavenProject; |
25 | import org.junit.Rule; | 25 | import org.junit.Rule; |
26 | import org.junit.Test; | 26 | import org.junit.Test; |
27 | import org.junit.rules.ExpectedException; | 27 | import org.junit.rules.ExpectedException; |
28 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
28 | import org.onosproject.yangutils.utils.UtilConstants; | 29 | import org.onosproject.yangutils.utils.UtilConstants; |
29 | import org.sonatype.plexus.build.incremental.BuildContext; | 30 | import org.sonatype.plexus.build.incremental.BuildContext; |
30 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; | 31 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; |
... | @@ -68,7 +69,7 @@ public final class YangIoUtilsTest { | ... | @@ -68,7 +69,7 @@ public final class YangIoUtilsTest { |
68 | 69 | ||
69 | File dirPath = new File(CREATE_PATH); | 70 | File dirPath = new File(CREATE_PATH); |
70 | dirPath.mkdirs(); | 71 | dirPath.mkdirs(); |
71 | - addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); | 72 | + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig()); |
72 | File filePath = new File(dirPath + File.separator + PKG_INFO); | 73 | File filePath = new File(dirPath + File.separator + PKG_INFO); |
73 | assertThat(filePath.isFile(), is(true)); | 74 | assertThat(filePath.isFile(), is(true)); |
74 | } | 75 | } |
... | @@ -83,7 +84,7 @@ public final class YangIoUtilsTest { | ... | @@ -83,7 +84,7 @@ public final class YangIoUtilsTest { |
83 | 84 | ||
84 | File dirPath = new File(CREATE_PATH); | 85 | File dirPath = new File(CREATE_PATH); |
85 | dirPath.mkdirs(); | 86 | dirPath.mkdirs(); |
86 | - addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false); | 87 | + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig()); |
87 | File filePath = new File(dirPath + File.separator + PKG_INFO); | 88 | File filePath = new File(dirPath + File.separator + PKG_INFO); |
88 | assertThat(filePath.isFile(), is(true)); | 89 | assertThat(filePath.isFile(), is(true)); |
89 | } | 90 | } |
... | @@ -98,7 +99,7 @@ public final class YangIoUtilsTest { | ... | @@ -98,7 +99,7 @@ public final class YangIoUtilsTest { |
98 | 99 | ||
99 | File dirPath = new File(CREATE_PATH); | 100 | File dirPath = new File(CREATE_PATH); |
100 | dirPath.mkdirs(); | 101 | dirPath.mkdirs(); |
101 | - addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true); | 102 | + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig()); |
102 | File filePath = new File(dirPath + File.separator + PKG_INFO); | 103 | File filePath = new File(dirPath + File.separator + PKG_INFO); |
103 | assertThat(filePath.isFile(), is(true)); | 104 | assertThat(filePath.isFile(), is(true)); |
104 | } | 105 | } |
... | @@ -114,7 +115,7 @@ public final class YangIoUtilsTest { | ... | @@ -114,7 +115,7 @@ public final class YangIoUtilsTest { |
114 | File dirPath = new File("invalid/check"); | 115 | File dirPath = new File("invalid/check"); |
115 | thrown.expect(IOException.class); | 116 | thrown.expect(IOException.class); |
116 | thrown.expectMessage(MSG); | 117 | thrown.expectMessage(MSG); |
117 | - addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); | 118 | + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig()); |
118 | File filePath1 = new File(dirPath + File.separator + PKG_INFO); | 119 | File filePath1 = new File(dirPath + File.separator + PKG_INFO); |
119 | assertThat(filePath1.isFile(), is(false)); | 120 | assertThat(filePath1.isFile(), is(false)); |
120 | } | 121 | } |
... | @@ -130,7 +131,8 @@ public final class YangIoUtilsTest { | ... | @@ -130,7 +131,8 @@ public final class YangIoUtilsTest { |
130 | * @throws InvocationTargetException when an exception occurs by the method or constructor | 131 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
131 | */ | 132 | */ |
132 | @Test | 133 | @Test |
133 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 134 | + public void callPrivateConstructors() |
135 | + throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
134 | InstantiationException, IllegalAccessException, InvocationTargetException { | 136 | InstantiationException, IllegalAccessException, InvocationTargetException { |
135 | 137 | ||
136 | Class<?>[] classesToConstruct = {YangIoUtils.class }; | 138 | Class<?>[] classesToConstruct = {YangIoUtils.class }; |
... | @@ -192,7 +194,7 @@ public final class YangIoUtilsTest { | ... | @@ -192,7 +194,7 @@ public final class YangIoUtilsTest { |
192 | addToSource(sourceDir.toString(), project, context); | 194 | addToSource(sourceDir.toString(), project, context); |
193 | } | 195 | } |
194 | 196 | ||
195 | - /* | 197 | + /** |
196 | * Unit test case for trim at last method. | 198 | * Unit test case for trim at last method. |
197 | */ | 199 | */ |
198 | @Test | 200 | @Test |
... | @@ -202,4 +204,14 @@ public final class YangIoUtilsTest { | ... | @@ -202,4 +204,14 @@ public final class YangIoUtilsTest { |
202 | assertThat(test.contains(TRIM_STRING), is(true)); | 204 | assertThat(test.contains(TRIM_STRING), is(true)); |
203 | } | 205 | } |
204 | 206 | ||
207 | + /** | ||
208 | + * Returns stub pluginConfig. | ||
209 | + * | ||
210 | + * @return stub pluginConfig | ||
211 | + */ | ||
212 | + private YangPluginConfig getStubPluginConfig() { | ||
213 | + YangPluginConfig pluginConfig = new YangPluginConfig(); | ||
214 | + pluginConfig.setConflictResolver(null); | ||
215 | + return pluginConfig; | ||
216 | + } | ||
205 | } | 217 | } | ... | ... |
-
Please register or login to post a comment