Bharat saraswal

[ONOS-3906],[ONOS-3910] Implementation of YANG module and leaf/leaf-list translator.

Change-Id: If1a8a991ffafa14b51211f97c435176ee1bf856f
Showing 43 changed files with 2133 additions and 379 deletions
...@@ -44,23 +44,17 @@ ...@@ -44,23 +44,17 @@
44 <dependency> 44 <dependency>
45 <groupId>org.apache.maven</groupId> 45 <groupId>org.apache.maven</groupId>
46 <artifactId>maven-artifact</artifactId> 46 <artifactId>maven-artifact</artifactId>
47 - <version>2.0.8</version> 47 + <version>3.2.5</version>
48 </dependency> 48 </dependency>
49 <dependency> 49 <dependency>
50 <groupId>org.apache.maven</groupId> 50 <groupId>org.apache.maven</groupId>
51 <artifactId>maven-project</artifactId> 51 <artifactId>maven-project</artifactId>
52 - <version>2.0.8</version> 52 + <version>2.2.1</version>
53 - </dependency>
54 - <dependency>
55 - <groupId>org.assertj</groupId>
56 - <artifactId>assertj-core</artifactId>
57 - <version>1.7.0</version>
58 - <scope>test</scope>
59 </dependency> 53 </dependency>
60 <dependency> 54 <dependency>
61 <groupId>org.apache.maven.plugin-testing</groupId> 55 <groupId>org.apache.maven.plugin-testing</groupId>
62 <artifactId>maven-plugin-testing-harness</artifactId> 56 <artifactId>maven-plugin-testing-harness</artifactId>
63 - <version>2.1</version> 57 + <version>3.3.0</version>
64 <scope>test</scope> 58 <scope>test</scope>
65 </dependency> 59 </dependency>
66 <dependency> 60 <dependency>
...@@ -74,12 +68,13 @@ ...@@ -74,12 +68,13 @@
74 <version>3.2.5</version> 68 <version>3.2.5</version>
75 <scope>test</scope> 69 <scope>test</scope>
76 </dependency> 70 </dependency>
71 +
77 <dependency> 72 <dependency>
78 - <groupId>org.mockito</groupId> 73 + <groupId>org.apache.maven.plugins</groupId>
79 - <artifactId>mockito-core</artifactId> 74 + <artifactId>maven-surefire-plugin</artifactId>
80 - <version>1.9.5</version> 75 + <version>2.19.1</version>
81 - <scope>test</scope>
82 </dependency> 76 </dependency>
77 +
83 <dependency> 78 <dependency>
84 <groupId>junit</groupId> 79 <groupId>junit</groupId>
85 <artifactId>junit</artifactId> 80 <artifactId>junit</artifactId>
...@@ -95,13 +90,15 @@ ...@@ -95,13 +90,15 @@
95 <dependency> 90 <dependency>
96 <groupId>commons-io</groupId> 91 <groupId>commons-io</groupId>
97 <artifactId>commons-io</artifactId> 92 <artifactId>commons-io</artifactId>
98 - <version>1.3.2</version> 93 + <version>2.2</version>
99 </dependency> 94 </dependency>
95 +
100 <dependency> 96 <dependency>
101 - <groupId>commons-configuration</groupId> 97 + <groupId>org.hamcrest</groupId>
102 - <artifactId>commons-configuration</artifactId> 98 + <artifactId>hamcrest-all</artifactId>
103 - <version>1.10</version> 99 + <version>1.3</version>
104 </dependency> 100 </dependency>
101 +
105 <dependency> 102 <dependency>
106 <groupId>org.onosproject</groupId> 103 <groupId>org.onosproject</groupId>
107 <artifactId>onlab-junit</artifactId> 104 <artifactId>onlab-junit</artifactId>
...@@ -114,21 +111,6 @@ ...@@ -114,21 +111,6 @@
114 <version>4.5</version> 111 <version>4.5</version>
115 </dependency> 112 </dependency>
116 <dependency> 113 <dependency>
117 - <groupId>org.apache.maven.plugins</groupId>
118 - <artifactId>maven-surefire-plugin</artifactId>
119 - <version>2.19.1</version>
120 - </dependency>
121 - <dependency>
122 - <groupId>org.sonatype.aether</groupId>
123 - <artifactId>aether-api</artifactId>
124 - <version>1.8</version>
125 - </dependency>
126 - <dependency>
127 - <groupId>org.sonatype.aether</groupId>
128 - <artifactId>aether-util</artifactId>
129 - <version>1.8</version>
130 - </dependency>
131 - <dependency>
132 <groupId>org.codehaus.mojo</groupId> 114 <groupId>org.codehaus.mojo</groupId>
133 <artifactId>build-helper-maven-plugin</artifactId> 115 <artifactId>build-helper-maven-plugin</artifactId>
134 <version>1.10</version> 116 <version>1.10</version>
...@@ -237,4 +219,5 @@ ...@@ -237,4 +219,5 @@
237 </plugin> 219 </plugin>
238 </plugins> 220 </plugins>
239 </build> 221 </build>
222 +
240 </project> 223 </project>
......
...@@ -76,8 +76,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; ...@@ -76,8 +76,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
76 /** 76 /**
77 * Data model node to maintain information defined in YANG augment. 77 * Data model node to maintain information defined in YANG augment.
78 */ 78 */
79 -public class YangAugment extends YangNode 79 +public class YangAugment extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
80 - implements YangLeavesHolder, YangCommonInfo, Parsable {
81 80
82 /** 81 /**
83 * Augment target node. 82 * Augment target node.
...@@ -92,14 +91,12 @@ public class YangAugment extends YangNode ...@@ -92,14 +91,12 @@ public class YangAugment extends YangNode
92 /** 91 /**
93 * List of leaves. 92 * List of leaves.
94 */ 93 */
95 - @SuppressWarnings("rawtypes") 94 + private List<YangLeaf<?>> listOfLeaf;
96 - private List<YangLeaf> listOfLeaf;
97 95
98 /** 96 /**
99 * List of leaf-lists. 97 * List of leaf-lists.
100 */ 98 */
101 - @SuppressWarnings("rawtypes") 99 + private List<YangLeafList<?>> listOfLeafList;
102 - private List<YangLeafList> listOfLeafList;
103 100
104 /** 101 /**
105 * reference. 102 * reference.
...@@ -141,6 +138,7 @@ public class YangAugment extends YangNode ...@@ -141,6 +138,7 @@ public class YangAugment extends YangNode
141 * 138 *
142 * @return the description. 139 * @return the description.
143 */ 140 */
141 + @Override
144 public String getDescription() { 142 public String getDescription() {
145 return description; 143 return description;
146 } 144 }
...@@ -150,6 +148,7 @@ public class YangAugment extends YangNode ...@@ -150,6 +148,7 @@ public class YangAugment extends YangNode
150 * 148 *
151 * @param description set the description. 149 * @param description set the description.
152 */ 150 */
151 + @Override
153 public void setDescription(String description) { 152 public void setDescription(String description) {
154 this.description = description; 153 this.description = description;
155 } 154 }
...@@ -159,8 +158,8 @@ public class YangAugment extends YangNode ...@@ -159,8 +158,8 @@ public class YangAugment extends YangNode
159 * 158 *
160 * @return the list of leaves. 159 * @return the list of leaves.
161 */ 160 */
162 - @SuppressWarnings("rawtypes") 161 + @Override
163 - public List<YangLeaf> getListOfLeaf() { 162 + public List<YangLeaf<?>> getListOfLeaf() {
164 return listOfLeaf; 163 return listOfLeaf;
165 } 164 }
166 165
...@@ -169,8 +168,7 @@ public class YangAugment extends YangNode ...@@ -169,8 +168,7 @@ public class YangAugment extends YangNode
169 * 168 *
170 * @param leafsList the list of leaf to set. 169 * @param leafsList the list of leaf to set.
171 */ 170 */
172 - @SuppressWarnings("rawtypes") 171 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
173 - private void setListOfLeaf(List<YangLeaf> leafsList) {
174 listOfLeaf = leafsList; 172 listOfLeaf = leafsList;
175 } 173 }
176 174
...@@ -179,10 +177,10 @@ public class YangAugment extends YangNode ...@@ -179,10 +177,10 @@ public class YangAugment extends YangNode
179 * 177 *
180 * @param leaf the leaf to be added. 178 * @param leaf the leaf to be added.
181 */ 179 */
182 - @SuppressWarnings("rawtypes") 180 + @Override
183 public void addLeaf(YangLeaf<?> leaf) { 181 public void addLeaf(YangLeaf<?> leaf) {
184 if (getListOfLeaf() == null) { 182 if (getListOfLeaf() == null) {
185 - setListOfLeaf(new LinkedList<YangLeaf>()); 183 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
186 } 184 }
187 185
188 getListOfLeaf().add(leaf); 186 getListOfLeaf().add(leaf);
...@@ -193,8 +191,8 @@ public class YangAugment extends YangNode ...@@ -193,8 +191,8 @@ public class YangAugment extends YangNode
193 * 191 *
194 * @return the list of leaf-list. 192 * @return the list of leaf-list.
195 */ 193 */
196 - @SuppressWarnings("rawtypes") 194 + @Override
197 - public List<YangLeafList> getListOfLeafList() { 195 + public List<YangLeafList<?>> getListOfLeafList() {
198 return listOfLeafList; 196 return listOfLeafList;
199 } 197 }
200 198
...@@ -203,8 +201,7 @@ public class YangAugment extends YangNode ...@@ -203,8 +201,7 @@ public class YangAugment extends YangNode
203 * 201 *
204 * @param listOfLeafList the list of leaf-list to set. 202 * @param listOfLeafList the list of leaf-list to set.
205 */ 203 */
206 - @SuppressWarnings("rawtypes") 204 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
207 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
208 this.listOfLeafList = listOfLeafList; 205 this.listOfLeafList = listOfLeafList;
209 } 206 }
210 207
...@@ -213,10 +210,10 @@ public class YangAugment extends YangNode ...@@ -213,10 +210,10 @@ public class YangAugment extends YangNode
213 * 210 *
214 * @param leafList the leaf-list to be added. 211 * @param leafList the leaf-list to be added.
215 */ 212 */
216 - @SuppressWarnings("rawtypes") 213 + @Override
217 public void addLeafList(YangLeafList<?> leafList) { 214 public void addLeafList(YangLeafList<?> leafList) {
218 if (getListOfLeafList() == null) { 215 if (getListOfLeafList() == null) {
219 - setListOfLeafList(new LinkedList<YangLeafList>()); 216 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
220 } 217 }
221 218
222 getListOfLeafList().add(leafList); 219 getListOfLeafList().add(leafList);
...@@ -227,6 +224,7 @@ public class YangAugment extends YangNode ...@@ -227,6 +224,7 @@ public class YangAugment extends YangNode
227 * 224 *
228 * @return the reference. 225 * @return the reference.
229 */ 226 */
227 + @Override
230 public String getReference() { 228 public String getReference() {
231 return reference; 229 return reference;
232 } 230 }
...@@ -236,6 +234,7 @@ public class YangAugment extends YangNode ...@@ -236,6 +234,7 @@ public class YangAugment extends YangNode
236 * 234 *
237 * @param reference the reference to set. 235 * @param reference the reference to set.
238 */ 236 */
237 + @Override
239 public void setReference(String reference) { 238 public void setReference(String reference) {
240 this.reference = reference; 239 this.reference = reference;
241 } 240 }
...@@ -245,6 +244,7 @@ public class YangAugment extends YangNode ...@@ -245,6 +244,7 @@ public class YangAugment extends YangNode
245 * 244 *
246 * @return the status. 245 * @return the status.
247 */ 246 */
247 + @Override
248 public YangStatusType getStatus() { 248 public YangStatusType getStatus() {
249 return status; 249 return status;
250 } 250 }
...@@ -254,6 +254,7 @@ public class YangAugment extends YangNode ...@@ -254,6 +254,7 @@ public class YangAugment extends YangNode
254 * 254 *
255 * @param status the status to set. 255 * @param status the status to set.
256 */ 256 */
257 + @Override
257 public void setStatus(YangStatusType status) { 258 public void setStatus(YangStatusType status) {
258 this.status = status; 259 this.status = status;
259 } 260 }
...@@ -263,6 +264,7 @@ public class YangAugment extends YangNode ...@@ -263,6 +264,7 @@ public class YangAugment extends YangNode
263 * 264 *
264 * @return returns AUGMENT_DATA. 265 * @return returns AUGMENT_DATA.
265 */ 266 */
267 + @Override
266 public ParsableDataType getParsableDataType() { 268 public ParsableDataType getParsableDataType() {
267 return ParsableDataType.AUGMENT_DATA; 269 return ParsableDataType.AUGMENT_DATA;
268 } 270 }
...@@ -272,6 +274,7 @@ public class YangAugment extends YangNode ...@@ -272,6 +274,7 @@ public class YangAugment extends YangNode
272 * 274 *
273 * @throws DataModelException a violation of data model rules. 275 * @throws DataModelException a violation of data model rules.
274 */ 276 */
277 + @Override
275 public void validateDataOnEntry() throws DataModelException { 278 public void validateDataOnEntry() throws DataModelException {
276 // TODO auto-generated method stub, to be implemented by parser 279 // TODO auto-generated method stub, to be implemented by parser
277 } 280 }
...@@ -281,6 +284,7 @@ public class YangAugment extends YangNode ...@@ -281,6 +284,7 @@ public class YangAugment extends YangNode
281 * 284 *
282 * @throws DataModelException a violation of data model rules. 285 * @throws DataModelException a violation of data model rules.
283 */ 286 */
287 + @Override
284 public void validateDataOnExit() throws DataModelException { 288 public void validateDataOnExit() throws DataModelException {
285 // TODO auto-generated method stub, to be implemented by parser 289 // TODO auto-generated method stub, to be implemented by parser
286 } 290 }
...@@ -324,6 +328,7 @@ public class YangAugment extends YangNode ...@@ -324,6 +328,7 @@ public class YangAugment extends YangNode
324 /* (non-Javadoc) 328 /* (non-Javadoc)
325 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 329 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
326 */ 330 */
331 + @Override
327 public void generateJavaCodeEntry() { 332 public void generateJavaCodeEntry() {
328 // TODO Auto-generated method stub 333 // TODO Auto-generated method stub
329 334
...@@ -332,6 +337,7 @@ public class YangAugment extends YangNode ...@@ -332,6 +337,7 @@ public class YangAugment extends YangNode
332 /* (non-Javadoc) 337 /* (non-Javadoc)
333 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 338 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
334 */ 339 */
340 + @Override
335 public void generateJavaCodeExit() { 341 public void generateJavaCodeExit() {
336 // TODO Auto-generated method stub 342 // TODO Auto-generated method stub
337 343
......
...@@ -88,8 +88,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; ...@@ -88,8 +88,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
88 /** 88 /**
89 * Data model node to maintain information defined in YANG case. 89 * Data model node to maintain information defined in YANG case.
90 */ 90 */
91 -public class YangCase extends YangNode 91 +public class YangCase extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
92 - implements YangLeavesHolder, YangCommonInfo, Parsable {
93 92
94 /** 93 /**
95 * Case name. 94 * Case name.
...@@ -106,14 +105,12 @@ public class YangCase extends YangNode ...@@ -106,14 +105,12 @@ public class YangCase extends YangNode
106 /** 105 /**
107 * List of leaves. 106 * List of leaves.
108 */ 107 */
109 - @SuppressWarnings("rawtypes") 108 + private List<YangLeaf<?>> listOfLeaf;
110 - private List<YangLeaf> listOfLeaf;
111 109
112 /** 110 /**
113 * List of leaf lists. 111 * List of leaf lists.
114 */ 112 */
115 - @SuppressWarnings("rawtypes") 113 + private List<YangLeafList<?>> listOfLeafList;
116 - private List<YangLeafList> listOfLeafList;
117 114
118 /** 115 /**
119 * Reference of the module. 116 * Reference of the module.
...@@ -153,6 +150,7 @@ public class YangCase extends YangNode ...@@ -153,6 +150,7 @@ public class YangCase extends YangNode
153 * 150 *
154 * @return the description. 151 * @return the description.
155 */ 152 */
153 + @Override
156 public String getDescription() { 154 public String getDescription() {
157 return description; 155 return description;
158 } 156 }
...@@ -162,6 +160,7 @@ public class YangCase extends YangNode ...@@ -162,6 +160,7 @@ public class YangCase extends YangNode
162 * 160 *
163 * @param description set the description. 161 * @param description set the description.
164 */ 162 */
163 + @Override
165 public void setDescription(String description) { 164 public void setDescription(String description) {
166 this.description = description; 165 this.description = description;
167 } 166 }
...@@ -171,8 +170,8 @@ public class YangCase extends YangNode ...@@ -171,8 +170,8 @@ public class YangCase extends YangNode
171 * 170 *
172 * @return the list of leaves. 171 * @return the list of leaves.
173 */ 172 */
174 - @SuppressWarnings("rawtypes") 173 + @Override
175 - public List<YangLeaf> getListOfLeaf() { 174 + public List<YangLeaf<?>> getListOfLeaf() {
176 return listOfLeaf; 175 return listOfLeaf;
177 } 176 }
178 177
...@@ -181,8 +180,7 @@ public class YangCase extends YangNode ...@@ -181,8 +180,7 @@ public class YangCase extends YangNode
181 * 180 *
182 * @param leafsList the list of leaf to set. 181 * @param leafsList the list of leaf to set.
183 */ 182 */
184 - @SuppressWarnings("rawtypes") 183 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
185 - private void setListOfLeaf(List<YangLeaf> leafsList) {
186 listOfLeaf = leafsList; 184 listOfLeaf = leafsList;
187 } 185 }
188 186
...@@ -191,10 +189,10 @@ public class YangCase extends YangNode ...@@ -191,10 +189,10 @@ public class YangCase extends YangNode
191 * 189 *
192 * @param leaf the leaf to be added. 190 * @param leaf the leaf to be added.
193 */ 191 */
194 - @SuppressWarnings("rawtypes") 192 + @Override
195 public void addLeaf(YangLeaf<?> leaf) { 193 public void addLeaf(YangLeaf<?> leaf) {
196 if (getListOfLeaf() == null) { 194 if (getListOfLeaf() == null) {
197 - setListOfLeaf(new LinkedList<YangLeaf>()); 195 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
198 } 196 }
199 197
200 getListOfLeaf().add(leaf); 198 getListOfLeaf().add(leaf);
...@@ -205,8 +203,8 @@ public class YangCase extends YangNode ...@@ -205,8 +203,8 @@ public class YangCase extends YangNode
205 * 203 *
206 * @return the list of leaf-list. 204 * @return the list of leaf-list.
207 */ 205 */
208 - @SuppressWarnings("rawtypes") 206 + @Override
209 - public List<YangLeafList> getListOfLeafList() { 207 + public List<YangLeafList<?>> getListOfLeafList() {
210 return listOfLeafList; 208 return listOfLeafList;
211 } 209 }
212 210
...@@ -215,8 +213,7 @@ public class YangCase extends YangNode ...@@ -215,8 +213,7 @@ public class YangCase extends YangNode
215 * 213 *
216 * @param listOfLeafList the list of leaf-list to set. 214 * @param listOfLeafList the list of leaf-list to set.
217 */ 215 */
218 - @SuppressWarnings("rawtypes") 216 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
219 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
220 this.listOfLeafList = listOfLeafList; 217 this.listOfLeafList = listOfLeafList;
221 } 218 }
222 219
...@@ -225,10 +222,10 @@ public class YangCase extends YangNode ...@@ -225,10 +222,10 @@ public class YangCase extends YangNode
225 * 222 *
226 * @param leafList the leaf-list to be added. 223 * @param leafList the leaf-list to be added.
227 */ 224 */
228 - @SuppressWarnings("rawtypes") 225 + @Override
229 public void addLeafList(YangLeafList<?> leafList) { 226 public void addLeafList(YangLeafList<?> leafList) {
230 if (getListOfLeafList() == null) { 227 if (getListOfLeafList() == null) {
231 - setListOfLeafList(new LinkedList<YangLeafList>()); 228 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
232 } 229 }
233 230
234 getListOfLeafList().add(leafList); 231 getListOfLeafList().add(leafList);
...@@ -239,6 +236,7 @@ public class YangCase extends YangNode ...@@ -239,6 +236,7 @@ public class YangCase extends YangNode
239 * 236 *
240 * @return the reference. 237 * @return the reference.
241 */ 238 */
239 + @Override
242 public String getReference() { 240 public String getReference() {
243 return reference; 241 return reference;
244 } 242 }
...@@ -248,6 +246,7 @@ public class YangCase extends YangNode ...@@ -248,6 +246,7 @@ public class YangCase extends YangNode
248 * 246 *
249 * @param reference the reference to set. 247 * @param reference the reference to set.
250 */ 248 */
249 + @Override
251 public void setReference(String reference) { 250 public void setReference(String reference) {
252 this.reference = reference; 251 this.reference = reference;
253 } 252 }
...@@ -257,6 +256,7 @@ public class YangCase extends YangNode ...@@ -257,6 +256,7 @@ public class YangCase extends YangNode
257 * 256 *
258 * @return the status. 257 * @return the status.
259 */ 258 */
259 + @Override
260 public YangStatusType getStatus() { 260 public YangStatusType getStatus() {
261 return status; 261 return status;
262 } 262 }
...@@ -266,6 +266,7 @@ public class YangCase extends YangNode ...@@ -266,6 +266,7 @@ public class YangCase extends YangNode
266 * 266 *
267 * @param status the status to set. 267 * @param status the status to set.
268 */ 268 */
269 + @Override
269 public void setStatus(YangStatusType status) { 270 public void setStatus(YangStatusType status) {
270 this.status = status; 271 this.status = status;
271 } 272 }
...@@ -275,6 +276,7 @@ public class YangCase extends YangNode ...@@ -275,6 +276,7 @@ public class YangCase extends YangNode
275 * 276 *
276 * @return returns CASE_DATA 277 * @return returns CASE_DATA
277 */ 278 */
279 + @Override
278 public ParsableDataType getParsableDataType() { 280 public ParsableDataType getParsableDataType() {
279 return ParsableDataType.CASE_DATA; 281 return ParsableDataType.CASE_DATA;
280 } 282 }
...@@ -284,6 +286,7 @@ public class YangCase extends YangNode ...@@ -284,6 +286,7 @@ public class YangCase extends YangNode
284 * 286 *
285 * @throws DataModelException a violation of data model rules. 287 * @throws DataModelException a violation of data model rules.
286 */ 288 */
289 + @Override
287 public void validateDataOnEntry() throws DataModelException { 290 public void validateDataOnEntry() throws DataModelException {
288 // TODO auto-generated method stub, to be implemented by parser 291 // TODO auto-generated method stub, to be implemented by parser
289 } 292 }
...@@ -293,6 +296,7 @@ public class YangCase extends YangNode ...@@ -293,6 +296,7 @@ public class YangCase extends YangNode
293 * 296 *
294 * @throws DataModelException a violation of data model rules. 297 * @throws DataModelException a violation of data model rules.
295 */ 298 */
299 + @Override
296 public void validateDataOnExit() throws DataModelException { 300 public void validateDataOnExit() throws DataModelException {
297 // TODO auto-generated method stub, to be implemented by parser 301 // TODO auto-generated method stub, to be implemented by parser
298 } 302 }
...@@ -318,6 +322,7 @@ public class YangCase extends YangNode ...@@ -318,6 +322,7 @@ public class YangCase extends YangNode
318 /* (non-Javadoc) 322 /* (non-Javadoc)
319 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 323 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
320 */ 324 */
325 + @Override
321 public void generateJavaCodeEntry() { 326 public void generateJavaCodeEntry() {
322 // TODO Auto-generated method stub 327 // TODO Auto-generated method stub
323 328
...@@ -326,6 +331,7 @@ public class YangCase extends YangNode ...@@ -326,6 +331,7 @@ public class YangCase extends YangNode
326 /* (non-Javadoc) 331 /* (non-Javadoc)
327 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 332 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
328 */ 333 */
334 + @Override
329 public void generateJavaCodeExit() { 335 public void generateJavaCodeExit() {
330 // TODO Auto-generated method stub 336 // TODO Auto-generated method stub
331 337
......
...@@ -16,13 +16,17 @@ ...@@ -16,13 +16,17 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 +import java.io.IOException;
19 import java.util.LinkedList; 20 import java.util.LinkedList;
20 import java.util.List; 21 import java.util.List;
21 22
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 23 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.parser.Parsable; 24 import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.ParsableDataType; 25 import org.onosproject.yangutils.parser.ParsableDataType;
25 -import org.onosproject.yangutils.utils.io.CachedFileHandle; 26 +import org.onosproject.yangutils.translator.CachedFileHandle;
27 +import org.onosproject.yangutils.translator.GeneratedFileType;
28 +import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
29 +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
26 /*- 30 /*-
27 * Reference RFC 6020. 31 * Reference RFC 6020.
28 * 32 *
...@@ -105,14 +109,12 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -105,14 +109,12 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
105 /** 109 /**
106 * List of leaves contained. 110 * List of leaves contained.
107 */ 111 */
108 - @SuppressWarnings("rawtypes") 112 + private List<YangLeaf<?>> listOfLeaf;
109 - private List<YangLeaf> listOfLeaf;
110 113
111 /** 114 /**
112 * List of leaf-lists contained. 115 * List of leaf-lists contained.
113 */ 116 */
114 - @SuppressWarnings("rawtypes") 117 + private List<YangLeafList<?>> listOfLeafList;
115 - private List<YangLeafList> listOfLeafList;
116 118
117 /** 119 /**
118 * If it is a presence container, then the textual documentation of presence 120 * If it is a presence container, then the textual documentation of presence
...@@ -186,6 +188,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -186,6 +188,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
186 * 188 *
187 * @return the description. 189 * @return the description.
188 */ 190 */
191 + @Override
189 public String getDescription() { 192 public String getDescription() {
190 return description; 193 return description;
191 } 194 }
...@@ -195,6 +198,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -195,6 +198,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
195 * 198 *
196 * @param description set the description. 199 * @param description set the description.
197 */ 200 */
201 + @Override
198 public void setDescription(String description) { 202 public void setDescription(String description) {
199 this.description = description; 203 this.description = description;
200 } 204 }
...@@ -204,8 +208,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -204,8 +208,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
204 * 208 *
205 * @return the list of leaves. 209 * @return the list of leaves.
206 */ 210 */
207 - @SuppressWarnings("rawtypes") 211 + @Override
208 - public List<YangLeaf> getListOfLeaf() { 212 + public List<YangLeaf<?>> getListOfLeaf() {
209 return listOfLeaf; 213 return listOfLeaf;
210 } 214 }
211 215
...@@ -214,8 +218,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -214,8 +218,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
214 * 218 *
215 * @param leafsList the list of leaf to set. 219 * @param leafsList the list of leaf to set.
216 */ 220 */
217 - @SuppressWarnings("rawtypes") 221 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
218 - private void setListOfLeaf(List<YangLeaf> leafsList) {
219 listOfLeaf = leafsList; 222 listOfLeaf = leafsList;
220 } 223 }
221 224
...@@ -224,10 +227,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -224,10 +227,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
224 * 227 *
225 * @param leaf the leaf to be added. 228 * @param leaf the leaf to be added.
226 */ 229 */
227 - @SuppressWarnings("rawtypes") 230 + @Override
228 public void addLeaf(YangLeaf<?> leaf) { 231 public void addLeaf(YangLeaf<?> leaf) {
229 if (getListOfLeaf() == null) { 232 if (getListOfLeaf() == null) {
230 - setListOfLeaf(new LinkedList<YangLeaf>()); 233 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
231 } 234 }
232 235
233 getListOfLeaf().add(leaf); 236 getListOfLeaf().add(leaf);
...@@ -238,8 +241,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -238,8 +241,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
238 * 241 *
239 * @return the list of leaf-list. 242 * @return the list of leaf-list.
240 */ 243 */
241 - @SuppressWarnings("rawtypes") 244 + @Override
242 - public List<YangLeafList> getListOfLeafList() { 245 + public List<YangLeafList<?>> getListOfLeafList() {
243 return listOfLeafList; 246 return listOfLeafList;
244 } 247 }
245 248
...@@ -248,8 +251,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -248,8 +251,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
248 * 251 *
249 * @param listOfLeafList the list of leaf-list to set. 252 * @param listOfLeafList the list of leaf-list to set.
250 */ 253 */
251 - @SuppressWarnings("rawtypes") 254 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
252 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
253 this.listOfLeafList = listOfLeafList; 255 this.listOfLeafList = listOfLeafList;
254 } 256 }
255 257
...@@ -258,10 +260,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -258,10 +260,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
258 * 260 *
259 * @param leafList the leaf-list to be added. 261 * @param leafList the leaf-list to be added.
260 */ 262 */
261 - @SuppressWarnings("rawtypes") 263 + @Override
262 public void addLeafList(YangLeafList<?> leafList) { 264 public void addLeafList(YangLeafList<?> leafList) {
263 if (getListOfLeafList() == null) { 265 if (getListOfLeafList() == null) {
264 - setListOfLeafList(new LinkedList<YangLeafList>()); 266 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
265 } 267 }
266 268
267 getListOfLeafList().add(leafList); 269 getListOfLeafList().add(leafList);
...@@ -290,6 +292,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -290,6 +292,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
290 * 292 *
291 * @return the reference. 293 * @return the reference.
292 */ 294 */
295 + @Override
293 public String getReference() { 296 public String getReference() {
294 return reference; 297 return reference;
295 } 298 }
...@@ -299,6 +302,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -299,6 +302,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
299 * 302 *
300 * @param reference the reference to set. 303 * @param reference the reference to set.
301 */ 304 */
305 + @Override
302 public void setReference(String reference) { 306 public void setReference(String reference) {
303 this.reference = reference; 307 this.reference = reference;
304 } 308 }
...@@ -308,6 +312,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -308,6 +312,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
308 * 312 *
309 * @return the status. 313 * @return the status.
310 */ 314 */
315 + @Override
311 public YangStatusType getStatus() { 316 public YangStatusType getStatus() {
312 return status; 317 return status;
313 } 318 }
...@@ -317,6 +322,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -317,6 +322,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
317 * 322 *
318 * @param status the status to set. 323 * @param status the status to set.
319 */ 324 */
325 + @Override
320 public void setStatus(YangStatusType status) { 326 public void setStatus(YangStatusType status) {
321 this.status = status; 327 this.status = status;
322 } 328 }
...@@ -344,6 +350,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -344,6 +350,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
344 * 350 *
345 * @return returns CONTAINER_DATA. 351 * @return returns CONTAINER_DATA.
346 */ 352 */
353 + @Override
347 public ParsableDataType getParsableDataType() { 354 public ParsableDataType getParsableDataType() {
348 return ParsableDataType.CONTAINER_DATA; 355 return ParsableDataType.CONTAINER_DATA;
349 } 356 }
...@@ -353,6 +360,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -353,6 +360,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
353 * 360 *
354 * @throws DataModelException a violation of data model rules. 361 * @throws DataModelException a violation of data model rules.
355 */ 362 */
363 + @Override
356 public void validateDataOnEntry() throws DataModelException { 364 public void validateDataOnEntry() throws DataModelException {
357 // TODO auto-generated method stub, to be implemented by parser 365 // TODO auto-generated method stub, to be implemented by parser
358 } 366 }
...@@ -362,6 +370,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -362,6 +370,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
362 * 370 *
363 * @throws DataModelException a violation of data model rules. 371 * @throws DataModelException a violation of data model rules.
364 */ 372 */
373 + @Override
365 public void validateDataOnExit() throws DataModelException { 374 public void validateDataOnExit() throws DataModelException {
366 // TODO auto-generated method stub, to be implemented by parser 375 // TODO auto-generated method stub, to be implemented by parser
367 } 376 }
...@@ -388,17 +397,62 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -388,17 +397,62 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
388 397
389 /** 398 /**
390 * Generate the java code corresponding to YANG container. 399 * Generate the java code corresponding to YANG container.
400 + *
401 + * @throws IOException when fails to generate the source files.
402 + */
403 + @Override
404 + public void generateJavaCodeEntry() throws IOException {
405 + YangNode parent = getParent();
406 + String modPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), getName());
407 + setPackage(modPkg);
408 +
409 + CachedFileHandle handle = null;
410 + try {
411 + FileSystemUtil.createPackage(getPackage(), getName());
412 + handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
413 + } catch (IOException e) {
414 + throw new IOException("Failed to create the source files.");
415 + }
416 + setFileHandle(handle);
417 + addLavesAttributes();
418 + addLeafListAttributes();
419 + }
420 +
421 + /**
422 + * Adds leaf attributes in generated files.
423 + */
424 + private void addLavesAttributes() {
425 +
426 + List<YangLeaf<?>> leaves = getListOfLeaf();
427 + if (leaves != null) {
428 + for (YangLeaf<?> leaf : leaves) {
429 + getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
430 + }
431 + }
432 + }
433 +
434 + /**
435 + * Adds leaf list's attributes in generated files.
391 */ 436 */
392 - public void generateJavaCodeEntry() { 437 + private void addLeafListAttributes() {
393 - //TODO: autogenerated method stub, to be implemented 438 + List<YangLeafList<?>> leavesList = getListOfLeafList();
439 + if (leavesList != null) {
440 + for (YangLeafList<?> leafList : leavesList) {
441 + getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
442 + }
443 + }
394 return; 444 return;
445 +
395 } 446 }
396 447
397 /** 448 /**
398 * Free resources used to generate code. 449 * Free resources used to generate code.
450 + *
451 + * @throws IOException when fails to generate source files.
399 */ 452 */
400 - public void generateJavaCodeExit() { 453 + @Override
401 - //TODO: autogenerated method stub, to be implemented 454 + public void generateJavaCodeExit() throws IOException {
455 + getFileHandle().close();
402 return; 456 return;
403 } 457 }
404 } 458 }
......
...@@ -75,8 +75,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; ...@@ -75,8 +75,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
75 /** 75 /**
76 * Data model node to maintain information defined in YANG grouping. 76 * Data model node to maintain information defined in YANG grouping.
77 */ 77 */
78 -public class YangGrouping extends YangNode 78 +public class YangGrouping extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
79 - implements YangLeavesHolder, YangCommonInfo, Parsable {
80 79
81 /** 80 /**
82 * Name of the grouping. 81 * Name of the grouping.
...@@ -91,14 +90,12 @@ public class YangGrouping extends YangNode ...@@ -91,14 +90,12 @@ public class YangGrouping extends YangNode
91 /** 90 /**
92 * List of leaves. 91 * List of leaves.
93 */ 92 */
94 - @SuppressWarnings("rawtypes") 93 + private List<YangLeaf<?>> listOfLeaf;
95 - private List<YangLeaf> listOfLeaf;
96 94
97 /** 95 /**
98 * List of leaf lists. 96 * List of leaf lists.
99 */ 97 */
100 - @SuppressWarnings("rawtypes") 98 + private List<YangLeafList<?>> listOfLeafList;
101 - private List<YangLeafList> listOfLeafList;
102 99
103 /** 100 /**
104 * Reference of the module. 101 * Reference of the module.
...@@ -138,6 +135,7 @@ public class YangGrouping extends YangNode ...@@ -138,6 +135,7 @@ public class YangGrouping extends YangNode
138 * 135 *
139 * @return the description. 136 * @return the description.
140 */ 137 */
138 + @Override
141 public String getDescription() { 139 public String getDescription() {
142 return description; 140 return description;
143 } 141 }
...@@ -147,6 +145,7 @@ public class YangGrouping extends YangNode ...@@ -147,6 +145,7 @@ public class YangGrouping extends YangNode
147 * 145 *
148 * @param description set the description. 146 * @param description set the description.
149 */ 147 */
148 + @Override
150 public void setDescription(String description) { 149 public void setDescription(String description) {
151 this.description = description; 150 this.description = description;
152 } 151 }
...@@ -156,8 +155,8 @@ public class YangGrouping extends YangNode ...@@ -156,8 +155,8 @@ public class YangGrouping extends YangNode
156 * 155 *
157 * @return the list of leaves. 156 * @return the list of leaves.
158 */ 157 */
159 - @SuppressWarnings("rawtypes") 158 + @Override
160 - public List<YangLeaf> getListOfLeaf() { 159 + public List<YangLeaf<?>> getListOfLeaf() {
161 return listOfLeaf; 160 return listOfLeaf;
162 } 161 }
163 162
...@@ -166,8 +165,7 @@ public class YangGrouping extends YangNode ...@@ -166,8 +165,7 @@ public class YangGrouping extends YangNode
166 * 165 *
167 * @param leafsList the list of leaf to set. 166 * @param leafsList the list of leaf to set.
168 */ 167 */
169 - @SuppressWarnings("rawtypes") 168 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
170 - private void setListOfLeaf(List<YangLeaf> leafsList) {
171 listOfLeaf = leafsList; 169 listOfLeaf = leafsList;
172 } 170 }
173 171
...@@ -176,10 +174,10 @@ public class YangGrouping extends YangNode ...@@ -176,10 +174,10 @@ public class YangGrouping extends YangNode
176 * 174 *
177 * @param leaf the leaf to be added. 175 * @param leaf the leaf to be added.
178 */ 176 */
179 - @SuppressWarnings("rawtypes") 177 + @Override
180 public void addLeaf(YangLeaf<?> leaf) { 178 public void addLeaf(YangLeaf<?> leaf) {
181 if (getListOfLeaf() == null) { 179 if (getListOfLeaf() == null) {
182 - setListOfLeaf(new LinkedList<YangLeaf>()); 180 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
183 } 181 }
184 182
185 getListOfLeaf().add(leaf); 183 getListOfLeaf().add(leaf);
...@@ -190,8 +188,8 @@ public class YangGrouping extends YangNode ...@@ -190,8 +188,8 @@ public class YangGrouping extends YangNode
190 * 188 *
191 * @return the list of leaf-list. 189 * @return the list of leaf-list.
192 */ 190 */
193 - @SuppressWarnings("rawtypes") 191 + @Override
194 - public List<YangLeafList> getListOfLeafList() { 192 + public List<YangLeafList<?>> getListOfLeafList() {
195 return listOfLeafList; 193 return listOfLeafList;
196 } 194 }
197 195
...@@ -200,8 +198,7 @@ public class YangGrouping extends YangNode ...@@ -200,8 +198,7 @@ public class YangGrouping extends YangNode
200 * 198 *
201 * @param listOfLeafList the list of leaf-list to set. 199 * @param listOfLeafList the list of leaf-list to set.
202 */ 200 */
203 - @SuppressWarnings("rawtypes") 201 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
204 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
205 this.listOfLeafList = listOfLeafList; 202 this.listOfLeafList = listOfLeafList;
206 } 203 }
207 204
...@@ -210,10 +207,10 @@ public class YangGrouping extends YangNode ...@@ -210,10 +207,10 @@ public class YangGrouping extends YangNode
210 * 207 *
211 * @param leafList the leaf-list to be added. 208 * @param leafList the leaf-list to be added.
212 */ 209 */
213 - @SuppressWarnings("rawtypes") 210 + @Override
214 public void addLeafList(YangLeafList<?> leafList) { 211 public void addLeafList(YangLeafList<?> leafList) {
215 if (getListOfLeafList() == null) { 212 if (getListOfLeafList() == null) {
216 - setListOfLeafList(new LinkedList<YangLeafList>()); 213 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
217 } 214 }
218 215
219 getListOfLeafList().add(leafList); 216 getListOfLeafList().add(leafList);
...@@ -224,6 +221,7 @@ public class YangGrouping extends YangNode ...@@ -224,6 +221,7 @@ public class YangGrouping extends YangNode
224 * 221 *
225 * @return the reference. 222 * @return the reference.
226 */ 223 */
224 + @Override
227 public String getReference() { 225 public String getReference() {
228 return reference; 226 return reference;
229 } 227 }
...@@ -233,6 +231,7 @@ public class YangGrouping extends YangNode ...@@ -233,6 +231,7 @@ public class YangGrouping extends YangNode
233 * 231 *
234 * @param reference the reference to set. 232 * @param reference the reference to set.
235 */ 233 */
234 + @Override
236 public void setReference(String reference) { 235 public void setReference(String reference) {
237 this.reference = reference; 236 this.reference = reference;
238 } 237 }
...@@ -242,6 +241,7 @@ public class YangGrouping extends YangNode ...@@ -242,6 +241,7 @@ public class YangGrouping extends YangNode
242 * 241 *
243 * @return the status. 242 * @return the status.
244 */ 243 */
244 + @Override
245 public YangStatusType getStatus() { 245 public YangStatusType getStatus() {
246 return status; 246 return status;
247 } 247 }
...@@ -251,6 +251,7 @@ public class YangGrouping extends YangNode ...@@ -251,6 +251,7 @@ public class YangGrouping extends YangNode
251 * 251 *
252 * @param status the status to set. 252 * @param status the status to set.
253 */ 253 */
254 + @Override
254 public void setStatus(YangStatusType status) { 255 public void setStatus(YangStatusType status) {
255 this.status = status; 256 this.status = status;
256 } 257 }
...@@ -260,6 +261,7 @@ public class YangGrouping extends YangNode ...@@ -260,6 +261,7 @@ public class YangGrouping extends YangNode
260 * 261 *
261 * @return returns GROUPING_DATA. 262 * @return returns GROUPING_DATA.
262 */ 263 */
264 + @Override
263 public ParsableDataType getParsableDataType() { 265 public ParsableDataType getParsableDataType() {
264 return ParsableDataType.GROUPING_DATA; 266 return ParsableDataType.GROUPING_DATA;
265 } 267 }
...@@ -269,6 +271,7 @@ public class YangGrouping extends YangNode ...@@ -269,6 +271,7 @@ public class YangGrouping extends YangNode
269 * 271 *
270 * @throws DataModelException a violation of data model rules. 272 * @throws DataModelException a violation of data model rules.
271 */ 273 */
274 + @Override
272 public void validateDataOnEntry() throws DataModelException { 275 public void validateDataOnEntry() throws DataModelException {
273 // TODO auto-generated method stub, to be implemented by parser 276 // TODO auto-generated method stub, to be implemented by parser
274 } 277 }
...@@ -278,6 +281,7 @@ public class YangGrouping extends YangNode ...@@ -278,6 +281,7 @@ public class YangGrouping extends YangNode
278 * 281 *
279 * @throws DataModelException a violation of data model rules. 282 * @throws DataModelException a violation of data model rules.
280 */ 283 */
284 + @Override
281 public void validateDataOnExit() throws DataModelException { 285 public void validateDataOnExit() throws DataModelException {
282 // TODO auto-generated method stub, to be implemented by parser 286 // TODO auto-generated method stub, to be implemented by parser
283 } 287 }
...@@ -285,6 +289,7 @@ public class YangGrouping extends YangNode ...@@ -285,6 +289,7 @@ public class YangGrouping extends YangNode
285 /* (non-Javadoc) 289 /* (non-Javadoc)
286 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 290 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
287 */ 291 */
292 + @Override
288 public void generateJavaCodeEntry() { 293 public void generateJavaCodeEntry() {
289 // TODO Auto-generated method stub 294 // TODO Auto-generated method stub
290 295
...@@ -293,6 +298,7 @@ public class YangGrouping extends YangNode ...@@ -293,6 +298,7 @@ public class YangGrouping extends YangNode
293 /* (non-Javadoc) 298 /* (non-Javadoc)
294 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 299 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
295 */ 300 */
301 + @Override
296 public void generateJavaCodeExit() { 302 public void generateJavaCodeExit() {
297 // TODO Auto-generated method stub 303 // TODO Auto-generated method stub
298 304
......
...@@ -27,8 +27,7 @@ public interface YangLeavesHolder { ...@@ -27,8 +27,7 @@ public interface YangLeavesHolder {
27 * 27 *
28 * @return the list of leaves. 28 * @return the list of leaves.
29 */ 29 */
30 - @SuppressWarnings("rawtypes") 30 + public List<YangLeaf<?>> getListOfLeaf();
31 - public List<YangLeaf> getListOfLeaf();
32 31
33 /** 32 /**
34 * Add a leaf in data holder like container / list. 33 * Add a leaf in data holder like container / list.
...@@ -42,8 +41,7 @@ public interface YangLeavesHolder { ...@@ -42,8 +41,7 @@ public interface YangLeavesHolder {
42 * 41 *
43 * @return the list of leaf-list. 42 * @return the list of leaf-list.
44 */ 43 */
45 - @SuppressWarnings("rawtypes") 44 + List<YangLeafList<?>> getListOfLeafList();
46 - List<YangLeafList> getListOfLeafList();
47 45
48 /** 46 /**
49 * Add a leaf-list in data holder like container / list. 47 * Add a leaf-list in data holder like container / list.
......
...@@ -65,8 +65,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; ...@@ -65,8 +65,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
65 /** 65 /**
66 * List data represented in YANG. 66 * List data represented in YANG.
67 */ 67 */
68 -public class YangList extends YangNode 68 +public class YangList extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
69 - implements YangLeavesHolder, YangCommonInfo, Parsable {
70 69
71 /** 70 /**
72 * name of the YANG list. 71 * name of the YANG list.
...@@ -113,14 +112,12 @@ public class YangList extends YangNode ...@@ -113,14 +112,12 @@ public class YangList extends YangNode
113 /** 112 /**
114 * List of leaves. 113 * List of leaves.
115 */ 114 */
116 - @SuppressWarnings("rawtypes") 115 + private List<YangLeaf<?>> listOfLeaf;
117 - private List<YangLeaf> listOfLeaf;
118 116
119 /** 117 /**
120 * List of leaf-lists. 118 * List of leaf-lists.
121 */ 119 */
122 - @SuppressWarnings("rawtypes") 120 + private List<YangLeafList<?>> listOfLeafList;
123 - private List<YangLeafList> listOfLeafList;
124 121
125 /** 122 /**
126 * The "max-elements" statement, which is optional, takes as an argument a 123 * The "max-elements" statement, which is optional, takes as an argument a
...@@ -209,6 +206,7 @@ public class YangList extends YangNode ...@@ -209,6 +206,7 @@ public class YangList extends YangNode
209 * 206 *
210 * @return the description. 207 * @return the description.
211 */ 208 */
209 + @Override
212 public String getDescription() { 210 public String getDescription() {
213 return description; 211 return description;
214 } 212 }
...@@ -218,6 +216,7 @@ public class YangList extends YangNode ...@@ -218,6 +216,7 @@ public class YangList extends YangNode
218 * 216 *
219 * @param description set the description. 217 * @param description set the description.
220 */ 218 */
219 + @Override
221 public void setDescription(String description) { 220 public void setDescription(String description) {
222 this.description = description; 221 this.description = description;
223 } 222 }
...@@ -258,8 +257,8 @@ public class YangList extends YangNode ...@@ -258,8 +257,8 @@ public class YangList extends YangNode
258 * 257 *
259 * @return the list of leaves. 258 * @return the list of leaves.
260 */ 259 */
261 - @SuppressWarnings("rawtypes") 260 + @Override
262 - public List<YangLeaf> getListOfLeaf() { 261 + public List<YangLeaf<?>> getListOfLeaf() {
263 return listOfLeaf; 262 return listOfLeaf;
264 } 263 }
265 264
...@@ -268,8 +267,7 @@ public class YangList extends YangNode ...@@ -268,8 +267,7 @@ public class YangList extends YangNode
268 * 267 *
269 * @param leafsList the list of leaf to set. 268 * @param leafsList the list of leaf to set.
270 */ 269 */
271 - @SuppressWarnings("rawtypes") 270 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
272 - private void setListOfLeaf(List<YangLeaf> leafsList) {
273 listOfLeaf = leafsList; 271 listOfLeaf = leafsList;
274 } 272 }
275 273
...@@ -278,10 +276,10 @@ public class YangList extends YangNode ...@@ -278,10 +276,10 @@ public class YangList extends YangNode
278 * 276 *
279 * @param leaf the leaf to be added. 277 * @param leaf the leaf to be added.
280 */ 278 */
281 - @SuppressWarnings("rawtypes") 279 + @Override
282 public void addLeaf(YangLeaf<?> leaf) { 280 public void addLeaf(YangLeaf<?> leaf) {
283 if (getListOfLeaf() == null) { 281 if (getListOfLeaf() == null) {
284 - setListOfLeaf(new LinkedList<YangLeaf>()); 282 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
285 } 283 }
286 284
287 getListOfLeaf().add(leaf); 285 getListOfLeaf().add(leaf);
...@@ -292,8 +290,8 @@ public class YangList extends YangNode ...@@ -292,8 +290,8 @@ public class YangList extends YangNode
292 * 290 *
293 * @return the list of leaf-list. 291 * @return the list of leaf-list.
294 */ 292 */
295 - @SuppressWarnings("rawtypes") 293 + @Override
296 - public List<YangLeafList> getListOfLeafList() { 294 + public List<YangLeafList<?>> getListOfLeafList() {
297 return listOfLeafList; 295 return listOfLeafList;
298 } 296 }
299 297
...@@ -302,8 +300,7 @@ public class YangList extends YangNode ...@@ -302,8 +300,7 @@ public class YangList extends YangNode
302 * 300 *
303 * @param listOfLeafList the list of leaf-list to set. 301 * @param listOfLeafList the list of leaf-list to set.
304 */ 302 */
305 - @SuppressWarnings("rawtypes") 303 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
306 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
307 this.listOfLeafList = listOfLeafList; 304 this.listOfLeafList = listOfLeafList;
308 } 305 }
309 306
...@@ -312,10 +309,10 @@ public class YangList extends YangNode ...@@ -312,10 +309,10 @@ public class YangList extends YangNode
312 * 309 *
313 * @param leafList the leaf-list to be added. 310 * @param leafList the leaf-list to be added.
314 */ 311 */
315 - @SuppressWarnings("rawtypes") 312 + @Override
316 public void addLeafList(YangLeafList<?> leafList) { 313 public void addLeafList(YangLeafList<?> leafList) {
317 if (getListOfLeafList() == null) { 314 if (getListOfLeafList() == null) {
318 - setListOfLeafList(new LinkedList<YangLeafList>()); 315 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
319 } 316 }
320 317
321 getListOfLeafList().add(leafList); 318 getListOfLeafList().add(leafList);
...@@ -362,6 +359,7 @@ public class YangList extends YangNode ...@@ -362,6 +359,7 @@ public class YangList extends YangNode
362 * 359 *
363 * @return the reference. 360 * @return the reference.
364 */ 361 */
362 + @Override
365 public String getReference() { 363 public String getReference() {
366 return reference; 364 return reference;
367 } 365 }
...@@ -371,6 +369,7 @@ public class YangList extends YangNode ...@@ -371,6 +369,7 @@ public class YangList extends YangNode
371 * 369 *
372 * @param reference the reference to set. 370 * @param reference the reference to set.
373 */ 371 */
372 + @Override
374 public void setReference(String reference) { 373 public void setReference(String reference) {
375 this.reference = reference; 374 this.reference = reference;
376 } 375 }
...@@ -380,6 +379,7 @@ public class YangList extends YangNode ...@@ -380,6 +379,7 @@ public class YangList extends YangNode
380 * 379 *
381 * @return the status. 380 * @return the status.
382 */ 381 */
382 + @Override
383 public YangStatusType getStatus() { 383 public YangStatusType getStatus() {
384 return status; 384 return status;
385 } 385 }
...@@ -389,6 +389,7 @@ public class YangList extends YangNode ...@@ -389,6 +389,7 @@ public class YangList extends YangNode
389 * 389 *
390 * @param status the status to set. 390 * @param status the status to set.
391 */ 391 */
392 + @Override
392 public void setStatus(YangStatusType status) { 393 public void setStatus(YangStatusType status) {
393 this.status = status; 394 this.status = status;
394 } 395 }
...@@ -398,6 +399,7 @@ public class YangList extends YangNode ...@@ -398,6 +399,7 @@ public class YangList extends YangNode
398 * 399 *
399 * @return returns LIST_DATA. 400 * @return returns LIST_DATA.
400 */ 401 */
402 + @Override
401 public ParsableDataType getParsableDataType() { 403 public ParsableDataType getParsableDataType() {
402 return ParsableDataType.LIST_DATA; 404 return ParsableDataType.LIST_DATA;
403 } 405 }
...@@ -407,6 +409,7 @@ public class YangList extends YangNode ...@@ -407,6 +409,7 @@ public class YangList extends YangNode
407 * 409 *
408 * @throws DataModelException a violation of data model rules. 410 * @throws DataModelException a violation of data model rules.
409 */ 411 */
412 + @Override
410 public void validateDataOnEntry() throws DataModelException { 413 public void validateDataOnEntry() throws DataModelException {
411 // TODO auto-generated method stub, to be implemented by parser 414 // TODO auto-generated method stub, to be implemented by parser
412 } 415 }
...@@ -416,6 +419,7 @@ public class YangList extends YangNode ...@@ -416,6 +419,7 @@ public class YangList extends YangNode
416 * 419 *
417 * @throws DataModelException a violation of data model rules. 420 * @throws DataModelException a violation of data model rules.
418 */ 421 */
422 + @Override
419 public void validateDataOnExit() throws DataModelException { 423 public void validateDataOnExit() throws DataModelException {
420 // TODO auto-generated method stub, to be implemented by parser 424 // TODO auto-generated method stub, to be implemented by parser
421 } 425 }
...@@ -423,6 +427,7 @@ public class YangList extends YangNode ...@@ -423,6 +427,7 @@ public class YangList extends YangNode
423 /* (non-Javadoc) 427 /* (non-Javadoc)
424 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 428 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
425 */ 429 */
430 + @Override
426 public void generateJavaCodeEntry() { 431 public void generateJavaCodeEntry() {
427 // TODO Auto-generated method stub 432 // TODO Auto-generated method stub
428 433
...@@ -431,6 +436,7 @@ public class YangList extends YangNode ...@@ -431,6 +436,7 @@ public class YangList extends YangNode
431 /* (non-Javadoc) 436 /* (non-Javadoc)
432 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 437 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
433 */ 438 */
439 + @Override
434 public void generateJavaCodeExit() { 440 public void generateJavaCodeExit() {
435 // TODO Auto-generated method stub 441 // TODO Auto-generated method stub
436 442
......
...@@ -15,14 +15,18 @@ ...@@ -15,14 +15,18 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.io.IOException;
18 import java.util.LinkedList; 19 import java.util.LinkedList;
19 import java.util.List; 20 import java.util.List;
20 21
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.parser.ParsableDataType; 24 import org.onosproject.yangutils.parser.ParsableDataType;
25 +import org.onosproject.yangutils.translator.CachedFileHandle;
24 import org.onosproject.yangutils.translator.CodeGenerator; 26 import org.onosproject.yangutils.translator.CodeGenerator;
25 -import org.onosproject.yangutils.utils.io.CachedFileHandle; 27 +import org.onosproject.yangutils.translator.GeneratedFileType;
28 +import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
29 +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
26 30
27 /*- 31 /*-
28 * Reference:RFC 6020. 32 * Reference:RFC 6020.
...@@ -67,8 +71,7 @@ import org.onosproject.yangutils.utils.io.CachedFileHandle; ...@@ -67,8 +71,7 @@ import org.onosproject.yangutils.utils.io.CachedFileHandle;
67 /** 71 /**
68 * Data model node to maintain information defined in YANG module. 72 * Data model node to maintain information defined in YANG module.
69 */ 73 */
70 -public class YangModule extends YangNode 74 +public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
71 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
72 75
73 /** 76 /**
74 * Name of the module. 77 * Name of the module.
...@@ -109,14 +112,12 @@ public class YangModule extends YangNode ...@@ -109,14 +112,12 @@ public class YangModule extends YangNode
109 /** 112 /**
110 * List of leaves at root level in the module. 113 * List of leaves at root level in the module.
111 */ 114 */
112 - @SuppressWarnings("rawtypes") 115 + private List<YangLeaf<?>> listOfLeaf;
113 - private List<YangLeaf> listOfLeaf;
114 116
115 /** 117 /**
116 * List of leaf-lists at root level in the module. 118 * List of leaf-lists at root level in the module.
117 */ 119 */
118 - @SuppressWarnings("rawtypes") 120 + private List<YangLeafList<?>> listOfLeafList;
119 - private List<YangLeafList> listOfLeafList;
120 121
121 /** 122 /**
122 * Name space of the module. 123 * Name space of the module.
...@@ -209,6 +210,7 @@ public class YangModule extends YangNode ...@@ -209,6 +210,7 @@ public class YangModule extends YangNode
209 * 210 *
210 * @return the description of YANG module. 211 * @return the description of YANG module.
211 */ 212 */
213 + @Override
212 public String getDescription() { 214 public String getDescription() {
213 return description; 215 return description;
214 } 216 }
...@@ -218,6 +220,7 @@ public class YangModule extends YangNode ...@@ -218,6 +220,7 @@ public class YangModule extends YangNode
218 * 220 *
219 * @param description set the description of YANG module. 221 * @param description set the description of YANG module.
220 */ 222 */
223 + @Override
221 public void setDescription(String description) { 224 public void setDescription(String description) {
222 this.description = description; 225 this.description = description;
223 } 226 }
...@@ -294,8 +297,8 @@ public class YangModule extends YangNode ...@@ -294,8 +297,8 @@ public class YangModule extends YangNode
294 * 297 *
295 * @return the list of leaves. 298 * @return the list of leaves.
296 */ 299 */
297 - @SuppressWarnings("rawtypes") 300 + @Override
298 - public List<YangLeaf> getListOfLeaf() { 301 + public List<YangLeaf<?>> getListOfLeaf() {
299 return listOfLeaf; 302 return listOfLeaf;
300 } 303 }
301 304
...@@ -304,8 +307,7 @@ public class YangModule extends YangNode ...@@ -304,8 +307,7 @@ public class YangModule extends YangNode
304 * 307 *
305 * @param leafsList the list of leaf to set. 308 * @param leafsList the list of leaf to set.
306 */ 309 */
307 - @SuppressWarnings("rawtypes") 310 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
308 - private void setListOfLeaf(List<YangLeaf> leafsList) {
309 listOfLeaf = leafsList; 311 listOfLeaf = leafsList;
310 } 312 }
311 313
...@@ -314,10 +316,10 @@ public class YangModule extends YangNode ...@@ -314,10 +316,10 @@ public class YangModule extends YangNode
314 * 316 *
315 * @param leaf the leaf to be added. 317 * @param leaf the leaf to be added.
316 */ 318 */
317 - @SuppressWarnings("rawtypes") 319 + @Override
318 public void addLeaf(YangLeaf<?> leaf) { 320 public void addLeaf(YangLeaf<?> leaf) {
319 if (getListOfLeaf() == null) { 321 if (getListOfLeaf() == null) {
320 - setListOfLeaf(new LinkedList<YangLeaf>()); 322 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
321 } 323 }
322 324
323 getListOfLeaf().add(leaf); 325 getListOfLeaf().add(leaf);
...@@ -328,8 +330,8 @@ public class YangModule extends YangNode ...@@ -328,8 +330,8 @@ public class YangModule extends YangNode
328 * 330 *
329 * @return the list of leaf-list. 331 * @return the list of leaf-list.
330 */ 332 */
331 - @SuppressWarnings("rawtypes") 333 + @Override
332 - public List<YangLeafList> getListOfLeafList() { 334 + public List<YangLeafList<?>> getListOfLeafList() {
333 return listOfLeafList; 335 return listOfLeafList;
334 } 336 }
335 337
...@@ -338,8 +340,7 @@ public class YangModule extends YangNode ...@@ -338,8 +340,7 @@ public class YangModule extends YangNode
338 * 340 *
339 * @param listOfLeafList the list of leaf-list to set. 341 * @param listOfLeafList the list of leaf-list to set.
340 */ 342 */
341 - @SuppressWarnings("rawtypes") 343 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
342 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
343 this.listOfLeafList = listOfLeafList; 344 this.listOfLeafList = listOfLeafList;
344 } 345 }
345 346
...@@ -348,10 +349,10 @@ public class YangModule extends YangNode ...@@ -348,10 +349,10 @@ public class YangModule extends YangNode
348 * 349 *
349 * @param leafList the leaf-list to be added. 350 * @param leafList the leaf-list to be added.
350 */ 351 */
351 - @SuppressWarnings("rawtypes") 352 + @Override
352 public void addLeafList(YangLeafList<?> leafList) { 353 public void addLeafList(YangLeafList<?> leafList) {
353 if (getListOfLeafList() == null) { 354 if (getListOfLeafList() == null) {
354 - setListOfLeafList(new LinkedList<YangLeafList>()); 355 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
355 } 356 }
356 357
357 getListOfLeafList().add(leafList); 358 getListOfLeafList().add(leafList);
...@@ -416,6 +417,7 @@ public class YangModule extends YangNode ...@@ -416,6 +417,7 @@ public class YangModule extends YangNode
416 * 417 *
417 * @return the reference. 418 * @return the reference.
418 */ 419 */
420 + @Override
419 public String getReference() { 421 public String getReference() {
420 return reference; 422 return reference;
421 } 423 }
...@@ -425,6 +427,7 @@ public class YangModule extends YangNode ...@@ -425,6 +427,7 @@ public class YangModule extends YangNode
425 * 427 *
426 * @param reference the reference to set. 428 * @param reference the reference to set.
427 */ 429 */
430 + @Override
428 public void setReference(String reference) { 431 public void setReference(String reference) {
429 this.reference = reference; 432 this.reference = reference;
430 } 433 }
...@@ -508,6 +511,7 @@ public class YangModule extends YangNode ...@@ -508,6 +511,7 @@ public class YangModule extends YangNode
508 * 511 *
509 * @return returns MODULE_DATA. 512 * @return returns MODULE_DATA.
510 */ 513 */
514 + @Override
511 public ParsableDataType getParsableDataType() { 515 public ParsableDataType getParsableDataType() {
512 return ParsableDataType.MODULE_DATA; 516 return ParsableDataType.MODULE_DATA;
513 } 517 }
...@@ -517,6 +521,7 @@ public class YangModule extends YangNode ...@@ -517,6 +521,7 @@ public class YangModule extends YangNode
517 * 521 *
518 * @throws DataModelException a violation of data model rules 522 * @throws DataModelException a violation of data model rules
519 */ 523 */
524 + @Override
520 public void validateDataOnEntry() throws DataModelException { 525 public void validateDataOnEntry() throws DataModelException {
521 // TODO auto-generated method stub, to be implemented by parser 526 // TODO auto-generated method stub, to be implemented by parser
522 } 527 }
...@@ -526,24 +531,67 @@ public class YangModule extends YangNode ...@@ -526,24 +531,67 @@ public class YangModule extends YangNode
526 * 531 *
527 * @throws DataModelException a violation of data model rules 532 * @throws DataModelException a violation of data model rules
528 */ 533 */
534 + @Override
529 public void validateDataOnExit() throws DataModelException { 535 public void validateDataOnExit() throws DataModelException {
530 // TODO auto-generated method stub, to be implemented by parser 536 // TODO auto-generated method stub, to be implemented by parser
531 } 537 }
532 538
533 /** 539 /**
534 * Generates java code for module. 540 * Generates java code for module.
541 + *
542 + * @throws IOException when fails to generate the source files.
535 */ 543 */
536 - public void generateJavaCodeEntry() { 544 + @Override
537 - //TODO: autogenerated method stub, to be implemented 545 + public void generateJavaCodeEntry() throws IOException {
546 + String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
547 + getRevision().getRevDate());
548 + setPackage(modPkg);
538 549
539 - return; 550 + CachedFileHandle handle = null;
551 + try {
552 + FileSystemUtil.createPackage(getPackage(), getName());
553 + handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
554 + } catch (IOException e) {
555 + throw new IOException("Failed to create the source files.");
556 + }
557 + setFileHandle(handle);
558 + addLavesAttributes();
559 + addLeafListAttributes();
560 + }
561 +
562 + /**
563 + * Adds leaf attributes in generated files.
564 + */
565 + private void addLavesAttributes() {
566 +
567 + List<YangLeaf<?>> leaves = getListOfLeaf();
568 + if (leaves != null) {
569 + for (YangLeaf<?> leaf : leaves) {
570 + getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
571 + }
572 + }
573 + }
574 +
575 + /**
576 + * Adds leaf list's attributes in generated files.
577 + */
578 + private void addLeafListAttributes() {
579 + List<YangLeafList<?>> leavesList = getListOfLeafList();
580 + if (leavesList != null) {
581 + for (YangLeafList<?> leafList : leavesList) {
582 + getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
583 + }
584 + }
540 } 585 }
541 586
542 /** 587 /**
543 * Free resources used to generate code. 588 * Free resources used to generate code.
589 + *
590 + * @throws IOException when fails to generate source files.
544 */ 591 */
545 - public void generateJavaCodeExit() { 592 + @Override
546 - //TODO: autogenerated method stub, to be implemented 593 + public void generateJavaCodeExit() throws IOException {
594 + getFileHandle().close();
547 return; 595 return;
548 } 596 }
549 597
......
...@@ -72,8 +72,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; ...@@ -72,8 +72,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
72 /** 72 /**
73 * Data model node to maintain information defined in YANG sub-module. 73 * Data model node to maintain information defined in YANG sub-module.
74 */ 74 */
75 -public class YangSubModule extends YangNode 75 +public class YangSubModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable {
76 - implements YangLeavesHolder, YangDesc, YangReference, Parsable {
77 76
78 /** 77 /**
79 * Name of sub module. 78 * Name of sub module.
...@@ -114,14 +113,12 @@ public class YangSubModule extends YangNode ...@@ -114,14 +113,12 @@ public class YangSubModule extends YangNode
114 /** 113 /**
115 * List of leaves at root level in the sub-module. 114 * List of leaves at root level in the sub-module.
116 */ 115 */
117 - @SuppressWarnings("rawtypes") 116 + private List<YangLeaf<?>> listOfLeaf;
118 - private List<YangLeaf> listOfLeaf;
119 117
120 /** 118 /**
121 * List of leaf-lists at root level in the sub-module. 119 * List of leaf-lists at root level in the sub-module.
122 */ 120 */
123 - @SuppressWarnings("rawtypes") 121 + private List<YangLeafList<?>> listOfLeafList;
124 - private List<YangLeafList> listOfLeafList;
125 122
126 /** 123 /**
127 * organization owner of the sub-module. 124 * organization owner of the sub-module.
...@@ -207,6 +204,7 @@ public class YangSubModule extends YangNode ...@@ -207,6 +204,7 @@ public class YangSubModule extends YangNode
207 * 204 *
208 * @return the description. 205 * @return the description.
209 */ 206 */
207 + @Override
210 public String getDescription() { 208 public String getDescription() {
211 return description; 209 return description;
212 } 210 }
...@@ -216,6 +214,7 @@ public class YangSubModule extends YangNode ...@@ -216,6 +214,7 @@ public class YangSubModule extends YangNode
216 * 214 *
217 * @param description set the description. 215 * @param description set the description.
218 */ 216 */
217 + @Override
219 public void setDescription(String description) { 218 public void setDescription(String description) {
220 this.description = description; 219 this.description = description;
221 } 220 }
...@@ -292,8 +291,8 @@ public class YangSubModule extends YangNode ...@@ -292,8 +291,8 @@ public class YangSubModule extends YangNode
292 * 291 *
293 * @return the list of leaves. 292 * @return the list of leaves.
294 */ 293 */
295 - @SuppressWarnings("rawtypes") 294 + @Override
296 - public List<YangLeaf> getListOfLeaf() { 295 + public List<YangLeaf<?>> getListOfLeaf() {
297 return listOfLeaf; 296 return listOfLeaf;
298 } 297 }
299 298
...@@ -302,8 +301,7 @@ public class YangSubModule extends YangNode ...@@ -302,8 +301,7 @@ public class YangSubModule extends YangNode
302 * 301 *
303 * @param leafsList the list of leaf to set. 302 * @param leafsList the list of leaf to set.
304 */ 303 */
305 - @SuppressWarnings("rawtypes") 304 + private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
306 - private void setListOfLeaf(List<YangLeaf> leafsList) {
307 listOfLeaf = leafsList; 305 listOfLeaf = leafsList;
308 } 306 }
309 307
...@@ -312,10 +310,10 @@ public class YangSubModule extends YangNode ...@@ -312,10 +310,10 @@ public class YangSubModule extends YangNode
312 * 310 *
313 * @param leaf the leaf to be added. 311 * @param leaf the leaf to be added.
314 */ 312 */
315 - @SuppressWarnings("rawtypes") 313 + @Override
316 public void addLeaf(YangLeaf<?> leaf) { 314 public void addLeaf(YangLeaf<?> leaf) {
317 if (getListOfLeaf() == null) { 315 if (getListOfLeaf() == null) {
318 - setListOfLeaf(new LinkedList<YangLeaf>()); 316 + setListOfLeaf(new LinkedList<YangLeaf<?>>());
319 } 317 }
320 318
321 getListOfLeaf().add(leaf); 319 getListOfLeaf().add(leaf);
...@@ -326,8 +324,8 @@ public class YangSubModule extends YangNode ...@@ -326,8 +324,8 @@ public class YangSubModule extends YangNode
326 * 324 *
327 * @return the list of leaf-list. 325 * @return the list of leaf-list.
328 */ 326 */
329 - @SuppressWarnings("rawtypes") 327 + @Override
330 - public List<YangLeafList> getListOfLeafList() { 328 + public List<YangLeafList<?>> getListOfLeafList() {
331 return listOfLeafList; 329 return listOfLeafList;
332 } 330 }
333 331
...@@ -336,8 +334,7 @@ public class YangSubModule extends YangNode ...@@ -336,8 +334,7 @@ public class YangSubModule extends YangNode
336 * 334 *
337 * @param listOfLeafList the list of leaf-list to set. 335 * @param listOfLeafList the list of leaf-list to set.
338 */ 336 */
339 - @SuppressWarnings("rawtypes") 337 + private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
340 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
341 this.listOfLeafList = listOfLeafList; 338 this.listOfLeafList = listOfLeafList;
342 } 339 }
343 340
...@@ -346,10 +343,10 @@ public class YangSubModule extends YangNode ...@@ -346,10 +343,10 @@ public class YangSubModule extends YangNode
346 * 343 *
347 * @param leafList the leaf-list to be added. 344 * @param leafList the leaf-list to be added.
348 */ 345 */
349 - @SuppressWarnings("rawtypes") 346 + @Override
350 public void addLeafList(YangLeafList<?> leafList) { 347 public void addLeafList(YangLeafList<?> leafList) {
351 if (getListOfLeafList() == null) { 348 if (getListOfLeafList() == null) {
352 - setListOfLeafList(new LinkedList<YangLeafList>()); 349 + setListOfLeafList(new LinkedList<YangLeafList<?>>());
353 } 350 }
354 351
355 getListOfLeafList().add(leafList); 352 getListOfLeafList().add(leafList);
...@@ -378,6 +375,7 @@ public class YangSubModule extends YangNode ...@@ -378,6 +375,7 @@ public class YangSubModule extends YangNode
378 * 375 *
379 * @return the reference. 376 * @return the reference.
380 */ 377 */
378 + @Override
381 public String getReference() { 379 public String getReference() {
382 return reference; 380 return reference;
383 } 381 }
...@@ -387,6 +385,7 @@ public class YangSubModule extends YangNode ...@@ -387,6 +385,7 @@ public class YangSubModule extends YangNode
387 * 385 *
388 * @param reference the reference to set. 386 * @param reference the reference to set.
389 */ 387 */
388 + @Override
390 public void setReference(String reference) { 389 public void setReference(String reference) {
391 this.reference = reference; 390 this.reference = reference;
392 } 391 }
...@@ -432,6 +431,7 @@ public class YangSubModule extends YangNode ...@@ -432,6 +431,7 @@ public class YangSubModule extends YangNode
432 * 431 *
433 * @return returns SUB_MODULE_DATA. 432 * @return returns SUB_MODULE_DATA.
434 */ 433 */
434 + @Override
435 public ParsableDataType getParsableDataType() { 435 public ParsableDataType getParsableDataType() {
436 return ParsableDataType.SUB_MODULE_DATA; 436 return ParsableDataType.SUB_MODULE_DATA;
437 } 437 }
...@@ -441,6 +441,7 @@ public class YangSubModule extends YangNode ...@@ -441,6 +441,7 @@ public class YangSubModule extends YangNode
441 * 441 *
442 * @throws DataModelException a violation of data model rules. 442 * @throws DataModelException a violation of data model rules.
443 */ 443 */
444 + @Override
444 public void validateDataOnEntry() throws DataModelException { 445 public void validateDataOnEntry() throws DataModelException {
445 // TODO auto-generated method stub, to be implemented by parser 446 // TODO auto-generated method stub, to be implemented by parser
446 } 447 }
...@@ -450,6 +451,7 @@ public class YangSubModule extends YangNode ...@@ -450,6 +451,7 @@ public class YangSubModule extends YangNode
450 * 451 *
451 * @throws DataModelException a violation of data model rules. 452 * @throws DataModelException a violation of data model rules.
452 */ 453 */
454 + @Override
453 public void validateDataOnExit() throws DataModelException { 455 public void validateDataOnExit() throws DataModelException {
454 // TODO auto-generated method stub, to be implemented by parser 456 // TODO auto-generated method stub, to be implemented by parser
455 } 457 }
...@@ -457,6 +459,7 @@ public class YangSubModule extends YangNode ...@@ -457,6 +459,7 @@ public class YangSubModule extends YangNode
457 /* (non-Javadoc) 459 /* (non-Javadoc)
458 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() 460 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
459 */ 461 */
462 + @Override
460 public void generateJavaCodeEntry() { 463 public void generateJavaCodeEntry() {
461 // TODO Auto-generated method stub 464 // TODO Auto-generated method stub
462 465
...@@ -465,6 +468,7 @@ public class YangSubModule extends YangNode ...@@ -465,6 +468,7 @@ public class YangSubModule extends YangNode
465 /* (non-Javadoc) 468 /* (non-Javadoc)
466 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() 469 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
467 */ 470 */
471 + @Override
468 public void generateJavaCodeExit() { 472 public void generateJavaCodeExit() {
469 // TODO Auto-generated method stub 473 // TODO Auto-generated method stub
470 474
......
...@@ -24,24 +24,26 @@ import java.util.List; ...@@ -24,24 +24,26 @@ import java.util.List;
24 import org.apache.maven.plugin.AbstractMojo; 24 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException; 25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException; 26 import org.apache.maven.plugin.MojoFailureException;
27 +import org.apache.maven.plugins.annotations.Component;
27 import org.apache.maven.plugins.annotations.LifecyclePhase; 28 import org.apache.maven.plugins.annotations.LifecyclePhase;
28 import org.apache.maven.plugins.annotations.Mojo; 29 import org.apache.maven.plugins.annotations.Mojo;
30 +import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.plugins.annotations.ResolutionScope; 31 import org.apache.maven.plugins.annotations.ResolutionScope;
30 import org.apache.maven.project.MavenProject; 32 import org.apache.maven.project.MavenProject;
31 -import org.apache.maven.plugins.annotations.Parameter;
32 -import org.apache.maven.plugins.annotations.Component;
33 -import org.sonatype.plexus.build.incremental.BuildContext;
34 -
35 import org.onosproject.yangutils.datamodel.YangNode; 33 import org.onosproject.yangutils.datamodel.YangNode;
36 import org.onosproject.yangutils.parser.YangUtilsParser; 34 import org.onosproject.yangutils.parser.YangUtilsParser;
37 import org.onosproject.yangutils.parser.exceptions.ParserException; 35 import org.onosproject.yangutils.parser.exceptions.ParserException;
36 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
37 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
38 +import org.onosproject.yangutils.utils.UtilConstants;
39 +import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
38 import org.onosproject.yangutils.utils.io.impl.YangFileScanner; 40 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
41 +import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
42 +import org.sonatype.plexus.build.incremental.BuildContext;
39 43
40 /** 44 /**
41 - * ONOS YANG utility maven plugin. 45 + * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase
42 - * Goal of plugin is yang2java 46 + * in generate-sources requiresDependencyResolution at compile time
43 - * Execution phase in generate-sources
44 - * requiresDependencyResolution at compile time
45 */ 47 */
46 @Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES, 48 @Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
47 requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) 49 requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
...@@ -71,24 +73,32 @@ public class YangUtilManager extends AbstractMojo { ...@@ -71,24 +73,32 @@ public class YangUtilManager extends AbstractMojo {
71 @Component 73 @Component
72 private BuildContext context; 74 private BuildContext context;
73 75
74 - private YangUtilsParser yangUtilsParser; 76 + private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
75 private String baseDir; 77 private String baseDir;
76 private String searchDir; 78 private String searchDir;
77 79
78 /** 80 /**
79 * Set current project. 81 * Set current project.
80 * 82 *
81 - * @param project maven project. 83 + * @param curProject maven project.
82 */ 84 */
83 - public void setCurrentProject(final MavenProject project) { 85 + public void setCurrentProject(final MavenProject curProject) {
84 - this.project = project; 86 + project = curProject;
85 } 87 }
86 88
87 @Override 89 @Override
88 public void execute() throws MojoExecutionException, MojoFailureException { 90 public void execute() throws MojoExecutionException, MojoFailureException {
89 91
90 try { 92 try {
93 +
94 + CopyrightHeader.parseCopyrightHeader();
91 baseDir = project.getBasedir().toString(); 95 baseDir = project.getBasedir().toString();
96 +
97 + /**
98 + * For deleting the generated code in previous build.
99 + */
100 + YangIoUtils.clean(baseDir);
101 +
92 searchDir = baseDir + File.separator + yangFilesDir; 102 searchDir = baseDir + File.separator + yangFilesDir;
93 103
94 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); 104 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
...@@ -97,13 +107,25 @@ public class YangUtilManager extends AbstractMojo { ...@@ -97,13 +107,25 @@ public class YangUtilManager extends AbstractMojo {
97 String yangFile = yangFileIterator.next(); 107 String yangFile = yangFileIterator.next();
98 try { 108 try {
99 YangNode yangNode = yangUtilsParser.getDataModel(yangFile); 109 YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
100 - //TODO: send this data model to translator and create the corresponding java files. 110 + JavaCodeGenerator.generateJavaCode(yangNode);
101 } catch (ParserException e) { 111 } catch (ParserException e) {
102 - getLog().info("Invalid yang file."); 112 + String logInfo = "Error in file: " + e.getFileName();
113 + if (e.getLineNumber() != 0) {
114 + logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
115 + + e.getCharPositionInLine();
116 +
103 } 117 }
118 + if (e.getMessage() != null) {
119 + logInfo = logInfo + "\n" + e.getMessage();
104 } 120 }
121 + getLog().info(logInfo);
122 + }
123 + }
124 +
125 + YangIoUtils.addToSource(baseDir + File.separator + UtilConstants.YANG_GEN_DIR, project, context);
105 } catch (final IOException e) { 126 } catch (final IOException e) {
106 - getLog().info("Exception occured"); 127 + getLog().info("IOException occured");
107 } 128 }
108 } 129 }
130 +
109 } 131 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +/*
2 + * Copyright 2016 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;
18 +
19 +import java.io.IOException;
20 +
21 +import org.onosproject.yangutils.datamodel.YangType;
22 +
23 +/**
24 + * Cached java file handle, which supports the addition of member attributes and
25 + * methods.
26 + */
27 +public interface CachedFileHandle {
28 +
29 + /**
30 + * Add a new attribute to the file(s).
31 + *
32 + * @param attrType data type of the added attribute.
33 + * @param name name of the attribute.
34 + * @param isListAttr if the current added attribute needs to be maintained
35 + * in a list.
36 + */
37 + void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr);
38 +
39 + /**
40 + * Flushes the cached contents to the target file, frees used resources.
41 + *
42 + * @throws IOException when failes to generated java files.
43 + */
44 + void close() throws IOException;
45 +}
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.yangutils.translator; 17 package org.onosproject.yangutils.translator;
18 18
19 +import java.io.IOException;
20 +
19 /** 21 /**
20 * Abstraction of an entity which provides Code generator functionalities. 22 * Abstraction of an entity which provides Code generator functionalities.
21 */ 23 */
...@@ -23,12 +25,16 @@ public interface CodeGenerator { ...@@ -23,12 +25,16 @@ public interface CodeGenerator {
23 25
24 /** 26 /**
25 * Traverse the schema of application and generate corresponding code. 27 * Traverse the schema of application and generate corresponding code.
28 + *
29 + * @throws IOException when fails to translate the data model tree.
26 */ 30 */
27 - void generateJavaCodeEntry(); 31 + void generateJavaCodeEntry() throws IOException;
28 32
29 /** 33 /**
30 * Traverse the schema of application and generate corresponding code. 34 * Traverse the schema of application and generate corresponding code.
35 + *
36 + * @throws IOException when fails to generate java code.
31 */ 37 */
32 - void generateJavaCodeExit(); 38 + void generateJavaCodeExit() throws IOException;
33 39
34 } 40 }
......
1 -/*Copyright 2016.year Open Networking Laboratory 1 +/*
2 - 2 + * Copyright 2016 Open Networking Laboratory
3 -Licensed under the Apache License, Version 2.0 (the "License"); 3 + *
4 -you may not use this file except in compliance with the License. 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 -You may obtain a copy of the License at 5 + * you may not use this file except in compliance with the License.
6 - 6 + * You may obtain a copy of the License at
7 - http://www.apache.org/licenses/LICENSE-2.0 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 + */
8 16
9 -Unless required by applicable law or agreed to in writing, software
10 -distributed under the License is distributed on an "AS IS" BASIS,
11 -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 -See the License for the specific language governing permissions and
13 -limitations under the License.*/
14 package org.onosproject.yangutils.translator; 17 package org.onosproject.yangutils.translator;
15 18
16 /** 19 /**
...@@ -18,17 +21,27 @@ package org.onosproject.yangutils.translator; ...@@ -18,17 +21,27 @@ package org.onosproject.yangutils.translator;
18 */ 21 */
19 public enum GeneratedFileType { 22 public enum GeneratedFileType {
20 /** 23 /**
21 - * interface file. 24 + * Interface file.
22 */ 25 */
23 INTERFACE, 26 INTERFACE,
24 27
25 /** 28 /**
26 - * class file. 29 + * Builder class file.
27 */ 30 */
28 BUILDER_CLASS, 31 BUILDER_CLASS,
29 32
30 /** 33 /**
34 + * Builder interface file.
35 + */
36 + BUILDER_INTERFACE,
37 +
38 + /**
39 + * Impl class file.
40 + */
41 + IMPL,
42 +
43 + /**
31 * interface and class file. 44 * interface and class file.
32 */ 45 */
33 - BOTH 46 + ALL
34 } 47 }
......
1 +/*
2 + * Copyright 2016 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.Serializable;
20 +
21 +import org.onosproject.yangutils.datamodel.YangType;
22 +
23 +/**
24 + * Maintains the attribute info corresponding to class/interface generated.
25 + */
26 +public class AttributeInfo implements Serializable {
27 +
28 + /**
29 + * version of serialized info.
30 + */
31 + private static final long serialVersionUID = 201602151004L;
32 +
33 + /**
34 + * The data type info of attribute.
35 + */
36 + private YangType<?> attrType;
37 +
38 + /**
39 + * Name of the attribute.
40 + */
41 + private String name;
42 +
43 + /**
44 + * If the added attribute is a list of info.
45 + */
46 + private boolean isListAttr;
47 +
48 + /**
49 + * If the added attribute has to be accessed in a fully qualified manner.
50 + */
51 + private boolean isQualifiedName;
52 +
53 + /**
54 + * Default constructor.
55 + */
56 + public AttributeInfo() {
57 + }
58 +
59 + /**
60 + * Get the data type info of attribute.
61 + *
62 + * @return the data type info of attribute.
63 + */
64 + public YangType<?> getAttributeType() {
65 + return attrType;
66 + }
67 +
68 + /**
69 + * Set the data type info of attribute.
70 + *
71 + * @param type the data type info of attribute.
72 + */
73 + public void setAttributeType(YangType<?> type) {
74 + attrType = type;
75 + }
76 +
77 + /**
78 + * Get name of the attribute.
79 + *
80 + * @return name of the attribute.
81 + */
82 + public String getAttributeName() {
83 + return name;
84 + }
85 +
86 + /**
87 + * Set name of the attribute.
88 + *
89 + * @param attrName name of the attribute.
90 + */
91 + public void setAttributeName(String attrName) {
92 + name = attrName;
93 + }
94 +
95 + /**
96 + * Get if the added attribute is a list of info.
97 + *
98 + * @return the if the added attribute is a list of info.
99 + */
100 + public boolean isListAttr() {
101 + return isListAttr;
102 + }
103 +
104 + /**
105 + * Set if the added attribute is a list of info.
106 + *
107 + * @param isList if the added attribute is a list of info.
108 + */
109 + public void setListAttr(boolean isList) {
110 + isListAttr = isList;
111 + }
112 +
113 + /**
114 + * Get if the added attribute has to be accessed in a fully qualified
115 + * manner.
116 + *
117 + * @return the if the added attribute has to be accessed in a fully
118 + * qualified manner.
119 + */
120 + public boolean isQualifiedName() {
121 + return isQualifiedName;
122 + }
123 +
124 + /**
125 + * Set if the added attribute has to be accessed in a fully qualified
126 + * manner.
127 + *
128 + * @param isQualified if the added attribute has to be accessed in a fully
129 + * qualified manner.
130 + */
131 + public void setQualifiedName(boolean isQualified) {
132 + isQualifiedName = isQualified;
133 + }
134 +
135 +}
1 +/*
2 + * Copyright 2016 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 +/**
20 + * Type of method generated.
21 + */
22 +public enum GeneratedMethodTypes {
23 + /**
24 + * getter method.
25 + */
26 + GETTER,
27 +
28 + /**
29 + * setter method.
30 + */
31 + SETTER,
32 +
33 + /**
34 + * Constructor.
35 + */
36 + CONSTRUCTOR,
37 +
38 + /**
39 + * Build.
40 + */
41 + BUILD,
42 +
43 + /**
44 + * Default Constructor.
45 + */
46 + DEFAULT_CONSTRUCTOR
47 +}
1 +/*
2 + * Copyright 2016 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.util.Objects;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +/**
24 + * Maintains the information about individual imports in the generated file.
25 + */
26 +public class ImportInfo {
27 +
28 + /**
29 + * Package location where the imported class/interface is defined.
30 + */
31 + private String pkgInfo;
32 +
33 + /**
34 + * class/interface being referenced.
35 + */
36 + private String classInfo;
37 +
38 + /**
39 + * Default constructor.
40 + */
41 + public ImportInfo() {
42 + }
43 +
44 + /**
45 + * Get the imported package info.
46 + *
47 + * @return the imported package info.
48 + */
49 + public String getPkgInfo() {
50 + return pkgInfo;
51 + }
52 +
53 + /**
54 + * Set the imported package info.
55 + *
56 + * @param pkgInfo the imported package info.
57 + */
58 + public void setPkgInfo(String pkgInfo) {
59 + this.pkgInfo = pkgInfo;
60 + }
61 +
62 + /**
63 + * Get the imported class/interface info.
64 + *
65 + * @return the imported class/interface info.
66 + */
67 + public String getClassInfo() {
68 + return classInfo;
69 + }
70 +
71 + /**
72 + * Set the imported class/interface info.
73 + *
74 + * @param classInfo the imported class/interface info.
75 + */
76 + public void setClassInfo(String classInfo) {
77 + this.classInfo = classInfo;
78 + }
79 +
80 + @Override
81 + public int hashCode() {
82 + return Objects.hash(pkgInfo, classInfo);
83 + }
84 +
85 + @Override
86 + public boolean equals(Object obj) {
87 + if (this == obj) {
88 + return true;
89 + }
90 + if (obj instanceof ImportInfo) {
91 + ImportInfo other = (ImportInfo) obj;
92 + return Objects.equals(pkgInfo, other.pkgInfo) &&
93 + Objects.equals(classInfo, other.classInfo);
94 + }
95 + return false;
96 + }
97 +
98 + /**
99 + * check if the import info matches.
100 + *
101 + * @param importInfo matched import
102 + * @return if equal or not
103 + */
104 + public boolean exactMatch(ImportInfo importInfo) {
105 + return equals(importInfo)
106 + && Objects.equals(pkgInfo, importInfo.getPkgInfo())
107 + && Objects.equals(classInfo, importInfo.getClassInfo());
108 + }
109 +
110 + @Override
111 + public String toString() {
112 + return MoreObjects.toStringHelper(getClass())
113 + .add("pkgInfo", pkgInfo)
114 + .add("classInfo", classInfo).toString();
115 + }
116 +
117 +}
1 +/*
2 + * Copyright 2016 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.IOException;
20 +
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +
23 +/**
24 + * Implementation of Java code generator based on application schema.
25 + */
26 +public final class JavaCodeGenerator {
27 +
28 + /**
29 + * Default constructor.
30 + */
31 + private JavaCodeGenerator() {
32 + }
33 +
34 + /**
35 + * Generate Java code files corresponding to the YANG schema.
36 + *
37 + * @param rootNode root node of the data model tree.
38 + * @throws IOException when fails to generate java code file the current node.
39 + */
40 + public static void generateJavaCode(YangNode rootNode) throws IOException {
41 + YangNode curNode = rootNode;
42 + TraversalType curTraversal = TraversalType.ROOT;
43 +
44 + while (!(curNode == null)) {
45 + if (curTraversal != TraversalType.PARENT) {
46 + curNode.generateJavaCodeEntry();
47 + }
48 + if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) {
49 + curTraversal = TraversalType.CHILD;
50 + curNode = curNode.getChild();
51 + } else if (!(curNode.getNextSibling() == null)) {
52 + curTraversal = TraversalType.SIBILING;
53 + curNode = curNode.getNextSibling();
54 + } else {
55 + curTraversal = TraversalType.PARENT;
56 + curNode.generateJavaCodeExit();
57 + curNode = curNode.getParent();
58 + }
59 + }
60 + }
61 +}
1 +/*
2 + * Copyright 2016 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.utils;
18 +
19 +import org.onosproject.yangutils.translator.GeneratedFileType;
20 +import org.onosproject.yangutils.utils.UtilConstants;
21 +
22 +/**
23 + * Generates class definition for generated files.
24 + */
25 +public final class ClassDefinitionGenerator {
26 +
27 + /**
28 + * Default constructor.
29 + */
30 + private ClassDefinitionGenerator() {
31 + }
32 +
33 + /**
34 + * Generate class definition for specific classes.
35 + *
36 + * @param genFileTypes generated file type
37 + * @param yangName class name
38 + * @return class definition
39 + */
40 + public static String generateClassDefinition(GeneratedFileType genFileTypes, String yangName) {
41 +
42 + /**
43 + * based on the file type and the YANG name of the file, generate
44 + * the class / interface definition start.
45 + */
46 + if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
47 +
48 + return getInterfaceDefinition(yangName);
49 + } else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
50 +
51 + return getBuilderClassDefinition(yangName);
52 + } else if (genFileTypes.equals(GeneratedFileType.IMPL)) {
53 +
54 + return getImplClassDefinition(yangName);
55 + } else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) {
56 +
57 + return getBuilderInterfaceDefinition();
58 + }
59 + return null;
60 + }
61 +
62 + /**
63 + * Returns interface file class definition.
64 + *
65 + * @param yangName file name
66 + * @return definition
67 + */
68 + private static String getInterfaceDefinition(String yangName) {
69 +
70 + return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName
71 + + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
72 + }
73 +
74 + /**
75 + * Returns builder interface file class definition.
76 + *
77 + * @return definition
78 + */
79 + private static String getBuilderInterfaceDefinition() {
80 + return UtilConstants.INTERFACE + UtilConstants.SPACE + UtilConstants.BUILDER + UtilConstants.SPACE
81 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
82 + }
83 +
84 + /**
85 + * Returns builder file class definition.
86 + *
87 + * @param yangName file name
88 + * @return definition
89 + */
90 + private static String getBuilderClassDefinition(String yangName) {
91 +
92 + return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName
93 + + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE
94 + + yangName + UtilConstants.PERIOD + UtilConstants.BUILDER + UtilConstants.SPACE
95 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
96 + }
97 +
98 + /**
99 + * Returns impl file class definition.
100 + *
101 + * @param yangName file name
102 + * @return definition
103 + */
104 + private static String getImplClassDefinition(String yangName) {
105 +
106 + return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
107 + + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE
108 + + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.OPEN_CURLY_BRACKET
109 + + UtilConstants.SPACE + UtilConstants.NEW_LINE;
110 + }
111 +
112 +}
1 +/*
2 + * Copyright 2016 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.utils;
18 +
19 +import java.util.List;
20 +import java.util.SortedSet;
21 +
22 +import org.onosproject.yangutils.datamodel.YangType;
23 +import org.onosproject.yangutils.translator.GeneratedFileType;
24 +import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
25 +import org.onosproject.yangutils.translator.tojava.ImportInfo;
26 +import org.onosproject.yangutils.utils.UtilConstants;
27 +
28 +/**
29 + * Utility class to generate the java snippet.
30 + */
31 +public final class JavaCodeSnippetGen {
32 +
33 + /**
34 + * Default constructor.
35 + */
36 + private JavaCodeSnippetGen() {
37 + }
38 +
39 + /**
40 + * Get the java file header comment.
41 + *
42 + * @return the java file header comment.
43 + */
44 + public static String getFileHeaderComment() {
45 +
46 + /**
47 + * TODO return the file header.
48 + */
49 + return null;
50 + }
51 +
52 + /**
53 + * reorder the import list based on the ONOS import rules.
54 + *
55 + * @param importInfo the set of classes/interfaces to be imported.
56 + * @return string of import info.
57 + */
58 + public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) {
59 + /* TODO: reorder the import list based on the ONOS import rules. */
60 + return null;
61 + }
62 +
63 + /**
64 + * Get the textual java code information corresponding to the import list.
65 + *
66 + * @param importInfo sorted list of import info.
67 + * @return the textual java code information corresponding to the import
68 + * list.
69 + */
70 + public static String getImportText(List<ImportInfo> importInfo) {
71 + /*
72 + * TODO: get the textual java code information corresponding to the
73 + * import list
74 + */
75 + return null;
76 + }
77 +
78 + /**
79 + * Based on the file type and the YANG name of the file, generate the class
80 + * / interface definition start.
81 + *
82 + * @param genFileTypes type of file being generated.
83 + * @param yangName YANG name.
84 + * @return corresponding textual java code information.
85 + */
86 + public static String getJavaClassDefStart(GeneratedFileType genFileTypes, String yangName) {
87 + /*
88 + * get the camel case name for java class / interface.
89 + */
90 + yangName = JavaIdentifierSyntax.getCamelCase(yangName);
91 + return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName);
92 + }
93 +
94 + /**
95 + * Get the textual java code for attribute definition in class.
96 + *
97 + * @param genFileTypes type of file being generated.
98 + * @param yangName YANG name of the the attribute.
99 + * @param type type of the the attribute.
100 + * @return the textual java code for attribute definition in class.
101 + */
102 + public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) {
103 + yangName = JavaIdentifierSyntax.getCamelCase(yangName);
104 + return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName
105 + + UtilConstants.SEMI_COLAN;
106 + }
107 +
108 + /**
109 + * Based on the file type and method type(s) and the YANG name of the
110 + * method, generate the method definitions(s).
111 + *
112 + * @param genFileTypes type of file being generated
113 + * @param yangName name if the attribute whose getter / setter is required.
114 + * @param methodTypes getter and / or setter type of method indicator.
115 + * @param returnType type return type of the method.
116 + * @return based on the file type and method type(s) the method
117 + * definitions(s).
118 + */
119 + public static String getJavaMethodInfo(GeneratedFileType genFileTypes, String yangName,
120 + GeneratedMethodTypes methodTypes, YangType<?> returnType) {
121 +
122 + yangName = JavaIdentifierSyntax.getCamelCase(yangName);
123 + return MethodsGenerator.constructMethodInfo(genFileTypes, yangName, methodTypes, returnType);
124 + }
125 +
126 + /**
127 + * Based on the file type and the YANG name of the file, generate the class
128 + * / interface definition close.
129 + *
130 + * @param genFileTypes type of file being generated.
131 + * @param yangName YANG name.
132 + * @return corresponding textual java code information.
133 + */
134 + public static String getJavaClassDefClose(GeneratedFileType genFileTypes, String yangName) {
135 +
136 + if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
137 +
138 + return UtilConstants.CLOSE_CURLY_BRACKET;
139 + } else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
140 +
141 + return UtilConstants.CLOSE_CURLY_BRACKET;
142 + }
143 + return null;
144 + }
145 +
146 +}
1 +/*
2 + * Copyright 2016 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.utils;
18 +
19 +import java.util.ArrayList;
20 +
21 +import org.onosproject.yangutils.utils.UtilConstants;
22 +
23 +/**
24 + * Utility Class for translating the name from YANG to java convention.
25 + */
26 +public final class JavaIdentifierSyntax {
27 +
28 + /**
29 + * Util class, with static functions only.
30 + */
31 + private JavaIdentifierSyntax() {
32 + }
33 +
34 + /**
35 + * Get the root package string.
36 + *
37 + * @param version YANG version.
38 + * @param nameSpace name space of the module.
39 + * @param revision revision of the module defined
40 + * @return returns the root package string.
41 + */
42 + public static String getRootPackage(byte version, String nameSpace, String revision) {
43 +
44 + String pkg;
45 + pkg = UtilConstants.DEFAULT_BASE_PKG;
46 + pkg = pkg + UtilConstants.PERIOD;
47 + pkg = pkg + getYangVersion(version);
48 + pkg = pkg + UtilConstants.PERIOD;
49 + pkg = pkg + getPkgFromNameSpace(nameSpace);
50 + pkg = pkg + UtilConstants.PERIOD;
51 + pkg = pkg + getYangRevisionStr(revision);
52 +
53 + return pkg;
54 + }
55 +
56 + /**
57 + * Returns version.
58 + *
59 + * @param ver YANG version.
60 + * @return version
61 + */
62 + private static String getYangVersion(byte ver) {
63 + return "v" + ver;
64 + }
65 +
66 + /**
67 + * Get package name from name space.
68 + *
69 + * @param nameSpace name space of YANG module
70 + * @return java package name as per java rules.
71 + */
72 + public static String getPkgFromNameSpace(String nameSpace) {
73 + ArrayList<String> pkgArr = new ArrayList<String>();
74 + nameSpace = nameSpace.replace("\"", "");
75 +
76 + String[] nameSpaceArr = nameSpace.split(UtilConstants.COLAN);
77 +
78 + for (String nameSpaceString : nameSpaceArr) {
79 + pkgArr.add(nameSpaceString);
80 + }
81 + return getPkgFrmArr(pkgArr);
82 + }
83 +
84 + /**
85 + * Returns revision string array.
86 + *
87 + * @param date YANG module revision
88 + * @return revision string
89 + */
90 + public static String getYangRevisionStr(String date) {
91 + String[] revisionArr = date.split(UtilConstants.HYPHEN);
92 +
93 + String rev = "rev";
94 + for (String element : revisionArr) {
95 + Integer val = Integer.parseInt(element);
96 + if (val < 10) {
97 + rev = rev + "0";
98 + }
99 + rev = rev + val;
100 + }
101 + return rev;
102 + }
103 +
104 + /**
105 + * Returns the package string.
106 + *
107 + * @param pkgArr package array
108 + * @return package string
109 + */
110 + public static String getPkgFrmArr(ArrayList<String> pkgArr) {
111 +
112 + String pkg = "";
113 + int size = pkgArr.size();
114 + int i = 0;
115 + for (String member : pkgArr) {
116 + pkg = pkg + member;
117 + if (i != size - 1) {
118 + pkg = pkg + UtilConstants.PERIOD;
119 + }
120 + i++;
121 + }
122 + return pkg;
123 + }
124 +
125 + /**
126 + * Get the package from parent's package and string.
127 + *
128 + * @param parentPkg parent's package.
129 + * @param childName child's name.
130 + * @return package string.
131 + */
132 + public static String getPackageFromParent(String parentPkg, String childName) {
133 + return parentPkg + UtilConstants.PERIOD + getSubPkgFromName(childName);
134 + }
135 +
136 + /**
137 + * Get package sub name from YANG identifier name.
138 + *
139 + * @param name YANG identifier name.
140 + * @return java package sub name as per java rules.
141 + */
142 + public static String getSubPkgFromName(String name) {
143 + ArrayList<String> pkgArr = new ArrayList<String>();
144 + String[] nameArr = name.split(UtilConstants.COLAN);
145 +
146 + for (String nameString : nameArr) {
147 + pkgArr.add(nameString);
148 + }
149 + return getPkgFrmArr(pkgArr);
150 + }
151 +
152 + /**
153 + * Translate the YANG identifier name to java identifier.
154 + *
155 + * @param yangIdentifier identifier in YANG file.
156 + * @return corresponding java identifier
157 + */
158 + public static String getCamelCase(String yangIdentifier) {
159 + String[] strArray = yangIdentifier.split(UtilConstants.HYPHEN);
160 + String camelCase = strArray[0];
161 + for (int i = 1; i < strArray.length; i++) {
162 + camelCase = camelCase + (strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1));
163 + }
164 + return camelCase;
165 + }
166 +}
1 -/*Copyright 2016.year Open Networking Laboratory
2 -
3 -Licensed under the Apache License, Version 2.0 (the "License");
4 -you may not use this file except in compliance with the License.
5 -You may obtain a copy of the License at
6 -
7 - http://www.apache.org/licenses/LICENSE-2.0
8 -
9 -Unless required by applicable law or agreed to in writing, software
10 -distributed under the License is distributed on an "AS IS" BASIS,
11 -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 -See the License for the specific language governing permissions and
13 -limitations under the License.*/
14 -package org.onosproject.yangutils.utils.io;
15 -
16 -import org.onosproject.yangutils.translator.GeneratedFileType;
17 -
18 -/**
19 - * Cached java file handle, which supports the addition of member attributes and
20 - * methods.
21 - */
22 -public interface CachedFileHandle {
23 -
24 - /**
25 - * Add a new attribute to the file(s).
26 - *
27 - * @param attrType data type of the added attribute.
28 - * @param name name of the attribute.
29 - * @param isListAttr if the current added attribute needs to be maintained
30 - * in a list.
31 - * @param fileTypes types of files in which the attribute needs to be added.
32 - */
33 - void addAttributeInfo(String attrType, String name, boolean isListAttr, GeneratedFileType fileTypes);
34 -
35 - /**
36 - * Flushes the cached contents to the target file, frees used resources.
37 - */
38 - void close();
39 -}
...@@ -33,9 +33,11 @@ import org.slf4j.Logger; ...@@ -33,9 +33,11 @@ import org.slf4j.Logger;
33 public final class CopyrightHeader { 33 public final class CopyrightHeader {
34 34
35 private static final Logger log = getLogger(CopyrightHeader.class); 35 private static final Logger log = getLogger(CopyrightHeader.class);
36 - private static final int NULL = -1; 36 + private static final int EOF = -1;
37 private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); 37 private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader();
38 38
39 + private static String copyrightHeader;
40 +
39 /** 41 /**
40 * Default constructor. 42 * Default constructor.
41 */ 43 */
...@@ -43,21 +45,30 @@ public final class CopyrightHeader { ...@@ -43,21 +45,30 @@ public final class CopyrightHeader {
43 } 45 }
44 46
45 /** 47 /**
46 - * Returns Copyright file header. 48 + * Returns copyright file header.
47 * 49 *
48 - * @return Copyright file header 50 + * @return copyright file header
51 + * @throws IOException when fails to parse copyright header.
49 */ 52 */
50 - public static String getCopyrightHeader() { 53 + public static String getCopyrightHeader() throws IOException {
51 - return parseOnosHeader(); 54 + return copyrightHeader;
55 + }
56 +
57 + /**
58 + * Sets the copyright header.
59 + *
60 + * @param header copyright header
61 + */
62 + private static void setCopyrightHeader(String header) {
63 + copyrightHeader = header;
52 } 64 }
53 65
54 /** 66 /**
55 * parse Copyright to the temporary file. 67 * parse Copyright to the temporary file.
56 * 68 *
57 - * @param file generated file 69 + * @throws IOException when fails to get the copyright header.
58 - * @param stream input stream
59 */ 70 */
60 - private static String parseOnosHeader() { 71 + public static void parseCopyrightHeader() throws IOException {
61 72
62 File temp = new File("temp.txt"); 73 File temp = new File("temp.txt");
63 74
...@@ -65,17 +76,18 @@ public final class CopyrightHeader { ...@@ -65,17 +76,18 @@ public final class CopyrightHeader {
65 InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt"); 76 InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt");
66 OutputStream out = new FileOutputStream(temp); 77 OutputStream out = new FileOutputStream(temp);
67 int index; 78 int index;
68 - while ((index = stream.read()) != NULL) { 79 + while ((index = stream.read()) != EOF) {
69 out.write(index); 80 out.write(index);
70 } 81 }
71 out.close(); 82 out.close();
72 - return convertToString(temp.toString()); 83 + stream.close();
84 + getStringFileContent(temp);
85 + setCopyrightHeader(getStringFileContent(temp));
73 } catch (IOException e) { 86 } catch (IOException e) {
74 - log.info("Failed to insert onos header in files."); 87 + throw new IOException("failed to parse the Copyright header");
75 } finally { 88 } finally {
76 temp.delete(); 89 temp.delete();
77 } 90 }
78 - return "";
79 } 91 }
80 92
81 /** 93 /**
...@@ -85,7 +97,8 @@ public final class CopyrightHeader { ...@@ -85,7 +97,8 @@ public final class CopyrightHeader {
85 * @return string of file. 97 * @return string of file.
86 * @throws IOException when fails to convert to string 98 * @throws IOException when fails to convert to string
87 */ 99 */
88 - private static String convertToString(String toAppend) throws IOException { 100 + private static String getStringFileContent(File toAppend) throws IOException {
101 +
89 BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend)); 102 BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
90 try { 103 try {
91 StringBuilder stringBuilder = new StringBuilder(); 104 StringBuilder stringBuilder = new StringBuilder();
......
1 +/*
2 + * Copyright 2016 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.io.impl;
18 +
19 +import java.io.BufferedReader;
20 +import java.io.File;
21 +import java.io.FileReader;
22 +import java.io.FileWriter;
23 +import java.io.IOException;
24 +import java.io.PrintWriter;
25 +
26 +import org.onosproject.yangutils.translator.CachedFileHandle;
27 +import org.onosproject.yangutils.translator.GeneratedFileType;
28 +import org.onosproject.yangutils.translator.tojava.CachedJavaFileHandle;
29 +import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
30 +import org.onosproject.yangutils.utils.UtilConstants;
31 +
32 +/**
33 + * Utility to handle file system operations.
34 + */
35 +public final class FileSystemUtil {
36 + /**
37 + * Hiding constructor of a utility class.
38 + */
39 + private FileSystemUtil() {
40 + }
41 +
42 + /**
43 + * Check if the package directory structure created.
44 + *
45 + * @param pkg Package to check if it is created.
46 + * @return existence status of package.
47 + */
48 + public static boolean doesPackageExist(File pkg) {
49 + if (pkg.exists()) {
50 + return true;
51 + }
52 + return false;
53 + }
54 +
55 + /**
56 + * Create a package structure with package info java file if not present.
57 + *
58 + * @param pkg java package string
59 + * @param pkgInfo description of package
60 + * @throws IOException any IO exception
61 + */
62 + public static void createPackage(String pkg, String pkgInfo) throws IOException {
63 + if (!doesPackageExist(new File(pkg))) {
64 + try {
65 + File pack = YangIoUtils
66 + .createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
67 + YangIoUtils.addPackageInfo(pack, pkgInfo, pkg);
68 + } catch (IOException e) {
69 + throw new IOException("failed to create package-info file");
70 + }
71 + }
72 + }
73 +
74 + /**
75 + * Create a java source file in the specified package.
76 + *
77 + * @param pkg java package under which the interface file needs to be created.
78 + * @param yangName YANG name of the node for which java file needs to be created.
79 + * @param types types of files to be created.
80 + * @throws IOException when fails to create interface file.
81 + * @return the cached java file handle, which can be used to further add methods.
82 + */
83 + public static CachedFileHandle createSourceFiles(String pkg, String yangName, GeneratedFileType types)
84 + throws IOException {
85 + //if (!doesPackageExist(new File(pkg))) {
86 + // throw new IOException("package does not exist.");
87 + //}
88 + yangName = JavaIdentifierSyntax.getCamelCase(yangName);
89 + CachedFileHandle handler = new CachedJavaFileHandle(pkg, yangName, types);
90 +
91 + return handler;
92 + }
93 +
94 + /**
95 + * Read the contents from source file and append its contents to append
96 + * file.
97 + *
98 + * @param toAppend destination file in which the contents of source file is
99 + * appended.
100 + * @param srcFile source file from which data is read and added to to append
101 + * file.
102 + * @throws IOException any IO errors.
103 + */
104 + public static void appendFileContents(File toAppend, File srcFile) throws IOException {
105 +
106 + insertStringInFile(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString()));
107 + //TODO: read the contents from src file and append its contents to append file.
108 + return;
109 + }
110 +
111 + /**
112 + * Reads file and convert it to string.
113 + *
114 + * @param toAppend file to be converted.
115 + * @return string of file.
116 + * @throws IOException when fails to convert to string
117 + */
118 + private static String readAppendFile(String toAppend) throws IOException {
119 + BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
120 + try {
121 + StringBuilder stringBuilder = new StringBuilder();
122 + String line = bufferReader.readLine();
123 +
124 + while (line != null) {
125 + stringBuilder.append(UtilConstants.FOUR_SPACE_INDENTATION + line);
126 + stringBuilder.append("\n");
127 + line = bufferReader.readLine();
128 + }
129 + return stringBuilder.toString();
130 + } finally {
131 + bufferReader.close();
132 + }
133 + }
134 +
135 + /**
136 + * Insert content to the generated file.
137 + *
138 + * @param inputFile input file
139 + * @param contentTobeAdded content to be appended to the file.
140 + * @throws IOException when fails to append content to the file.
141 + */
142 + public static void insertStringInFile(File inputFile, String contentTobeAdded) throws IOException {
143 + FileWriter fileWriter = new FileWriter(inputFile, true);
144 + PrintWriter outputPrintWriter = new PrintWriter(fileWriter);
145 + outputPrintWriter.write(contentTobeAdded);
146 + outputPrintWriter.flush();
147 + outputPrintWriter.close();
148 +
149 + }
150 +}
1 +/*
2 + * Copyright 2016 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.io.impl;
18 +
19 +import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
20 +import org.onosproject.yangutils.utils.UtilConstants;
21 +
22 +/**
23 + * Provides javadoc for the generated classes.
24 + */
25 +public final class JavaDocGen {
26 +
27 + /**
28 + * Default Constructor.
29 + */
30 + private JavaDocGen() {
31 + }
32 +
33 + /**
34 + * JavaDocs types.
35 + */
36 + public static enum JavaDocType {
37 +
38 + /**
39 + * For class.
40 + */
41 + IMPL_CLASS,
42 +
43 + /**
44 + * For builder class.
45 + */
46 + BUILDER_CLASS,
47 +
48 + /**
49 + * For interface.
50 + */
51 + INTERFACE,
52 +
53 + /**
54 + * For builder interface.
55 + */
56 + BUILDER_INTERFACE,
57 +
58 + /**
59 + * For package-info.
60 + */
61 + PACKAGE_INFO,
62 +
63 + /**
64 + * For getters.
65 + */
66 + GETTER,
67 +
68 + /**
69 + * For setters.
70 + */
71 + SETTER,
72 +
73 + /**
74 + * For default constructor.
75 + */
76 + DEFAULT_CONSTRUCTOR,
77 +
78 + /**
79 + * For constructor.
80 + */
81 + CONSTRUCTOR,
82 +
83 + /**
84 + * For build.
85 + */
86 + BUILD
87 + }
88 +
89 + /**
90 + * Returns java docs.
91 + *
92 + * @param type java doc type
93 + * @param name name of the YangNode
94 + * @return javadocs.
95 + */
96 + public static String getJavaDoc(JavaDocType type, String name) {
97 + name = JavaIdentifierSyntax.getCamelCase(name);
98 + String javaDoc = "";
99 + if (type.equals(JavaDocType.IMPL_CLASS)) {
100 + javaDoc = generateForImplClass(name);
101 + } else if (type.equals(JavaDocType.BUILDER_CLASS)) {
102 + javaDoc = generateForBuilderClass(name);
103 + } else if (type.equals(JavaDocType.INTERFACE)) {
104 + javaDoc = generateForInterface(name);
105 + } else if (type.equals(JavaDocType.BUILDER_INTERFACE)) {
106 + javaDoc = generateForBuilderInterface(name);
107 + } else if (type.equals(JavaDocType.PACKAGE_INFO)) {
108 + javaDoc = generateForPackage(name);
109 + } else if (type.equals(JavaDocType.GETTER)) {
110 + javaDoc = generateForGetters(name);
111 + } else if (type.equals(JavaDocType.SETTER)) {
112 + javaDoc = generateForSetters(name);
113 + } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
114 + javaDoc = generateForDefaultConstructors();
115 + } else if (type.equals(JavaDocType.BUILD)) {
116 + javaDoc = generateForBuild(name);
117 + } else if (type.equals(JavaDocType.CONSTRUCTOR)) {
118 + javaDoc = generateForConstructors(name);
119 + }
120 + return javaDoc;
121 + }
122 +
123 + /**
124 + * Generate javaDocs for getter method.
125 + *
126 + * @param attribute attribute
127 + * @return javaDocs
128 + */
129 + private static String generateForGetters(String attribute) {
130 + return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
131 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute
132 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
133 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
134 + + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
135 + + UtilConstants.JAVA_DOC_END_LINE);
136 + }
137 +
138 + /**
139 + * Generates javaDocs for setter method.
140 + *
141 + * @param attribute attribute
142 + * @return javaDocs
143 + */
144 + private static String generateForSetters(String attribute) {
145 + return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
146 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute
147 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
148 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
149 + + attribute + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
150 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT
151 + + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
152 + + UtilConstants.JAVA_DOC_END_LINE);
153 + }
154 +
155 + /**
156 + * Generate javaDocs for the impl class.
157 + *
158 + * @param className class name
159 + * @return javaDocs.
160 + */
161 + private static String generateForImplClass(String className) {
162 + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC + className + UtilConstants.PERIOD
163 + + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
164 + }
165 +
166 + /**
167 + * Generate javaDocs for the builder class.
168 + *
169 + * @param className class name
170 + * @return javaDocs.
171 + */
172 + private static String generateForBuilderClass(String className) {
173 + return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC
174 + + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
175 + }
176 +
177 + /**
178 + * Generate javaDoc for the interface.
179 + *
180 + * @param interfaceName interface name
181 + * @return javaDocs.
182 + */
183 + private static String generateForInterface(String interfaceName) {
184 + return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC
185 + + interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
186 + }
187 +
188 + /**
189 + * Generate javaDoc for the builder interface.
190 + *
191 + * @param builderforName builder for name
192 + * @return javaDocs.
193 + */
194 + private static String generateForBuilderInterface(String builderforName) {
195 + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_INTERFACE_JAVA_DOC + builderforName
196 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
197 + }
198 +
199 + /**
200 + * Generate javaDocs for package-info.
201 + *
202 + * @param packageName package name
203 + * @return javaDocs
204 + */
205 + private static String generateForPackage(String packageName) {
206 + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.PACKAGE_INFO_JAVADOC + packageName
207 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
208 + }
209 +
210 + /**
211 + * Generate javaDocs for default constructor.
212 + *
213 + * @return javaDocs
214 + */
215 + private static String generateForDefaultConstructors() {
216 + return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR
217 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
218 + }
219 +
220 + /**
221 + * Generate javaDocs for constructor with parameters.
222 + *
223 + * @param params list of parameters
224 + * @param className class name
225 + * @return javaDocs
226 + */
227 + private static String generateForConstructors(String className) {
228 + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
229 + + UtilConstants.JAVA_DOC_SETTERS + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE
230 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
231 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
232 + + (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT
233 + + UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className
234 + + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
235 + }
236 +
237 + /**
238 + * Generate javaDocs for build.
239 + *
240 + * @return javaDocs
241 + */
242 + private static String generateForBuild(String buildName) {
243 + return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
244 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_BUILD + buildName + UtilConstants.PERIOD
245 + + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
246 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
247 + + UtilConstants.JAVA_DOC_BUILD_RETURN + buildName + UtilConstants.PERIOD + UtilConstants.NEW_LINE
248 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
249 + }
250 +}
1 +/*
2 + * Copyright 2016 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.io.impl;
18 +
19 +import java.io.BufferedInputStream;
20 +import java.io.BufferedOutputStream;
21 +import java.io.FileInputStream;
22 +import java.io.FileOutputStream;
23 +import java.io.IOException;
24 +import java.io.InputStream;
25 +import java.io.ObjectInput;
26 +import java.io.ObjectInputStream;
27 +import java.io.ObjectOutput;
28 +import java.io.ObjectOutputStream;
29 +import java.io.OutputStream;
30 +import java.util.List;
31 +
32 +/**
33 + * Provides storage for serialized data while traversing data model tree for code generation.
34 + */
35 +public final class SerializedDataStore {
36 +
37 + /**
38 + * Data Store types.
39 + */
40 + public static enum SerializedDataStoreType {
41 +
42 + /**
43 + * Methods.
44 + */
45 + INTERFACE_METHODS,
46 +
47 + /**
48 + * Methods.
49 + */
50 + BUILDER_METHODS,
51 +
52 + /**
53 + * Methods.
54 + */
55 + BUILDER_INTERFACE_METHODS,
56 +
57 + /**
58 + * Methods.
59 + */
60 + IMPL_METHODS,
61 +
62 + /**
63 + * Attributes.
64 + */
65 + ATTRIBUTE,
66 +
67 + /**
68 + * Imports.
69 + */
70 + IMPORT
71 + }
72 +
73 + /**
74 + * File name string for serialized files of methods.
75 + */
76 + private static final String INTERFACE_METHOD_FILE_NAME = "SerializedInterfaceMethodDataStore";
77 +
78 + /**
79 + * File name string for serialized files of methods.
80 + */
81 + private static final String BUILDER_METHOD_FILE_NAME = "SerializedBuilderMethodDataStore";
82 +
83 + /**
84 + * File name string for serialized files of methods.
85 + */
86 + private static final String BUILDER_INTERFACE_METHOD_FILE_NAME = "SerializedBuilderInterfaceMethodDataStore";
87 +
88 + /**
89 + * File name string for serialized files of methods.
90 + */
91 + private static final String IMPL_METHOD_FILE_NAME = "SerializedImplMethodDataStore";
92 +
93 + /**
94 + * File name string for serialized files of attributes.
95 + */
96 + private static final String ATTRIBUTE_FILE_NAME = "SerializedAttributeDataStore";
97 +
98 + /**
99 + * File name string for serialized files of imports.
100 + */
101 + private static final String IMPORT_FILE_NAME = "SerializedImportDataStore";
102 +
103 + /**
104 + * File extension of serialized files.
105 + */
106 + private static final String SERIALIZE_FILE_EXTENSION = ".ser";
107 +
108 + /**
109 + * Buffer size.
110 + */
111 + private static final int BUFFER_SIZE = 8 * 1024;
112 +
113 + /**
114 + * Default constructor.
115 + */
116 + private SerializedDataStore() {
117 + }
118 +
119 + /**
120 + * Writes specific info to a serialized file.
121 + *
122 + * @param data data to be stored
123 + * @param type type of serialized data store
124 + * @throws IOException when fails to create a serialized data file.
125 + */
126 + public static void setSerializeData(String data, SerializedDataStoreType type) throws IOException {
127 +
128 + String fileName = "";
129 + if (type.equals(SerializedDataStoreType.ATTRIBUTE)) {
130 + fileName = ATTRIBUTE_FILE_NAME;
131 + } else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) {
132 + fileName = INTERFACE_METHOD_FILE_NAME;
133 + } else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) {
134 + fileName = BUILDER_INTERFACE_METHOD_FILE_NAME;
135 + } else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) {
136 + fileName = BUILDER_METHOD_FILE_NAME;
137 + } else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) {
138 + fileName = IMPL_METHOD_FILE_NAME;
139 + } else if (type.equals(SerializedDataStoreType.IMPORT)) {
140 + fileName = IMPORT_FILE_NAME;
141 + } else {
142 + throw new IOException("Unresolved file type.");
143 + }
144 +
145 + try {
146 + OutputStream file = new FileOutputStream(fileName + SERIALIZE_FILE_EXTENSION);
147 + OutputStream buffer = new BufferedOutputStream(file, BUFFER_SIZE);
148 +
149 + ObjectOutput output = new ObjectOutputStream(buffer);
150 + try {
151 + output.writeObject(data);
152 + } finally {
153 + output.close();
154 + }
155 + } catch (IOException ex) {
156 + throw new IOException("failed to serialize data");
157 + }
158 + }
159 +
160 + /**
161 + * Get the serialized data.
162 + *
163 + * @param type type of serialized data store
164 + * @return list of attribute info.
165 + * @throws IOException when fails to read from the file.
166 + * @throws ClassNotFoundException when file is missing.
167 + */
168 + @SuppressWarnings("unchecked")
169 + public static List<String> getSerializeData(SerializedDataStoreType type)
170 + throws IOException, ClassNotFoundException {
171 +
172 + String fileName = "";
173 + if (type.equals(SerializedDataStoreType.ATTRIBUTE)) {
174 + fileName = ATTRIBUTE_FILE_NAME;
175 + } else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) {
176 + fileName = INTERFACE_METHOD_FILE_NAME;
177 + } else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) {
178 + fileName = BUILDER_INTERFACE_METHOD_FILE_NAME;
179 + } else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) {
180 + fileName = BUILDER_METHOD_FILE_NAME;
181 + } else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) {
182 + fileName = IMPL_METHOD_FILE_NAME;
183 + } else if (type.equals(SerializedDataStoreType.IMPORT)) {
184 + fileName = IMPORT_FILE_NAME;
185 + } else {
186 + throw new IOException("Unresolved file type.");
187 + }
188 +
189 + try {
190 + InputStream file = new FileInputStream(fileName + SERIALIZE_FILE_EXTENSION);
191 + InputStream buffer = new BufferedInputStream(file);
192 + ObjectInput input = new ObjectInputStream(buffer);
193 + try {
194 + List<String> recoveredData = (List<String>) input.readObject();
195 + return recoveredData;
196 + } finally {
197 + input.close();
198 + }
199 + } catch (ClassNotFoundException ex) {
200 + throw new ClassNotFoundException("failed to fetch the serialized data file.");
201 + }
202 + }
203 +}
...@@ -34,14 +34,39 @@ public final class YangFileScanner { ...@@ -34,14 +34,39 @@ public final class YangFileScanner {
34 } 34 }
35 35
36 /** 36 /**
37 - * Returns the list of yang files. 37 + * Returns the list of YANG files.
38 * 38 *
39 * @param root specified directory 39 * @param root specified directory
40 - * @return list of yang files. 40 + * @return list of YANG files.
41 - * @throws IOException when files get deleted while performing the operations. 41 + * @throws IOException when files get deleted while performing the
42 + * operations.
42 */ 43 */
43 public static List<String> getYangFiles(String root) throws IOException { 44 public static List<String> getYangFiles(String root) throws IOException {
45 + return getFiles(root, ".yang");
46 + }
44 47
48 + /**
49 + * Returns the list of java files.
50 + *
51 + * @param root specified directory
52 + * @return list of java files.
53 + * @throws IOException when files get deleted while performing the
54 + * operations.
55 + */
56 + public static List<String> getJavaFiles(String root) throws IOException {
57 + return getFiles(root, ".java");
58 + }
59 +
60 + /**
61 + * Returns the list of required files.
62 + *
63 + * @param root specified directory
64 + * @param extension file extension.
65 + * @return list of required files.
66 + * @throws IOException when files get deleted while performing the
67 + * operations.
68 + */
69 + public static List<String> getFiles(String root, String extension) throws IOException {
45 List<String> store = new LinkedList<>(); 70 List<String> store = new LinkedList<>();
46 Stack<String> stack = new Stack<>(); 71 Stack<String> stack = new Stack<>();
47 stack.push(root); 72 stack.push(root);
...@@ -60,7 +85,7 @@ public final class YangFileScanner { ...@@ -60,7 +85,7 @@ public final class YangFileScanner {
60 stack.push(current.toString()); 85 stack.push(current.toString());
61 } else { 86 } else {
62 String yangFile = current.getCanonicalPath(); 87 String yangFile = current.getCanonicalPath();
63 - if (yangFile.endsWith(".yang")) { 88 + if (yangFile.endsWith(extension)) {
64 store.add(yangFile); 89 store.add(yangFile);
65 } 90 }
66 } 91 }
......
1 +/*
2 + * Copyright 2016 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.io.impl;
18 +
19 +import java.io.BufferedWriter;
20 +import java.io.File;
21 +import java.io.FileWriter;
22 +import java.io.IOException;
23 +import java.util.List;
24 +
25 +import org.sonatype.plexus.build.incremental.BuildContext;
26 +import org.apache.maven.project.MavenProject;
27 +import org.apache.maven.model.Resource;
28 +
29 +import org.onosproject.yangutils.utils.UtilConstants;
30 +
31 +import static org.slf4j.LoggerFactory.getLogger;
32 +import org.slf4j.Logger;
33 +
34 +/**
35 + * Provides common utility functionalities for code generation.
36 + */
37 +public final class YangIoUtils {
38 +
39 + private static final Logger log = getLogger(YangIoUtils.class);
40 +
41 + /**
42 + * Default constructor.
43 + */
44 + private YangIoUtils() {
45 + }
46 +
47 + /**
48 + * Creates the directory structure.
49 + *
50 + * @param path directory path
51 + * @return directory structure
52 + */
53 + public static File createDirectories(String path) {
54 +
55 + File generatedDir = new File(UtilConstants.YANG_GEN_DIR + File.separator + path);
56 + generatedDir.mkdirs();
57 + return generatedDir;
58 + }
59 +
60 + /**
61 + * Adds package info file for the created directory.
62 + *
63 + * @param path directory path
64 + * @param classInfo class info for the package
65 + * @param pack package of the directory
66 + * @throws IOException when fails to create package info file.
67 + */
68 + public static void addPackageInfo(File path, String classInfo, String pack) throws IOException {
69 +
70 + try {
71 +
72 + File packageInfo = new File(path + File.separator + "package-info.java");
73 + packageInfo.createNewFile();
74 + if (packageInfo.exists()) {
75 +
76 + FileWriter fileWriter = null;
77 + BufferedWriter bufferedWriter = null;
78 + fileWriter = new FileWriter(packageInfo);
79 + bufferedWriter = new BufferedWriter(fileWriter);
80 + bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
81 + bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo));
82 + bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN);
83 + bufferedWriter.close();
84 + }
85 + } catch (IOException e) {
86 + throw new IOException("Exception occured while creating package info file.");
87 + }
88 + }
89 +
90 + /**
91 + * Cleans the generated directory if already exist in source folder.
92 + *
93 + * @param baseDir generated directory in previous build.
94 + */
95 + public static void clean(String baseDir) {
96 + File generatedDirectory = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR);
97 + if (generatedDirectory.exists()) {
98 + List<String> javafiles;
99 + try {
100 + javafiles = YangFileScanner.getJavaFiles(generatedDirectory.toString());
101 + for (String file : javafiles) {
102 + File currentFile = new File(file);
103 + currentFile.delete();
104 + }
105 + } catch (IOException e) {
106 + log.info("Failed to delete the generated files in " + generatedDirectory + " directory");
107 + }
108 + generatedDirectory.delete();
109 + }
110 + }
111 +
112 + /**
113 + * Adds generated source directory to the compilation root.
114 + *
115 + * @param source directory
116 + * @param project current maven project
117 + * @param context current build context
118 + */
119 + public static void addToSource(String source, MavenProject project, BuildContext context) {
120 +
121 + project.addCompileSourceRoot(source);
122 + Resource rsc = new Resource();
123 + rsc.setDirectory(source);
124 + project.addResource(rsc);
125 + context.refresh(project.getBasedir());
126 + log.info("Source directory added to compilation root: " + source);
127 + }
128 +
129 +}
...@@ -66,8 +66,8 @@ public class ConfigListenerTest { ...@@ -66,8 +66,8 @@ public class ConfigListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 69 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
70 - YangLeaf leafInfo = leafIterator.next(); 70 + YangLeaf<?> leafInfo = leafIterator.next();
71 71
72 // Check whether the Config value is set correctly. 72 // Check whether the Config value is set correctly.
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 73 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -92,8 +92,8 @@ public class ConfigListenerTest { ...@@ -92,8 +92,8 @@ public class ConfigListenerTest {
92 YangModule yangNode = (YangModule) node; 92 YangModule yangNode = (YangModule) node;
93 assertThat(yangNode.getName(), is("Test")); 93 assertThat(yangNode.getName(), is("Test"));
94 94
95 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 95 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
96 - YangLeaf leafInfo = leafIterator.next(); 96 + YangLeaf<?> leafInfo = leafIterator.next();
97 97
98 // Check whether the Config value is set correctly. 98 // Check whether the Config value is set correctly.
99 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 99 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -136,10 +136,10 @@ public class ConfigListenerTest { ...@@ -136,10 +136,10 @@ public class ConfigListenerTest {
136 @Test 136 @Test
137 public void processModuleSubStatementConfig() throws IOException, ParserException { 137 public void processModuleSubStatementConfig() throws IOException, ParserException {
138 thrown.expect(ParserException.class); 138 thrown.expect(ParserException.class);
139 - thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container'," + 139 + thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container',"
140 - " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', " + 140 + + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', "
141 - "'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," + 141 + + "'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
142 - " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 142 + + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
143 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang"); 143 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang");
144 } 144 }
145 145
...@@ -167,8 +167,8 @@ public class ConfigListenerTest { ...@@ -167,8 +167,8 @@ public class ConfigListenerTest {
167 assertThat(container.isConfig(), is(true)); 167 assertThat(container.isConfig(), is(true));
168 168
169 // Check whether leaf properties as set correctly. 169 // Check whether leaf properties as set correctly.
170 - ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); 170 + ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
171 - YangLeaf leafInfo = leafIterator.next(); 171 + YangLeaf<?> leafInfo = leafIterator.next();
172 172
173 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 173 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
174 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 174 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -203,8 +203,8 @@ public class ConfigListenerTest { ...@@ -203,8 +203,8 @@ public class ConfigListenerTest {
203 assertThat(yangList.isConfig(), is(true)); 203 assertThat(yangList.isConfig(), is(true));
204 204
205 // Check whether leaf properties as set correctly. 205 // Check whether leaf properties as set correctly.
206 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 206 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
207 - YangLeaf leafInfo = leafIterator.next(); 207 + YangLeaf<?> leafInfo = leafIterator.next();
208 208
209 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 209 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
210 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 210 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -234,8 +234,8 @@ public class ConfigListenerTest { ...@@ -234,8 +234,8 @@ public class ConfigListenerTest {
234 YangModule yangNode = (YangModule) node; 234 YangModule yangNode = (YangModule) node;
235 assertThat(yangNode.getName(), is("Test")); 235 assertThat(yangNode.getName(), is("Test"));
236 236
237 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 237 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
238 - YangLeafList leafListInfo = leafListIterator.next(); 238 + YangLeafList<?> leafListInfo = leafListIterator.next();
239 239
240 // Check whether config value is set correctly. 240 // Check whether config value is set correctly.
241 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 241 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
......
...@@ -154,8 +154,8 @@ public class ContainerListenerTest { ...@@ -154,8 +154,8 @@ public class ContainerListenerTest {
154 assertThat(yangContainer.getReference(), is("\"container reference\"")); 154 assertThat(yangContainer.getReference(), is("\"container reference\""));
155 155
156 // Check whether leaf properties as set correctly. 156 // Check whether leaf properties as set correctly.
157 - ListIterator<YangLeaf> leafIterator = yangContainer.getListOfLeaf().listIterator(); 157 + ListIterator<YangLeaf<?>> leafIterator = yangContainer.getListOfLeaf().listIterator();
158 - YangLeaf leafInfo = leafIterator.next(); 158 + YangLeaf<?> leafInfo = leafIterator.next();
159 159
160 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 160 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
161 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 161 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
......
...@@ -66,8 +66,8 @@ public class DescriptionListenerTest { ...@@ -66,8 +66,8 @@ public class DescriptionListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 69 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
70 - YangLeaf leafInfo = leafIterator.next(); 70 + YangLeaf<?> leafInfo = leafIterator.next();
71 71
72 // Check whether the description is set correctly. 72 // Check whether the description is set correctly.
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 73 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -175,8 +175,8 @@ public class DescriptionListenerTest { ...@@ -175,8 +175,8 @@ public class DescriptionListenerTest {
175 assertThat(container.getDescription(), is("\"container description\"")); 175 assertThat(container.getDescription(), is("\"container description\""));
176 176
177 // Check whether leaf properties as set correctly. 177 // Check whether leaf properties as set correctly.
178 - ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); 178 + ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
179 - YangLeaf leafInfo = leafIterator.next(); 179 + YangLeaf<?> leafInfo = leafIterator.next();
180 180
181 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 181 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
182 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 182 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -212,8 +212,8 @@ public class DescriptionListenerTest { ...@@ -212,8 +212,8 @@ public class DescriptionListenerTest {
212 assertThat(yangList.getDescription(), is("\"list description\"")); 212 assertThat(yangList.getDescription(), is("\"list description\""));
213 213
214 // Check whether leaf properties as set correctly. 214 // Check whether leaf properties as set correctly.
215 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 215 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
216 - YangLeaf leafInfo = leafIterator.next(); 216 + YangLeaf<?> leafInfo = leafIterator.next();
217 217
218 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 218 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
219 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 219 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -243,8 +243,8 @@ public class DescriptionListenerTest { ...@@ -243,8 +243,8 @@ public class DescriptionListenerTest {
243 YangModule yangNode = (YangModule) node; 243 YangModule yangNode = (YangModule) node;
244 assertThat(yangNode.getName(), is("Test")); 244 assertThat(yangNode.getName(), is("Test"));
245 245
246 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 246 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
247 - YangLeafList leafListInfo = leafListIterator.next(); 247 + YangLeafList<?> leafListInfo = leafListIterator.next();
248 248
249 // Check whether description value is set correctly. 249 // Check whether description value is set correctly.
250 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 250 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
......
...@@ -66,8 +66,8 @@ public class LeafListListenerTest { ...@@ -66,8 +66,8 @@ public class LeafListListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 69 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
70 - YangLeafList leafListInfo = leafListIterator.next(); 70 + YangLeafList<?> leafListInfo = leafListIterator.next();
71 71
72 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 72 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
73 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 73 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -98,10 +98,10 @@ public class LeafListListenerTest { ...@@ -98,10 +98,10 @@ public class LeafListListenerTest {
98 @Test 98 @Test
99 public void processLeafListInvalidStatement() throws IOException, ParserException { 99 public void processLeafListInvalidStatement() throws IOException, ParserException {
100 thrown.expect(ParserException.class); 100 thrown.expect(ParserException.class);
101 - thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container'," + 101 + thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container',"
102 - " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," + 102 + + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
103 - " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," + 103 + + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
104 - " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 104 + + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
105 YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang"); 105 YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang");
106 } 106 }
107 107
...@@ -161,8 +161,8 @@ public class LeafListListenerTest { ...@@ -161,8 +161,8 @@ public class LeafListListenerTest {
161 assertThat(container.getName(), is("valid")); 161 assertThat(container.getName(), is("valid"));
162 162
163 // Check whether leaf-list properties as set correctly. 163 // Check whether leaf-list properties as set correctly.
164 - ListIterator<YangLeafList> leafListIterator = container.getListOfLeafList().listIterator(); 164 + ListIterator<YangLeafList<?>> leafListIterator = container.getListOfLeafList().listIterator();
165 - YangLeafList leafListInfo = leafListIterator.next(); 165 + YangLeafList<?> leafListInfo = leafListIterator.next();
166 166
167 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 167 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
168 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 168 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -198,8 +198,8 @@ public class LeafListListenerTest { ...@@ -198,8 +198,8 @@ public class LeafListListenerTest {
198 assertThat(yangList.getName(), is("valid")); 198 assertThat(yangList.getName(), is("valid"));
199 199
200 // Check whether leaf-list properties as set correctly. 200 // Check whether leaf-list properties as set correctly.
201 - ListIterator<YangLeafList> leafListIterator = yangList.getListOfLeafList().listIterator(); 201 + ListIterator<YangLeafList<?>> leafListIterator = yangList.getListOfLeafList().listIterator();
202 - YangLeafList leafListInfo = leafListIterator.next(); 202 + YangLeafList<?> leafListInfo = leafListIterator.next();
203 203
204 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 204 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
205 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 205 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
......
...@@ -66,8 +66,8 @@ public class LeafListenerTest { ...@@ -66,8 +66,8 @@ public class LeafListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 69 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
70 - YangLeaf leafInfo = leafIterator.next(); 70 + YangLeaf<?> leafInfo = leafIterator.next();
71 71
72 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 72 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
73 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 73 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -98,10 +98,10 @@ public class LeafListenerTest { ...@@ -98,10 +98,10 @@ public class LeafListenerTest {
98 @Test 98 @Test
99 public void processLeafInvalidStatement() throws IOException, ParserException { 99 public void processLeafInvalidStatement() throws IOException, ParserException {
100 thrown.expect(ParserException.class); 100 thrown.expect(ParserException.class);
101 - thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container'," + 101 + thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container',"
102 - " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," + 102 + + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
103 - " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," + 103 + + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
104 - " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 104 + + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
105 YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang"); 105 YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang");
106 } 106 }
107 107
...@@ -161,8 +161,8 @@ public class LeafListenerTest { ...@@ -161,8 +161,8 @@ public class LeafListenerTest {
161 assertThat(container.getName(), is("valid")); 161 assertThat(container.getName(), is("valid"));
162 162
163 // Check whether leaf properties as set correctly. 163 // Check whether leaf properties as set correctly.
164 - ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); 164 + ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
165 - YangLeaf leafInfo = leafIterator.next(); 165 + YangLeaf<?> leafInfo = leafIterator.next();
166 166
167 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 167 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
168 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 168 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -197,8 +197,8 @@ public class LeafListenerTest { ...@@ -197,8 +197,8 @@ public class LeafListenerTest {
197 assertThat(yangList.getName(), is("valid")); 197 assertThat(yangList.getName(), is("valid"));
198 198
199 // Check whether leaf properties as set correctly. 199 // Check whether leaf properties as set correctly.
200 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 200 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
201 - YangLeaf leafInfo = leafIterator.next(); 201 + YangLeaf<?> leafInfo = leafIterator.next();
202 202
203 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 203 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
204 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 204 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
......
...@@ -159,8 +159,8 @@ public class ListListenerTest { ...@@ -159,8 +159,8 @@ public class ListListenerTest {
159 assertThat(yangList.getReference(), is("\"list reference\"")); 159 assertThat(yangList.getReference(), is("\"list reference\""));
160 160
161 // Check whether leaf properties as set correctly. 161 // Check whether leaf properties as set correctly.
162 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 162 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
163 - YangLeaf leafInfo = leafIterator.next(); 163 + YangLeaf<?> leafInfo = leafIterator.next();
164 164
165 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 165 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
166 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 166 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
......
...@@ -60,8 +60,8 @@ public class MandatoryListenerTest { ...@@ -60,8 +60,8 @@ public class MandatoryListenerTest {
60 YangModule yangNode = (YangModule) node; 60 YangModule yangNode = (YangModule) node;
61 assertThat(yangNode.getName(), is("Test")); 61 assertThat(yangNode.getName(), is("Test"));
62 62
63 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 63 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
64 - YangLeaf leafInfo = leafIterator.next(); 64 + YangLeaf<?> leafInfo = leafIterator.next();
65 65
66 // Check whether the mandatory value is set correctly. 66 // Check whether the mandatory value is set correctly.
67 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 67 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -86,8 +86,8 @@ public class MandatoryListenerTest { ...@@ -86,8 +86,8 @@ public class MandatoryListenerTest {
86 YangModule yangNode = (YangModule) node; 86 YangModule yangNode = (YangModule) node;
87 assertThat(yangNode.getName(), is("Test")); 87 assertThat(yangNode.getName(), is("Test"));
88 88
89 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 89 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
90 - YangLeaf leafInfo = leafIterator.next(); 90 + YangLeaf<?> leafInfo = leafIterator.next();
91 91
92 // Check whether the mandatory value is set correctly. 92 // Check whether the mandatory value is set correctly.
93 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 93 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -112,8 +112,8 @@ public class MandatoryListenerTest { ...@@ -112,8 +112,8 @@ public class MandatoryListenerTest {
112 YangModule yangNode = (YangModule) node; 112 YangModule yangNode = (YangModule) node;
113 assertThat(yangNode.getName(), is("Test")); 113 assertThat(yangNode.getName(), is("Test"));
114 114
115 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 115 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
116 - YangLeaf leafInfo = leafIterator.next(); 116 + YangLeaf<?> leafInfo = leafIterator.next();
117 117
118 // Check whether the mandatory value is set correctly. 118 // Check whether the mandatory value is set correctly.
119 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 119 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -146,10 +146,10 @@ public class MandatoryListenerTest { ...@@ -146,10 +146,10 @@ public class MandatoryListenerTest {
146 @Test 146 @Test
147 public void processModuleSubStatementMandatory() throws IOException, ParserException { 147 public void processModuleSubStatementMandatory() throws IOException, ParserException {
148 thrown.expect(ParserException.class); 148 thrown.expect(ParserException.class);
149 - thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container'," + 149 + thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container',"
150 - " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," + 150 + + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
151 - " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," + 151 + + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
152 - " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 152 + + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
153 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang"); 153 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang");
154 } 154 }
155 } 155 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -62,8 +62,8 @@ public class MaxElementsListenerTest { ...@@ -62,8 +62,8 @@ public class MaxElementsListenerTest {
62 YangModule yangNode = (YangModule) node; 62 YangModule yangNode = (YangModule) node;
63 assertThat(yangNode.getName(), is("Test")); 63 assertThat(yangNode.getName(), is("Test"));
64 64
65 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 65 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
66 - YangLeafList leafListInfo = leafListIterator.next(); 66 + YangLeafList<?> leafListInfo = leafListIterator.next();
67 67
68 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 68 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
69 assertThat(leafListInfo.getMaxElelements(), is(3)); 69 assertThat(leafListInfo.getMaxElelements(), is(3));
...@@ -99,9 +99,9 @@ public class MaxElementsListenerTest { ...@@ -99,9 +99,9 @@ public class MaxElementsListenerTest {
99 @Test 99 @Test
100 public void processMaxElementsInvalidStatement() throws IOException, ParserException { 100 public void processMaxElementsInvalidStatement() throws IOException, ParserException {
101 thrown.expect(ParserException.class); 101 thrown.expect(ParserException.class);
102 - thrown.expectMessage("extraneous input 'max-element' expecting {'config', 'description', 'if-feature'," + 102 + thrown.expectMessage("extraneous input 'max-element' expecting {'config', 'description', 'if-feature',"
103 - " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units', " + 103 + + " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units', "
104 - "'when', '}'}"); 104 + + "'when', '}'}");
105 YangNode node = manager.getDataModel("src/test/resources/MaxElementsInvalidStatement.yang"); 105 YangNode node = manager.getDataModel("src/test/resources/MaxElementsInvalidStatement.yang");
106 } 106 }
107 107
...@@ -145,8 +145,8 @@ public class MaxElementsListenerTest { ...@@ -145,8 +145,8 @@ public class MaxElementsListenerTest {
145 YangModule yangNode = (YangModule) node; 145 YangModule yangNode = (YangModule) node;
146 assertThat(yangNode.getName(), is("Test")); 146 assertThat(yangNode.getName(), is("Test"));
147 147
148 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 148 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
149 - YangLeafList leafListInfo = leafListIterator.next(); 149 + YangLeafList<?> leafListInfo = leafListIterator.next();
150 150
151 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 151 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
152 assertThat(leafListInfo.getMaxElelements(), is(2147483647)); 152 assertThat(leafListInfo.getMaxElelements(), is(2147483647));
......
...@@ -62,8 +62,8 @@ public class MinElementsListenerTest { ...@@ -62,8 +62,8 @@ public class MinElementsListenerTest {
62 YangModule yangNode = (YangModule) node; 62 YangModule yangNode = (YangModule) node;
63 assertThat(yangNode.getName(), is("Test")); 63 assertThat(yangNode.getName(), is("Test"));
64 64
65 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 65 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
66 - YangLeafList leafListInfo = leafListIterator.next(); 66 + YangLeafList<?> leafListInfo = leafListIterator.next();
67 67
68 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 68 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
69 assertThat(leafListInfo.getMinElements(), is(3)); 69 assertThat(leafListInfo.getMinElements(), is(3));
...@@ -99,9 +99,9 @@ public class MinElementsListenerTest { ...@@ -99,9 +99,9 @@ public class MinElementsListenerTest {
99 @Test 99 @Test
100 public void processMinElementsInvalidKeyword() throws IOException, ParserException { 100 public void processMinElementsInvalidKeyword() throws IOException, ParserException {
101 thrown.expect(ParserException.class); 101 thrown.expect(ParserException.class);
102 - thrown.expectMessage("extraneous input 'min-element' expecting {'config', 'description', 'if-feature'," + 102 + thrown.expectMessage("extraneous input 'min-element' expecting {'config', 'description', 'if-feature',"
103 - " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units'," + 103 + + " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units',"
104 - " 'when', '}'}"); 104 + + " 'when', '}'}");
105 YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidKeyword.yang"); 105 YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidKeyword.yang");
106 } 106 }
107 107
...@@ -134,8 +134,8 @@ public class MinElementsListenerTest { ...@@ -134,8 +134,8 @@ public class MinElementsListenerTest {
134 @Test 134 @Test
135 public void processMinElementsInvalidCardinality() throws IOException, ParserException { 135 public void processMinElementsInvalidCardinality() throws IOException, ParserException {
136 thrown.expect(ParserException.class); 136 thrown.expect(ParserException.class);
137 - thrown.expectMessage("Internal parser error detected: Invalid cardinality in" + 137 + thrown.expectMessage(
138 - " min-elements before processing."); 138 + "Internal parser error detected: Invalid cardinality in" + " min-elements before processing.");
139 YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidCardinality.yang"); 139 YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidCardinality.yang");
140 } 140 }
141 } 141 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -66,8 +66,8 @@ public class ReferenceListenerTest { ...@@ -66,8 +66,8 @@ public class ReferenceListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 69 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
70 - YangLeaf leafInfo = leafIterator.next(); 70 + YangLeaf<?> leafInfo = leafIterator.next();
71 71
72 // Check whether the reference is set correctly. 72 // Check whether the reference is set correctly.
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 73 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -174,8 +174,8 @@ public class ReferenceListenerTest { ...@@ -174,8 +174,8 @@ public class ReferenceListenerTest {
174 assertThat(container.getReference(), is("\"container reference\"")); 174 assertThat(container.getReference(), is("\"container reference\""));
175 175
176 // Check whether leaf properties as set correctly. 176 // Check whether leaf properties as set correctly.
177 - ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); 177 + ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
178 - YangLeaf leafInfo = leafIterator.next(); 178 + YangLeaf<?> leafInfo = leafIterator.next();
179 179
180 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 180 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
181 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 181 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -211,8 +211,8 @@ public class ReferenceListenerTest { ...@@ -211,8 +211,8 @@ public class ReferenceListenerTest {
211 assertThat(yangList.getReference(), is("\"list reference\"")); 211 assertThat(yangList.getReference(), is("\"list reference\""));
212 212
213 // Check whether leaf properties as set correctly. 213 // Check whether leaf properties as set correctly.
214 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 214 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
215 - YangLeaf leafInfo = leafIterator.next(); 215 + YangLeaf<?> leafInfo = leafIterator.next();
216 216
217 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 217 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
218 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 218 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -242,8 +242,8 @@ public class ReferenceListenerTest { ...@@ -242,8 +242,8 @@ public class ReferenceListenerTest {
242 YangModule yangNode = (YangModule) node; 242 YangModule yangNode = (YangModule) node;
243 assertThat(yangNode.getName(), is("Test")); 243 assertThat(yangNode.getName(), is("Test"));
244 244
245 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 245 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
246 - YangLeafList leafListInfo = leafListIterator.next(); 246 + YangLeafList<?> leafListInfo = leafListIterator.next();
247 247
248 // Check whether description value is set correctly. 248 // Check whether description value is set correctly.
249 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 249 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
......
...@@ -66,8 +66,8 @@ public class StatusListenerTest { ...@@ -66,8 +66,8 @@ public class StatusListenerTest {
66 YangModule yangNode = (YangModule) node; 66 YangModule yangNode = (YangModule) node;
67 assertThat(yangNode.getName(), is("Test")); 67 assertThat(yangNode.getName(), is("Test"));
68 68
69 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 69 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
70 - YangLeaf leafInfo = leafIterator.next(); 70 + YangLeaf<?> leafInfo = leafIterator.next();
71 71
72 // Check whether the status is set correctly. 72 // Check whether the status is set correctly.
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 73 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -92,8 +92,8 @@ public class StatusListenerTest { ...@@ -92,8 +92,8 @@ public class StatusListenerTest {
92 YangModule yangNode = (YangModule) node; 92 YangModule yangNode = (YangModule) node;
93 assertThat(yangNode.getName(), is("Test")); 93 assertThat(yangNode.getName(), is("Test"));
94 94
95 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 95 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
96 - YangLeaf leafInfo = leafIterator.next(); 96 + YangLeaf<?> leafInfo = leafIterator.next();
97 97
98 // Check whether the status is set correctly. 98 // Check whether the status is set correctly.
99 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 99 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -118,8 +118,8 @@ public class StatusListenerTest { ...@@ -118,8 +118,8 @@ public class StatusListenerTest {
118 YangModule yangNode = (YangModule) node; 118 YangModule yangNode = (YangModule) node;
119 assertThat(yangNode.getName(), is("Test")); 119 assertThat(yangNode.getName(), is("Test"));
120 120
121 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 121 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
122 - YangLeaf leafInfo = leafIterator.next(); 122 + YangLeaf<?> leafInfo = leafIterator.next();
123 123
124 // Check whether the status is set correctly. 124 // Check whether the status is set correctly.
125 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 125 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -152,10 +152,10 @@ public class StatusListenerTest { ...@@ -152,10 +152,10 @@ public class StatusListenerTest {
152 @Test 152 @Test
153 public void processModuleSubStatementStatus() throws IOException, ParserException { 153 public void processModuleSubStatementStatus() throws IOException, ParserException {
154 thrown.expect(ParserException.class); 154 thrown.expect(ParserException.class);
155 - thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', " + 155 + thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', "
156 - "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," + 156 + + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
157 - " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference', " + 157 + + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference', "
158 - "'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 158 + + "'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
159 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang"); 159 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang");
160 } 160 }
161 161
...@@ -184,8 +184,8 @@ public class StatusListenerTest { ...@@ -184,8 +184,8 @@ public class StatusListenerTest {
184 assertThat(container.getStatus(), is(YangStatusType.OBSOLETE)); 184 assertThat(container.getStatus(), is(YangStatusType.OBSOLETE));
185 185
186 // Check whether leaf properties as set correctly. 186 // Check whether leaf properties as set correctly.
187 - ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); 187 + ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
188 - YangLeaf leafInfo = leafIterator.next(); 188 + YangLeaf<?> leafInfo = leafIterator.next();
189 189
190 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 190 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
191 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 191 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -221,8 +221,8 @@ public class StatusListenerTest { ...@@ -221,8 +221,8 @@ public class StatusListenerTest {
221 assertThat(yangList.getStatus(), is(YangStatusType.CURRENT)); 221 assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
222 222
223 // Check whether leaf properties as set correctly. 223 // Check whether leaf properties as set correctly.
224 - ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); 224 + ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
225 - YangLeaf leafInfo = leafIterator.next(); 225 + YangLeaf<?> leafInfo = leafIterator.next();
226 226
227 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 227 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
228 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 228 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -252,8 +252,8 @@ public class StatusListenerTest { ...@@ -252,8 +252,8 @@ public class StatusListenerTest {
252 YangModule yangNode = (YangModule) node; 252 YangModule yangNode = (YangModule) node;
253 assertThat(yangNode.getName(), is("Test")); 253 assertThat(yangNode.getName(), is("Test"));
254 254
255 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 255 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
256 - YangLeafList leafListInfo = leafListIterator.next(); 256 + YangLeafList<?> leafListInfo = leafListIterator.next();
257 257
258 // Check whether status is set correctly. 258 // Check whether status is set correctly.
259 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 259 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
......
...@@ -41,8 +41,8 @@ public class TypeListenerTest { ...@@ -41,8 +41,8 @@ public class TypeListenerTest {
41 YangModule yangNode = (YangModule) node; 41 YangModule yangNode = (YangModule) node;
42 assertThat(yangNode.getName(), is("Test")); 42 assertThat(yangNode.getName(), is("Test"));
43 43
44 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 44 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
45 - YangLeaf leafInfo = leafIterator.next(); 45 + YangLeaf<?> leafInfo = leafIterator.next();
46 46
47 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 47 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
48 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\"")); 48 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\""));
...@@ -67,8 +67,8 @@ public class TypeListenerTest { ...@@ -67,8 +67,8 @@ public class TypeListenerTest {
67 YangModule yangNode = (YangModule) node; 67 YangModule yangNode = (YangModule) node;
68 assertThat(yangNode.getName(), is("Test")); 68 assertThat(yangNode.getName(), is("Test"));
69 69
70 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 70 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
71 - YangLeaf leafInfo = leafIterator.next(); 71 + YangLeaf<?> leafInfo = leafIterator.next();
72 72
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 73 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
74 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 74 assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
...@@ -93,8 +93,8 @@ public class TypeListenerTest { ...@@ -93,8 +93,8 @@ public class TypeListenerTest {
93 YangModule yangNode = (YangModule) node; 93 YangModule yangNode = (YangModule) node;
94 assertThat(yangNode.getName(), is("Test")); 94 assertThat(yangNode.getName(), is("Test"));
95 95
96 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 96 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
97 - YangLeafList leafListInfo = leafListIterator.next(); 97 + YangLeafList<?> leafListInfo = leafListIterator.next();
98 98
99 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 99 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
100 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 100 assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
......
...@@ -64,8 +64,8 @@ public class UnitsListenerTest { ...@@ -64,8 +64,8 @@ public class UnitsListenerTest {
64 YangModule yangNode = (YangModule) node; 64 YangModule yangNode = (YangModule) node;
65 assertThat(yangNode.getName(), is("Test")); 65 assertThat(yangNode.getName(), is("Test"));
66 66
67 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 67 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
68 - YangLeaf leafInfo = leafIterator.next(); 68 + YangLeaf<?> leafInfo = leafIterator.next();
69 69
70 // Check whether units value is set correctly. 70 // Check whether units value is set correctly.
71 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 71 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -78,10 +78,10 @@ public class UnitsListenerTest { ...@@ -78,10 +78,10 @@ public class UnitsListenerTest {
78 @Test 78 @Test
79 public void processModuleSubStatementUnits() throws IOException, ParserException { 79 public void processModuleSubStatementUnits() throws IOException, ParserException {
80 thrown.expect(ParserException.class); 80 thrown.expect(ParserException.class);
81 - thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', " + 81 + thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', "
82 - "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', " + 82 + + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', "
83 - "'include', 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', " + 83 + + "'include', 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', "
84 - "'prefix', 'reference', 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}"); 84 + + "'prefix', 'reference', 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
85 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang"); 85 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang");
86 } 86 }
87 87
...@@ -113,8 +113,8 @@ public class UnitsListenerTest { ...@@ -113,8 +113,8 @@ public class UnitsListenerTest {
113 YangModule yangNode = (YangModule) node; 113 YangModule yangNode = (YangModule) node;
114 assertThat(yangNode.getName(), is("Test")); 114 assertThat(yangNode.getName(), is("Test"));
115 115
116 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 116 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
117 - YangLeaf leafInfo = leafIterator.next(); 117 + YangLeaf<?> leafInfo = leafIterator.next();
118 118
119 // Check whether leaf properties is set correctly. 119 // Check whether leaf properties is set correctly.
120 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 120 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
...@@ -145,8 +145,8 @@ public class UnitsListenerTest { ...@@ -145,8 +145,8 @@ public class UnitsListenerTest {
145 YangModule yangNode = (YangModule) node; 145 YangModule yangNode = (YangModule) node;
146 assertThat(yangNode.getName(), is("Test")); 146 assertThat(yangNode.getName(), is("Test"));
147 147
148 - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); 148 + ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
149 - YangLeaf leafInfo = leafIterator.next(); 149 + YangLeaf<?> leafInfo = leafIterator.next();
150 150
151 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 151 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
152 assertThat(leafInfo.getUnits(), is(nullValue())); 152 assertThat(leafInfo.getUnits(), is(nullValue()));
...@@ -180,8 +180,8 @@ public class UnitsListenerTest { ...@@ -180,8 +180,8 @@ public class UnitsListenerTest {
180 YangModule yangNode = (YangModule) node; 180 YangModule yangNode = (YangModule) node;
181 assertThat(yangNode.getName(), is("Test")); 181 assertThat(yangNode.getName(), is("Test"));
182 182
183 - ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); 183 + ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
184 - YangLeafList leafListInfo = leafListIterator.next(); 184 + YangLeafList<?> leafListInfo = leafListIterator.next();
185 185
186 // Check whether units value is set correctly. 186 // Check whether units value is set correctly.
187 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 187 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
......
...@@ -31,7 +31,7 @@ public class YangFileScannerTest { ...@@ -31,7 +31,7 @@ public class YangFileScannerTest {
31 31
32 private final Logger log = getLogger(getClass()); 32 private final Logger log = getLogger(getClass());
33 33
34 - String baseDir = "target/UnitTestCase"; 34 + private static final String BASEDIR = "target/UnitTestCase";
35 35
36 /** 36 /**
37 * Checks an empty directory. 37 * Checks an empty directory.
...@@ -39,9 +39,9 @@ public class YangFileScannerTest { ...@@ -39,9 +39,9 @@ public class YangFileScannerTest {
39 @Test 39 @Test
40 public void testWithSingleEmptyDirectoryInRoot() { 40 public void testWithSingleEmptyDirectoryInRoot() {
41 try { 41 try {
42 - File dir = new File(baseDir); 42 + File dir = new File(BASEDIR);
43 dir.mkdirs(); 43 dir.mkdirs();
44 - List<String> list = YangFileScanner.getYangFiles(baseDir.toString()); 44 + List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
45 } catch (IOException e) { 45 } catch (IOException e) {
46 log.info("IO Exception throwed"); 46 log.info("IO Exception throwed");
47 } 47 }
...@@ -63,7 +63,7 @@ public class YangFileScannerTest { ...@@ -63,7 +63,7 @@ public class YangFileScannerTest {
63 File firstpath2 = createDirectory(dir2); 63 File firstpath2 = createDirectory(dir2);
64 File firstpath3 = createDirectory(dir3); 64 File firstpath3 = createDirectory(dir3);
65 File firstpath4 = createDirectory(dir4); 65 File firstpath4 = createDirectory(dir4);
66 - List<String> list = YangFileScanner.getYangFiles(baseDir.toString()); 66 + List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
67 } catch (IOException e) { 67 } catch (IOException e) {
68 log.info("IO Exception throwed"); 68 log.info("IO Exception throwed");
69 } 69 }
...@@ -79,7 +79,7 @@ public class YangFileScannerTest { ...@@ -79,7 +79,7 @@ public class YangFileScannerTest {
79 String firstFileName1 = "secondFile.yang"; 79 String firstFileName1 = "secondFile.yang";
80 File firstpath1 = createDirectory(dir1); 80 File firstpath1 = createDirectory(dir1);
81 createFile(firstpath1, firstFileName1); 81 createFile(firstpath1, firstFileName1);
82 - List<String> list = YangFileScanner.getYangFiles(baseDir.toString()); 82 + List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
83 } catch (IOException e) { 83 } catch (IOException e) {
84 log.info("IO Exception throwed"); 84 log.info("IO Exception throwed");
85 } 85 }
...@@ -101,7 +101,7 @@ public class YangFileScannerTest { ...@@ -101,7 +101,7 @@ public class YangFileScannerTest {
101 createFile(firstpath2, firstFileName3); 101 createFile(firstpath2, firstFileName3);
102 createFile(firstpath2, firstFileName4); 102 createFile(firstpath2, firstFileName4);
103 createFile(firstpath2, firstFileName5); 103 createFile(firstpath2, firstFileName5);
104 - List<String> list = YangFileScanner.getYangFiles(baseDir.toString()); 104 + List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
105 } catch (IOException e) { 105 } catch (IOException e) {
106 log.info("IO Exception throwed"); 106 log.info("IO Exception throwed");
107 } 107 }
...@@ -143,7 +143,49 @@ public class YangFileScannerTest { ...@@ -143,7 +143,49 @@ public class YangFileScannerTest {
143 createFile(dir6, firstFileName3); 143 createFile(dir6, firstFileName3);
144 createFile(dir6, firstFileName4); 144 createFile(dir6, firstFileName4);
145 createFile(dir6, firstFileName5); 145 createFile(dir6, firstFileName5);
146 - List<String> list = YangFileScanner.getYangFiles(baseDir.toString()); 146 + List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
147 + } catch (IOException e) {
148 + log.info("IO Exception throwed");
149 + }
150 + }
151 +
152 + /**
153 + * Checks multi directories with many .java file.
154 + */
155 + @Test
156 + public void testWithMultiDirectoriesMultiJavaFiles() {
157 + try {
158 + String dir2 = "newDir1/newDir2/newDir3/newDir4";
159 + File dir3 = new File("target/UnitTestCase/newDir1");
160 + File dir4 = new File("target/UnitTestCase/newDir1/newDir2");
161 + File dir5 = new File("target/UnitTestCase/newDir1/newDir2/newDir3");
162 + File dir6 = new File("target/UnitTestCase/newDir1/newDir2/newDir3/newDir4");
163 + String firstFileName2 = "thirdFile.java";
164 + String firstFileName3 = "fourthFile.java";
165 + String firstFileName4 = "fifthFile.java";
166 + String firstFileName5 = "sixthFile.java";
167 + File firstpath2 = createDirectory(dir2);
168 + createFile(firstpath2, firstFileName2);
169 + createFile(firstpath2, firstFileName3);
170 + createFile(firstpath2, firstFileName4);
171 + createFile(dir3, firstFileName5);
172 + createFile(dir3, firstFileName2);
173 + createFile(dir3, firstFileName3);
174 + createFile(dir3, firstFileName4);
175 + createFile(dir3, firstFileName5);
176 + createFile(dir4, firstFileName2);
177 + createFile(dir4, firstFileName3);
178 + createFile(dir4, firstFileName4);
179 + createFile(dir4, firstFileName5);
180 + createFile(dir5, firstFileName2);
181 + createFile(dir5, firstFileName3);
182 + createFile(dir5, firstFileName4);
183 + createFile(dir5, firstFileName5);
184 + createFile(dir6, firstFileName2);
185 + createFile(dir6, firstFileName3);
186 + createFile(dir6, firstFileName4);
187 + createFile(dir6, firstFileName5);
188 + List<String> list = YangFileScanner.getJavaFiles(BASEDIR.toString());
147 } catch (IOException e) { 189 } catch (IOException e) {
148 log.info("IO Exception throwed"); 190 log.info("IO Exception throwed");
149 } 191 }
...@@ -156,7 +198,7 @@ public class YangFileScannerTest { ...@@ -156,7 +198,7 @@ public class YangFileScannerTest {
156 * @return directory path 198 * @return directory path
157 */ 199 */
158 public File createDirectory(String path) { 200 public File createDirectory(String path) {
159 - File myDir = new File(baseDir + File.separator + path); 201 + File myDir = new File(BASEDIR + File.separator + path);
160 myDir.mkdirs(); 202 myDir.mkdirs();
161 return myDir; 203 return myDir;
162 } 204 }
......