Bharat saraswal
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 1235 additions and 652 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 }
......
...@@ -84,6 +84,11 @@ public final class GeneratedJavaFileType { ...@@ -84,6 +84,11 @@ public final class GeneratedJavaFileType {
84 public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512; 84 public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
85 85
86 /** 86 /**
87 + * Event listener class.
88 + */
89 + public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
90 +
91 + /**
87 * Creates an instance of generate java file type. 92 * Creates an instance of generate java file type.
88 */ 93 */
89 private GeneratedJavaFileType() { 94 private GeneratedJavaFileType() {
......
...@@ -97,6 +97,31 @@ public final class GeneratedTempFileType { ...@@ -97,6 +97,31 @@ public final class GeneratedTempFileType {
97 public static final int RPC_IMPL_MASK = 16384; 97 public static final int RPC_IMPL_MASK = 16384;
98 98
99 /** 99 /**
100 + * Event enum implementation of class.
101 + */
102 + public static final int EVENT_ENUM_MASK = 32768;
103 +
104 + /**
105 + * Event method implementation of class.
106 + */
107 + public static final int EVENT_METHOD_MASK = 65536;
108 +
109 + /**
110 + * Event subject attribute implementation of class.
111 + */
112 + public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 131072;
113 +
114 + /**
115 + * Event subject getter implementation of class.
116 + */
117 + public static final int EVENT_SUBJECT_GETTER_MASK = 262144;
118 +
119 + /**
120 + * Event subject setter implementation of class.
121 + */
122 + public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
123 +
124 + /**
100 * Creates an instance of generated temp file type. 125 * Creates an instance of generated temp file type.
101 */ 126 */
102 private GeneratedTempFileType() { 127 private GeneratedTempFileType() {
......
...@@ -66,11 +66,10 @@ public final class JavaCodeGeneratorUtil { ...@@ -66,11 +66,10 @@ public final class JavaCodeGeneratorUtil {
66 * 66 *
67 * @param rootNode root node of the data model tree 67 * @param rootNode root node of the data model tree
68 * @param yangPlugin YANG plugin config 68 * @param yangPlugin YANG plugin config
69 - * @param fileName YANG file name
70 * @throws TranslatorException when fails to generate java code file the current 69 * @throws TranslatorException when fails to generate java code file the current
71 * node 70 * node
72 */ 71 */
73 - public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName) 72 + public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
74 throws TranslatorException { 73 throws TranslatorException {
75 74
76 YangNode codeGenNode = rootNode; 75 YangNode codeGenNode = rootNode;
...@@ -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,26 +155,28 @@ public final class JavaCodeGeneratorUtil { ...@@ -162,26 +155,28 @@ public final class JavaCodeGeneratorUtil {
162 private static void freeRestResources() { 155 private static void freeRestResources() {
163 156
164 YangNode freedNode = getCurNode(); 157 YangNode freedNode = getCurNode();
165 - YangNode tempNode = freedNode; 158 + if (getCurNode() != null) {
166 - TraversalType curTraversal = ROOT; 159 + YangNode tempNode = freedNode;
167 - 160 + TraversalType curTraversal = ROOT;
168 - while (freedNode != tempNode.getParent()) { 161 +
169 - 162 + while (freedNode != tempNode.getParent()) {
170 - if (curTraversal != PARENT && freedNode.getChild() != null) { 163 +
171 - curTraversal = CHILD; 164 + if (curTraversal != PARENT && freedNode.getChild() != null) {
172 - freedNode = freedNode.getChild(); 165 + curTraversal = CHILD;
173 - } else if (freedNode.getNextSibling() != null) { 166 + freedNode = freedNode.getChild();
174 - curTraversal = SIBILING; 167 + } else if (freedNode.getNextSibling() != null) {
175 - if (freedNode != tempNode) { 168 + curTraversal = SIBILING;
176 - free(freedNode); 169 + if (freedNode != tempNode) {
177 - } 170 + free(freedNode);
178 - freedNode = freedNode.getNextSibling(); 171 + }
179 - } else { 172 + freedNode = freedNode.getNextSibling();
180 - curTraversal = PARENT; 173 + } else {
181 - if (freedNode != tempNode) { 174 + curTraversal = PARENT;
182 - free(freedNode); 175 + if (freedNode != tempNode) {
176 + free(freedNode);
177 + }
178 + freedNode = freedNode.getParent();
183 } 179 }
184 - freedNode = freedNode.getParent();
185 } 180 }
186 } 181 }
187 } 182 }
...@@ -213,36 +208,38 @@ public final class JavaCodeGeneratorUtil { ...@@ -213,36 +208,38 @@ 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
216 - /** 211 + if (rootNode != null) {
217 - * Free other resources where translator has failed. 212 + /**
218 - */ 213 + * Free other resources where translator has failed.
219 - freeRestResources(); 214 + */
215 + freeRestResources();
220 216
221 - /** 217 + /**
222 - * Start removing all open files. 218 + * Start removing all open files.
223 - */ 219 + */
224 - YangNode tempNode = rootNode; 220 + YangNode tempNode = rootNode;
225 - setCurNode(tempNode.getChild()); 221 + setCurNode(tempNode.getChild());
226 - TraversalType curTraversal = ROOT; 222 + TraversalType curTraversal = ROOT;
227 223
228 - while (tempNode != null) { 224 + while (tempNode != null) {
229 225
230 - if (curTraversal != PARENT) { 226 + if (curTraversal != PARENT) {
231 - close(tempNode); 227 + close(tempNode);
232 - } 228 + }
233 - if (curTraversal != PARENT && tempNode.getChild() != null) { 229 + if (curTraversal != PARENT && tempNode.getChild() != null) {
234 - curTraversal = CHILD; 230 + curTraversal = CHILD;
235 - tempNode = tempNode.getChild(); 231 + tempNode = tempNode.getChild();
236 - } else if (tempNode.getNextSibling() != null) { 232 + } else if (tempNode.getNextSibling() != null) {
237 - curTraversal = SIBILING; 233 + curTraversal = SIBILING;
238 - tempNode = tempNode.getNextSibling(); 234 + tempNode = tempNode.getNextSibling();
239 - } else { 235 + } else {
240 - curTraversal = PARENT; 236 + curTraversal = PARENT;
241 - tempNode = tempNode.getParent(); 237 + tempNode = tempNode.getParent();
238 + }
242 } 239 }
243 - }
244 240
245 - freeRestResources(); 241 + freeRestResources();
242 + }
246 } 243 }
247 244
248 /** 245 /**
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.yangutils.translator.tojava; 17 package org.onosproject.yangutils.translator.tojava;
18 18
19 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
20 +
19 /** 21 /**
20 * Represents cached java file handle, which supports the addition of member attributes and 22 * Represents cached java file handle, which supports the addition of member attributes and
21 * methods. 23 * methods.
...@@ -49,6 +51,11 @@ public class JavaFileInfo { ...@@ -49,6 +51,11 @@ public class JavaFileInfo {
49 private String codeGenDirFilePath; 51 private String codeGenDirFilePath;
50 52
51 /** 53 /**
54 + * Plugin configuration for naming convention.
55 + */
56 + private YangPluginConfig pluginConfig;
57 +
58 + /**
52 * Returns the types of files being generated corresponding to the YANG 59 * Returns the types of files being generated corresponding to the YANG
53 * definition. 60 * definition.
54 * 61 *
...@@ -152,4 +159,22 @@ public class JavaFileInfo { ...@@ -152,4 +159,22 @@ public class JavaFileInfo {
152 public void setBaseCodeGenPath(String path) { 159 public void setBaseCodeGenPath(String path) {
153 codeGenDirFilePath = path; 160 codeGenDirFilePath = path;
154 } 161 }
162 +
163 + /**
164 + * Returns plugin configurations.
165 + *
166 + * @return the pluginConfig
167 + */
168 + public YangPluginConfig getPluginConfig() {
169 + return pluginConfig;
170 + }
171 +
172 + /**
173 + * Sets plugin configurations.
174 + *
175 + * @param pluginConfig the pluginConfig to set
176 + */
177 + public void setPluginConfig(YangPluginConfig pluginConfig) {
178 + this.pluginConfig = pluginConfig;
179 + }
155 } 180 }
......
...@@ -22,12 +22,14 @@ import java.util.TreeSet; ...@@ -22,12 +22,14 @@ import java.util.TreeSet;
22 22
23 import static java.util.Collections.sort; 23 import static java.util.Collections.sort;
24 24
25 +import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
25 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; 26 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
26 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS; 27 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
27 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS; 28 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
28 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG; 29 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
29 import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; 30 import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
30 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 31 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
32 +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
31 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; 33 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
32 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; 34 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
33 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; 35 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
...@@ -35,10 +37,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; ...@@ -35,10 +37,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
35 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; 37 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
36 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; 38 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
37 import static org.onosproject.yangutils.utils.UtilConstants.LIST; 39 import static org.onosproject.yangutils.utils.UtilConstants.LIST;
38 -import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
39 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; 40 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
40 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; 41 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
41 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 42 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
43 +import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
42 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 44 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
43 import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG; 45 import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
44 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 46 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
...@@ -218,7 +220,7 @@ public class JavaImportData { ...@@ -218,7 +220,7 @@ public class JavaImportData {
218 * @return import string for ListenerService class 220 * @return import string for ListenerService class
219 */ 221 */
220 public String getListenerServiceImport() { 222 public String getListenerServiceImport() {
221 - return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE; 223 + return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
222 } 224 }
223 225
224 /** 226 /**
...@@ -227,6 +229,24 @@ public class JavaImportData { ...@@ -227,6 +229,24 @@ public class JavaImportData {
227 * @return import string for ListenerRegistry class 229 * @return import string for ListenerRegistry class
228 */ 230 */
229 public String getListenerRegistryImport() { 231 public String getListenerRegistryImport() {
230 - return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE; 232 + return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
233 + }
234 +
235 + /**
236 + * Returns import string for AbstractEvent class.
237 + *
238 + * @return import string for AbstractEvent class
239 + */
240 + public String getAbstractEventsImport() {
241 + return IMPORT + ONOS_EVENT_PKG + PERIOD + ABSTRACT_EVENT + SEMI_COLAN + NEW_LINE;
242 + }
243 +
244 + /**
245 + * Returns import string for EventListener class.
246 + *
247 + * @return import string for EventListener class
248 + */
249 + public String getEventListenerImport() {
250 + return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
231 } 251 }
232 } 252 }
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 22 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; 23 import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
24 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; 24 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
25 26
26 import com.google.common.base.MoreObjects; 27 import com.google.common.base.MoreObjects;
27 28
...@@ -88,7 +89,7 @@ public class JavaQualifiedTypeInfo ...@@ -88,7 +89,7 @@ public class JavaQualifiedTypeInfo
88 /** 89 /**
89 * Updates the leaf's java information. 90 * Updates the leaf's java information.
90 * 91 *
91 - * @param leaf leaf whose jave information is being updated 92 + * @param leaf leaf whose java information is being updated
92 */ 93 */
93 public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) { 94 public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) {
94 95
...@@ -102,7 +103,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 -}
...@@ -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 }
......
...@@ -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:
...@@ -112,7 +119,7 @@ public final class AttributesJavaDataType { ...@@ -112,7 +119,7 @@ public final class AttributesJavaDataType {
112 * Returns from string method parsed string. 119 * Returns from string method parsed string.
113 * 120 *
114 * @param targetDataType target data type 121 * @param targetDataType target data type
115 - * @param yangType YANG type 122 + * @param yangType YANG type
116 * @return parsed string 123 * @return parsed string
117 */ 124 */
118 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) { 125 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
...@@ -136,18 +143,16 @@ public final class AttributesJavaDataType { ...@@ -136,18 +143,16 @@ public final class AttributesJavaDataType {
136 return LONG_WRAPPER + PERIOD + PARSE_LONG; 143 return LONG_WRAPPER + PERIOD + PARSE_LONG;
137 case UINT64: 144 case UINT64:
138 return NEW + SPACE + BIG_INTEGER; 145 return NEW + SPACE + BIG_INTEGER;
139 - case DECIMAL64:
140 - //TODO: DECIMAL64.
141 case STRING: 146 case STRING:
142 return EMPTY_STRING; 147 return EMPTY_STRING;
148 + case EMPTY:
143 case BOOLEAN: 149 case BOOLEAN:
144 - return BOOLEAN_DATA_TYPE; 150 + return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
145 - case ENUMERATION: 151 + case DECIMAL64:
146 - //TODO:ENUMERATION.
147 case BITS: 152 case BITS:
148 - //TODO:BITS
149 case BINARY: 153 case BINARY:
150 - //TODO:BINARY 154 + case UNION:
155 + case ENUMERATION:
151 case DERIVED: 156 case DERIVED:
152 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; 157 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
153 default: 158 default:
...@@ -158,11 +163,13 @@ public final class AttributesJavaDataType { ...@@ -158,11 +163,13 @@ public final class AttributesJavaDataType {
158 /** 163 /**
159 * Returns java import class. 164 * Returns java import class.
160 * 165 *
161 - * @param yangType YANG type 166 + * @param yangType YANG type
162 * @param isListAttr if the attribute need to be a list 167 * @param isListAttr if the attribute need to be a list
168 + * @param pluginConfig plugin configurations
163 * @return java import class 169 * @return java import class
164 */ 170 */
165 - public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) { 171 + public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr,
172 + YangToJavaNamingConflictUtil pluginConfig) {
166 173
167 YangDataTypes type = yangType.getDataType(); 174 YangDataTypes type = yangType.getDataType();
168 175
...@@ -185,21 +192,19 @@ public final class AttributesJavaDataType { ...@@ -185,21 +192,19 @@ public final class AttributesJavaDataType {
185 case UINT64: 192 case UINT64:
186 return BIG_INTEGER; 193 return BIG_INTEGER;
187 case DECIMAL64: 194 case DECIMAL64:
188 - //TODO: DECIMAL64. 195 + return YANG_DECIMAL64_CLASS;
189 - break;
190 case STRING: 196 case STRING:
191 return STRING_DATA_TYPE; 197 return STRING_DATA_TYPE;
192 case BOOLEAN: 198 case BOOLEAN:
193 return BOOLEAN_WRAPPER; 199 return BOOLEAN_WRAPPER;
194 case ENUMERATION: 200 case ENUMERATION:
195 return getCapitalCase( 201 return getCapitalCase(
196 - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); 202 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
203 + pluginConfig));
197 case BITS: 204 case BITS:
198 - //TODO:BITS 205 + return YANG_BITS_CLASS;
199 - break;
200 case BINARY: 206 case BINARY:
201 - //TODO:BINARY 207 + return YANG_BINARY_CLASS;
202 - break;
203 case LEAFREF: 208 case LEAFREF:
204 //TODO:LEAFREF 209 //TODO:LEAFREF
205 break; 210 break;
...@@ -210,11 +215,13 @@ public final class AttributesJavaDataType { ...@@ -210,11 +215,13 @@ public final class AttributesJavaDataType {
210 return BOOLEAN_WRAPPER; 215 return BOOLEAN_WRAPPER;
211 case UNION: 216 case UNION:
212 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 217 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
213 - null)); 218 + pluginConfig));
214 case INSTANCE_IDENTIFIER: 219 case INSTANCE_IDENTIFIER:
215 //TODO:INSTANCE_IDENTIFIER 220 //TODO:INSTANCE_IDENTIFIER
221 + break;
216 case DERIVED: 222 case DERIVED:
217 - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); 223 + return getCapitalCase(
224 + getCamelCase(yangType.getDataTypeName(), pluginConfig));
218 default: 225 default:
219 throw new TranslatorException("given data type is not supported."); 226 throw new TranslatorException("given data type is not supported.");
220 } 227 }
...@@ -223,19 +230,17 @@ public final class AttributesJavaDataType { ...@@ -223,19 +230,17 @@ public final class AttributesJavaDataType {
223 case UINT64: 230 case UINT64:
224 return BIG_INTEGER; 231 return BIG_INTEGER;
225 case DECIMAL64: 232 case DECIMAL64:
226 - //TODO: DECIMAL64. 233 + return YANG_DECIMAL64_CLASS;
227 - break;
228 case STRING: 234 case STRING:
229 return STRING_DATA_TYPE; 235 return STRING_DATA_TYPE;
230 case ENUMERATION: 236 case ENUMERATION:
231 return getCapitalCase( 237 return getCapitalCase(
232 - getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); 238 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
239 + pluginConfig));
233 case BITS: 240 case BITS:
234 - //TODO:BITS 241 + return YANG_BITS_CLASS;
235 - break;
236 case BINARY: 242 case BINARY:
237 - //TODO:BINARY 243 + return YANG_BINARY_CLASS;
238 - break;
239 case LEAFREF: 244 case LEAFREF:
240 //TODO:LEAFREF 245 //TODO:LEAFREF
241 break; 246 break;
...@@ -243,16 +248,16 @@ public final class AttributesJavaDataType { ...@@ -243,16 +248,16 @@ public final class AttributesJavaDataType {
243 //TODO:IDENTITYREF 248 //TODO:IDENTITYREF
244 break; 249 break;
245 case EMPTY: 250 case EMPTY:
246 - //TODO:EMPTY 251 + return BOOLEAN_DATA_TYPE;
247 - break;
248 case UNION: 252 case UNION:
249 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 253 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
250 - null)); 254 + pluginConfig));
251 case INSTANCE_IDENTIFIER: 255 case INSTANCE_IDENTIFIER:
252 //TODO:INSTANCE_IDENTIFIER 256 //TODO:INSTANCE_IDENTIFIER
253 break; 257 break;
254 case DERIVED: 258 case DERIVED:
255 - return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null)); 259 + return getCapitalCase(
260 + getCamelCase(yangType.getDataTypeName(), pluginConfig));
256 default: 261 default:
257 return null; 262 return null;
258 } 263 }
...@@ -263,9 +268,9 @@ public final class AttributesJavaDataType { ...@@ -263,9 +268,9 @@ public final class AttributesJavaDataType {
263 /** 268 /**
264 * Returns java import package. 269 * Returns java import package.
265 * 270 *
266 - * @param yangType YANG type 271 + * @param yangType YANG type
267 * @param isListAttr if the attribute is of list type 272 * @param isListAttr if the attribute is of list type
268 - * @param classInfo java import class info 273 + * @param classInfo java import class info
269 * @return java import package 274 * @return java import package
270 */ 275 */
271 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { 276 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
...@@ -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
......
...@@ -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 : ";
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents binary data type.
25 + */
26 +public final class YangBinary {
27 +
28 + private byte[] byteArray;
29 +
30 + /**
31 + * Creates an instance of YANG binary.
32 + */
33 + private YangBinary() {
34 + }
35 +
36 + /**
37 + * Creates an instance of YANG binary.
38 + *
39 + * @param bytes byte array
40 + */
41 + public YangBinary(byte[] bytes) {
42 + this.byteArray = bytes;
43 + }
44 +
45 + /**
46 + * Returns object of YANG binary.
47 + *
48 + * @param bytes byte array
49 + * @return object of YANG binary
50 + */
51 + public static YangBinary of(byte[] bytes) {
52 + return new YangBinary(bytes);
53 + }
54 +
55 + /**
56 + * Returns byte array.
57 + *
58 + * @return byte array
59 + */
60 + public byte[] byteArray() {
61 + return byteArray;
62 + }
63 +
64 + @Override
65 + public int hashCode() {
66 + return Objects.hash(byteArray);
67 + }
68 +
69 + @Override
70 + public boolean equals(Object obj) {
71 + if (this == obj) {
72 + return true;
73 + }
74 + if (obj instanceof YangBinary) {
75 + YangBinary other = (YangBinary) obj;
76 + return Objects.equals(byteArray, other.byteArray);
77 + }
78 + return false;
79 + }
80 +
81 + @Override
82 + public String toString() {
83 + return MoreObjects.toStringHelper(getClass())
84 + .omitNullValues()
85 + .add("byteArray", byteArray)
86 + .toString();
87 + }
88 +
89 + /**
90 + * Returns the object of YANG binary fromString input String.
91 + *
92 + * @param valInString input String
93 + * @return Object of YANG binary
94 + */
95 + public static YangBinary fromString(String valInString) {
96 + try {
97 + byte[] tmpVal = valInString.getBytes();
98 + return of(tmpVal);
99 + } catch (Exception e) {
100 + }
101 + return null;
102 + }
103 +
104 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents bits data type.
25 + */
26 +public class YangBits {
27 +
28 + private byte[] byteArray;
29 +
30 + /**
31 + * Creates an instance of YANG bits.
32 + */
33 + private YangBits() {
34 + }
35 +
36 + /**
37 + * Creates an instance of YANG bits.
38 + *
39 + * @param bytes byte array
40 + */
41 + public YangBits(byte[] bytes) {
42 + this.byteArray = bytes;
43 + }
44 +
45 + /**
46 + * Returns object of YANG bits.
47 + *
48 + * @param bytes byte array
49 + * @return object of YANG bits
50 + */
51 + public static YangBits of(byte[] bytes) {
52 + return new YangBits(bytes);
53 + }
54 +
55 + /**
56 + * Returns byte array.
57 + *
58 + * @return byte array
59 + */
60 + public byte[] byteArray() {
61 + return byteArray;
62 + }
63 +
64 + @Override
65 + public int hashCode() {
66 + return Objects.hash(byteArray);
67 + }
68 +
69 + @Override
70 + public boolean equals(Object obj) {
71 + if (this == obj) {
72 + return true;
73 + }
74 + if (obj instanceof YangBits) {
75 + YangBits other = (YangBits) obj;
76 + return Objects.equals(byteArray, other.byteArray);
77 + }
78 + return false;
79 + }
80 +
81 + @Override
82 + public String toString() {
83 + return MoreObjects.toStringHelper(getClass())
84 + .omitNullValues()
85 + .add("byteArray", byteArray)
86 + .toString();
87 + }
88 +
89 + /**
90 + * Returns the object of YANG bits fromString input String.
91 + *
92 + * @param valInString input String
93 + * @return Object of YANG bits
94 + */
95 + public static YangBits fromString(String valInString) {
96 + try {
97 + byte[] tmpVal = valInString.getBytes();
98 + return of(tmpVal);
99 + } catch (Exception e) {
100 + }
101 + return null;
102 + }
103 +
104 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.utils.builtindatatype;
18 +
19 +import java.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Represents YANG decimal 64.
25 + */
26 +public class YangDecimal64 {
27 +
28 + private int fractionDigit;
29 +
30 + /**
31 + * Creates an instance of YANG decimal64.
32 + */
33 + public YangDecimal64() {
34 + }
35 +
36 + /**
37 + * Creates an instance of of YANG decimal64.
38 + *
39 + * @param fractionDigit fraction digit
40 + */
41 + public YangDecimal64(int fractionDigit) {
42 + this.setFractionDigit(fractionDigit);
43 + }
44 +
45 + /**
46 + * Returns fraction digit.
47 + *
48 + * @return the fractionDigit
49 + */
50 + public int getFractionDigit() {
51 + return fractionDigit;
52 + }
53 +
54 + /**
55 + * Sets fraction digit.
56 + *
57 + * @param fractionDigit fraction digits.
58 + */
59 + public void setFractionDigit(int fractionDigit) {
60 + this.fractionDigit = fractionDigit;
61 + }
62 +
63 + /**
64 + * Returns object of YANG decimal64.
65 + *
66 + * @param value fraction digit
67 + * @return YANG decimal64
68 + */
69 + public static YangDecimal64 of(int value) {
70 + return new YangDecimal64(value);
71 + }
72 +
73 + @Override
74 + public int hashCode() {
75 + return Objects.hash(fractionDigit);
76 + }
77 +
78 + @Override
79 + public boolean equals(Object obj) {
80 + if (this == obj) {
81 + return true;
82 + }
83 + if (obj instanceof YangDecimal64) {
84 + YangDecimal64 other = (YangDecimal64) obj;
85 + return Objects.equals(fractionDigit, other.fractionDigit);
86 + }
87 + return false;
88 + }
89 +
90 + @Override
91 + public String toString() {
92 + return MoreObjects.toStringHelper(getClass())
93 + .omitNullValues()
94 + .add("fractionDigit", fractionDigit)
95 + .toString();
96 + }
97 +
98 + /**
99 + * Returns the object of YANG decimal64 fromString input String.
100 + *
101 + * @param valInString input String
102 + * @return Object of YANG decimal64
103 + */
104 + public static YangDecimal64 fromString(String valInString) {
105 + try {
106 + int tmpVal = Integer.parseInt(valInString);
107 + return of(tmpVal);
108 + } catch (Exception e) {
109 + }
110 + return null;
111 + }
112 +}
...@@ -22,6 +22,8 @@ import java.io.FileReader; ...@@ -22,6 +22,8 @@ import java.io.FileReader;
22 import java.io.FileWriter; 22 import java.io.FileWriter;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.PrintWriter; 24 import java.io.PrintWriter;
25 +import java.util.ArrayList;
26 +import java.util.List;
25 27
26 import org.onosproject.yangutils.datamodel.YangNode; 28 import org.onosproject.yangutils.datamodel.YangNode;
27 import org.onosproject.yangutils.translator.exception.TranslatorException; 29 import org.onosproject.yangutils.translator.exception.TranslatorException;
...@@ -84,10 +86,12 @@ public final class FileSystemUtil { ...@@ -84,10 +86,12 @@ public final class FileSystemUtil {
84 YangNode parent = getParentNodeInGenCode(yangNode); 86 YangNode parent = getParentNodeInGenCode(yangNode);
85 if (parent != null) { 87 if (parent != null) {
86 pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); 88 pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
87 - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true); 89 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
90 + ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
88 } else { 91 } else {
89 pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName(); 92 pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
90 - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false); 93 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
94 + ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
91 } 95 }
92 } catch (IOException e) { 96 } catch (IOException e) {
93 throw new IOException("failed to create package-info file"); 97 throw new IOException("failed to create package-info file");
...@@ -120,6 +124,7 @@ public final class FileSystemUtil { ...@@ -120,6 +124,7 @@ public final class FileSystemUtil {
120 */ 124 */
121 public static String readAppendFile(String toAppend, String spaces) 125 public static String readAppendFile(String toAppend, String spaces)
122 throws IOException { 126 throws IOException {
127 +
123 FileReader fileReader = new FileReader(toAppend); 128 FileReader fileReader = new FileReader(toAppend);
124 BufferedReader bufferReader = new BufferedReader(fileReader); 129 BufferedReader bufferReader = new BufferedReader(fileReader);
125 try { 130 try {
...@@ -156,15 +161,22 @@ public final class FileSystemUtil { ...@@ -156,15 +161,22 @@ public final class FileSystemUtil {
156 */ 161 */
157 public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) 162 public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
158 throws IOException { 163 throws IOException {
164 +
165 + List<FileWriter> fileWriterStore = new ArrayList<>();
166 +
159 FileWriter fileWriter = new FileWriter(inputFile, true); 167 FileWriter fileWriter = new FileWriter(inputFile, true);
168 + fileWriterStore.add(fileWriter);
160 PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); 169 PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
161 if (!isClose) { 170 if (!isClose) {
162 outputPrintWriter.write(contentTobeAdded); 171 outputPrintWriter.write(contentTobeAdded);
163 outputPrintWriter.flush(); 172 outputPrintWriter.flush();
164 outputPrintWriter.close(); 173 outputPrintWriter.close();
165 } else { 174 } else {
166 - fileWriter.flush(); 175 + for (FileWriter curWriter : fileWriterStore) {
167 - fileWriter.close(); 176 + curWriter.flush();
177 + curWriter.close();
178 + curWriter = null;
179 + }
168 } 180 }
169 } 181 }
170 } 182 }
......
...@@ -17,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,14 +289,17 @@ public final class JavaDocGen { ...@@ -279,14 +289,17 @@ 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) {
286 - 297 + rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
287 - String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC 298 +
288 - + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK 299 + String javadoc =
289 - + getInputString(inputName, rpcName); 300 + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
301 + + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
302 + + getInputString(inputName, rpcName);
290 if (!outputName.equals(VOID)) { 303 if (!outputName.equals(VOID)) {
291 javadoc = javadoc + getOutputString(outputName, rpcName); 304 javadoc = javadoc + getOutputString(outputName, rpcName);
292 } 305 }
...@@ -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 /**
......
...@@ -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 }
......