Committed by
Gerrit Code Review
[ONOS-4351][ONOS-4524] Augment linking and defect fixed.
Change-Id: I7c8e8c90579eea4631e014c4906a543a3c249427
Showing
56 changed files
with
1294 additions
and
589 deletions
utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.datamodel; | ||
18 | + | ||
19 | +/** | ||
20 | + * Represents YANG constructs which can be augmented. | ||
21 | + */ | ||
22 | +public interface YangAugmentationHolder { | ||
23 | +} |
... | @@ -92,7 +92,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ... | @@ -92,7 +92,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; |
92 | * Represents data model node to maintain information defined in YANG case. | 92 | * Represents data model node to maintain information defined in YANG case. |
93 | */ | 93 | */ |
94 | public class YangCase extends YangNode | 94 | public class YangCase extends YangNode |
95 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { | 95 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { |
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Case name. | 98 | * Case name. | ... | ... |
... | @@ -59,7 +59,8 @@ import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA; | ... | @@ -59,7 +59,8 @@ import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA; |
59 | /** | 59 | /** |
60 | * Represents data model node to maintain information defined in YANG choice. | 60 | * Represents data model node to maintain information defined in YANG choice. |
61 | */ | 61 | */ |
62 | -public class YangChoice extends YangNode implements YangCommonInfo, Parsable, CollisionDetector { | 62 | +public class YangChoice extends YangNode |
63 | + implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | ||
63 | 64 | ||
64 | /** | 65 | /** |
65 | * Name of choice. | 66 | * Name of choice. | ... | ... |
... | @@ -87,7 +87,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -87,7 +87,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
87 | /** | 87 | /** |
88 | * Represents data model node to maintain information defined in YANG container. | 88 | * Represents data model node to maintain information defined in YANG container. |
89 | */ | 89 | */ |
90 | -public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { | 90 | +public class YangContainer extends YangNode |
91 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | ||
91 | 92 | ||
92 | /** | 93 | /** |
93 | * Name of the container. | 94 | * Name of the container. | ... | ... |
... | @@ -68,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -68,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
68 | /** | 68 | /** |
69 | * Represents data model node to maintain information defined in YANG input. | 69 | * Represents data model node to maintain information defined in YANG input. |
70 | */ | 70 | */ |
71 | -public class YangInput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector { | 71 | +public class YangInput extends YangNode |
72 | + implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder { | ||
72 | 73 | ||
73 | /** | 74 | /** |
74 | * Name of the input. | 75 | * Name of the input. | ... | ... |
... | @@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
68 | * Represents list data represented in YANG. | 68 | * Represents list data represented in YANG. |
69 | */ | 69 | */ |
70 | public class YangList extends YangNode | 70 | public class YangList extends YangNode |
71 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { | 71 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Name of the YANG list. | 74 | * Name of the YANG list. | ... | ... |
... | @@ -74,8 +74,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -74,8 +74,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
74 | /** | 74 | /** |
75 | * Represents data model node to maintain information defined in YANG notification. | 75 | * Represents data model node to maintain information defined in YANG notification. |
76 | */ | 76 | */ |
77 | -public class YangNotification extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, | 77 | +public class YangNotification extends YangNode |
78 | - CollisionDetector { | 78 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Name of the notification. | 81 | * Name of the notification. | ... | ... |
... | @@ -67,7 +67,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -67,7 +67,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
67 | /** | 67 | /** |
68 | * Represents data model node to maintain information defined in YANG output. | 68 | * Represents data model node to maintain information defined in YANG output. |
69 | */ | 69 | */ |
70 | -public class YangOutput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector { | 70 | +public class YangOutput extends YangNode |
71 | + implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder { | ||
71 | 72 | ||
72 | /** | 73 | /** |
73 | * Name of the output. | 74 | * Name of the output. | ... | ... |
... | @@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | import java.util.List; | 19 | import java.util.List; |
20 | 20 | ||
21 | -import org.onosproject.yangutils.datamodel.CollisionDetector; | ||
22 | import org.onosproject.yangutils.datamodel.YangAugment; | 21 | import org.onosproject.yangutils.datamodel.YangAugment; |
23 | import org.onosproject.yangutils.datamodel.YangModule; | 22 | import org.onosproject.yangutils.datamodel.YangModule; |
24 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
... | @@ -33,9 +32,10 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -33,9 +32,10 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
33 | 32 | ||
34 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 33 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
35 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode; | 34 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode; |
36 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount; | 35 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.generateNameForAugmentNode; |
37 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment; | 36 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getParentsPrefix; |
38 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence; | 37 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.parserException; |
38 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.validateNodeInTargetPath; | ||
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
... | @@ -119,8 +119,11 @@ public final class AugmentListener { | ... | @@ -119,8 +119,11 @@ public final class AugmentListener { |
119 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) { | 119 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) { |
120 | YangNode curNode = (YangNode) curData; | 120 | YangNode curNode = (YangNode) curData; |
121 | YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION); | 121 | YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION); |
122 | + | ||
123 | + validateTargetNodePath(targetNodes, curNode, ctx); | ||
124 | + | ||
122 | yangAugment.setTargetNode(targetNodes); | 125 | yangAugment.setTargetNode(targetNodes); |
123 | - yangAugment.setName(detectCollisionForTargetNode(curData, targetNodes, line, charPositionInLine, listener)); | 126 | + yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener)); |
124 | 127 | ||
125 | try { | 128 | try { |
126 | curNode.addChild(yangAugment); | 129 | curNode.addChild(yangAugment); |
... | @@ -171,58 +174,34 @@ public final class AugmentListener { | ... | @@ -171,58 +174,34 @@ public final class AugmentListener { |
171 | } | 174 | } |
172 | 175 | ||
173 | /** | 176 | /** |
174 | - * Detects collision for java file generation of augment node when | 177 | + * Validates whether the current target node path is correct or not. |
175 | - * it is updating the same target node in same parent multiple times. | ||
176 | - * Returns name for generated java file of augment node | ||
177 | * | 178 | * |
178 | - * @param curData parsable data | ||
179 | * @param targetNodes list of target nodes | 179 | * @param targetNodes list of target nodes |
180 | * @param line line in YANG file | 180 | * @param line line in YANG file |
181 | * @param charPositionInLine char position in YANG file | 181 | * @param charPositionInLine char position in YANG file |
182 | - * @param listener tree walk listener | 182 | + * @param curNode current YANG node |
183 | - * @return name for generated java file for augment node | ||
184 | */ | 183 | */ |
185 | - private static String detectCollisionForTargetNode(Parsable curData, List<YangNodeIdentifier> targetNodes, int line, | 184 | + private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode, |
186 | - int charPositionInLine, TreeWalkListener listener) { | 185 | + GeneratedYangParser.AugmentStatementContext ctx) { |
187 | - | ||
188 | - String curPrefix = null; | ||
189 | - if (curData instanceof YangModule) { | ||
190 | - curPrefix = ((YangModule) curData).getPrefix(); | ||
191 | - } else if (curData instanceof YangSubModule) { | ||
192 | - curPrefix = ((YangSubModule) curData).getPrefix(); | ||
193 | - } | ||
194 | - YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1); | ||
195 | - boolean isPrefix = isPrefixPresent(nodeId, curPrefix); | ||
196 | - String xpath = createValidNameForAugment(nodeId, isPrefix); | ||
197 | 186 | ||
198 | - if (listener.getParsedDataStack().peek() instanceof CollisionDetector) { | 187 | + YangNodeIdentifier moduleId = targetNodes.get(0); |
199 | - try { | 188 | + if (moduleId.getPrefix() == null) { |
200 | - ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(xpath, | 189 | + if (!moduleId.getName().equals(curNode.getName())) { |
201 | - AUGMENT_DATA); | 190 | + throw parserException(ctx); |
202 | - } catch (DataModelException e) { | 191 | + } else { |
203 | - return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix); | 192 | + validateNodeInTargetPath(curNode, targetNodes, ctx); |
204 | } | 193 | } |
194 | + } else { | ||
195 | + String parentPrefix = getParentsPrefix(curNode); | ||
196 | + if (parentPrefix != null) { | ||
197 | + if (!parentPrefix.equals(moduleId.getPrefix())) { | ||
198 | + // TODO: handle in linker. | ||
199 | + } else { | ||
200 | + validateNodeInTargetPath(curNode, targetNodes, ctx); | ||
205 | } | 201 | } |
206 | - | 202 | + } else { |
207 | - clearOccurrenceCount(); | 203 | + // TODO: handle in linker. |
208 | - return xpath; | ||
209 | } | 204 | } |
210 | - | ||
211 | - /** | ||
212 | - * Returns true if a prefix is present and it is not equals to parents prefix. | ||
213 | - * | ||
214 | - * @param nodeId YANG node identifier | ||
215 | - * @param parentsPrefix parent's prefix | ||
216 | - * @return true if a prefix is present and it is not equals to parents prefix | ||
217 | - */ | ||
218 | - private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) { | ||
219 | - return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix; | ||
220 | } | 205 | } |
221 | - | ||
222 | - /** | ||
223 | - * Validates for the child nodes of augment node. | ||
224 | - */ | ||
225 | - private static void validateForChildNodes() { | ||
226 | - //TODO: implement with linker. | ||
227 | } | 206 | } |
228 | } | 207 | } | ... | ... |
... | @@ -110,7 +110,7 @@ public final class EnumListener { | ... | @@ -110,7 +110,7 @@ public final class EnumListener { |
110 | listener.getParsedDataStack().push(enumNode); | 110 | listener.getParsedDataStack().push(enumNode); |
111 | } | 111 | } |
112 | 112 | ||
113 | - /* Removes quotes from the enum name if present.*/ | 113 | + /*Removes quotes from the enum name if present.*/ |
114 | private static String getValidNamedValue(String name) { | 114 | private static String getValidNamedValue(String name) { |
115 | if (name.contains(QUOTES)) { | 115 | if (name.contains(QUOTES)) { |
116 | name = name.replace(QUOTES, EMPTY_STRING); | 116 | name = name.replace(QUOTES, EMPTY_STRING); | ... | ... |
... | @@ -19,14 +19,24 @@ package org.onosproject.yangutils.parser.impl.parserutils; | ... | @@ -19,14 +19,24 @@ package org.onosproject.yangutils.parser.impl.parserutils; |
19 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
20 | import java.util.List; | 20 | import java.util.List; |
21 | 21 | ||
22 | +import org.onosproject.yangutils.datamodel.CollisionDetector; | ||
23 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
24 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
22 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 25 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
26 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
27 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
28 | +import org.onosproject.yangutils.parser.Parsable; | ||
29 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
30 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
31 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
23 | 32 | ||
24 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
34 | +import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA; | ||
25 | 35 | ||
26 | /** | 36 | /** |
27 | - * Represents a utility which provides valid name for generated java file for augment node. | 37 | + * Represents a utility which provides listener utilities augment node. |
28 | */ | 38 | */ |
29 | -public final class AugmentJavaFileNameGenUtil { | 39 | +public final class AugmentListenerUtil { |
30 | 40 | ||
31 | /** | 41 | /** |
32 | * Prefix to be added to generated java file for augment node. | 42 | * Prefix to be added to generated java file for augment node. |
... | @@ -39,7 +49,7 @@ public final class AugmentJavaFileNameGenUtil { | ... | @@ -39,7 +49,7 @@ public final class AugmentJavaFileNameGenUtil { |
39 | private static int occurrenceCount = 1; | 49 | private static int occurrenceCount = 1; |
40 | 50 | ||
41 | /** | 51 | /** |
42 | - * List of names for generated augment java file. | 52 | + * List of names for augment's generated java file. |
43 | */ | 53 | */ |
44 | private static List<String> augmentJavaFileNameList = new ArrayList<>(); | 54 | private static List<String> augmentJavaFileNameList = new ArrayList<>(); |
45 | 55 | ||
... | @@ -50,7 +60,7 @@ public final class AugmentJavaFileNameGenUtil { | ... | @@ -50,7 +60,7 @@ public final class AugmentJavaFileNameGenUtil { |
50 | /** | 60 | /** |
51 | * Creates an instance of augment java file name generator utility. | 61 | * Creates an instance of augment java file name generator utility. |
52 | */ | 62 | */ |
53 | - private AugmentJavaFileNameGenUtil() { | 63 | + private AugmentListenerUtil() { |
54 | } | 64 | } |
55 | 65 | ||
56 | /** | 66 | /** |
... | @@ -90,6 +100,36 @@ public final class AugmentJavaFileNameGenUtil { | ... | @@ -90,6 +100,36 @@ public final class AugmentJavaFileNameGenUtil { |
90 | } | 100 | } |
91 | 101 | ||
92 | /** | 102 | /** |
103 | + * Generates name for augment node also detects collision for java file generation of augment node when | ||
104 | + * augment is updating the same target node in same parent multiple times. | ||
105 | + * | ||
106 | + * @param curData parsable data | ||
107 | + * @param targetNodes list of target nodes | ||
108 | + * @param listener tree walk listener | ||
109 | + * @return name for augment node | ||
110 | + */ | ||
111 | + public static String generateNameForAugmentNode(Parsable curData, List<YangNodeIdentifier> targetNodes, | ||
112 | + TreeWalkListener listener) { | ||
113 | + | ||
114 | + String curPrefix = getParentsPrefix((YangNode) curData); | ||
115 | + YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1); | ||
116 | + boolean isPrefix = isPrefixPresent(nodeId, curPrefix); | ||
117 | + String generateName = createValidNameForAugment(nodeId, isPrefix); | ||
118 | + | ||
119 | + if (listener.getParsedDataStack().peek() instanceof CollisionDetector) { | ||
120 | + try { | ||
121 | + ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(generateName, | ||
122 | + AUGMENT_DATA); | ||
123 | + } catch (DataModelException e) { | ||
124 | + return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix); | ||
125 | + } | ||
126 | + } | ||
127 | + | ||
128 | + clearOccurrenceCount(); | ||
129 | + return generateName; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
93 | * Creates a name identifier for augment. | 133 | * Creates a name identifier for augment. |
94 | * | 134 | * |
95 | * @param nodeId node identifier | 135 | * @param nodeId node identifier |
... | @@ -119,7 +159,7 @@ public final class AugmentJavaFileNameGenUtil { | ... | @@ -119,7 +159,7 @@ public final class AugmentJavaFileNameGenUtil { |
119 | /** | 159 | /** |
120 | * Updates occurrence count of augment. | 160 | * Updates occurrence count of augment. |
121 | */ | 161 | */ |
122 | - public static void updateOccurenceCount() { | 162 | + private static void updateOccurenceCount() { |
123 | int count = getOccurrenceCount(); | 163 | int count = getOccurrenceCount(); |
124 | count++; | 164 | count++; |
125 | setOccurrenceCount(count); | 165 | setOccurrenceCount(count); |
... | @@ -157,4 +197,113 @@ public final class AugmentJavaFileNameGenUtil { | ... | @@ -157,4 +197,113 @@ public final class AugmentJavaFileNameGenUtil { |
157 | setOccurrenceCount(ONE); | 197 | setOccurrenceCount(ONE); |
158 | } | 198 | } |
159 | 199 | ||
200 | + /** | ||
201 | + * Returns true if a prefix is present and it is not equals to parents prefix. | ||
202 | + * | ||
203 | + * @param nodeId YANG node identifier | ||
204 | + * @param parentsPrefix parent's prefix | ||
205 | + * @return true if a prefix is present and it is not equals to parents prefix | ||
206 | + */ | ||
207 | + private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) { | ||
208 | + return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix; | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * Validates whether current node in target path is valid or not. | ||
213 | + * | ||
214 | + * @param curNode current YANG node | ||
215 | + * @param targetNodes list of target nodes | ||
216 | + * @param ctx augment statement context | ||
217 | + */ | ||
218 | + public static void validateNodeInTargetPath(YangNode curNode, List<YangNodeIdentifier> targetNodes, | ||
219 | + GeneratedYangParser.AugmentStatementContext ctx) { | ||
220 | + | ||
221 | + curNode = curNode.getChild(); | ||
222 | + YangNode tempNode = validateCurrentTargetNode(targetNodes, curNode); | ||
223 | + if (tempNode != null) { | ||
224 | + switch (tempNode.getNodeType()) { | ||
225 | + case CONTAINER_NODE: | ||
226 | + break; | ||
227 | + case LIST_NODE: | ||
228 | + break; | ||
229 | + case CHOICE_NODE: | ||
230 | + break; | ||
231 | + case CASE_NODE: | ||
232 | + break; | ||
233 | + case INPUT_NODE: | ||
234 | + break; | ||
235 | + case OUTPUT_NODE: | ||
236 | + break; | ||
237 | + case NOTIFICATION_NODE: | ||
238 | + break; | ||
239 | + default: | ||
240 | + throw parserException(ctx); | ||
241 | + } | ||
242 | + } else { | ||
243 | + throw parserException(ctx); | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Validates whether nodes in target node list are valid or not. | ||
249 | + * | ||
250 | + * @param targetNodeName current target node | ||
251 | + * @param curNode YANG node | ||
252 | + * @return true or false | ||
253 | + */ | ||
254 | + private static YangNode validateCurrentTargetNode(List<YangNodeIdentifier> targetNodes, YangNode curNode) { | ||
255 | + YangNode tempNode = null; | ||
256 | + while (curNode != null) { | ||
257 | + tempNode = curNode; | ||
258 | + for (int i = 1; i < targetNodes.size(); i++) { | ||
259 | + if (curNode.getName().equals(targetNodes.get(i).getName())) { | ||
260 | + if (curNode.getChild() != null && targetNodes.size() - 1 != i) { | ||
261 | + curNode = curNode.getChild(); | ||
262 | + } else if (curNode.getChild() != null && targetNodes.size() - 1 == i) { | ||
263 | + return curNode; | ||
264 | + } else if (curNode.getChild() == null && targetNodes.size() - 1 == i) { | ||
265 | + return curNode; | ||
266 | + } else { | ||
267 | + break; | ||
268 | + } | ||
269 | + } else { | ||
270 | + curNode = tempNode; | ||
271 | + break; | ||
272 | + } | ||
273 | + } | ||
274 | + curNode = curNode.getNextSibling(); | ||
275 | + } | ||
276 | + return null; | ||
277 | + } | ||
278 | + | ||
279 | + /** | ||
280 | + * Builds parser exception. | ||
281 | + * | ||
282 | + * @param ctx augment statement context | ||
283 | + * @return parser exception | ||
284 | + */ | ||
285 | + public static ParserException parserException(GeneratedYangParser.AugmentStatementContext ctx) { | ||
286 | + int line = ctx.getStart().getLine(); | ||
287 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
288 | + ParserException exception = new ParserException("invalid target node path."); | ||
289 | + exception.setLine(line); | ||
290 | + exception.setCharPosition(charPositionInLine); | ||
291 | + return exception; | ||
292 | + } | ||
293 | + | ||
294 | + /** | ||
295 | + * Returns parent nodes prefix. | ||
296 | + * | ||
297 | + * @param curNode current YANG node | ||
298 | + * @return parent nodes prefix | ||
299 | + */ | ||
300 | + public static String getParentsPrefix(YangNode curNode) { | ||
301 | + String curPrefix = null; | ||
302 | + if (curNode instanceof YangModule) { | ||
303 | + curPrefix = ((YangModule) curNode).getPrefix(); | ||
304 | + } else if (curNode instanceof YangSubModule) { | ||
305 | + curPrefix = ((YangSubModule) curNode).getPrefix(); | ||
306 | + } | ||
307 | + return curPrefix; | ||
308 | + } | ||
160 | } | 309 | } | ... | ... |
... | @@ -28,10 +28,10 @@ import org.apache.maven.plugins.annotations.Mojo; | ... | @@ -28,10 +28,10 @@ import org.apache.maven.plugins.annotations.Mojo; |
28 | import org.apache.maven.plugins.annotations.Parameter; | 28 | import org.apache.maven.plugins.annotations.Parameter; |
29 | import org.apache.maven.project.MavenProject; | 29 | import org.apache.maven.project.MavenProject; |
30 | import org.onosproject.yangutils.datamodel.YangNode; | 30 | import org.onosproject.yangutils.datamodel.YangNode; |
31 | -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
32 | import org.onosproject.yangutils.parser.YangUtilsParser; | 31 | import org.onosproject.yangutils.parser.YangUtilsParser; |
33 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 32 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
34 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 33 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
34 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
35 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 35 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
36 | import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; | 36 | import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; |
37 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 37 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
... | @@ -114,7 +114,8 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -114,7 +114,8 @@ public class YangUtilManager extends AbstractMojo { |
114 | @Component | 114 | @Component |
115 | private BuildContext context; | 115 | private BuildContext context; |
116 | 116 | ||
117 | - private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); | 117 | + private static final String DEFAULT_PKG = SLASH |
118 | + + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); | ||
118 | 119 | ||
119 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 120 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
120 | private YangNode rootNode; | 121 | private YangNode rootNode; |
... | @@ -124,7 +125,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -124,7 +125,7 @@ public class YangUtilManager extends AbstractMojo { |
124 | 125 | ||
125 | try { | 126 | try { |
126 | 127 | ||
127 | - /** | 128 | + /* |
128 | * For deleting the generated code in previous build. | 129 | * For deleting the generated code in previous build. |
129 | */ | 130 | */ |
130 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); | 131 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); |
... | @@ -146,7 +147,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -146,7 +147,7 @@ public class YangUtilManager extends AbstractMojo { |
146 | try { | 147 | try { |
147 | YangNode yangNode = yangUtilsParser.getDataModel(yangFile); | 148 | YangNode yangNode = yangUtilsParser.getDataModel(yangFile); |
148 | setRootNode(yangNode); | 149 | setRootNode(yangNode); |
149 | - generateJavaCode(yangNode, yangPlugin); | 150 | + generateJavaCode(yangNode, yangPlugin, yangFile); |
150 | } catch (ParserException e) { | 151 | } catch (ParserException e) { |
151 | String logInfo = "Error in file: " + e.getFileName(); | 152 | String logInfo = "Error in file: " + e.getFileName(); |
152 | if (e.getLineNumber() != 0) { | 153 | if (e.getLineNumber() != 0) { |
... | @@ -165,13 +166,20 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -165,13 +166,20 @@ public class YangUtilManager extends AbstractMojo { |
165 | addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); | 166 | addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); |
166 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); | 167 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); |
167 | } catch (Exception e) { | 168 | } catch (Exception e) { |
169 | + String fileName = ""; | ||
170 | + if (e instanceof TranslatorException) { | ||
171 | + fileName = ((TranslatorException) e).getFileName(); | ||
172 | + } | ||
168 | try { | 173 | try { |
169 | translatorErrorHandler(getRootNode()); | 174 | translatorErrorHandler(getRootNode()); |
170 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); | 175 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); |
171 | - } catch (IOException | DataModelException ex) { | 176 | + } catch (IOException ex) { |
172 | - throw new MojoExecutionException("Error handler failed to delete files for data model node."); | 177 | + throw new MojoExecutionException( |
178 | + "Error handler failed to delete files for data model node."); | ||
173 | } | 179 | } |
174 | - throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); | 180 | + throw new MojoExecutionException( |
181 | + "Exception occured due to " + e.getLocalizedMessage() + " in " + fileName | ||
182 | + + " YANG file."); | ||
175 | } | 183 | } |
176 | } | 184 | } |
177 | 185 | ... | ... |
... | @@ -21,7 +21,7 @@ import java.util.List; | ... | @@ -21,7 +21,7 @@ import java.util.List; |
21 | /** | 21 | /** |
22 | * Abstraction of an entity which represents augmentation of a YANG node. | 22 | * Abstraction of an entity which represents augmentation of a YANG node. |
23 | */ | 23 | */ |
24 | -public interface HasAugmentation { | 24 | +public interface AugmentationHolder { |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Adds augment info to the augment info list. | 27 | * Adds augment info to the augment info list. | ... | ... |
... | @@ -16,8 +16,7 @@ | ... | @@ -16,8 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava; | 17 | package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | -import java.io.IOException; | 19 | +import org.onosproject.yangutils.translator.exception.TranslatorException; |
20 | - | ||
21 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 20 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
22 | 21 | ||
23 | /** | 22 | /** |
... | @@ -29,16 +28,16 @@ public interface JavaCodeGenerator { | ... | @@ -29,16 +28,16 @@ public interface JavaCodeGenerator { |
29 | * Traverse the schema of application and generate corresponding code. | 28 | * Traverse the schema of application and generate corresponding code. |
30 | * | 29 | * |
31 | * @param yangPlugin YANG plugin config | 30 | * @param yangPlugin YANG plugin config |
32 | - * @throws IOException when fails to translate the data model tree | 31 | + * @throws TranslatorException when fails to translate the data model tree |
33 | */ | 32 | */ |
34 | void generateCodeEntry(YangPluginConfig yangPlugin) | 33 | void generateCodeEntry(YangPluginConfig yangPlugin) |
35 | - throws IOException; | 34 | + throws TranslatorException; |
36 | 35 | ||
37 | /** | 36 | /** |
38 | * Traverse the schema of application and generate corresponding code. | 37 | * Traverse the schema of application and generate corresponding code. |
39 | * | 38 | * |
40 | - * @throws IOException when fails to generate java code | 39 | + * @throws TranslatorException when fails to generate java code |
41 | */ | 40 | */ |
42 | void generateCodeExit() | 41 | void generateCodeExit() |
43 | - throws IOException; | 42 | + throws TranslatorException; |
44 | } | 43 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 22 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
24 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 23 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
25 | 24 | ||
... | @@ -67,11 +66,12 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -67,11 +66,12 @@ public final class JavaCodeGeneratorUtil { |
67 | * | 66 | * |
68 | * @param rootNode root node of the data model tree | 67 | * @param rootNode root node of the data model tree |
69 | * @param yangPlugin YANG plugin config | 68 | * @param yangPlugin YANG plugin config |
70 | - * @throws IOException when fails to generate java code file the current | 69 | + * @param fileName YANG file name |
70 | + * @throws TranslatorException when fails to generate java code file the current | ||
71 | * node | 71 | * node |
72 | */ | 72 | */ |
73 | - public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin) | 73 | + public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName) |
74 | - throws IOException { | 74 | + throws TranslatorException { |
75 | 75 | ||
76 | YangNode codeGenNode = rootNode; | 76 | YangNode codeGenNode = rootNode; |
77 | TraversalType curTraversal = ROOT; | 77 | TraversalType curTraversal = ROOT; |
... | @@ -80,7 +80,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -80,7 +80,7 @@ public final class JavaCodeGeneratorUtil { |
80 | if (curTraversal != PARENT) { | 80 | if (curTraversal != PARENT) { |
81 | if (codeGenNode instanceof JavaCodeGenerator) { | 81 | if (codeGenNode instanceof JavaCodeGenerator) { |
82 | setCurNode(codeGenNode); | 82 | setCurNode(codeGenNode); |
83 | - generateCodeEntry(codeGenNode, yangPlugin); | 83 | + generateCodeEntry(codeGenNode, yangPlugin, fileName); |
84 | } else { | 84 | } else { |
85 | /* | 85 | /* |
86 | * For grouping and uses, there is no code generation, skip the generation for the child. | 86 | * For grouping and uses, there is no code generation, skip the generation for the child. |
... | @@ -100,11 +100,11 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -100,11 +100,11 @@ public final class JavaCodeGeneratorUtil { |
100 | curTraversal = CHILD; | 100 | curTraversal = CHILD; |
101 | codeGenNode = codeGenNode.getChild(); | 101 | codeGenNode = codeGenNode.getChild(); |
102 | } else if (codeGenNode.getNextSibling() != null) { | 102 | } else if (codeGenNode.getNextSibling() != null) { |
103 | - generateCodeExit(codeGenNode); | 103 | + generateCodeExit(codeGenNode, fileName); |
104 | curTraversal = SIBILING; | 104 | curTraversal = SIBILING; |
105 | codeGenNode = codeGenNode.getNextSibling(); | 105 | codeGenNode = codeGenNode.getNextSibling(); |
106 | } else { | 106 | } else { |
107 | - generateCodeExit(codeGenNode); | 107 | + generateCodeExit(codeGenNode, fileName); |
108 | curTraversal = PARENT; | 108 | curTraversal = PARENT; |
109 | codeGenNode = codeGenNode.getParent(); | 109 | codeGenNode = codeGenNode.getParent(); |
110 | } | 110 | } |
... | @@ -117,16 +117,20 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -117,16 +117,20 @@ public final class JavaCodeGeneratorUtil { |
117 | * @param codeGenNode current data model node for which the code needs to be | 117 | * @param codeGenNode current data model node for which the code needs to be |
118 | * generated | 118 | * generated |
119 | * @param yangPlugin YANG plugin config | 119 | * @param yangPlugin YANG plugin config |
120 | - * @throws IOException IO operation exception | 120 | + * @param fileName YANG file name |
121 | + * @throws TranslatorException when fails to generate java code file the current | ||
122 | + * node | ||
121 | */ | 123 | */ |
122 | - private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin) | 124 | + private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName) |
123 | - throws IOException { | 125 | + throws TranslatorException { |
124 | 126 | ||
125 | if (codeGenNode instanceof JavaCodeGenerator) { | 127 | if (codeGenNode instanceof JavaCodeGenerator) { |
126 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); | 128 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); |
127 | } else { | 129 | } else { |
128 | - throw new TranslatorException( | 130 | + TranslatorException ex = new TranslatorException( |
129 | "Generated data model node cannot be translated to target language code"); | 131 | "Generated data model node cannot be translated to target language code"); |
132 | + ex.setFileName(fileName); | ||
133 | + throw ex; | ||
130 | } | 134 | } |
131 | } | 135 | } |
132 | 136 | ||
... | @@ -135,27 +139,27 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -135,27 +139,27 @@ public final class JavaCodeGeneratorUtil { |
135 | * | 139 | * |
136 | * @param codeGenNode current data model node for which the code needs to be | 140 | * @param codeGenNode current data model node for which the code needs to be |
137 | * generated | 141 | * generated |
138 | - * @throws IOException IO operation exception | 142 | + * @param fileName YANG file name |
143 | + * @throws TranslatorException when fails to generate java code file the current | ||
144 | + * node | ||
139 | */ | 145 | */ |
140 | - private static void generateCodeExit(YangNode codeGenNode) | 146 | + private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException { |
141 | - throws IOException { | ||
142 | 147 | ||
143 | if (codeGenNode instanceof JavaCodeGenerator) { | 148 | if (codeGenNode instanceof JavaCodeGenerator) { |
144 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); | 149 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); |
145 | } else { | 150 | } else { |
146 | - throw new TranslatorException( | 151 | + TranslatorException ex = new TranslatorException( |
147 | "Generated data model node cannot be translated to target language code"); | 152 | "Generated data model node cannot be translated to target language code"); |
153 | + ex.setFileName(fileName); | ||
154 | + throw ex; | ||
148 | } | 155 | } |
149 | } | 156 | } |
150 | 157 | ||
151 | /** | 158 | /** |
152 | * Free other YANG nodes of data-model tree when error occurs while file | 159 | * Free other YANG nodes of data-model tree when error occurs while file |
153 | * generation of current node. | 160 | * generation of current node. |
154 | - * | ||
155 | - * @throws DataModelException when fails to do datamodel operations | ||
156 | */ | 161 | */ |
157 | - private static void freeRestResources() | 162 | + private static void freeRestResources() { |
158 | - throws DataModelException { | ||
159 | 163 | ||
160 | YangNode freedNode = getCurNode(); | 164 | YangNode freedNode = getCurNode(); |
161 | YangNode tempNode = freedNode; | 165 | YangNode tempNode = freedNode; |
... | @@ -205,10 +209,9 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -205,10 +209,9 @@ public final class JavaCodeGeneratorUtil { |
205 | * | 209 | * |
206 | * @param rootNode root node of data-model tree | 210 | * @param rootNode root node of data-model tree |
207 | * @throws IOException when fails to delete java code file the current node | 211 | * @throws IOException when fails to delete java code file the current node |
208 | - * @throws DataModelException when fails to do datamodel operations | ||
209 | */ | 212 | */ |
210 | public static void translatorErrorHandler(YangNode rootNode) | 213 | public static void translatorErrorHandler(YangNode rootNode) |
211 | - throws IOException, DataModelException { | 214 | + throws IOException { |
212 | 215 | ||
213 | /** | 216 | /** |
214 | * Free other resources where translator has failed. | 217 | * Free other resources where translator has failed. | ... | ... |
... | @@ -20,26 +20,29 @@ import java.util.List; | ... | @@ -20,26 +20,29 @@ import java.util.List; |
20 | import java.util.SortedSet; | 20 | import java.util.SortedSet; |
21 | import java.util.TreeSet; | 21 | import java.util.TreeSet; |
22 | 22 | ||
23 | +import static java.util.Collections.sort; | ||
24 | + | ||
23 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; |
26 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS; | ||
24 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS; | 27 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG; |
26 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; |
30 | -import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_CLASS; | ||
31 | -import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_PKG; | ||
32 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
38 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | ||
37 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
43 | +import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG; | ||
39 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
40 | 45 | ||
41 | -import static java.util.Collections.sort; | ||
42 | - | ||
43 | /** | 46 | /** |
44 | * Represents that generated Java file can contain imports. | 47 | * Represents that generated Java file can contain imports. |
45 | */ | 48 | */ |
... | @@ -178,7 +181,7 @@ public class JavaImportData { | ... | @@ -178,7 +181,7 @@ public class JavaImportData { |
178 | * | 181 | * |
179 | * @return import for list attribute | 182 | * @return import for list attribute |
180 | */ | 183 | */ |
181 | - public static String getImportForList() { | 184 | + public String getImportForList() { |
182 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; | 185 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; |
183 | } | 186 | } |
184 | 187 | ||
... | @@ -187,17 +190,17 @@ public class JavaImportData { | ... | @@ -187,17 +190,17 @@ public class JavaImportData { |
187 | * | 190 | * |
188 | * @return import for array list attribute | 191 | * @return import for array list attribute |
189 | */ | 192 | */ |
190 | - public static String getImportForArrayList() { | 193 | + public String getImportForArrayList() { |
191 | return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE; | 194 | return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE; |
192 | } | 195 | } |
193 | 196 | ||
194 | /** | 197 | /** |
195 | - * Returns import string for HasAugmentation class. | 198 | + * Returns import string for AugmentationHolder class. |
196 | * | 199 | * |
197 | - * @return import string for HasAugmentation class | 200 | + * @return import string for AugmentationHolder class |
198 | */ | 201 | */ |
199 | - public static String getHasAugmentationImport() { | 202 | + public String getAugmentationHolderImport() { |
200 | - return IMPORT + HAS_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + HAS_AUGMENTATION_CLASS_IMPORT_CLASS; | 203 | + return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS; |
201 | } | 204 | } |
202 | 205 | ||
203 | /** | 206 | /** |
... | @@ -205,7 +208,25 @@ public class JavaImportData { | ... | @@ -205,7 +208,25 @@ public class JavaImportData { |
205 | * | 208 | * |
206 | * @return import string for AugmentedInfo class | 209 | * @return import string for AugmentedInfo class |
207 | */ | 210 | */ |
208 | - public static String getAugmentedInfoImport() { | 211 | + public String getAugmentedInfoImport() { |
209 | return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS; | 212 | return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS; |
210 | } | 213 | } |
214 | + | ||
215 | + /** | ||
216 | + * Returns import string for ListenerService class. | ||
217 | + * | ||
218 | + * @return import string for ListenerService class | ||
219 | + */ | ||
220 | + public String getListenerServiceImport() { | ||
221 | + return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE; | ||
222 | + } | ||
223 | + | ||
224 | + /** | ||
225 | + * Returns import string for ListenerRegistry class. | ||
226 | + * | ||
227 | + * @return import string for ListenerRegistry class | ||
228 | + */ | ||
229 | + public String getListenerRegistryImport() { | ||
230 | + return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE; | ||
231 | + } | ||
211 | } | 232 | } | ... | ... |
... | @@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList; | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Represents implementation of java code fragments temporary implementations. | 33 | * Represents implementation of java code fragments temporary implementations. |
... | @@ -309,15 +308,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -309,15 +308,6 @@ public class TempJavaCodeFragmentFiles { |
309 | } | 308 | } |
310 | 309 | ||
311 | /** | 310 | /** |
312 | - * Adds class to the extends list. | ||
313 | - * | ||
314 | - * @param extend class to be extended | ||
315 | - */ | ||
316 | - public void addToExtendsList(String extend) { | ||
317 | - getExtendsList().add(extend); | ||
318 | - } | ||
319 | - | ||
320 | - /** | ||
321 | * Adds build method for interface. | 311 | * Adds build method for interface. |
322 | * | 312 | * |
323 | * @return build method for interface | 313 | * @return build method for interface | ... | ... |
... | @@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | -import java.util.ArrayList; | ||
22 | 21 | ||
23 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
23 | +import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | ||
24 | 24 | ||
25 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; | 25 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; |
26 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
26 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 27 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
27 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 28 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
28 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 29 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
... | @@ -53,7 +54,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -53,7 +54,7 @@ public class TempJavaEventFragmentFiles |
53 | */ | 54 | */ |
54 | public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo) | 55 | public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo) |
55 | throws IOException { | 56 | throws IOException { |
56 | - setExtendsList(new ArrayList<>()); | 57 | + setJavaExtendsListHolder(new JavaExtendsListHolder()); |
57 | setJavaImportData(new JavaImportData()); | 58 | setJavaImportData(new JavaImportData()); |
58 | setJavaFileInfo(javaFileInfo); | 59 | setJavaFileInfo(javaFileInfo); |
59 | 60 | ||
... | @@ -92,11 +93,13 @@ public class TempJavaEventFragmentFiles | ... | @@ -92,11 +93,13 @@ public class TempJavaEventFragmentFiles |
92 | throws IOException { | 93 | throws IOException { |
93 | 94 | ||
94 | createPackage(curNode); | 95 | createPackage(curNode); |
96 | + String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent()) | ||
97 | + .getJavaFileInfo().getJavaName()); | ||
95 | 98 | ||
96 | /** | 99 | /** |
97 | * Creates event interface file. | 100 | * Creates event interface file. |
98 | */ | 101 | */ |
99 | - setEventJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_FILE_NAME_SUFFIX))); | 102 | + setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX)); |
100 | generateEventFile(getEventJavaFileHandle(), curNode, null); | 103 | generateEventFile(getEventJavaFileHandle(), curNode, null); |
101 | 104 | ||
102 | /** | 105 | /** | ... | ... |
... | @@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | -import java.util.ArrayList; | ||
22 | 21 | ||
23 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
23 | +import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | ||
24 | 24 | ||
25 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; | 25 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; |
26 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
26 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 27 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
27 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 28 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
28 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 29 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
... | @@ -53,7 +54,7 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -53,7 +54,7 @@ public class TempJavaEventListenerFragmentFiles |
53 | */ | 54 | */ |
54 | public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo) | 55 | public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo) |
55 | throws IOException { | 56 | throws IOException { |
56 | - setExtendsList(new ArrayList<>()); | 57 | + setJavaExtendsListHolder(new JavaExtendsListHolder()); |
57 | setJavaImportData(new JavaImportData()); | 58 | setJavaImportData(new JavaImportData()); |
58 | setJavaFileInfo(javaFileInfo); | 59 | setJavaFileInfo(javaFileInfo); |
59 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), | 60 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
... | @@ -90,11 +91,12 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -90,11 +91,12 @@ public class TempJavaEventListenerFragmentFiles |
90 | throws IOException { | 91 | throws IOException { |
91 | 92 | ||
92 | createPackage(curNode); | 93 | createPackage(curNode); |
93 | - | 94 | + String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent()) |
95 | + .getJavaFileInfo().getJavaName()); | ||
94 | /** | 96 | /** |
95 | * Creates event listener interface file. | 97 | * Creates event listener interface file. |
96 | */ | 98 | */ |
97 | - setEventListenerJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_LISTENER_FILE_NAME_SUFFIX))); | 99 | + setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX)); |
98 | generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null); | 100 | generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null); |
99 | 101 | ||
100 | /** | 102 | /** | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
28 | import org.onosproject.yangutils.datamodel.YangNode; | 28 | import org.onosproject.yangutils.datamodel.YangNode; |
29 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 29 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; | 30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
31 | +import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | ||
31 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 32 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
32 | 33 | ||
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
... | @@ -74,13 +75,12 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -74,13 +75,12 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
76 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; | 77 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
78 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport; | ||
77 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; | 79 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
78 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport; | ||
79 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 80 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
80 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport; | 81 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport; |
82 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; | ||
81 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; | 83 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; |
82 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; | ||
83 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList; | ||
84 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports; | 84 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports; |
85 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
86 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 86 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
... | @@ -131,8 +131,7 @@ public class TempJavaFragmentFiles { | ... | @@ -131,8 +131,7 @@ public class TempJavaFragmentFiles { |
131 | /** | 131 | /** |
132 | * Contains all the interface(s)/class name which will be extended by generated files. | 132 | * Contains all the interface(s)/class name which will be extended by generated files. |
133 | */ | 133 | */ |
134 | - private List<String> extendsList = new ArrayList<>(); | 134 | + private JavaExtendsListHolder javaExtendsListHolder; |
135 | - | ||
136 | /** | 135 | /** |
137 | * File type extension for java classes. | 136 | * File type extension for java classes. |
138 | */ | 137 | */ |
... | @@ -499,9 +498,8 @@ public class TempJavaFragmentFiles { | ... | @@ -499,9 +498,8 @@ public class TempJavaFragmentFiles { |
499 | * @param javaFileInfo generated java file information | 498 | * @param javaFileInfo generated java file information |
500 | * @throws IOException when fails to create new file handle | 499 | * @throws IOException when fails to create new file handle |
501 | */ | 500 | */ |
502 | - TempJavaFragmentFiles(JavaFileInfo javaFileInfo) | 501 | + TempJavaFragmentFiles(JavaFileInfo javaFileInfo) throws IOException { |
503 | - throws IOException { | 502 | + setJavaExtendsListHolder(new JavaExtendsListHolder()); |
504 | - setExtendsList(new ArrayList<>()); | ||
505 | setJavaImportData(new JavaImportData()); | 503 | setJavaImportData(new JavaImportData()); |
506 | setJavaFileInfo(javaFileInfo); | 504 | setJavaFileInfo(javaFileInfo); |
507 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), | 505 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
... | @@ -776,30 +774,21 @@ public class TempJavaFragmentFiles { | ... | @@ -776,30 +774,21 @@ public class TempJavaFragmentFiles { |
776 | } | 774 | } |
777 | 775 | ||
778 | /** | 776 | /** |
779 | - * Returns list of classes to be extended by generated files. | 777 | + * Returns java extends list holder. |
780 | - * | ||
781 | - * @return list of classes to be extended by generated files | ||
782 | - */ | ||
783 | - List<String> getExtendsList() { | ||
784 | - return extendsList; | ||
785 | - } | ||
786 | - | ||
787 | - /** | ||
788 | - * Sets class to be extended by generated file. | ||
789 | * | 778 | * |
790 | - * @param extendsList list of classes to be extended | 779 | + * @return java extends list holder |
791 | */ | 780 | */ |
792 | - void setExtendsList(List<String> extendsList) { | 781 | + public JavaExtendsListHolder getJavaExtendsListHolder() { |
793 | - this.extendsList = extendsList; | 782 | + return javaExtendsListHolder; |
794 | } | 783 | } |
795 | 784 | ||
796 | /** | 785 | /** |
797 | - * Adds class to the extends list. | 786 | + * Sets java extends list holder. |
798 | * | 787 | * |
799 | - * @param extend class to be extended | 788 | + * @param javaExtendsListHolder java extends list holder |
800 | */ | 789 | */ |
801 | - public void addToExtendsList(String extend) { | 790 | + public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) { |
802 | - getExtendsList().add(extend); | 791 | + this.javaExtendsListHolder = javaExtendsListHolder; |
803 | } | 792 | } |
804 | 793 | ||
805 | /** | 794 | /** |
... | @@ -1323,10 +1312,6 @@ public class TempJavaFragmentFiles { | ... | @@ -1323,10 +1312,6 @@ public class TempJavaFragmentFiles { |
1323 | if (isAttributePresent()) { | 1312 | if (isAttributePresent()) { |
1324 | imports = getJavaImportData().getImports(); | 1313 | imports = getJavaImportData().getImports(); |
1325 | } | 1314 | } |
1326 | - /* | ||
1327 | - * Prepares java file generator for extends list. | ||
1328 | - */ | ||
1329 | - prepareJavaFileGeneratorForExtendsList(getExtendsList()); | ||
1330 | createPackage(curNode); | 1315 | createPackage(curNode); |
1331 | 1316 | ||
1332 | /* | 1317 | /* |
... | @@ -1347,16 +1332,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1347,16 +1332,7 @@ public class TempJavaFragmentFiles { |
1347 | } | 1332 | } |
1348 | } | 1333 | } |
1349 | } | 1334 | } |
1350 | - /* | 1335 | + |
1351 | - * Adds import for HasAugmentation class. | ||
1352 | - */ | ||
1353 | - if (isHasAugmentationExtended(getExtendsList())) { | ||
1354 | - addHasAugmentationImport(curNode, imports, true); | ||
1355 | - } | ||
1356 | - if (isAugmentedInfoExtended(getExtendsList())) { | ||
1357 | - addAugmentedInfoImport(curNode, imports, true); | ||
1358 | - } | ||
1359 | - sortImports(imports); | ||
1360 | /* | 1336 | /* |
1361 | * Create interface file. | 1337 | * Create interface file. |
1362 | */ | 1338 | */ |
... | @@ -1378,10 +1354,10 @@ public class TempJavaFragmentFiles { | ... | @@ -1378,10 +1354,10 @@ public class TempJavaFragmentFiles { |
1378 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); | 1354 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
1379 | } | 1355 | } |
1380 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); | 1356 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
1381 | - if (isHasAugmentationExtended(getExtendsList())) { | 1357 | + if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { |
1382 | - addHasAugmentationImport(curNode, imports, false); | 1358 | + addAugmentationHoldersImport(curNode, imports, false); |
1383 | } | 1359 | } |
1384 | - if (isAugmentedInfoExtended(getExtendsList())) { | 1360 | + if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) { |
1385 | addAugmentedInfoImport(curNode, imports, false); | 1361 | addAugmentedInfoImport(curNode, imports, false); |
1386 | } | 1362 | } |
1387 | if (curNode instanceof YangCase) { | 1363 | if (curNode instanceof YangCase) { |
... | @@ -1392,7 +1368,7 @@ public class TempJavaFragmentFiles { | ... | @@ -1392,7 +1368,7 @@ public class TempJavaFragmentFiles { |
1392 | if (isAttributePresent()) { | 1368 | if (isAttributePresent()) { |
1393 | addImportsToStringAndHasCodeMethods(curNode, imports); | 1369 | addImportsToStringAndHasCodeMethods(curNode, imports); |
1394 | } | 1370 | } |
1395 | - if (isHasAugmentationExtended(getExtendsList())) { | 1371 | + if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { |
1396 | addAugmentedInfoImport(curNode, imports, true); | 1372 | addAugmentedInfoImport(curNode, imports, true); |
1397 | addArrayListImport(curNode, imports, true); | 1373 | addArrayListImport(curNode, imports, true); |
1398 | } | 1374 | } |
... | @@ -1417,8 +1393,11 @@ public class TempJavaFragmentFiles { | ... | @@ -1417,8 +1393,11 @@ public class TempJavaFragmentFiles { |
1417 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); | 1393 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); |
1418 | } | 1394 | } |
1419 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); | 1395 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); |
1396 | + if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { | ||
1397 | + addAugmentedInfoImport(curNode, imports, false); | ||
1398 | + addArrayListImport(curNode, imports, false); | ||
1399 | + } | ||
1420 | } | 1400 | } |
1421 | - | ||
1422 | /* | 1401 | /* |
1423 | * Close all the file handles. | 1402 | * Close all the file handles. |
1424 | */ | 1403 | */ | ... | ... |
... | @@ -22,6 +22,7 @@ import java.util.ArrayList; | ... | @@ -22,6 +22,7 @@ import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | 23 | ||
24 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
25 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; | ||
25 | 26 | ||
26 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
27 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
... | @@ -31,11 +32,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato | ... | @@ -31,11 +32,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; | 34 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; |
34 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; | 35 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport; |
35 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; | ||
36 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 36 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
37 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; | ||
38 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
38 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | ||
39 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
... | @@ -183,7 +184,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -183,7 +184,7 @@ public class TempJavaServiceFragmentFiles |
183 | } | 184 | } |
184 | 185 | ||
185 | /** | 186 | /** |
186 | - * Generate java code. | 187 | + * Constructs java code exit. |
187 | * | 188 | * |
188 | * @param fileType generated file type | 189 | * @param fileType generated file type |
189 | * @param curNode current YANG node | 190 | * @param curNode current YANG node |
... | @@ -197,17 +198,29 @@ public class TempJavaServiceFragmentFiles | ... | @@ -197,17 +198,29 @@ public class TempJavaServiceFragmentFiles |
197 | 198 | ||
198 | createPackage(curNode); | 199 | createPackage(curNode); |
199 | 200 | ||
201 | + boolean isNotification = false; | ||
202 | + YangNode tempNode = curNode.getChild(); | ||
203 | + while (tempNode != null) { | ||
204 | + if (tempNode instanceof YangJavaNotification) { | ||
205 | + isNotification = true; | ||
206 | + break; | ||
207 | + } | ||
208 | + tempNode = tempNode.getNextSibling(); | ||
209 | + } | ||
210 | + | ||
211 | + if (isNotification) { | ||
212 | + addListnersImport(curNode, imports, true, LISTENER_SERVICE); | ||
213 | + } | ||
200 | /** | 214 | /** |
201 | * Creates rpc interface file. | 215 | * Creates rpc interface file. |
202 | */ | 216 | */ |
203 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); | 217 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); |
204 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); | 218 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); |
205 | 219 | ||
206 | - if (isHasAugmentationExtended(getExtendsList())) { | 220 | + if (isNotification) { |
207 | - addAugmentedInfoImport(curNode, imports, true); | 221 | + addListnersImport(curNode, imports, false, LISTENER_SERVICE); |
208 | - addArrayListImport(curNode, imports, true); | 222 | + addListnersImport(curNode, imports, true, LISTENER_REG); |
209 | } | 223 | } |
210 | - | ||
211 | /** | 224 | /** |
212 | * Create builder class file. | 225 | * Create builder class file. |
213 | */ | 226 | */ |
... | @@ -215,7 +228,9 @@ public class TempJavaServiceFragmentFiles | ... | @@ -215,7 +228,9 @@ public class TempJavaServiceFragmentFiles |
215 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent()); | 228 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent()); |
216 | 229 | ||
217 | insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose()); | 230 | insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose()); |
218 | - | 231 | + if (isNotification) { |
232 | + addListnersImport(curNode, imports, false, LISTENER_REG); | ||
233 | + } | ||
219 | /** | 234 | /** |
220 | * Close all the file handles. | 235 | * Close all the file handles. |
221 | */ | 236 | */ | ... | ... |
... | @@ -21,13 +21,13 @@ import java.io.IOException; | ... | @@ -21,13 +21,13 @@ import java.io.IOException; |
21 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | 23 | ||
24 | -import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
25 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
26 | import org.onosproject.yangutils.datamodel.YangType; | 25 | import org.onosproject.yangutils.datamodel.YangType; |
27 | import org.onosproject.yangutils.datamodel.YangTypeHolder; | 26 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
28 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 27 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
29 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; | 28 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; |
30 | 29 | ||
30 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
... | @@ -211,7 +211,7 @@ public class TempJavaTypeFragmentFiles | ... | @@ -211,7 +211,7 @@ public class TempJavaTypeFragmentFiles |
211 | javaType.updateJavaQualifiedInfo(); | 211 | javaType.updateJavaQualifiedInfo(); |
212 | String typeName = javaType.getDataTypeName(); | 212 | String typeName = javaType.getDataTypeName(); |
213 | 213 | ||
214 | - if (javaType.getDataType().equals(YangDataTypes.DERIVED)) { | 214 | + if (javaType.getDataType().equals(DERIVED)) { |
215 | typeName = getCamelCase(typeName, null); | 215 | typeName = getCamelCase(typeName, null); |
216 | } | 216 | } |
217 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 217 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | ... | ... |
... | @@ -19,7 +19,6 @@ import org.onosproject.yangutils.datamodel.YangType; | ... | @@ -19,7 +19,6 @@ import org.onosproject.yangutils.datamodel.YangType; |
19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer; | 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer; |
20 | import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; | 20 | import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; |
21 | 21 | ||
22 | - | ||
23 | /** | 22 | /** |
24 | * Represent java based identification of the YANG leaves. | 23 | * Represent java based identification of the YANG leaves. |
25 | */ | 24 | */ |
... | @@ -47,7 +46,6 @@ public interface JavaLeafInfoContainer | ... | @@ -47,7 +46,6 @@ public interface JavaLeafInfoContainer |
47 | */ | 46 | */ |
48 | String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig); | 47 | String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig); |
49 | 48 | ||
50 | - | ||
51 | /** | 49 | /** |
52 | * Identifies if object is a leaf-list. | 50 | * Identifies if object is a leaf-list. |
53 | * | 51 | * | ... | ... |
... | @@ -103,22 +103,28 @@ public class YangJavaAugment | ... | @@ -103,22 +103,28 @@ public class YangJavaAugment |
103 | * augment info. | 103 | * augment info. |
104 | * | 104 | * |
105 | * @param yangPlugin YANG plugin config | 105 | * @param yangPlugin YANG plugin config |
106 | - * @throws IOException IO operation fail | 106 | + * @throws TranslatorException translator operation fail |
107 | */ | 107 | */ |
108 | @Override | 108 | @Override |
109 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 109 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | - throws IOException { | 110 | + try { |
111 | generateCodeOfAugmentableNode(this, yangPlugin); | 111 | generateCodeOfAugmentableNode(this, yangPlugin); |
112 | + } catch (IOException e) { | ||
113 | + throw new TranslatorException("Failed to generate code for augmentable node " + this.getName()); | ||
114 | + } | ||
112 | } | 115 | } |
113 | 116 | ||
114 | /** | 117 | /** |
115 | * Create a java file using the YANG augment info. | 118 | * Create a java file using the YANG augment info. |
116 | * | 119 | * |
117 | - * @throws IOException when failed to do IO operations | 120 | + * @throws TranslatorException when failed to do translator operations |
118 | */ | 121 | */ |
119 | @Override | 122 | @Override |
120 | - public void generateCodeExit() | 123 | + public void generateCodeExit() throws TranslatorException { |
121 | - throws IOException { | 124 | + try { |
122 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
126 | + } catch (IOException e) { | ||
127 | + throw new TranslatorException("Failed to generate code for augmentable node " + this.getName()); | ||
128 | + } | ||
123 | } | 129 | } |
124 | } | 130 | } | ... | ... |
... | @@ -102,20 +102,27 @@ public class YangJavaCase | ... | @@ -102,20 +102,27 @@ public class YangJavaCase |
102 | * case info. | 102 | * case info. |
103 | * | 103 | * |
104 | * @param yangPlugin YANG plugin config | 104 | * @param yangPlugin YANG plugin config |
105 | - * @throws IOException IO operation fail | 105 | + * @throws TranslatorException translator operation fail |
106 | */ | 106 | */ |
107 | @Override | 107 | @Override |
108 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
109 | - throws IOException { | 109 | + try { |
110 | generateCodeOfAugmentableNode(this, yangPlugin); | 110 | generateCodeOfAugmentableNode(this, yangPlugin); |
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for case node " + this.getName()); | ||
114 | + } | ||
111 | } | 115 | } |
112 | 116 | ||
113 | /** | 117 | /** |
114 | * Creates a java file using the YANG case info. | 118 | * Creates a java file using the YANG case info. |
115 | */ | 119 | */ |
116 | @Override | 120 | @Override |
117 | - public void generateCodeExit() | 121 | + public void generateCodeExit() throws TranslatorException { |
118 | - throws IOException { | 122 | + try { |
119 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 123 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
124 | + } catch (IOException e) { | ||
125 | + throw new TranslatorException("Failed to generate code for case node " + this.getName()); | ||
126 | + } | ||
120 | } | 127 | } |
121 | } | 128 | } | ... | ... |
... | @@ -22,10 +22,10 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; | ... | @@ -22,10 +22,10 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
25 | -import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; | ||
26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 25 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
27 | 26 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
28 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Represents choice information extended to support java code generation. | 31 | * Represents choice information extended to support java code generation. |
... | @@ -102,20 +102,27 @@ public class YangJavaChoice | ... | @@ -102,20 +102,27 @@ public class YangJavaChoice |
102 | * choice info. | 102 | * choice info. |
103 | * | 103 | * |
104 | * @param yangPlugin YANG plugin config | 104 | * @param yangPlugin YANG plugin config |
105 | - * @throws IOException IO operation fail | 105 | + * @throws TranslatorException translator operation fail |
106 | */ | 106 | */ |
107 | @Override | 107 | @Override |
108 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
109 | - throws IOException { | 109 | + try { |
110 | - YangJavaModelUtils.generateCodeAndUpdateInParent(this, yangPlugin, false); | 110 | + generateCodeAndUpdateInParent(this, yangPlugin, false); |
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for choice node " + this.getName()); | ||
114 | + } | ||
111 | } | 115 | } |
112 | 116 | ||
113 | /** | 117 | /** |
114 | * Creates a java file using the YANG choice info. | 118 | * Creates a java file using the YANG choice info. |
115 | */ | 119 | */ |
116 | @Override | 120 | @Override |
117 | - public void generateCodeExit() | 121 | + public void generateCodeExit() throws TranslatorException { |
118 | - throws IOException { | 122 | + try { |
119 | getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this); | 123 | getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this); |
124 | + } catch (IOException e) { | ||
125 | + throw new TranslatorException("Failed to generate code for choice node " + this.getName()); | ||
126 | + } | ||
120 | } | 127 | } |
121 | } | 128 | } | ... | ... |
... | @@ -102,23 +102,30 @@ public class YangJavaContainer | ... | @@ -102,23 +102,30 @@ public class YangJavaContainer |
102 | * container info. | 102 | * container info. |
103 | * | 103 | * |
104 | * @param yangPlugin YANG plugin config | 104 | * @param yangPlugin YANG plugin config |
105 | - * @throws IOException IO operation fail | 105 | + * @throws TranslatorException translator operation fail |
106 | */ | 106 | */ |
107 | @Override | 107 | @Override |
108 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
109 | - throws IOException { | 109 | + try { |
110 | generateCodeAndUpdateInParent(this, yangPlugin, false); | 110 | generateCodeAndUpdateInParent(this, yangPlugin, false); |
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for container node " + this.getName()); | ||
114 | + } | ||
111 | } | 115 | } |
112 | 116 | ||
113 | /** | 117 | /** |
114 | * Create a java file using the YANG container info. | 118 | * Create a java file using the YANG container info. |
115 | * | 119 | * |
116 | - * @throws IOException IO operation fail | 120 | + * @throws TranslatorException translator operation fail |
117 | */ | 121 | */ |
118 | @Override | 122 | @Override |
119 | - public void generateCodeExit() | 123 | + public void generateCodeExit() throws TranslatorException { |
120 | - throws IOException { | 124 | + try { |
121 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
126 | + } catch (IOException e) { | ||
127 | + throw new TranslatorException("Failed to generate code for container node " + this.getName()); | ||
128 | + } | ||
122 | } | 129 | } |
123 | 130 | ||
124 | } | 131 | } | ... | ... |
... | @@ -104,23 +104,30 @@ public class YangJavaEnumeration | ... | @@ -104,23 +104,30 @@ public class YangJavaEnumeration |
104 | * enumeration info. | 104 | * enumeration info. |
105 | * | 105 | * |
106 | * @param yangPlugin YANG plugin config | 106 | * @param yangPlugin YANG plugin config |
107 | - * @throws IOException IO operations fails | 107 | + * @throws TranslatorException translator operations fails |
108 | */ | 108 | */ |
109 | @Override | 109 | @Override |
110 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 110 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
111 | - throws IOException { | 111 | + try { |
112 | generateCodeOfNode(this, yangPlugin); | 112 | generateCodeOfNode(this, yangPlugin); |
113 | + } catch (IOException e) { | ||
114 | + throw new TranslatorException( | ||
115 | + "Failed to prepare generate code entry for enumeration node " + this.getName()); | ||
116 | + } | ||
113 | } | 117 | } |
114 | 118 | ||
115 | /** | 119 | /** |
116 | * Creates a java file using the YANG enumeration info. | 120 | * Creates a java file using the YANG enumeration info. |
117 | * | 121 | * |
118 | - * @throws IOException IO operation fail | 122 | + * @throws TranslatorException translator operation fail |
119 | */ | 123 | */ |
120 | @Override | 124 | @Override |
121 | - public void generateCodeExit() | 125 | + public void generateCodeExit() throws TranslatorException { |
122 | - throws IOException { | 126 | + try { |
123 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this); | 127 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this); |
128 | + } catch (IOException e) { | ||
129 | + throw new TranslatorException("Failed to generate code for enumeration node " + this.getName()); | ||
130 | + } | ||
124 | } | 131 | } |
125 | 132 | ||
126 | } | 133 | } | ... | ... |
... | @@ -103,22 +103,29 @@ public class YangJavaInput | ... | @@ -103,22 +103,29 @@ public class YangJavaInput |
103 | * input info. | 103 | * input info. |
104 | * | 104 | * |
105 | * @param yangPlugin YANG plugin config | 105 | * @param yangPlugin YANG plugin config |
106 | - * @throws IOException IO operation fail | 106 | + * @throws TranslatorException translator operation fail |
107 | */ | 107 | */ |
108 | @Override | 108 | @Override |
109 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 109 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | - throws IOException { | 110 | + try { |
111 | generateCodeOfNode(this, yangPlugin); | 111 | generateCodeOfNode(this, yangPlugin); |
112 | + } catch (IOException e) { | ||
113 | + throw new TranslatorException( | ||
114 | + "Failed to prepare generate code entry for input node " + this.getName()); | ||
115 | + } | ||
112 | } | 116 | } |
113 | 117 | ||
114 | /** | 118 | /** |
115 | * Creates a java file using the YANG input info. | 119 | * Creates a java file using the YANG input info. |
116 | * | 120 | * |
117 | - * @throws IOException IO operation fail | 121 | + * @throws TranslatorException translator operation fail |
118 | */ | 122 | */ |
119 | @Override | 123 | @Override |
120 | - public void generateCodeExit() | 124 | + public void generateCodeExit() throws TranslatorException { |
121 | - throws IOException { | 125 | + try { |
122 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 126 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
127 | + } catch (IOException e) { | ||
128 | + throw new TranslatorException("Failed to generate code for input node " + this.getName()); | ||
129 | + } | ||
123 | } | 130 | } |
124 | } | 131 | } | ... | ... |
... | @@ -102,22 +102,29 @@ public class YangJavaList | ... | @@ -102,22 +102,29 @@ public class YangJavaList |
102 | * list info. | 102 | * list info. |
103 | * | 103 | * |
104 | * @param yangPlugin YANG plugin config | 104 | * @param yangPlugin YANG plugin config |
105 | - * @throws IOException IO operation fail | 105 | + * @throws TranslatorException translator operation fail |
106 | */ | 106 | */ |
107 | @Override | 107 | @Override |
108 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
109 | - throws IOException { | 109 | + try { |
110 | generateCodeAndUpdateInParent(this, yangPlugin, true); | 110 | generateCodeAndUpdateInParent(this, yangPlugin, true); |
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for list node " + this.getName()); | ||
114 | + } | ||
111 | } | 115 | } |
112 | 116 | ||
113 | /** | 117 | /** |
114 | * Creates a java file using the YANG list info. | 118 | * Creates a java file using the YANG list info. |
115 | * | 119 | * |
116 | - * @throws IOException IO operation fail | 120 | + * @throws TranslatorException translator operation fail |
117 | */ | 121 | */ |
118 | @Override | 122 | @Override |
119 | - public void generateCodeExit() | 123 | + public void generateCodeExit() throws TranslatorException { |
120 | - throws IOException { | 124 | + try { |
121 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
126 | + } catch (IOException e) { | ||
127 | + throw new TranslatorException("Failed to generate code for list node " + this.getName()); | ||
128 | + } | ||
122 | } | 129 | } |
123 | } | 130 | } | ... | ... |
... | @@ -22,11 +22,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; | ... | @@ -22,11 +22,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
25 | -import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; | ||
26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 25 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
27 | 26 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
29 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode; | ||
30 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | 30 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; |
31 | 31 | ||
32 | /** | 32 | /** |
... | @@ -103,23 +103,30 @@ public class YangJavaModule | ... | @@ -103,23 +103,30 @@ public class YangJavaModule |
103 | * Generates java code for module. | 103 | * Generates java code for module. |
104 | * | 104 | * |
105 | * @param yangPlugin YANG plugin config | 105 | * @param yangPlugin YANG plugin config |
106 | - * @throws IOException when fails to generate the source files | 106 | + * @throws TranslatorException when fails to generate the source files |
107 | */ | 107 | */ |
108 | @Override | 108 | @Override |
109 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 109 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | - throws IOException { | ||
111 | String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); | 110 | String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); |
112 | - YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg); | 111 | + try { |
112 | + generateCodeOfRootNode(this, yangPlugin, modulePkg); | ||
113 | + } catch (IOException e) { | ||
114 | + throw new TranslatorException( | ||
115 | + "Failed to prepare generate code entry for module node " + this.getName()); | ||
116 | + } | ||
113 | } | 117 | } |
114 | 118 | ||
115 | /** | 119 | /** |
116 | * Creates a java file using the YANG module info. | 120 | * Creates a java file using the YANG module info. |
117 | */ | 121 | */ |
118 | @Override | 122 | @Override |
119 | - public void generateCodeExit() | 123 | + public void generateCodeExit() throws TranslatorException { |
120 | - throws IOException { | 124 | + try { |
121 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); | 125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); |
122 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + | 126 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + |
123 | getJavaFileInfo().getPackageFilePath()); | 127 | getJavaFileInfo().getPackageFilePath()); |
128 | + } catch (IOException e) { | ||
129 | + throw new TranslatorException("Failed to generate code for module node " + this.getName()); | ||
130 | + } | ||
124 | } | 131 | } |
125 | } | 132 | } | ... | ... |
... | @@ -18,17 +18,25 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,17 +18,25 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
21 | import org.onosproject.yangutils.datamodel.YangNotification; | 22 | import org.onosproject.yangutils.datamodel.YangNotification; |
22 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
23 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 24 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
26 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
27 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | ||
30 | +import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | ||
26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 31 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
27 | 32 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | 36 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
37 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ||
32 | 40 | ||
33 | /** | 41 | /** |
34 | * Represents notification information extended to support java code generation. | 42 | * Represents notification information extended to support java code generation. |
... | @@ -107,11 +115,10 @@ public class YangJavaNotification | ... | @@ -107,11 +115,10 @@ public class YangJavaNotification |
107 | * notification info. | 115 | * notification info. |
108 | * | 116 | * |
109 | * @param yangPlugin YANG plugin config | 117 | * @param yangPlugin YANG plugin config |
110 | - * @throws IOException IO operation fail | 118 | + * @throws TranslatorException translator operation fail |
111 | */ | 119 | */ |
112 | @Override | 120 | @Override |
113 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 121 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
114 | - throws IOException { | ||
115 | 122 | ||
116 | /** | 123 | /** |
117 | * As part of the notification support the following files needs to be generated. | 124 | * As part of the notification support the following files needs to be generated. |
... | @@ -122,17 +129,44 @@ public class YangJavaNotification | ... | @@ -122,17 +129,44 @@ public class YangJavaNotification |
122 | * The manager class needs to extend the ListenerRegistry. | 129 | * The manager class needs to extend the ListenerRegistry. |
123 | */ | 130 | */ |
124 | 131 | ||
132 | + // Generate subject of the notification(event), this is simple interface | ||
133 | + // with builder class. | ||
134 | + try { | ||
135 | + generateCodeOfAugmentableNode(this, yangPlugin); | ||
136 | + addNotificationToExtendsList(); | ||
137 | + } catch (IOException e) { | ||
138 | + throw new TranslatorException( | ||
139 | + "Failed to prepare generate code entry for notification node " + this.getName()); | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | + /*Adds current notification info to the extends list so its parents service*/ | ||
144 | + private void addNotificationToExtendsList() { | ||
145 | + YangNode parent = this.getParent(); | ||
146 | + JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent) | ||
147 | + .getTempJavaCodeFragmentFiles() | ||
148 | + .getServiceTempFiles().getJavaExtendsListHolder(); | ||
149 | + JavaQualifiedTypeInfo event = new JavaQualifiedTypeInfo(); | ||
150 | + | ||
151 | + String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent) | ||
152 | + .getJavaFileInfo().getJavaName()); | ||
153 | + event.setClassInfo(parentInfo + EVENT_STRING); | ||
154 | + event.setPkgInfo(getJavaFileInfo().getPackage()); | ||
155 | + holder.addToExtendsList(event, parent); | ||
156 | + | ||
157 | + JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo(); | ||
158 | + | ||
159 | + eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING); | ||
160 | + eventListener.setPkgInfo(getJavaFileInfo().getPackage()); | ||
161 | + holder.addToExtendsList(eventListener, parent); | ||
125 | 162 | ||
126 | - // Generate subject of the notification(event), this is simple interface with builder class. | ||
127 | - generateCodeOfNode(this, yangPlugin); | ||
128 | } | 163 | } |
129 | 164 | ||
130 | /** | 165 | /** |
131 | * Creates a java file using the YANG notification info. | 166 | * Creates a java file using the YANG notification info. |
132 | */ | 167 | */ |
133 | @Override | 168 | @Override |
134 | - public void generateCodeExit() | 169 | + public void generateCodeExit() throws TranslatorException { |
135 | - throws IOException { | ||
136 | /** | 170 | /** |
137 | * As part of the notification support the following files needs to be generated. | 171 | * As part of the notification support the following files needs to be generated. |
138 | * 1) Subject of the notification(event), this is simple interface with builder class. | 172 | * 1) Subject of the notification(event), this is simple interface with builder class. |
... | @@ -141,8 +175,12 @@ public class YangJavaNotification | ... | @@ -141,8 +175,12 @@ public class YangJavaNotification |
141 | * | 175 | * |
142 | * The manager class needs to extend the "ListenerRegistry". | 176 | * The manager class needs to extend the "ListenerRegistry". |
143 | */ | 177 | */ |
178 | + try { | ||
144 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER | 179 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER |
145 | | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this); | 180 | | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this); |
181 | + } catch (IOException e) { | ||
182 | + throw new TranslatorException("Failed to generate code for notification node " + this.getName()); | ||
183 | + } | ||
146 | 184 | ||
147 | } | 185 | } |
148 | } | 186 | } | ... | ... |
... | @@ -103,23 +103,31 @@ public class YangJavaOutput | ... | @@ -103,23 +103,31 @@ public class YangJavaOutput |
103 | * output info. | 103 | * output info. |
104 | * | 104 | * |
105 | * @param yangPlugin YANG plugin config | 105 | * @param yangPlugin YANG plugin config |
106 | - * @throws IOException IO operation fail | 106 | + * @throws TranslatorException translator operation fail |
107 | */ | 107 | */ |
108 | @Override | 108 | @Override |
109 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 109 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | - throws IOException { | 110 | + try { |
111 | generateCodeOfNode(this, yangPlugin); | 111 | generateCodeOfNode(this, yangPlugin); |
112 | + } catch (IOException e) { | ||
113 | + throw new TranslatorException( | ||
114 | + "Failed to prepare generate code entry for output node " + this.getName()); | ||
115 | + } | ||
112 | 116 | ||
113 | } | 117 | } |
114 | 118 | ||
115 | /** | 119 | /** |
116 | * Creates a java file using the YANG output info. | 120 | * Creates a java file using the YANG output info. |
117 | * | 121 | * |
118 | - * @throws IOException IO operation fail | 122 | + * @throws TranslatorException translator operation fail |
119 | */ | 123 | */ |
120 | @Override | 124 | @Override |
121 | - public void generateCodeExit() | 125 | + public void generateCodeExit() throws TranslatorException { |
122 | - throws IOException { | 126 | + try { |
123 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 127 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
128 | + } catch (IOException e) { | ||
129 | + throw new TranslatorException( | ||
130 | + "Failed to prepare generate code exit for output node " + this.getName()); | ||
131 | + } | ||
124 | } | 132 | } |
125 | } | 133 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
... | @@ -71,31 +71,32 @@ public class YangJavaRpc | ... | @@ -71,31 +71,32 @@ public class YangJavaRpc |
71 | * RPC info. | 71 | * RPC info. |
72 | * | 72 | * |
73 | * @param yangPlugin YANG plugin config | 73 | * @param yangPlugin YANG plugin config |
74 | - * @throws IOException IO operations fails | 74 | + * @throws TranslatorException translator operations fails |
75 | */ | 75 | */ |
76 | @Override | 76 | @Override |
77 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 77 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
78 | - throws IOException { | ||
79 | 78 | ||
80 | if (!(this instanceof JavaCodeGeneratorInfo)) { | 79 | if (!(this instanceof JavaCodeGeneratorInfo)) { |
81 | // TODO:throw exception | 80 | // TODO:throw exception |
82 | } | 81 | } |
83 | 82 | ||
84 | // Add package information for rpc and create corresponding folder. | 83 | // Add package information for rpc and create corresponding folder. |
85 | - updatePackageInfo((JavaCodeGeneratorInfo) this, yangPlugin); | 84 | + try { |
86 | - | 85 | + updatePackageInfo(this, yangPlugin); |
86 | + } catch (IOException e) { | ||
87 | + throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName()); | ||
88 | + } | ||
87 | } | 89 | } |
88 | 90 | ||
89 | /** | 91 | /** |
90 | * Creates a java file using the YANG RPC info. | 92 | * Creates a java file using the YANG RPC info. |
91 | * | 93 | * |
92 | - * @throws IOException IO operations fails | 94 | + * @throws TranslatorException translator operations fails |
93 | */ | 95 | */ |
94 | @Override | 96 | @Override |
95 | - public void generateCodeExit() | 97 | + public void generateCodeExit() throws TranslatorException { |
96 | - throws IOException { | ||
97 | // Get the parent module/sub-module. | 98 | // Get the parent module/sub-module. |
98 | - YangNode parent = getParentNodeInGenCode((YangNode) this); | 99 | + YangNode parent = getParentNodeInGenCode(this); |
99 | 100 | ||
100 | // Parent should be holder of rpc or notification. | 101 | // Parent should be holder of rpc or notification. |
101 | if (!(parent instanceof RpcNotificationContainer)) { | 102 | if (!(parent instanceof RpcNotificationContainer)) { |
... | @@ -110,7 +111,8 @@ public class YangJavaRpc | ... | @@ -110,7 +111,8 @@ public class YangJavaRpc |
110 | JavaAttributeInfo javaAttributeInfoOfInput = null; | 111 | JavaAttributeInfo javaAttributeInfoOfInput = null; |
111 | JavaAttributeInfo javaAttributeInfoOfOutput = null; | 112 | JavaAttributeInfo javaAttributeInfoOfOutput = null; |
112 | 113 | ||
113 | - // Get the child input and output node and obtain create java attribute info. | 114 | + // Get the child input and output node and obtain create java attribute |
115 | + // info. | ||
114 | YangNode yangNode = this.getChild(); | 116 | YangNode yangNode = this.getChild(); |
115 | while (yangNode != null) { | 117 | while (yangNode != null) { |
116 | if (yangNode instanceof YangInput) { | 118 | if (yangNode instanceof YangInput) { |
... | @@ -130,10 +132,13 @@ public class YangJavaRpc | ... | @@ -130,10 +132,13 @@ public class YangJavaRpc |
130 | /* | 132 | /* |
131 | * Add the rpc information to the parent's service temp file. | 133 | * Add the rpc information to the parent's service temp file. |
132 | */ | 134 | */ |
133 | - ((TempJavaCodeFragmentFilesContainer) parent) | 135 | + try { |
134 | - .getTempJavaCodeFragmentFiles().getServiceTempFiles() | 136 | + ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() |
135 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, | 137 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, |
136 | ((YangNode) this).getName()); | 138 | ((YangNode) this).getName()); |
139 | + } catch (IOException e) { | ||
140 | + throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); | ||
141 | + } | ||
137 | // No file will be generated during RPC exit. | 142 | // No file will be generated during RPC exit. |
138 | } | 143 | } |
139 | 144 | ||
... | @@ -210,5 +215,5 @@ public class YangJavaRpc | ... | @@ -210,5 +215,5 @@ public class YangJavaRpc |
210 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 215 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
211 | tempJavaCodeFragmentFiles = fileHandle; | 216 | tempJavaCodeFragmentFiles = fileHandle; |
212 | } | 217 | } |
213 | -} | ||
214 | 218 | ||
219 | +} | ... | ... |
... | @@ -23,11 +23,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; | ... | @@ -23,11 +23,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; |
23 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 23 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
26 | -import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; | ||
27 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
28 | 27 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
30 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode; | ||
31 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | 31 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; |
32 | 32 | ||
33 | /** | 33 | /** |
... | @@ -117,24 +117,32 @@ public class YangJavaSubModule | ... | @@ -117,24 +117,32 @@ public class YangJavaSubModule |
117 | * submodule info. | 117 | * submodule info. |
118 | * | 118 | * |
119 | * @param yangPlugin YANG plugin config | 119 | * @param yangPlugin YANG plugin config |
120 | - * @throws IOException IO operation fail | 120 | + * @throws TranslatorException when fails to translate |
121 | */ | 121 | */ |
122 | @Override | 122 | @Override |
123 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 123 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
124 | - throws IOException { | ||
125 | String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), | 124 | String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), |
126 | getRevision().getRevDate()); | 125 | getRevision().getRevDate()); |
127 | - YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg); | 126 | + try { |
127 | + generateCodeOfRootNode(this, yangPlugin, subModulePkg); | ||
128 | + } catch (IOException e) { | ||
129 | + throw new TranslatorException( | ||
130 | + "failed to prepare generate code entry for submodule node " + this.getName()); | ||
131 | + } | ||
132 | + | ||
128 | } | 133 | } |
129 | 134 | ||
130 | /** | 135 | /** |
131 | * Creates a java file using the YANG submodule info. | 136 | * Creates a java file using the YANG submodule info. |
132 | */ | 137 | */ |
133 | @Override | 138 | @Override |
134 | - public void generateCodeExit() | 139 | + public void generateCodeExit() throws TranslatorException { |
135 | - throws IOException { | 140 | + try { |
136 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); | 141 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); |
137 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + | 142 | searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + |
138 | getJavaFileInfo().getPackageFilePath()); | 143 | getJavaFileInfo().getPackageFilePath()); |
144 | + } catch (IOException e) { | ||
145 | + throw new TranslatorException("Failed to generate code for submodule node " + this.getName()); | ||
146 | + } | ||
139 | } | 147 | } |
140 | } | 148 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Represents java information corresponding to the YANG type. | 24 | * Represents java information corresponding to the YANG type. |
25 | + * | ||
26 | + * @param <T> generic parameter for YANG java type | ||
25 | */ | 27 | */ |
26 | public class YangJavaType<T> | 28 | public class YangJavaType<T> |
27 | extends YangType<T> | 29 | extends YangType<T> | ... | ... |
... | @@ -103,23 +103,31 @@ public class YangJavaTypeDef | ... | @@ -103,23 +103,31 @@ public class YangJavaTypeDef |
103 | * typedef info. | 103 | * typedef info. |
104 | * | 104 | * |
105 | * @param yangPlugin YANG plugin config | 105 | * @param yangPlugin YANG plugin config |
106 | - * @throws IOException IO operations fails | 106 | + * @throws TranslatorException when fails to translate |
107 | */ | 107 | */ |
108 | @Override | 108 | @Override |
109 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 109 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | - throws IOException { | 110 | + try { |
111 | generateCodeOfNode(this, yangPlugin); | 111 | generateCodeOfNode(this, yangPlugin); |
112 | + } catch (IOException e) { | ||
113 | + throw new TranslatorException( | ||
114 | + "Failed to prepare generate code entry for typedef node " + this.getName()); | ||
115 | + } | ||
116 | + | ||
112 | } | 117 | } |
113 | 118 | ||
114 | /** | 119 | /** |
115 | * Create a java file using the YANG typedef info. | 120 | * Create a java file using the YANG typedef info. |
116 | * | 121 | * |
117 | - * @throws IOException IO operations fails | 122 | + * @throws TranslatorException when fails to translate |
118 | */ | 123 | */ |
119 | @Override | 124 | @Override |
120 | - public void generateCodeExit() | 125 | + public void generateCodeExit() throws TranslatorException { |
121 | - throws IOException { | 126 | + try { |
122 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); | 127 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); |
128 | + } catch (IOException e) { | ||
129 | + throw new TranslatorException("Failed to generate code for typedef node " + this.getName()); | ||
130 | + } | ||
123 | } | 131 | } |
124 | 132 | ||
125 | } | 133 | } | ... | ... |
... | @@ -18,13 +18,13 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,13 +18,13 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangUnion; | 20 | import org.onosproject.yangutils.datamodel.YangUnion; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
23 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
24 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 25 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
25 | 26 | ||
26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
27 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
28 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
29 | 29 | ||
30 | /** | 30 | /** |
... | @@ -84,10 +84,6 @@ public class YangJavaUnion | ... | @@ -84,10 +84,6 @@ public class YangJavaUnion |
84 | */ | 84 | */ |
85 | @Override | 85 | @Override |
86 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 86 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
87 | - if (tempFileHandle == null) { | ||
88 | - throw new RuntimeException("Missing temp file hand for current node " | ||
89 | - + getCapitalCase(getJavaFileInfo().getJavaName())); | ||
90 | - } | ||
91 | return tempFileHandle; | 87 | return tempFileHandle; |
92 | } | 88 | } |
93 | 89 | ||
... | @@ -106,22 +102,30 @@ public class YangJavaUnion | ... | @@ -106,22 +102,30 @@ public class YangJavaUnion |
106 | * union info. | 102 | * union info. |
107 | * | 103 | * |
108 | * @param yangPlugin YANG plugin config | 104 | * @param yangPlugin YANG plugin config |
109 | - * @throws IOException IO operations fails | 105 | + * @throws TranslatorException when fails to translate |
110 | */ | 106 | */ |
111 | @Override | 107 | @Override |
112 | - public void generateCodeEntry(YangPluginConfig yangPlugin) | 108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
113 | - throws IOException { | 109 | + try { |
114 | generateCodeOfNode(this, yangPlugin); | 110 | generateCodeOfNode(this, yangPlugin); |
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for union node " + this.getName()); | ||
114 | + } | ||
115 | + | ||
115 | } | 116 | } |
116 | 117 | ||
117 | /** | 118 | /** |
118 | * Creates a java file using the YANG union info. | 119 | * Creates a java file using the YANG union info. |
119 | * | 120 | * |
120 | - * @throws IOException IO operations fails | 121 | + * @throws TranslatorException when fails to translate |
121 | */ | 122 | */ |
122 | @Override | 123 | @Override |
123 | - public void generateCodeExit() | 124 | + public void generateCodeExit() throws TranslatorException { |
124 | - throws IOException { | 125 | + try { |
125 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this); | 126 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this); |
127 | + } catch (IOException e) { | ||
128 | + throw new TranslatorException("Failed to generate code for union node " + this.getName()); | ||
129 | + } | ||
126 | } | 130 | } |
127 | } | 131 | } | ... | ... |
... | @@ -16,6 +16,12 @@ | ... | @@ -16,6 +16,12 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
20 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
21 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
22 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | ||
23 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; | ||
24 | + | ||
19 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 25 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
20 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
21 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
... | @@ -26,17 +32,23 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -26,17 +32,23 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
29 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList; | 35 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.isExtendsList; | ||
31 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
39 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
43 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ||
35 | import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; | 45 | import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; |
37 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
50 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | ||
51 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | ||
40 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | 52 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
... | @@ -71,29 +83,53 @@ public final class ClassDefinitionGenerator { | ... | @@ -71,29 +83,53 @@ public final class ClassDefinitionGenerator { |
71 | * Based on the file type and the YANG name of the file, generate the | 83 | * Based on the file type and the YANG name of the file, generate the |
72 | * class / interface definition start. | 84 | * class / interface definition start. |
73 | */ | 85 | */ |
74 | - if ((genFileTypes & INTERFACE_MASK) != 0) { | 86 | + switch (genFileTypes) { |
75 | - return getInterfaceDefinition(yangName); | 87 | + case BUILDER_CLASS_MASK: |
76 | - } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { | ||
77 | return getBuilderClassDefinition(yangName); | 88 | return getBuilderClassDefinition(yangName); |
78 | - } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { | 89 | + case IMPL_CLASS_MASK: |
79 | return getImplClassDefinition(yangName); | 90 | return getImplClassDefinition(yangName); |
80 | - } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { | 91 | + case BUILDER_INTERFACE_MASK: |
81 | return getBuilderInterfaceDefinition(yangName); | 92 | return getBuilderInterfaceDefinition(yangName); |
82 | - } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) { | 93 | + case GENERATE_TYPEDEF_CLASS: |
83 | - return getTypeClassDefinition(yangName); | 94 | + case GENERATE_UNION_CLASS: |
84 | - } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) { | ||
85 | return getTypeClassDefinition(yangName); | 95 | return getTypeClassDefinition(yangName); |
86 | - } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) { | 96 | + case GENERATE_ENUM_CLASS: |
87 | return getEnumClassDefinition(yangName); | 97 | return getEnumClassDefinition(yangName); |
88 | - } else if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) { | 98 | + case GENERATE_EVENT_LISTENER_INTERFACE: |
89 | - return getRpcInterfaceDefinition(yangName); | ||
90 | - } else if ((genFileTypes & GENERATE_EVENT_CLASS) != 0) { | ||
91 | - return getEventDefinition(yangName); | ||
92 | - } else if ((genFileTypes & GENERATE_EVENT_LISTENER_INTERFACE) != 0) { | ||
93 | return getEventListenerDefinition(yangName); | 99 | return getEventListenerDefinition(yangName); |
100 | + default: | ||
101 | + return null; | ||
94 | } | 102 | } |
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Based on the file type and the YANG name of the file, generate the class | ||
107 | + * / interface definition start. | ||
108 | + * | ||
109 | + * @param genFileTypes generated file type | ||
110 | + * @param yangName class name | ||
111 | + * @param curNode current YANG node | ||
112 | + * @return class definition | ||
113 | + */ | ||
114 | + public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) { | ||
115 | + | ||
116 | + /** | ||
117 | + * Based on the file type and the YANG name of the file, generate the | ||
118 | + * class / interface definition start. | ||
119 | + */ | ||
120 | + switch (genFileTypes) { | ||
121 | + case INTERFACE_MASK: | ||
122 | + return getInterfaceDefinition(yangName, curNode); | ||
123 | + case GENERATE_SERVICE_AND_MANAGER: | ||
124 | + return getRpcInterfaceDefinition(yangName, curNode); | ||
125 | + case GENERATE_EVENT_CLASS: | ||
126 | + String eventName = getCapitalCase(((JavaFileInfoContainer) curNode) | ||
127 | + .getJavaFileInfo().getJavaName()); | ||
128 | + return getEventDefinition(yangName, eventName); | ||
129 | + default: | ||
95 | return null; | 130 | return null; |
96 | } | 131 | } |
132 | + } | ||
97 | 133 | ||
98 | /** | 134 | /** |
99 | * Returns enum file class definition. | 135 | * Returns enum file class definition. |
... | @@ -111,18 +147,26 @@ public final class ClassDefinitionGenerator { | ... | @@ -111,18 +147,26 @@ public final class ClassDefinitionGenerator { |
111 | * @param yangName file name | 147 | * @param yangName file name |
112 | * @return definition | 148 | * @return definition |
113 | */ | 149 | */ |
114 | - private static String getInterfaceDefinition(String yangName) { | 150 | + private static String getInterfaceDefinition(String yangName, YangNode curNode) { |
115 | - if (!isExtendsList()) { | 151 | + JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode) |
116 | - return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 152 | + .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder(); |
117 | - } | 153 | + |
154 | + if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) { | ||
118 | String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; | 155 | String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; |
119 | - for (String extend : getExtendsList()) { | 156 | + for (JavaQualifiedTypeInfo info : holder.getExtendsList()) { |
120 | - def = def + extend + COMMA + SPACE; | 157 | + if (!holder.getExtendedClassStore().get(info)) { |
158 | + def = def + info.getClassInfo() + COMMA + SPACE; | ||
159 | + } else { | ||
160 | + def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE; | ||
161 | + } | ||
121 | } | 162 | } |
163 | + | ||
122 | def = trimAtLast(def, COMMA); | 164 | def = trimAtLast(def, COMMA); |
123 | 165 | ||
124 | return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 166 | return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
125 | } | 167 | } |
168 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
169 | + } | ||
126 | 170 | ||
127 | /** | 171 | /** |
128 | * Returns builder interface file class definition. | 172 | * Returns builder interface file class definition. |
... | @@ -169,17 +213,47 @@ public final class ClassDefinitionGenerator { | ... | @@ -169,17 +213,47 @@ public final class ClassDefinitionGenerator { |
169 | } | 213 | } |
170 | 214 | ||
171 | /** | 215 | /** |
172 | - * Returns rpc file interface definition. | 216 | + * Returns RPC file interface definition. |
173 | * | 217 | * |
174 | * @param yangName file name | 218 | * @param yangName file name |
219 | + * @param curNode current YANG node | ||
175 | * @return definition | 220 | * @return definition |
176 | */ | 221 | */ |
177 | - private static String getRpcInterfaceDefinition(String yangName) { | 222 | + private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) { |
223 | + JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode) | ||
224 | + .getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder(); | ||
225 | + if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) { | ||
226 | + curNode = curNode.getChild(); | ||
227 | + while (curNode != null) { | ||
228 | + if (curNode instanceof YangJavaNotification) { | ||
229 | + return getRpcInterfaceDefinitionWhenItExtends(yangName, holder); | ||
230 | + } | ||
231 | + curNode = curNode.getNextSibling(); | ||
232 | + } | ||
233 | + } | ||
178 | if (yangName.contains(SERVICE)) { | 234 | if (yangName.contains(SERVICE)) { |
179 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 235 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
180 | } | 236 | } |
181 | - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + SERVICE | 237 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName |
182 | - + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 238 | + + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
239 | + } | ||
240 | + | ||
241 | + /* Provides class definition when RPC interface needs to extends any event.*/ | ||
242 | + private static String getRpcInterfaceDefinitionWhenItExtends(String yangName, | ||
243 | + JavaExtendsListHolder holder) { | ||
244 | + | ||
245 | + if (yangName.contains(SERVICE)) { | ||
246 | + String[] strArray = yangName.split(SERVICE); | ||
247 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
248 | + + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA | ||
249 | + + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE | ||
250 | + + OPEN_CURLY_BRACKET + NEW_LINE; | ||
251 | + } | ||
252 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
253 | + + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE | ||
254 | + + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE | ||
255 | + + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET | ||
256 | + + NEW_LINE; | ||
183 | } | 257 | } |
184 | 258 | ||
185 | /** | 259 | /** |
... | @@ -188,14 +262,9 @@ public final class ClassDefinitionGenerator { | ... | @@ -188,14 +262,9 @@ public final class ClassDefinitionGenerator { |
188 | * @param javaName file name | 262 | * @param javaName file name |
189 | * @return definition | 263 | * @return definition |
190 | */ | 264 | */ |
191 | - private static String getEventDefinition(String javaName) { | 265 | + private static String getEventDefinition(String javaName, String eventName) { |
192 | String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<" | 266 | String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<" |
193 | - + javaName + ".Type, " + javaName; | 267 | + + javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
194 | - if (classDef.length() < 5) { | ||
195 | - throw new RuntimeException("Event class name is error"); | ||
196 | - } | ||
197 | - classDef = classDef.substring(0, classDef.length() - 5); | ||
198 | - classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
199 | 268 | ||
200 | return classDef; | 269 | return classDef; |
201 | } | 270 | } | ... | ... |
... | @@ -18,7 +18,6 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -18,7 +18,6 @@ package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
20 | 20 | ||
21 | -import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | ||
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; | 21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; |
23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
24 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; | 23 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; |
... | @@ -78,18 +77,6 @@ public final class JavaCodeSnippetGen { | ... | @@ -78,18 +77,6 @@ public final class JavaCodeSnippetGen { |
78 | } | 77 | } |
79 | 78 | ||
80 | /** | 79 | /** |
81 | - * Returns based on the file type and the YANG name of the file, generate the class | ||
82 | - * / interface definition start. | ||
83 | - * | ||
84 | - * @param genFileTypes type of file being generated | ||
85 | - * @param yangName YANG name | ||
86 | - * @return corresponding textual java code information | ||
87 | - */ | ||
88 | - public static String getJavaClassDefStart(int genFileTypes, String yangName) { | ||
89 | - return generateClassDefinition(genFileTypes, yangName); | ||
90 | - } | ||
91 | - | ||
92 | - /** | ||
93 | * Returns the textual java code for attribute definition in class. | 80 | * Returns the textual java code for attribute definition in class. |
94 | * | 81 | * |
95 | * @param javaAttributeTypePkg Package of the attribute type | 82 | * @param javaAttributeTypePkg Package of the attribute type |
... | @@ -128,7 +115,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -128,7 +115,7 @@ public final class JavaCodeSnippetGen { |
128 | * @param type attribute type | 115 | * @param type attribute type |
129 | * @return list attribute string | 116 | * @return list attribute string |
130 | */ | 117 | */ |
131 | - public static String getListAttribute(String type) { | 118 | + private static String getListAttribute(String type) { |
132 | return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; | 119 | return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; |
133 | } | 120 | } |
134 | 121 | ||
... | @@ -138,10 +125,9 @@ public final class JavaCodeSnippetGen { | ... | @@ -138,10 +125,9 @@ public final class JavaCodeSnippetGen { |
138 | * @return attribute of augmented info for generated impl file | 125 | * @return attribute of augmented info for generated impl file |
139 | */ | 126 | */ |
140 | public static String getAugmentedInfoAttribute() { | 127 | public static String getAugmentedInfoAttribute() { |
141 | - return FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE | 128 | + return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE |
142 | + getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST | 129 | + getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST |
143 | - + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN | 130 | + + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
144 | - + NEW_LINE; | ||
145 | } | 131 | } |
146 | 132 | ||
147 | /** | 133 | /** | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.translator.tojava.utils; | ||
18 | + | ||
19 | +import java.util.ArrayList; | ||
20 | +import java.util.HashMap; | ||
21 | +import java.util.List; | ||
22 | +import java.util.Map; | ||
23 | + | ||
24 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
25 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
26 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
27 | +import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
28 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
29 | + | ||
30 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
42 | + | ||
43 | +/** | ||
44 | + * Represent the extends list for generated java classes. It holds the class details which needs | ||
45 | + * to be extended by the generated java code. | ||
46 | + */ | ||
47 | +public class JavaExtendsListHolder { | ||
48 | + | ||
49 | + /** | ||
50 | + * Creates an instance of JavaExtendsListHolder. | ||
51 | + */ | ||
52 | + public JavaExtendsListHolder() { | ||
53 | + setExtendedClassStore(new HashMap<>()); | ||
54 | + setExtendsList(new ArrayList<>()); | ||
55 | + } | ||
56 | + | ||
57 | + private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore; | ||
58 | + private List<JavaQualifiedTypeInfo> extendsList; | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns extends list. | ||
62 | + * | ||
63 | + * @return extends list | ||
64 | + */ | ||
65 | + public Map<JavaQualifiedTypeInfo, Boolean> getExtendedClassStore() { | ||
66 | + return extendedClassStore; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Sets extends list. | ||
71 | + * | ||
72 | + * @param extendsList list of classes need to be extended | ||
73 | + */ | ||
74 | + private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) { | ||
75 | + this.extendedClassStore = extendedClass; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Adds to the extends list. | ||
80 | + * | ||
81 | + * @param info java file info | ||
82 | + * @param node YANG node | ||
83 | + */ | ||
84 | + public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) { | ||
85 | + JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo(); | ||
86 | + | ||
87 | + if (!fileInfo.getPackage().equals(info.getPkgInfo())) { | ||
88 | + JavaImportData importData = getTempJavaFragement(node).getJavaImportData(); | ||
89 | + importData.addImportInfo(info); | ||
90 | + /*true means import should be added*/ | ||
91 | + getExtendedClassStore().put(info, true); | ||
92 | + } | ||
93 | + getExtendedClassStore().put(info, false); | ||
94 | + addToExtendsList(info); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Returns extends string for class. | ||
99 | + * | ||
100 | + * @param genFileType generated file type | ||
101 | + * @param className class name | ||
102 | + * @param isNotificationPresent if notification node is present | ||
103 | + * @return extends string | ||
104 | + */ | ||
105 | + public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) { | ||
106 | + String extend = EXTEND + SPACE; | ||
107 | + if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) { | ||
108 | + extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE | ||
109 | + + className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE; | ||
110 | + } else { | ||
111 | + for (JavaQualifiedTypeInfo info : getExtendsList()) { | ||
112 | + if (info.getClassInfo().equals(className)) { | ||
113 | + if (!getExtendedClassStore().get(info)) { | ||
114 | + return extend + info.getClassInfo(); | ||
115 | + } else { | ||
116 | + return extend + info.getPkgInfo() + PERIOD + info.getClassInfo(); | ||
117 | + } | ||
118 | + } | ||
119 | + } | ||
120 | + } | ||
121 | + return null; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Returns extends list. | ||
126 | + * | ||
127 | + * @return the extendsList | ||
128 | + */ | ||
129 | + public List<JavaQualifiedTypeInfo> getExtendsList() { | ||
130 | + return extendsList; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Sets extends info list. | ||
135 | + * | ||
136 | + * @param classInfoList the extends List to set | ||
137 | + */ | ||
138 | + private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) { | ||
139 | + this.extendsList = classInfoList; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Adds extends info to list. | ||
144 | + * | ||
145 | + * @param classInfo class info | ||
146 | + */ | ||
147 | + private void addToExtendsList(JavaQualifiedTypeInfo classInfo) { | ||
148 | + getExtendsList().add(classInfo); | ||
149 | + } | ||
150 | + | ||
151 | +} |
... | @@ -24,6 +24,7 @@ import java.util.List; | ... | @@ -24,6 +24,7 @@ import java.util.List; |
24 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
27 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
29 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
... | @@ -74,8 +75,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -74,8 +75,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; |
75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; | 77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
77 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils | 78 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; |
78 | - .isHasAugmentationExtended; | ||
79 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 79 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
80 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 80 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
81 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 81 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
... | @@ -102,59 +102,10 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | ... | @@ -102,59 +102,10 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
102 | */ | 102 | */ |
103 | public final class JavaFileGenerator { | 103 | public final class JavaFileGenerator { |
104 | 104 | ||
105 | - /** | ||
106 | - * Flag to check whether generated interface file need to extends any class. | ||
107 | - */ | ||
108 | - private static boolean isExtendsList = false; | ||
109 | - | ||
110 | - /** | ||
111 | - * List of classes to be extended by generated interface file. | ||
112 | - */ | ||
113 | - private static List<String> extendsList = new ArrayList<>(); | ||
114 | - | ||
115 | - /** | ||
116 | - * Creates an instance of java file generator. | ||
117 | - */ | ||
118 | private JavaFileGenerator() { | 105 | private JavaFileGenerator() { |
119 | } | 106 | } |
120 | 107 | ||
121 | /** | 108 | /** |
122 | - * Returns true if extends list is not empty. | ||
123 | - * | ||
124 | - * @return true or false | ||
125 | - */ | ||
126 | - public static boolean isExtendsList() { | ||
127 | - return isExtendsList; | ||
128 | - } | ||
129 | - | ||
130 | - /** | ||
131 | - * Sets the value of is extends list. | ||
132 | - * | ||
133 | - * @param isExtends true or false | ||
134 | - */ | ||
135 | - public static void setIsExtendsList(boolean isExtends) { | ||
136 | - isExtendsList = isExtends; | ||
137 | - } | ||
138 | - | ||
139 | - /** | ||
140 | - * Returns list of extended classes. | ||
141 | - * | ||
142 | - * @return list of extended classes | ||
143 | - */ | ||
144 | - public static List<String> getExtendsList() { | ||
145 | - return extendsList; | ||
146 | - } | ||
147 | - | ||
148 | - /** | ||
149 | - * Sets the list of extended classes. | ||
150 | - * | ||
151 | - * @param extendList list of extended classes | ||
152 | - */ | ||
153 | - public static void setExtendsList(List<String> extendList) { | ||
154 | - extendsList = extendList; | ||
155 | - } | ||
156 | - | ||
157 | - /** | ||
158 | * Returns generated interface file for current node. | 109 | * Returns generated interface file for current node. |
159 | * | 110 | * |
160 | * @param file file | 111 | * @param file file |
... | @@ -171,9 +122,8 @@ public final class JavaFileGenerator { | ... | @@ -171,9 +122,8 @@ public final class JavaFileGenerator { |
171 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 122 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
172 | 123 | ||
173 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 124 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
174 | - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
175 | 125 | ||
176 | - initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); | 126 | + initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className); |
177 | 127 | ||
178 | if (isAttrPresent) { | 128 | if (isAttrPresent) { |
179 | /** | 129 | /** |
... | @@ -343,9 +293,8 @@ public final class JavaFileGenerator { | ... | @@ -343,9 +293,8 @@ public final class JavaFileGenerator { |
343 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 293 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
344 | 294 | ||
345 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 295 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
346 | - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
347 | 296 | ||
348 | - initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path); | 297 | + initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
349 | 298 | ||
350 | List<String> methods = new ArrayList<>(); | 299 | List<String> methods = new ArrayList<>(); |
351 | 300 | ||
... | @@ -412,6 +361,17 @@ public final class JavaFileGenerator { | ... | @@ -412,6 +361,17 @@ public final class JavaFileGenerator { |
412 | initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); | 361 | initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); |
413 | 362 | ||
414 | List<String> methods = new ArrayList<>(); | 363 | List<String> methods = new ArrayList<>(); |
364 | + | ||
365 | + TempJavaCodeFragmentFiles javaCodeFragmentFiles = ((TempJavaCodeFragmentFilesContainer) curNode) | ||
366 | + .getTempJavaCodeFragmentFiles(); | ||
367 | + boolean isAugmentationHolderExtended = isAugmentationHolderExtended( | ||
368 | + javaCodeFragmentFiles.getBeanTempFiles().getJavaExtendsListHolder().getExtendsList()); | ||
369 | + /** | ||
370 | + * Add attribute for augmented info's list. | ||
371 | + */ | ||
372 | + if (isAugmentationHolderExtended) { | ||
373 | + insertDataIntoJavaFile(file, getAugmentedInfoAttribute()); | ||
374 | + } | ||
415 | if (isAttrPresent) { | 375 | if (isAttrPresent) { |
416 | /** | 376 | /** |
417 | * Add attribute strings. | 377 | * Add attribute strings. |
... | @@ -426,12 +386,6 @@ public final class JavaFileGenerator { | ... | @@ -426,12 +386,6 @@ public final class JavaFileGenerator { |
426 | + " while impl class file generation"); | 386 | + " while impl class file generation"); |
427 | } | 387 | } |
428 | 388 | ||
429 | - /** | ||
430 | - * Add attribute for augmented info's list. | ||
431 | - */ | ||
432 | - if (isHasAugmentationExtended(getExtendsList())) { | ||
433 | - insertDataIntoJavaFile(file, getAugmentedInfoAttribute()); | ||
434 | - } | ||
435 | insertDataIntoJavaFile(file, NEW_LINE); | 389 | insertDataIntoJavaFile(file, NEW_LINE); |
436 | try { | 390 | try { |
437 | /** | 391 | /** |
... | @@ -471,12 +425,15 @@ public final class JavaFileGenerator { | ... | @@ -471,12 +425,15 @@ public final class JavaFileGenerator { |
471 | insertDataIntoJavaFile(file, NEW_LINE); | 425 | insertDataIntoJavaFile(file, NEW_LINE); |
472 | } | 426 | } |
473 | try { | 427 | try { |
428 | + | ||
474 | /** | 429 | /** |
475 | * Constructor. | 430 | * Constructor. |
476 | */ | 431 | */ |
477 | - methods.add(getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, | 432 | + String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, |
478 | - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()) | 433 | + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
479 | - + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); | 434 | + .getBeanTempFiles()); |
435 | + | ||
436 | + methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); | ||
480 | } catch (IOException e) { | 437 | } catch (IOException e) { |
481 | throw new IOException("No data found in temporary java code fragment files for " + className | 438 | throw new IOException("No data found in temporary java code fragment files for " + className |
482 | + " while impl class file generation"); | 439 | + " while impl class file generation"); |
... | @@ -485,7 +442,7 @@ public final class JavaFileGenerator { | ... | @@ -485,7 +442,7 @@ public final class JavaFileGenerator { |
485 | /** | 442 | /** |
486 | * Add method for augment info's list. | 443 | * Add method for augment info's list. |
487 | */ | 444 | */ |
488 | - if (isHasAugmentationExtended(getExtendsList())) { | 445 | + if (isAugmentationHolderExtended) { |
489 | methods.add(getAddAugmentInfoMethodImpl()); | 446 | methods.add(getAddAugmentInfoMethodImpl()); |
490 | methods.add(getAugmentInfoListImpl()); | 447 | methods.add(getAugmentInfoListImpl()); |
491 | methods.add(getRemoveAugmentationImpl()); | 448 | methods.add(getRemoveAugmentationImpl()); |
... | @@ -802,9 +759,7 @@ public final class JavaFileGenerator { | ... | @@ -802,9 +759,7 @@ public final class JavaFileGenerator { |
802 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 759 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
803 | 760 | ||
804 | String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING; | 761 | String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING; |
805 | - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 762 | + initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
806 | - | ||
807 | - initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path); | ||
808 | 763 | ||
809 | List<String> methods = new ArrayList<>(); | 764 | List<String> methods = new ArrayList<>(); |
810 | 765 | ||
... | @@ -853,16 +808,16 @@ public final class JavaFileGenerator { | ... | @@ -853,16 +808,16 @@ public final class JavaFileGenerator { |
853 | * @param imports imports for file | 808 | * @param imports imports for file |
854 | * @throws IOException when fails to generate class file | 809 | * @throws IOException when fails to generate class file |
855 | */ | 810 | */ |
856 | - public static void generateEventFile(File file, YangNode curNode, List<String> imports) | 811 | + public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { |
857 | - throws IOException { | ||
858 | 812 | ||
813 | + YangNode parent = curNode.getParent(); | ||
859 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 814 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
860 | 815 | ||
861 | - String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_STRING; | 816 | + String className = |
862 | - String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 817 | + getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) |
863 | - | 818 | + + EVENT_STRING; |
864 | - initiateJavaFileGeneration(file, className, GENERATE_EVENT_CLASS, imports, path); | ||
865 | 819 | ||
820 | + initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); | ||
866 | insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName())); | 821 | insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName())); |
867 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 822 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
868 | } | 823 | } |
... | @@ -871,7 +826,7 @@ public final class JavaFileGenerator { | ... | @@ -871,7 +826,7 @@ public final class JavaFileGenerator { |
871 | return "\n" + | 826 | return "\n" + |
872 | " public enum Type {\n" + | 827 | " public enum Type {\n" + |
873 | " /**\n" + | 828 | " /**\n" + |
874 | - " * " + eventClassname + "notification.\n" + | 829 | + " * " + getCapitalCase(classname) + " notification.\n" + |
875 | " */\n" + | 830 | " */\n" + |
876 | " " + classname.toUpperCase() + "_EVENT\n" + | 831 | " " + classname.toUpperCase() + "_EVENT\n" + |
877 | " }\n" + | 832 | " }\n" + |
... | @@ -880,9 +835,9 @@ public final class JavaFileGenerator { | ... | @@ -880,9 +835,9 @@ public final class JavaFileGenerator { |
880 | " * Creates " + classname + " event with type and subject.\n" + | 835 | " * Creates " + classname + " event with type and subject.\n" + |
881 | " *\n" + | 836 | " *\n" + |
882 | " * @param type event type\n" + | 837 | " * @param type event type\n" + |
883 | - " * @param subject subject interface\n" + | 838 | + " * @param subject subject " + classname + "\n" + |
884 | " */\n" + | 839 | " */\n" + |
885 | - " public " + eventClassname + "(Type type, Interface subject) {\n" + | 840 | + " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" + |
886 | " super(type, subject);\n" + | 841 | " super(type, subject);\n" + |
887 | " }\n" + | 842 | " }\n" + |
888 | "\n" + | 843 | "\n" + |
... | @@ -890,10 +845,11 @@ public final class JavaFileGenerator { | ... | @@ -890,10 +845,11 @@ public final class JavaFileGenerator { |
890 | " * Creates " + classname + " event with type, subject and time.\n" + | 845 | " * Creates " + classname + " event with type, subject and time.\n" + |
891 | " *\n" + | 846 | " *\n" + |
892 | " * @param type event type\n" + | 847 | " * @param type event type\n" + |
893 | - " * @param subject subject interface\n" + | 848 | + " * @param subject subject " + classname + "\n" + |
894 | " * @param time time of event\n" + | 849 | " * @param time time of event\n" + |
895 | " */\n" + | 850 | " */\n" + |
896 | - " public " + eventClassname + "(Type type, Interface subject, long time) {\n" + | 851 | + " public " + eventClassname + "(Type type, " + getCapitalCase(classname) |
852 | + + " subject, long time) {\n" + | ||
897 | " super(type, subject, time);\n" + | 853 | " super(type, subject, time);\n" + |
898 | " }\n" + | 854 | " }\n" + |
899 | "\n"; | 855 | "\n"; |
... | @@ -909,10 +865,12 @@ public final class JavaFileGenerator { | ... | @@ -909,10 +865,12 @@ public final class JavaFileGenerator { |
909 | */ | 865 | */ |
910 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) | 866 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) |
911 | throws IOException { | 867 | throws IOException { |
912 | - | 868 | + YangNode parent = curNode.getParent(); |
913 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 869 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
914 | 870 | ||
915 | - String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING; | 871 | + String className = |
872 | + getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()) | ||
873 | + + EVENT_LISTENER_STRING; | ||
916 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 874 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
917 | 875 | ||
918 | initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path); | 876 | initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path); | ... | ... |
... | @@ -20,8 +20,10 @@ import java.io.File; | ... | @@ -20,8 +20,10 @@ import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | import java.util.List; | 21 | import java.util.List; |
22 | 22 | ||
23 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
23 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 24 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
26 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
25 | import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; |
26 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; |
... | @@ -55,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -55,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
58 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | 60 | +import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
59 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | 61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; |
60 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
61 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 63 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
... | @@ -226,6 +228,27 @@ public final class JavaFileGeneratorUtils { | ... | @@ -226,6 +228,27 @@ public final class JavaFileGeneratorUtils { |
226 | } | 228 | } |
227 | 229 | ||
228 | /** | 230 | /** |
231 | + * Initiates generation of file based on generated file type. | ||
232 | + * | ||
233 | + * @param file generated file | ||
234 | + * @param type generated file type | ||
235 | + * @param imports imports for the file | ||
236 | + * @param curNode current YANG node | ||
237 | + * @param className class name | ||
238 | + * @throws IOException when fails to generate a file | ||
239 | + */ | ||
240 | + public static void initiateJavaFileGeneration(File file, int type, List<String> imports, | ||
241 | + YangNode curNode, String className) throws IOException { | ||
242 | + | ||
243 | + try { | ||
244 | + file.createNewFile(); | ||
245 | + appendContents(file, type, imports, curNode, className); | ||
246 | + } catch (IOException e) { | ||
247 | + throw new IOException("Failed to create " + file.getName() + " class file."); | ||
248 | + } | ||
249 | + } | ||
250 | + | ||
251 | + /** | ||
229 | * Appends all the contents into a generated java file. | 252 | * Appends all the contents into a generated java file. |
230 | * | 253 | * |
231 | * @param file generated file | 254 | * @param file generated file |
... | @@ -235,40 +258,76 @@ public final class JavaFileGeneratorUtils { | ... | @@ -235,40 +258,76 @@ public final class JavaFileGeneratorUtils { |
235 | * @param importsList list of java imports. | 258 | * @param importsList list of java imports. |
236 | * @throws IOException when fails to append contents | 259 | * @throws IOException when fails to append contents |
237 | */ | 260 | */ |
238 | - private static void appendContents(File file, String fileName, int type, List<String> importsList, | 261 | + private static void appendContents(File file, int type, List<String> importsList, YangNode curNode, |
239 | - String pkg) | 262 | + String className) throws IOException { |
263 | + | ||
264 | + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | ||
265 | + | ||
266 | + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
267 | + String pkgString = parsePackageString(path, importsList); | ||
268 | + | ||
269 | + switch (type) { | ||
270 | + case INTERFACE_MASK: | ||
271 | + appendHeaderContents(file, pkgString, importsList); | ||
272 | + write(file, type, INTERFACE, curNode, className); | ||
273 | + break; | ||
274 | + case GENERATE_SERVICE_AND_MANAGER: | ||
275 | + appendHeaderContents(file, pkgString, importsList); | ||
276 | + write(file, type, RPC_INTERFACE, curNode, className); | ||
277 | + break; | ||
278 | + case GENERATE_EVENT_CLASS: | ||
279 | + appendHeaderContents(file, pkgString, importsList); | ||
280 | + write(file, type, EVENT, curNode, className); | ||
281 | + break; | ||
282 | + default: | ||
283 | + break; | ||
284 | + } | ||
285 | + } | ||
286 | + | ||
287 | + /** | ||
288 | + * Appends all the contents into a generated java file. | ||
289 | + * | ||
290 | + * @param file generated file | ||
291 | + * @param fileName generated file name | ||
292 | + * @param type generated file type | ||
293 | + * @param pkg generated file package | ||
294 | + * @param importsList list of java imports. | ||
295 | + * @throws IOException when fails to append contents | ||
296 | + */ | ||
297 | + private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg) | ||
240 | throws IOException { | 298 | throws IOException { |
241 | 299 | ||
242 | String pkgString = parsePackageString(pkg, importsList); | 300 | String pkgString = parsePackageString(pkg, importsList); |
243 | 301 | ||
244 | - if ((type & IMPL_CLASS_MASK) != 0) { | 302 | + switch (type) { |
303 | + case IMPL_CLASS_MASK: | ||
245 | write(file, fileName, type, IMPL_CLASS); | 304 | write(file, fileName, type, IMPL_CLASS); |
246 | - } else if ((type & BUILDER_INTERFACE_MASK) != 0) { | 305 | + break; |
306 | + case BUILDER_INTERFACE_MASK: | ||
247 | write(file, fileName, type, BUILDER_INTERFACE); | 307 | write(file, fileName, type, BUILDER_INTERFACE); |
248 | - } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) { | 308 | + break; |
309 | + case GENERATE_TYPEDEF_CLASS: | ||
249 | appendHeaderContents(file, pkgString, importsList); | 310 | appendHeaderContents(file, pkgString, importsList); |
250 | write(file, fileName, type, IMPL_CLASS); | 311 | write(file, fileName, type, IMPL_CLASS); |
251 | - } else if ((type & INTERFACE_MASK) != 0) { | 312 | + break; |
252 | - appendHeaderContents(file, pkgString, importsList); | 313 | + case BUILDER_CLASS_MASK: |
253 | - write(file, fileName, type, INTERFACE); | ||
254 | - } else if ((type & BUILDER_CLASS_MASK) != 0) { | ||
255 | appendHeaderContents(file, pkgString, importsList); | 314 | appendHeaderContents(file, pkgString, importsList); |
256 | write(file, fileName, type, BUILDER_CLASS); | 315 | write(file, fileName, type, BUILDER_CLASS); |
257 | - } else if ((type & GENERATE_UNION_CLASS) != 0) { | 316 | + break; |
317 | + case GENERATE_UNION_CLASS: | ||
258 | appendHeaderContents(file, pkgString, importsList); | 318 | appendHeaderContents(file, pkgString, importsList); |
259 | write(file, fileName, type, IMPL_CLASS); | 319 | write(file, fileName, type, IMPL_CLASS); |
260 | - } else if ((type & GENERATE_ENUM_CLASS) != 0) { | 320 | + break; |
321 | + case GENERATE_ENUM_CLASS: | ||
261 | appendHeaderContents(file, pkgString, importsList); | 322 | appendHeaderContents(file, pkgString, importsList); |
262 | write(file, fileName, type, ENUM_CLASS); | 323 | write(file, fileName, type, ENUM_CLASS); |
263 | - } else if ((type & GENERATE_SERVICE_AND_MANAGER) != 0) { | 324 | + break; |
264 | - appendHeaderContents(file, pkgString, importsList); | 325 | + case GENERATE_EVENT_LISTENER_INTERFACE: |
265 | - write(file, fileName, type, RPC_INTERFACE); | ||
266 | - } else if ((type & GENERATE_EVENT_CLASS) != 0) { | ||
267 | - appendHeaderContents(file, pkgString, importsList); | ||
268 | - write(file, fileName, type, EVENT); | ||
269 | - } else if ((type & GENERATE_EVENT_LISTENER_INTERFACE) != 0) { | ||
270 | appendHeaderContents(file, pkgString, importsList); | 326 | appendHeaderContents(file, pkgString, importsList); |
271 | write(file, fileName, type, EVENT_LISTENER); | 327 | write(file, fileName, type, EVENT_LISTENER); |
328 | + break; | ||
329 | + default: | ||
330 | + break; | ||
272 | } | 331 | } |
273 | } | 332 | } |
274 | 333 | ||
... | @@ -333,8 +392,9 @@ public final class JavaFileGeneratorUtils { | ... | @@ -333,8 +392,9 @@ public final class JavaFileGeneratorUtils { |
333 | * @param javaDocType java doc type | 392 | * @param javaDocType java doc type |
334 | * @throws IOException when fails to write into a file | 393 | * @throws IOException when fails to write into a file |
335 | */ | 394 | */ |
336 | - private static void write(File file, String fileName, int genType, JavaDocType javaDocType) | 395 | + private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName) |
337 | throws IOException { | 396 | throws IOException { |
397 | + | ||
338 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { | 398 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { |
339 | if (!fileName.contains(SERVICE)) { | 399 | if (!fileName.contains(SERVICE)) { |
340 | insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false)); | 400 | insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false)); |
... | @@ -344,7 +404,22 @@ public final class JavaFileGeneratorUtils { | ... | @@ -344,7 +404,22 @@ public final class JavaFileGeneratorUtils { |
344 | } else { | 404 | } else { |
345 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | 405 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); |
346 | } | 406 | } |
347 | - insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); | 407 | + insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode)); |
408 | + } | ||
409 | + | ||
410 | + /** | ||
411 | + * Writes data to the specific generated file. | ||
412 | + * | ||
413 | + * @param file generated file | ||
414 | + * @param fileName file name | ||
415 | + * @param genType generated file type | ||
416 | + * @param javaDocType java doc type | ||
417 | + * @throws IOException when fails to write into a file | ||
418 | + */ | ||
419 | + private static void write(File file, String fileName, int genType, JavaDocType javaDocType) | ||
420 | + throws IOException { | ||
421 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | ||
422 | + insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName)); | ||
348 | } | 423 | } |
349 | 424 | ||
350 | /** | 425 | /** |
... | @@ -354,8 +429,8 @@ public final class JavaFileGeneratorUtils { | ... | @@ -354,8 +429,8 @@ public final class JavaFileGeneratorUtils { |
354 | * @return enum's attribute | 429 | * @return enum's attribute |
355 | */ | 430 | */ |
356 | public static String getEnumsValueAttribute(String className) { | 431 | public static String getEnumsValueAttribute(String className) { |
357 | - return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) + SEMI_COLAN | 432 | + return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) |
358 | - + NEW_LINE; | 433 | + + SEMI_COLAN + NEW_LINE; |
359 | } | 434 | } |
360 | 435 | ||
361 | } | 436 | } | ... | ... |
... | @@ -19,7 +19,11 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -19,7 +19,11 @@ package org.onosproject.yangutils.translator.tojava.utils; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | import java.util.Map; | 20 | import java.util.Map; |
21 | 21 | ||
22 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
23 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
24 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
26 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; | ||
23 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | 27 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; |
24 | 28 | ||
25 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
... | @@ -29,11 +33,13 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -29,11 +33,13 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.AND; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
36 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE; | ||
32 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
42 | +import static org.onosproject.yangutils.utils.UtilConstants.BYTE; | ||
37 | import static org.onosproject.yangutils.utils.UtilConstants.CASE; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.CASE; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; | 45 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
... | @@ -64,6 +70,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ... | @@ -64,6 +70,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
64 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; | 70 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; |
65 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 71 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
66 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 72 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
73 | +import static org.onosproject.yangutils.utils.UtilConstants.LONG; | ||
67 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 74 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
68 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 75 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
69 | import static org.onosproject.yangutils.utils.UtilConstants.NULL; | 76 | import static org.onosproject.yangutils.utils.UtilConstants.NULL; |
... | @@ -83,6 +90,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.RETURN; | ... | @@ -83,6 +90,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
83 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; | 90 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
84 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 91 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
85 | import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; | 92 | import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; |
93 | +import static org.onosproject.yangutils.utils.UtilConstants.SHORT; | ||
86 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; | 94 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; |
87 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 95 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
88 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; | 96 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
... | @@ -241,11 +249,12 @@ public final class MethodsGenerator { | ... | @@ -241,11 +249,12 @@ public final class MethodsGenerator { |
241 | * @return getter for attribute | 249 | * @return getter for attribute |
242 | */ | 250 | */ |
243 | public static String getGetter(String type, String name, int generatedJavaFiles) { | 251 | public static String getGetter(String type, String name, int generatedJavaFiles) { |
252 | + String ret = parseTypeForGetter(type); | ||
244 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { | 253 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
245 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) | 254 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) |
246 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + | 255 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
247 | EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION + | 256 | EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION + |
248 | - RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 257 | + RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
249 | } else { | 258 | } else { |
250 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name | 259 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name |
251 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + | 260 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
... | @@ -255,6 +264,21 @@ public final class MethodsGenerator { | ... | @@ -255,6 +264,21 @@ public final class MethodsGenerator { |
255 | 264 | ||
256 | } | 265 | } |
257 | 266 | ||
267 | + /*Provides string to return for type.*/ | ||
268 | + private static String parseTypeForGetter(String type) { | ||
269 | + switch (type) { | ||
270 | + case BYTE: | ||
271 | + case INT: | ||
272 | + case SHORT: | ||
273 | + case LONG: | ||
274 | + return "0"; | ||
275 | + case BOOLEAN_DATA_TYPE: | ||
276 | + return FALSE; | ||
277 | + default: | ||
278 | + return null; | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
258 | /** | 282 | /** |
259 | * Returns the setter method strings for class file. | 283 | * Returns the setter method strings for class file. |
260 | * | 284 | * |
... | @@ -524,8 +548,7 @@ public final class MethodsGenerator { | ... | @@ -524,8 +548,7 @@ public final class MethodsGenerator { |
524 | outputName = getCapitalCase(outputName); | 548 | outputName = getCapitalCase(outputName); |
525 | } | 549 | } |
526 | 550 | ||
527 | - String method = | 551 | + String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName |
528 | - getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName | ||
529 | + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE | 552 | + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE |
530 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; | 553 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; |
531 | if (!outputName.contentEquals(VOID)) { | 554 | if (!outputName.contentEquals(VOID)) { |
... | @@ -805,22 +828,6 @@ public final class MethodsGenerator { | ... | @@ -805,22 +828,6 @@ public final class MethodsGenerator { |
805 | } | 828 | } |
806 | 829 | ||
807 | /** | 830 | /** |
808 | - * Returns implementation of add augmentation method of HasAugmentation class. | ||
809 | - * | ||
810 | - * @return implementation of add augmentation method of HasAugmentation class | ||
811 | - */ | ||
812 | - public static String getAddAugmentInfoMethodImpl() { | ||
813 | - String method = FOUR_SPACE_INDENTATION; | ||
814 | - method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING | ||
815 | - + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE | ||
816 | - + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST | ||
817 | - + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE | ||
818 | - + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
819 | - | ||
820 | - return method; | ||
821 | - } | ||
822 | - | ||
823 | - /** | ||
824 | * Returns of method's string and java doc for special type. | 831 | * Returns of method's string and java doc for special type. |
825 | * | 832 | * |
826 | * @param attr attribute info | 833 | * @param attr attribute info |
... | @@ -884,9 +891,25 @@ public final class MethodsGenerator { | ... | @@ -884,9 +891,25 @@ public final class MethodsGenerator { |
884 | } | 891 | } |
885 | 892 | ||
886 | /** | 893 | /** |
887 | - * Returns implementation of get augment info list method of HasAugmentation class. | 894 | + * Returns implementation of add augmentation method of AugmentationHolder class. |
888 | * | 895 | * |
889 | - * @return implementation of get augment info list method of HasAugmentation class | 896 | + * @return implementation of add augmentation method of AugmentationHolder class |
897 | + */ | ||
898 | + public static String getAddAugmentInfoMethodImpl() { | ||
899 | + String method = FOUR_SPACE_INDENTATION; | ||
900 | + method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING | ||
901 | + + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE | ||
902 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST | ||
903 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE | ||
904 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
905 | + | ||
906 | + return method; | ||
907 | + } | ||
908 | + | ||
909 | + /** | ||
910 | + * Returns implementation of get augment info list method of AugmentationHolder class. | ||
911 | + * | ||
912 | + * @return implementation of get augment info list method of AugmentationHolder class | ||
890 | */ | 913 | */ |
891 | public static String getAugmentInfoListImpl() { | 914 | public static String getAugmentInfoListImpl() { |
892 | 915 | ||
... | @@ -900,9 +923,9 @@ public final class MethodsGenerator { | ... | @@ -900,9 +923,9 @@ public final class MethodsGenerator { |
900 | } | 923 | } |
901 | 924 | ||
902 | /** | 925 | /** |
903 | - * Returns implementation of remove augmentation method of HasAugmentation class. | 926 | + * Returns implementation of remove augmentation method of AugmentationHolder class. |
904 | * | 927 | * |
905 | - * @return implementation of remove augmentation method of HasAugmentation class | 928 | + * @return implementation of remove augmentation method of AugmentationHolder class |
906 | */ | 929 | */ |
907 | public static String getRemoveAugmentationImpl() { | 930 | public static String getRemoveAugmentationImpl() { |
908 | String method = FOUR_SPACE_INDENTATION; | 931 | String method = FOUR_SPACE_INDENTATION; |
... | @@ -927,6 +950,36 @@ public final class MethodsGenerator { | ... | @@ -927,6 +950,36 @@ public final class MethodsGenerator { |
927 | } | 950 | } |
928 | 951 | ||
929 | /** | 952 | /** |
953 | + * Provides string to be added in augment node's constructor. | ||
954 | + * | ||
955 | + * @param curNode current YANG node | ||
956 | + * @return constructors string | ||
957 | + */ | ||
958 | + public static String getAugmentsAddToAugmentedMethod(YangNode curNode) { | ||
959 | + | ||
960 | + if (!(curNode instanceof YangJavaAugment)) { | ||
961 | + throw new TranslatorException("current node should be of type augment node."); | ||
962 | + } | ||
963 | + YangJavaAugment augment = (YangJavaAugment) curNode; | ||
964 | + List<YangNodeIdentifier> targetNodes = augment.getTargetNode(); | ||
965 | + | ||
966 | + String name = targetNodes.get(targetNodes.size() - 1).getName(); | ||
967 | + String captialCase = getCapitalCase(name); | ||
968 | + String smallCase = getSmallCase(captialCase); | ||
969 | + return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE | ||
970 | + + NEW + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE | ||
971 | + + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE | ||
972 | + + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION | ||
973 | + + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
974 | + | ||
975 | + } | ||
976 | + | ||
977 | + private static String getAugmentsAddToAugmentedMethodStart() { | ||
978 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING + AUGMENTABLE + OPEN_PARENTHESIS | ||
979 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET; | ||
980 | + } | ||
981 | + | ||
982 | + /** | ||
930 | * Returns of method for enum class. | 983 | * Returns of method for enum class. |
931 | * | 984 | * |
932 | * @param className class name | 985 | * @param className class name | ... | ... |
... | @@ -21,18 +21,38 @@ import java.io.IOException; | ... | @@ -21,18 +21,38 @@ import java.io.IOException; |
21 | import java.util.List; | 21 | import java.util.List; |
22 | 22 | ||
23 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
24 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
25 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
25 | -import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer; | ||
26 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 27 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
28 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
29 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | ||
30 | +import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; | ||
31 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; | ||
32 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | ||
27 | 33 | ||
28 | import static java.util.Collections.sort; | 34 | import static java.util.Collections.sort; |
29 | 35 | ||
30 | -import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport; | 36 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
31 | -import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport; | 37 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
32 | -import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForArrayList; | 38 | +import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
33 | -import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForList; | 39 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
40 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
35 | -import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | 42 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
43 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW; | ||
50 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
51 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | ||
52 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
53 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
54 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.THIS; | ||
36 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | 56 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; |
37 | 57 | ||
38 | /** | 58 | /** |
... | @@ -47,21 +67,16 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -47,21 +67,16 @@ public final class TempJavaCodeFragmentFilesUtils { |
47 | } | 67 | } |
48 | 68 | ||
49 | /** | 69 | /** |
50 | - * Adds import for HasAugmentation class. | 70 | + * Adds import for AugmentationHolders class. |
51 | * | 71 | * |
52 | * @param curNode current YANG node | 72 | * @param curNode current YANG node |
53 | * @param imports list of imports | 73 | * @param imports list of imports |
54 | * @param operation add or delete import | 74 | * @param operation add or delete import |
55 | - * @return import for HasAugmentation class | ||
56 | */ | 75 | */ |
57 | - public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, | 76 | + public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) { |
58 | - boolean operation) { | 77 | + String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport(); |
59 | - if (curNode instanceof JavaImportDataContainer) { | ||
60 | - String thisImport = getHasAugmentationImport(); | ||
61 | performOperationOnImports(imports, thisImport, operation); | 78 | performOperationOnImports(imports, thisImport, operation); |
62 | } | 79 | } |
63 | - return imports; | ||
64 | - } | ||
65 | 80 | ||
66 | /** | 81 | /** |
67 | * Adds import for AugmentedInfo class. | 82 | * Adds import for AugmentedInfo class. |
... | @@ -69,14 +84,113 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -69,14 +84,113 @@ public final class TempJavaCodeFragmentFilesUtils { |
69 | * @param curNode current YANG node | 84 | * @param curNode current YANG node |
70 | * @param imports list of imports | 85 | * @param imports list of imports |
71 | * @param operation add or delete import | 86 | * @param operation add or delete import |
72 | - * @return import for AugmentedInfo class | ||
73 | */ | 87 | */ |
74 | - public static List<String> addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) { | 88 | + public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) { |
75 | - if (curNode instanceof JavaImportDataContainer) { | 89 | + String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport(); |
76 | - String thisImport = getAugmentedInfoImport(); | ||
77 | performOperationOnImports(imports, thisImport, operation); | 90 | performOperationOnImports(imports, thisImport, operation); |
78 | } | 91 | } |
79 | - return imports; | 92 | + |
93 | + /** | ||
94 | + * Returns temp java fragment. | ||
95 | + * | ||
96 | + * @param curNode current YANG node | ||
97 | + * @return temp java fragments | ||
98 | + */ | ||
99 | + public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) { | ||
100 | + TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode) | ||
101 | + .getTempJavaCodeFragmentFiles(); | ||
102 | + if (container.getBeanTempFiles() != null) { | ||
103 | + return container.getBeanTempFiles(); | ||
104 | + } | ||
105 | + if (container.getEventTempFiles() != null) { | ||
106 | + return container.getEventTempFiles(); | ||
107 | + } | ||
108 | + if (container.getEventListenerTempFiles() != null) { | ||
109 | + return container.getEventListenerTempFiles(); | ||
110 | + } | ||
111 | + if (container.getServiceTempFiles() != null) { | ||
112 | + return container.getServiceTempFiles(); | ||
113 | + } | ||
114 | + | ||
115 | + return null; | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Updated imports with augmented nodes import. | ||
120 | + * | ||
121 | + * @param curNode current YANG node | ||
122 | + * @param imports list of imports | ||
123 | + * @param operation to add or to delete | ||
124 | + */ | ||
125 | + public static void addAugmentedNodesImport(YangNode curNode, List<String> imports, boolean operation) { | ||
126 | + | ||
127 | + String nodesImport = ""; | ||
128 | + | ||
129 | + if (!(curNode instanceof YangJavaAugment)) { | ||
130 | + throw new TranslatorException("current node should be of type augment node."); | ||
131 | + } | ||
132 | + YangJavaAugment augment = (YangJavaAugment) curNode; | ||
133 | + List<YangNodeIdentifier> targetNodes = augment.getTargetNode(); | ||
134 | + YangNode parent = curNode.getParent(); | ||
135 | + if (parent instanceof YangJavaModule) { | ||
136 | + // Add impl class import. | ||
137 | + nodesImport = getAugmendtedNodesImports(parent, targetNodes, true) + SEMI_COLAN + NEW_LINE; | ||
138 | + performOperationOnImports(imports, nodesImport, operation); | ||
139 | + // Add builder class import. | ||
140 | + if (targetNodes.size() > 2) { | ||
141 | + nodesImport = getAugmendtedNodesImports(parent, targetNodes, false) + SEMI_COLAN + NEW_LINE; | ||
142 | + performOperationOnImports(imports, nodesImport, operation); | ||
143 | + } | ||
144 | + } | ||
145 | + // TODO: add functionality for submodule and uses. | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Returns imports for augmented node. | ||
150 | + * | ||
151 | + * @param parent parent YANG node | ||
152 | + * @param targetNodes list of target nodes | ||
153 | + * @param isImplClass if impl class's import required | ||
154 | + * @return imports for augmented node | ||
155 | + */ | ||
156 | + private static String getAugmendtedNodesImports(YangNode parent, List<YangNodeIdentifier> targetNodes, | ||
157 | + boolean isImplClass) { | ||
158 | + String pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); | ||
159 | + | ||
160 | + for (int i = 0; i < targetNodes.size() - 1; i++) { | ||
161 | + pkgInfo = pkgInfo + PERIOD + targetNodes.get(i).getName(); | ||
162 | + } | ||
163 | + String classInfo = targetNodes.get(targetNodes.size() - 1).getName(); | ||
164 | + if (!isImplClass) { | ||
165 | + return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER; | ||
166 | + } | ||
167 | + return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER + PERIOD | ||
168 | + + getCapitalCase(classInfo) + IMPL; | ||
169 | + } | ||
170 | + | ||
171 | + /** | ||
172 | + * Provides string to be added in augment node's constructor. | ||
173 | + * | ||
174 | + * @param curNode current YANG node | ||
175 | + * @return constructors string | ||
176 | + */ | ||
177 | + public static String getAugmentsAddToAugmentedClassString(YangNode curNode) { | ||
178 | + | ||
179 | + if (!(curNode instanceof YangJavaAugment)) { | ||
180 | + throw new TranslatorException("current node should be of type augment node."); | ||
181 | + } | ||
182 | + YangJavaAugment augment = (YangJavaAugment) curNode; | ||
183 | + List<YangNodeIdentifier> targetNodes = augment.getTargetNode(); | ||
184 | + | ||
185 | + String name = targetNodes.get(targetNodes.size() - 1).getName(); | ||
186 | + String captialCase = getCapitalCase(name); | ||
187 | + String smallCase = getSmallCase(captialCase); | ||
188 | + return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE + NEW | ||
189 | + + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE | ||
190 | + + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE | ||
191 | + + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION + OPEN_PARENTHESIS | ||
192 | + + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
193 | + | ||
80 | } | 194 | } |
81 | 195 | ||
82 | /** | 196 | /** |
... | @@ -85,12 +199,10 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -85,12 +199,10 @@ public final class TempJavaCodeFragmentFilesUtils { |
85 | * @param curNode current YANG node | 199 | * @param curNode current YANG node |
86 | * @param imports list of imports | 200 | * @param imports list of imports |
87 | * @param operation add or delete import | 201 | * @param operation add or delete import |
88 | - * @return import for HasAugmentation class | ||
89 | */ | 202 | */ |
90 | - public static List<String> addArrayListImport(YangNode curNode, List<String> imports, boolean operation) { | 203 | + public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) { |
91 | - if (curNode instanceof JavaImportDataContainer) { | 204 | + String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList(); |
92 | - String arrayListImport = getImportForArrayList(); | 205 | + String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList(); |
93 | - String listImport = getImportForList(); | ||
94 | performOperationOnImports(imports, arrayListImport, operation); | 206 | performOperationOnImports(imports, arrayListImport, operation); |
95 | if (!imports.contains(listImport)) { | 207 | if (!imports.contains(listImport)) { |
96 | /** | 208 | /** |
... | @@ -101,7 +213,24 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -101,7 +213,24 @@ public final class TempJavaCodeFragmentFilesUtils { |
101 | } | 213 | } |
102 | } | 214 | } |
103 | 215 | ||
104 | - return imports; | 216 | + /** |
217 | + * Adds listener's imports. | ||
218 | + * | ||
219 | + * @param curNode currentYangNode. | ||
220 | + * @param imports import list | ||
221 | + * @param operation add or remove | ||
222 | + * @param classInfo class info to be added to import list | ||
223 | + */ | ||
224 | + public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation, | ||
225 | + String classInfo) { | ||
226 | + String thisImport = ""; | ||
227 | + if (classInfo.equals(LISTENER_SERVICE)) { | ||
228 | + thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport(); | ||
229 | + performOperationOnImports(imports, thisImport, operation); | ||
230 | + } else { | ||
231 | + thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport(); | ||
232 | + performOperationOnImports(imports, thisImport, operation); | ||
233 | + } | ||
105 | } | 234 | } |
106 | 235 | ||
107 | /** | 236 | /** |
... | @@ -124,29 +253,16 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -124,29 +253,16 @@ public final class TempJavaCodeFragmentFilesUtils { |
124 | } | 253 | } |
125 | 254 | ||
126 | /** | 255 | /** |
127 | - * Prepares java file generator for extends list. | 256 | + * Returns true if AugmentationHolder class needs to be extended. |
128 | - * | ||
129 | - * @param extendsList list of classes need to be extended | ||
130 | - */ | ||
131 | - public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) { | ||
132 | - | ||
133 | - if (extendsList != null && !extendsList.isEmpty()) { | ||
134 | - JavaFileGenerator.setExtendsList(extendsList); | ||
135 | - JavaFileGenerator.setIsExtendsList(true); | ||
136 | - } else { | ||
137 | - JavaFileGenerator.getExtendsList().clear(); | ||
138 | - JavaFileGenerator.setIsExtendsList(false); | ||
139 | - } | ||
140 | - } | ||
141 | - | ||
142 | - /** | ||
143 | - * Returns true if HasAugmentation class needs to be extended. | ||
144 | * | 257 | * |
145 | * @param extendsList list of classes need to be extended | 258 | * @param extendsList list of classes need to be extended |
146 | * @return true or false | 259 | * @return true or false |
147 | */ | 260 | */ |
148 | - public static boolean isHasAugmentationExtended(List<String> extendsList) { | 261 | + public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) { |
149 | - return extendsList != null && extendsList.contains(HAS_AUGMENTATION); | 262 | + for (JavaQualifiedTypeInfo info : extendsList) { |
263 | + return info.getClassInfo().equals(AUGMENTATION_HOLDER); | ||
264 | + } | ||
265 | + return false; | ||
150 | } | 266 | } |
151 | 267 | ||
152 | /** | 268 | /** |
... | @@ -155,8 +271,11 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -155,8 +271,11 @@ public final class TempJavaCodeFragmentFilesUtils { |
155 | * @param extendsList list of classes need to be extended | 271 | * @param extendsList list of classes need to be extended |
156 | * @return true or false | 272 | * @return true or false |
157 | */ | 273 | */ |
158 | - public static boolean isAugmentedInfoExtended(List<String> extendsList) { | 274 | + public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) { |
159 | - return extendsList != null && extendsList.contains(AUGMENTED_INFO); | 275 | + for (JavaQualifiedTypeInfo info : extendsList) { |
276 | + return info.getClassInfo().equals(AUGMENTED_INFO); | ||
277 | + } | ||
278 | + return false; | ||
160 | } | 279 | } |
161 | 280 | ||
162 | /** | 281 | /** |
... | @@ -190,7 +309,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -190,7 +309,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
190 | JavaQualifiedTypeInfo qualifiedTypeInfo) { | 309 | JavaQualifiedTypeInfo qualifiedTypeInfo) { |
191 | 310 | ||
192 | YangNode parent = curNode.getParent(); | 311 | YangNode parent = curNode.getParent(); |
193 | - String parentsClassInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); | 312 | + String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); |
194 | String childsClassInfo = qualifiedTypeInfo.getClassInfo(); | 313 | String childsClassInfo = qualifiedTypeInfo.getClassInfo(); |
195 | if (childsClassInfo.equals(parentsClassInfo)) { | 314 | if (childsClassInfo.equals(parentsClassInfo)) { |
196 | return true; | 315 | return true; | ... | ... |
... | @@ -20,18 +20,15 @@ import java.io.IOException; | ... | @@ -20,18 +20,15 @@ import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; | 21 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; |
22 | import org.onosproject.yangutils.datamodel.YangAugment; | 22 | import org.onosproject.yangutils.datamodel.YangAugment; |
23 | +import org.onosproject.yangutils.datamodel.YangAugmentationHolder; | ||
23 | import org.onosproject.yangutils.datamodel.YangCase; | 24 | import org.onosproject.yangutils.datamodel.YangCase; |
24 | import org.onosproject.yangutils.datamodel.YangChoice; | 25 | import org.onosproject.yangutils.datamodel.YangChoice; |
25 | -import org.onosproject.yangutils.datamodel.YangContainer; | ||
26 | -import org.onosproject.yangutils.datamodel.YangInput; | ||
27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
28 | -import org.onosproject.yangutils.datamodel.YangList; | ||
29 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
30 | -import org.onosproject.yangutils.datamodel.YangNotification; | ||
31 | -import org.onosproject.yangutils.datamodel.YangOutput; | ||
32 | import org.onosproject.yangutils.datamodel.YangTypeHolder; | 28 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
33 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 29 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
34 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 30 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
31 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
35 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 32 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
36 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 33 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
37 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; | 34 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; |
... | @@ -40,12 +37,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChil | ... | @@ -40,12 +37,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChil |
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
41 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; | 38 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; |
42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 39 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
43 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 40 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 41 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
42 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; | ||
46 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
47 | -import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | 44 | +import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG; |
48 | -import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
49 | 45 | ||
50 | /** | 46 | /** |
51 | * Represents utility class for YANG java model. | 47 | * Represents utility class for YANG java model. |
... | @@ -118,14 +114,14 @@ public final class YangJavaModelUtils { | ... | @@ -118,14 +114,14 @@ public final class YangJavaModelUtils { |
118 | YangPluginConfig yangPluginConfig) | 114 | YangPluginConfig yangPluginConfig) |
119 | throws IOException { | 115 | throws IOException { |
120 | if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) { | 116 | if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) { |
121 | - /** | 117 | + /* |
122 | * Module / sub module node code generation. | 118 | * Module / sub module node code generation. |
123 | */ | 119 | */ |
124 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 120 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
125 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( | 121 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( |
126 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); | 122 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
127 | } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { | 123 | } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { |
128 | - /** | 124 | + /* |
129 | * Container | 125 | * Container |
130 | * Case | 126 | * Case |
131 | * Grouping | 127 | * Grouping |
... | @@ -138,14 +134,14 @@ public final class YangJavaModelUtils { | ... | @@ -138,14 +134,14 @@ public final class YangJavaModelUtils { |
138 | .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles( | 134 | .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles( |
139 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); | 135 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
140 | } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) { | 136 | } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) { |
141 | - /** | 137 | + /* |
142 | * Typedef | 138 | * Typedef |
143 | * Union | 139 | * Union |
144 | */ | 140 | */ |
145 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 141 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
146 | .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo); | 142 | .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo); |
147 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { | 143 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { |
148 | - /** | 144 | + /* |
149 | * Enumeration | 145 | * Enumeration |
150 | */ | 146 | */ |
151 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() | 147 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() |
... | @@ -189,12 +185,12 @@ public final class YangJavaModelUtils { | ... | @@ -189,12 +185,12 @@ public final class YangJavaModelUtils { |
189 | throw new TranslatorException("Invalid node for translation"); | 185 | throw new TranslatorException("Invalid node for translation"); |
190 | } | 186 | } |
191 | 187 | ||
192 | - /** | 188 | + /* |
193 | * Generate the Java files corresponding to the current node. | 189 | * Generate the Java files corresponding to the current node. |
194 | */ | 190 | */ |
195 | generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin); | 191 | generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin); |
196 | 192 | ||
197 | - /** | 193 | + /* |
198 | * Update the current nodes info in its parent nodes generated files. | 194 | * Update the current nodes info in its parent nodes generated files. |
199 | */ | 195 | */ |
200 | addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | 196 | addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); |
... | @@ -216,34 +212,38 @@ public final class YangJavaModelUtils { | ... | @@ -216,34 +212,38 @@ public final class YangJavaModelUtils { |
216 | 212 | ||
217 | generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin); | 213 | generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin); |
218 | 214 | ||
219 | - /** | 215 | + /* |
220 | * For augmentation of nodes. | 216 | * For augmentation of nodes. |
221 | */ | 217 | */ |
222 | - if (javaCodeGeneratorInfo instanceof YangContainer | 218 | + if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) { |
223 | - || javaCodeGeneratorInfo instanceof YangCase | 219 | + JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo(); |
224 | - || javaCodeGeneratorInfo instanceof YangChoice | 220 | + augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER); |
225 | - || javaCodeGeneratorInfo instanceof YangInput | 221 | + augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG); |
226 | - || javaCodeGeneratorInfo instanceof YangList | 222 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() |
227 | - || javaCodeGeneratorInfo instanceof YangNotification | 223 | + .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo); |
228 | - || javaCodeGeneratorInfo instanceof YangOutput) { | 224 | + |
229 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(HAS_AUGMENTATION); | ||
230 | } else if (javaCodeGeneratorInfo instanceof YangAugment) { | 225 | } else if (javaCodeGeneratorInfo instanceof YangAugment) { |
231 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO); | 226 | + JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo(); |
227 | + augmentedInfo.setClassInfo(AUGMENTED_INFO); | ||
228 | + augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG); | ||
229 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() | ||
230 | + .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo); | ||
231 | + | ||
232 | } | 232 | } |
233 | 233 | ||
234 | if (javaCodeGeneratorInfo instanceof YangCase) { | 234 | if (javaCodeGeneratorInfo instanceof YangCase) { |
235 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); | 235 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); |
236 | - String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName(); | 236 | + JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo(); |
237 | - if (!parent.getName().equals(curNodeName)) { | 237 | + String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); |
238 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCapitalCase(getCamelCase( | 238 | + String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); |
239 | - parent.getName(), null))); | 239 | + parentsInfo.setClassInfo(parentName); |
240 | + parentsInfo.setPkgInfo(parentPkg); | ||
241 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() | ||
242 | + .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo); | ||
243 | + | ||
240 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() | 244 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() |
241 | .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo); | 245 | .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo); |
242 | - } else { | 246 | + |
243 | - String parentPackage = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); | ||
244 | - String caseExtendInfo = parentPackage + PERIOD + parent.getName(); | ||
245 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(caseExtendInfo); | ||
246 | - } | ||
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ... | ... |
... | @@ -242,6 +242,21 @@ public final class UtilConstants { | ... | @@ -242,6 +242,21 @@ public final class UtilConstants { |
242 | public static final String SPACE = " "; | 242 | public static final String SPACE = " "; |
243 | 243 | ||
244 | /** | 244 | /** |
245 | + * Static attribute for ListenerRegistry. | ||
246 | + */ | ||
247 | + public static final String LISTENER_REG = "ListenerRegistry"; | ||
248 | + | ||
249 | + /** | ||
250 | + * Static attribute for ListenerService. | ||
251 | + */ | ||
252 | + public static final String LISTENER_SERVICE = "ListenerService"; | ||
253 | + | ||
254 | + /** | ||
255 | + * Static attribute for listener package. | ||
256 | + */ | ||
257 | + public static final String LISTENER_PKG = "org.onosproject.event"; | ||
258 | + | ||
259 | + /** | ||
245 | * Static attribute for input string. | 260 | * Static attribute for input string. |
246 | */ | 261 | */ |
247 | public static final String INPUT = "input"; | 262 | public static final String INPUT = "input"; |
... | @@ -862,14 +877,15 @@ public final class UtilConstants { | ... | @@ -862,14 +877,15 @@ public final class UtilConstants { |
862 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; | 877 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; |
863 | 878 | ||
864 | /** | 879 | /** |
865 | - * Static attribute for HasAugmentation class import package. | 880 | + * Static attribute for AugmentationHolder class import package. |
866 | */ | 881 | */ |
867 | - public static final String HAS_AUGMENTATION_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava"; | 882 | + public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG = |
883 | + "org.onosproject.yangutils.translator.tojava"; | ||
868 | 884 | ||
869 | /** | 885 | /** |
870 | - * Static attribute for HasAugmentation class import class. | 886 | + * Static attribute for AugmentationHolder class import class. |
871 | */ | 887 | */ |
872 | - public static final String HAS_AUGMENTATION_CLASS_IMPORT_CLASS = "HasAugmentation;\n"; | 888 | + public static final String AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS = "AugmentationHolder;\n"; |
873 | 889 | ||
874 | /** | 890 | /** |
875 | * Static attribute for AugmentedInfo class import package. | 891 | * Static attribute for AugmentedInfo class import package. |
... | @@ -887,9 +903,9 @@ public final class UtilConstants { | ... | @@ -887,9 +903,9 @@ public final class UtilConstants { |
887 | public static final String AUGMENTATION = "Augmentation"; | 903 | public static final String AUGMENTATION = "Augmentation"; |
888 | 904 | ||
889 | /** | 905 | /** |
890 | - * Static attribute for HasAugmentation class. | 906 | + * Static attribute for AugmentationHolder class. |
891 | */ | 907 | */ |
892 | - public static final String HAS_AUGMENTATION = "HasAugmentation"; | 908 | + public static final String AUGMENTATION_HOLDER = "AugmentationHolder"; |
893 | 909 | ||
894 | /** | 910 | /** |
895 | * Static attribute for AugmentedInfo class. | 911 | * Static attribute for AugmentedInfo class. |
... | @@ -897,6 +913,10 @@ public final class UtilConstants { | ... | @@ -897,6 +913,10 @@ public final class UtilConstants { |
897 | public static final String AUGMENTED_INFO = "AugmentedInfo"; | 913 | public static final String AUGMENTED_INFO = "AugmentedInfo"; |
898 | 914 | ||
899 | /** | 915 | /** |
916 | + * Static attribute for augmentable. | ||
917 | + */ | ||
918 | + public static final String AUGMENTABLE = "Augmentable"; | ||
919 | + /** | ||
900 | * Static attribute for list. | 920 | * Static attribute for list. |
901 | */ | 921 | */ |
902 | public static final String LIST = "List"; | 922 | public static final String LIST = "List"; | ... | ... |
... | @@ -21,15 +21,15 @@ import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ... | @@ -21,15 +21,15 @@ import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
21 | 21 | ||
22 | import static org.hamcrest.core.Is.is; | 22 | import static org.hamcrest.core.Is.is; |
23 | import static org.junit.Assert.assertThat; | 23 | import static org.junit.Assert.assertThat; |
24 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount; | 24 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.clearOccurrenceCount; |
25 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment; | 25 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.createValidNameForAugment; |
26 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.getAugmentJavaFileNameList; | 26 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getAugmentJavaFileNameList; |
27 | -import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence; | 27 | +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.updateNameWhenHasMultipleOuccrrence; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | - * Unit test case for augment java file name generator utility. | 30 | + * Unit test case for augment listener utility. |
31 | */ | 31 | */ |
32 | -public class AugmentJavaFileNameGenUtilTest { | 32 | +public class AugmentListnerUtilTest { |
33 | 33 | ||
34 | private static final String TEST1 = "test1Node"; | 34 | private static final String TEST1 = "test1Node"; |
35 | private static final String PARENT_PREFIX = "if"; | 35 | private static final String PARENT_PREFIX = "if"; | ... | ... |
... | @@ -44,7 +44,7 @@ public final class ChoiceCaseTranslatorTest { | ... | @@ -44,7 +44,7 @@ public final class ChoiceCaseTranslatorTest { |
44 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 44 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
45 | yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); | 45 | yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); |
46 | 46 | ||
47 | - generateJavaCode(node, yangPluginConfig); | 47 | + generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator"); |
48 | 48 | ||
49 | deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/"); | 49 | deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/"); |
50 | } | 50 | } | ... | ... |
... | @@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
31 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
32 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
33 | 32 | ||
34 | /** | 33 | /** |
... | @@ -55,7 +54,8 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -55,7 +54,8 @@ public final class ClassDefinitionGeneratorTest { |
55 | * @throws InvocationTargetException when an exception occurs by the method or constructor | 54 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
56 | */ | 55 | */ |
57 | @Test | 56 | @Test |
58 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 57 | + public void callPrivateConstructors() |
58 | + throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
59 | InstantiationException, IllegalAccessException, InvocationTargetException { | 59 | InstantiationException, IllegalAccessException, InvocationTargetException { |
60 | 60 | ||
61 | Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class }; | 61 | Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class }; |
... | @@ -98,8 +98,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -98,8 +98,7 @@ public final class ClassDefinitionGeneratorTest { |
98 | */ | 98 | */ |
99 | @Test | 99 | @Test |
100 | public void generateinterfaceDefinitionTest() { | 100 | public void generateinterfaceDefinitionTest() { |
101 | - String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); | 101 | + // TODO: need to add this test case. |
102 | - assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF))); | ||
103 | } | 102 | } |
104 | 103 | ||
105 | /** | 104 | /** | ... | ... |
... | @@ -46,7 +46,7 @@ public final class EnumTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class EnumTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig); | 49 | + generateJavaCode(node, yangPluginConfig, "EnumTranslator"); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/EnumTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/EnumTestGenFile/"); |
52 | } | 52 | } | ... | ... |
... | @@ -25,24 +25,18 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ... | @@ -25,24 +25,18 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
25 | import static org.hamcrest.MatcherAssert.assertThat; | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
26 | import static org.hamcrest.core.Is.is; | 26 | import static org.hamcrest.core.Is.is; |
27 | import static org.hamcrest.core.IsNot.not; | 27 | import static org.hamcrest.core.IsNot.not; |
28 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; |
30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
37 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
38 | -import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
39 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
42 | -import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
43 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
44 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
45 | -import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
46 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
47 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
48 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
... | @@ -54,7 +48,6 @@ public class JavaCodeSnippetGenTest { | ... | @@ -54,7 +48,6 @@ public class JavaCodeSnippetGenTest { |
54 | 48 | ||
55 | private static final String PKG_INFO = "org.onosproject.unittest"; | 49 | private static final String PKG_INFO = "org.onosproject.unittest"; |
56 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; | 50 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; |
57 | - private static final int FILE_GEN_TYPE = INTERFACE_MASK; | ||
58 | private static final String YANG_NAME = "Test"; | 51 | private static final String YANG_NAME = "Test"; |
59 | 52 | ||
60 | /** | 53 | /** |
... | @@ -68,7 +61,8 @@ public class JavaCodeSnippetGenTest { | ... | @@ -68,7 +61,8 @@ public class JavaCodeSnippetGenTest { |
68 | * @throws InvocationTargetException when an exception occurs by the method or constructor | 61 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
69 | */ | 62 | */ |
70 | @Test | 63 | @Test |
71 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 64 | + public void callPrivateConstructors() |
65 | + throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
72 | InstantiationException, IllegalAccessException, InvocationTargetException { | 66 | InstantiationException, IllegalAccessException, InvocationTargetException { |
73 | 67 | ||
74 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; | 68 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; |
... | @@ -94,26 +88,6 @@ public class JavaCodeSnippetGenTest { | ... | @@ -94,26 +88,6 @@ public class JavaCodeSnippetGenTest { |
94 | } | 88 | } |
95 | 89 | ||
96 | /** | 90 | /** |
97 | - * Unit test case for java class definition start. | ||
98 | - */ | ||
99 | - @Test | ||
100 | - public void testForJavaClassDefStart() { | ||
101 | - String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); | ||
102 | - assertThat(true, is(classDef | ||
103 | - .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * Unit test case for list attribute. | ||
108 | - */ | ||
109 | - @Test | ||
110 | - public void testForListAttribute() { | ||
111 | - String listAttribute = getListAttribute(STRING_DATA_TYPE); | ||
112 | - assertThat(true, | ||
113 | - is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET))); | ||
114 | - } | ||
115 | - | ||
116 | - /** | ||
117 | * Unit test case for java class interface definition close. | 91 | * Unit test case for java class interface definition close. |
118 | */ | 92 | */ |
119 | @Test | 93 | @Test | ... | ... |
... | @@ -46,7 +46,7 @@ public final class NotificationTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class NotificationTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig); | 49 | + generateJavaCode(node, yangPluginConfig, "NotificationTest"); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/NotificationTest/"); | 51 | deleteDirectory(userDir + "/target/NotificationTest/"); |
52 | } | 52 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public final class RpcTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class RpcTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig); | 49 | + generateJavaCode(node, yangPluginConfig, "RpcTranslator"); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/RpcTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/RpcTestGenFile/"); |
52 | } | 52 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public final class UnionTranslatorTest { | ... | @@ -46,7 +46,7 @@ public final class UnionTranslatorTest { |
46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); | 46 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
47 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); | 47 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); |
48 | 48 | ||
49 | - generateJavaCode(node, yangPluginConfig); | 49 | + generateJavaCode(node, yangPluginConfig, "UnionTranslator"); |
50 | 50 | ||
51 | deleteDirectory(userDir + "/target/UnionTestGenFile/"); | 51 | deleteDirectory(userDir + "/target/UnionTestGenFile/"); |
52 | } | 52 | } | ... | ... |
-
Please register or login to post a comment