Committed by
Gerrit Code Review
Optimizing Generate Code Function in Translator and updating enum/union to suppo…
…rt a special hierarchical scenario Change-Id: I14a971ff6fcda6ae5e86ffe4c11d17a844e371ce
Showing
20 changed files
with
442 additions
and
365 deletions
... | @@ -31,18 +31,19 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -31,18 +31,19 @@ import org.onosproject.yangutils.utils.YangConstructType; |
31 | /** | 31 | /** |
32 | * Represents the enumeration data type information. | 32 | * Represents the enumeration data type information. |
33 | */ | 33 | */ |
34 | -public class YangEnumeration implements Parsable { | 34 | +public class YangEnumeration extends YangNode implements Parsable { |
35 | 35 | ||
36 | // Enumeration info set. | 36 | // Enumeration info set. |
37 | private Set<YangEnum> enumSet; | 37 | private Set<YangEnum> enumSet; |
38 | 38 | ||
39 | // Enumeration name. | 39 | // Enumeration name. |
40 | - private String enumerationName; | 40 | + private String name; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Creates an enumeration object. | 43 | * Creates an enumeration object. |
44 | */ | 44 | */ |
45 | public YangEnumeration() { | 45 | public YangEnumeration() { |
46 | + super(YangNodeType.ENUMERATION_NODE); | ||
46 | setEnumSet(new HashSet<YangEnum>()); | 47 | setEnumSet(new HashSet<YangEnum>()); |
47 | } | 48 | } |
48 | 49 | ||
... | @@ -77,21 +78,23 @@ public class YangEnumeration implements Parsable { | ... | @@ -77,21 +78,23 @@ public class YangEnumeration implements Parsable { |
77 | } | 78 | } |
78 | 79 | ||
79 | /** | 80 | /** |
80 | - * Return enumeration name. | 81 | + * Returns enumeration name. |
81 | * | 82 | * |
82 | * @return the enumeration name | 83 | * @return the enumeration name |
83 | */ | 84 | */ |
84 | - public String getEnumerationName() { | 85 | + @Override |
85 | - return enumerationName; | 86 | + public String getName() { |
87 | + return name; | ||
86 | } | 88 | } |
87 | 89 | ||
88 | /** | 90 | /** |
89 | * Sets the enumeration name. | 91 | * Sets the enumeration name. |
90 | * | 92 | * |
91 | - * @param enumerationName enumeration name | 93 | + * @param name enumeration name |
92 | */ | 94 | */ |
93 | - public void setEnumerationName(String enumerationName) { | 95 | + @Override |
94 | - this.enumerationName = enumerationName; | 96 | + public void setName(String name) { |
97 | + this.name = name; | ||
95 | } | 98 | } |
96 | 99 | ||
97 | /** | 100 | /** | ... | ... |
... | @@ -95,6 +95,11 @@ public enum YangNodeType { | ... | @@ -95,6 +95,11 @@ public enum YangNodeType { |
95 | RPC_NODE, | 95 | RPC_NODE, |
96 | 96 | ||
97 | /** | 97 | /** |
98 | + * Node contains "YANG's union" information. | ||
99 | + */ | ||
100 | + UNION_NODE, | ||
101 | + | ||
102 | + /** | ||
98 | * Node contains "YANG's list" information. | 103 | * Node contains "YANG's list" information. |
99 | */ | 104 | */ |
100 | LIST_NODE | 105 | LIST_NODE | ... | ... |
... | @@ -16,13 +16,13 @@ | ... | @@ -16,13 +16,13 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | -import java.util.LinkedList; | ||
20 | -import java.util.List; | ||
21 | - | ||
22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
23 | import org.onosproject.yangutils.parser.Parsable; | 20 | import org.onosproject.yangutils.parser.Parsable; |
24 | import org.onosproject.yangutils.utils.YangConstructType; | 21 | import org.onosproject.yangutils.utils.YangConstructType; |
25 | 22 | ||
23 | +import java.util.LinkedList; | ||
24 | +import java.util.List; | ||
25 | + | ||
26 | /* | 26 | /* |
27 | * Reference RFC 6020. | 27 | * Reference RFC 6020. |
28 | * | 28 | * |
... | @@ -48,19 +48,24 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -48,19 +48,24 @@ import org.onosproject.yangutils.utils.YangConstructType; |
48 | /** | 48 | /** |
49 | * Represents data model node to maintain information defined in YANG union. | 49 | * Represents data model node to maintain information defined in YANG union. |
50 | */ | 50 | */ |
51 | -public class YangUnion implements Parsable { | 51 | +public class YangUnion extends YangNode implements Parsable { |
52 | 52 | ||
53 | // List of YANG type. | 53 | // List of YANG type. |
54 | private List<YangType<?>> typeList; | 54 | private List<YangType<?>> typeList; |
55 | 55 | ||
56 | // Name of union. | 56 | // Name of union. |
57 | - private String unionName; | 57 | + private String name; |
58 | + | ||
59 | + // Current child union number. | ||
60 | + private int childUnionNumber; | ||
58 | 61 | ||
59 | /** | 62 | /** |
60 | * Creates a YANG union node. | 63 | * Creates a YANG union node. |
61 | */ | 64 | */ |
62 | public YangUnion() { | 65 | public YangUnion() { |
66 | + super(YangNodeType.UNION_NODE); | ||
63 | typeList = new LinkedList<>(); | 67 | typeList = new LinkedList<>(); |
68 | + childUnionNumber = 1; | ||
64 | } | 69 | } |
65 | 70 | ||
66 | /** | 71 | /** |
... | @@ -73,31 +78,40 @@ public class YangUnion implements Parsable { | ... | @@ -73,31 +78,40 @@ public class YangUnion implements Parsable { |
73 | } | 78 | } |
74 | 79 | ||
75 | /** | 80 | /** |
76 | - * Returns union name. | 81 | + * Sets the list of YANG type. |
77 | * | 82 | * |
78 | - * @return the union name | 83 | + * @param typeList list of YANG type. |
79 | */ | 84 | */ |
80 | - public String getUnionName() { | 85 | + public void setTypeList(List<YangType<?>> typeList) { |
81 | - return unionName; | 86 | + this.typeList = typeList; |
82 | } | 87 | } |
83 | 88 | ||
84 | /** | 89 | /** |
85 | - * Sets the list of YANG type. | 90 | + * Returns running child union number. |
86 | * | 91 | * |
87 | - * @param typeList list of YANG type. | 92 | + * @return running child union number |
88 | */ | 93 | */ |
89 | - public void setTypeList(List<YangType<?>> typeList) { | 94 | + public int getChildUnionNumber() { |
90 | - this.typeList = typeList; | 95 | + return childUnionNumber; |
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Sets the running child union number. | ||
100 | + * | ||
101 | + * @param childUnionNumber running child union number | ||
102 | + */ | ||
103 | + public void setChildUnionNumber(int childUnionNumber) { | ||
104 | + this.childUnionNumber = childUnionNumber; | ||
91 | } | 105 | } |
92 | 106 | ||
93 | /** | 107 | /** |
94 | - * Adds YANG type to type list. | 108 | + * Add YANG type to type list. |
95 | * | 109 | * |
96 | * @param yangType YANG type to be added to list | 110 | * @param yangType YANG type to be added to list |
97 | * @throws DataModelException union member type must not be one of the | 111 | * @throws DataModelException union member type must not be one of the |
98 | * built-in types "empty" or "leafref" | 112 | * built-in types "empty" or "leafref" |
99 | */ | 113 | */ |
100 | - public void addToTypeList(YangType<?> yangType) throws DataModelException { | 114 | + public void addType(YangType<?> yangType) throws DataModelException { |
101 | if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) { | 115 | if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) { |
102 | throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " + | 116 | throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " + |
103 | "\"leafref\""); | 117 | "\"leafref\""); |
... | @@ -106,12 +120,23 @@ public class YangUnion implements Parsable { | ... | @@ -106,12 +120,23 @@ public class YangUnion implements Parsable { |
106 | } | 120 | } |
107 | 121 | ||
108 | /** | 122 | /** |
123 | + * Returns union name. | ||
124 | + * | ||
125 | + * @return the union name | ||
126 | + */ | ||
127 | + @Override | ||
128 | + public String getName() { | ||
129 | + return name; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
109 | * Sets the union name. | 133 | * Sets the union name. |
110 | * | 134 | * |
111 | - * @param unionName name of the union. | 135 | + * @param name union name |
112 | */ | 136 | */ |
113 | - public void setUnionName(String unionName) { | 137 | + @Override |
114 | - this.unionName = unionName; | 138 | + public void setName(String name) { |
139 | + this.name = name; | ||
115 | } | 140 | } |
116 | 141 | ||
117 | @Override | 142 | @Override | ... | ... |
... | @@ -44,19 +44,25 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -44,19 +44,25 @@ package org.onosproject.yangutils.parser.impl.listeners; |
44 | import org.onosproject.yangutils.datamodel.YangEnumeration; | 44 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
45 | import org.onosproject.yangutils.datamodel.YangLeaf; | 45 | import org.onosproject.yangutils.datamodel.YangLeaf; |
46 | import org.onosproject.yangutils.datamodel.YangLeafList; | 46 | import org.onosproject.yangutils.datamodel.YangLeafList; |
47 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
47 | import org.onosproject.yangutils.datamodel.YangType; | 48 | import org.onosproject.yangutils.datamodel.YangType; |
49 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
48 | import org.onosproject.yangutils.datamodel.YangUnion; | 50 | import org.onosproject.yangutils.datamodel.YangUnion; |
51 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
49 | import org.onosproject.yangutils.parser.Parsable; | 52 | import org.onosproject.yangutils.parser.Parsable; |
50 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 53 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
51 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 54 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
52 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 55 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
56 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
53 | 57 | ||
54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
60 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 61 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 62 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 63 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 64 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
65 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
60 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 66 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
61 | import static org.onosproject.yangutils.utils.YangConstructType.ENUMERATION_DATA; | 67 | import static org.onosproject.yangutils.utils.YangConstructType.ENUMERATION_DATA; |
62 | import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; | 68 | import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; |
... | @@ -69,6 +75,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; | ... | @@ -69,6 +75,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; |
69 | public final class EnumerationListener { | 75 | public final class EnumerationListener { |
70 | 76 | ||
71 | /** | 77 | /** |
78 | + * Suffix to be used while creating enumeration class. | ||
79 | + */ | ||
80 | + private static final String ENUMERATION_CLASS_SUFFIX = "_enum"; | ||
81 | + | ||
82 | + /** | ||
72 | * Creates a new enumeration listener. | 83 | * Creates a new enumeration listener. |
73 | */ | 84 | */ |
74 | private EnumerationListener() { | 85 | private EnumerationListener() { |
... | @@ -98,15 +109,48 @@ public final class EnumerationListener { | ... | @@ -98,15 +109,48 @@ public final class EnumerationListener { |
98 | 109 | ||
99 | switch (tmpData.getYangConstructType()) { | 110 | switch (tmpData.getYangConstructType()) { |
100 | case LEAF_DATA: | 111 | case LEAF_DATA: |
101 | - enumerationNode.setEnumerationName(((YangLeaf) tmpData).getLeafName()); | 112 | + // Set the name of enumeration same as leaf. |
113 | + enumerationNode.setName(((YangLeaf) tmpData).getLeafName() + ENUMERATION_CLASS_SUFFIX); | ||
114 | + // Pop the stack entry to obtain the parent YANG node. | ||
115 | + Parsable leaf = listener.getParsedDataStack().pop(); | ||
116 | + // Add the enumeration node to the parent holder of leaf. | ||
117 | + addChildToParentNode(listener, enumerationNode); | ||
118 | + // Push the popped entry back to the stack. | ||
119 | + listener.getParsedDataStack().push(leaf); | ||
102 | break; | 120 | break; |
103 | case LEAF_LIST_DATA: | 121 | case LEAF_LIST_DATA: |
104 | - enumerationNode.setEnumerationName(((YangLeafList) tmpData).getLeafName()); | 122 | + // Set the name of enumeration same as leaf list. |
123 | + enumerationNode.setName(((YangLeafList) tmpData).getLeafName() + ENUMERATION_CLASS_SUFFIX); | ||
124 | + // Pop the stack entry to obtain the parent YANG node. | ||
125 | + Parsable leafList = listener.getParsedDataStack().pop(); | ||
126 | + // Add the enumeration node to the parent holder of leaf. | ||
127 | + addChildToParentNode(listener, enumerationNode); | ||
128 | + // Push the popped entry back to the stack. | ||
129 | + listener.getParsedDataStack().push(leafList); | ||
105 | break; | 130 | break; |
106 | case UNION_DATA: | 131 | case UNION_DATA: |
107 | - enumerationNode.setEnumerationName(((YangUnion) tmpData).getUnionName()); | 132 | + YangUnion yangUnion = (YangUnion) tmpData; |
133 | + /* | ||
134 | + * In case parent of enumeration is a union, name of the | ||
135 | + * enumeration is parent union name suffixed with running | ||
136 | + * integer number, this is done because under union there | ||
137 | + * could be multiple child union types. | ||
138 | + */ | ||
139 | + enumerationNode.setName(yangUnion.getName() + yangUnion.getChildUnionNumber() | ||
140 | + + ENUMERATION_CLASS_SUFFIX); | ||
141 | + // Increment the running number. | ||
142 | + yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1); | ||
143 | + // Add union as a child to parent union. | ||
144 | + addChildToParentNode(listener, enumerationNode); | ||
108 | break; | 145 | break; |
109 | - // TODO typedef, deviate. | 146 | + case TYPEDEF_DATA: |
147 | + YangTypeDef typeDef = (YangTypeDef) tmpData; | ||
148 | + // Set the name of enumeration same as typedef name. | ||
149 | + enumerationNode.setName(typeDef.getName() + ENUMERATION_CLASS_SUFFIX); | ||
150 | + // Add enumeration as a child to parent type def. | ||
151 | + addChildToParentNode(listener, enumerationNode); | ||
152 | + break; | ||
153 | + // TODO deviate. | ||
110 | default: | 154 | default: |
111 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, | 155 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, |
112 | ((YangType<?>) typeData).getDataTypeName(), ENTRY)); | 156 | ((YangType<?>) typeData).getDataTypeName(), ENTRY)); |
... | @@ -155,4 +199,25 @@ public final class EnumerationListener { | ... | @@ -155,4 +199,25 @@ public final class EnumerationListener { |
155 | constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUMERATION_DATA, "", EXIT)); | 199 | constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUMERATION_DATA, "", EXIT)); |
156 | } | 200 | } |
157 | } | 201 | } |
202 | + | ||
203 | + /** | ||
204 | + * Adds the enumeration node to the parent holder. | ||
205 | + * | ||
206 | + * @param listener listener's object | ||
207 | + * @param enumerationNode enumeration node which needs to be added to parent | ||
208 | + */ | ||
209 | + private static void addChildToParentNode(TreeWalkListener listener, YangEnumeration enumerationNode) { | ||
210 | + if (!(listener.getParsedDataStack().peek() instanceof YangNode)) { | ||
211 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA, | ||
212 | + "", ENTRY)); | ||
213 | + } else { | ||
214 | + YangNode curNode = (YangNode) listener.getParsedDataStack().peek(); | ||
215 | + try { | ||
216 | + curNode.addChild(enumerationNode); | ||
217 | + } catch (DataModelException e) { | ||
218 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
219 | + YangConstructType.ENUMERATION_DATA, "", ENTRY, e.getMessage())); | ||
220 | + } | ||
221 | + } | ||
222 | + } | ||
158 | } | 223 | } | ... | ... |
... | @@ -204,7 +204,7 @@ public final class TypeListener { | ... | @@ -204,7 +204,7 @@ public final class TypeListener { |
204 | case UNION_DATA: | 204 | case UNION_DATA: |
205 | YangUnion unionNode = (YangUnion) tmpData; | 205 | YangUnion unionNode = (YangUnion) tmpData; |
206 | try { | 206 | try { |
207 | - unionNode.addToTypeList((YangType<?>) type); | 207 | + unionNode.addType((YangType<?>) type); |
208 | } catch (DataModelException e) { | 208 | } catch (DataModelException e) { |
209 | ParserException parserException = new ParserException(e.getMessage()); | 209 | ParserException parserException = new ParserException(e.getMessage()); |
210 | parserException.setLine(ctx.getStart().getLine()); | 210 | parserException.setLine(ctx.getStart().getLine()); | ... | ... |
... | @@ -42,19 +42,25 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -42,19 +42,25 @@ package org.onosproject.yangutils.parser.impl.listeners; |
42 | 42 | ||
43 | import org.onosproject.yangutils.datamodel.YangLeaf; | 43 | import org.onosproject.yangutils.datamodel.YangLeaf; |
44 | import org.onosproject.yangutils.datamodel.YangLeafList; | 44 | import org.onosproject.yangutils.datamodel.YangLeafList; |
45 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
45 | import org.onosproject.yangutils.datamodel.YangType; | 46 | import org.onosproject.yangutils.datamodel.YangType; |
47 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
46 | import org.onosproject.yangutils.datamodel.YangUnion; | 48 | import org.onosproject.yangutils.datamodel.YangUnion; |
49 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
47 | import org.onosproject.yangutils.parser.Parsable; | 50 | import org.onosproject.yangutils.parser.Parsable; |
48 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 51 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
49 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 52 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
50 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 53 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
54 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
51 | 55 | ||
52 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
53 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
58 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 60 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 61 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 62 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
63 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 64 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
59 | import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; | 65 | import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; |
60 | import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA; | 66 | import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA; |
... | @@ -66,6 +72,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA; | ... | @@ -66,6 +72,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA; |
66 | public final class UnionListener { | 72 | public final class UnionListener { |
67 | 73 | ||
68 | /** | 74 | /** |
75 | + * Suffix to be used while creating union class. | ||
76 | + */ | ||
77 | + private static final String UNION_CLASS_SUFFIX = "_union"; | ||
78 | + | ||
79 | + /** | ||
69 | * Creates a new union listener. | 80 | * Creates a new union listener. |
70 | */ | 81 | */ |
71 | private UnionListener() { | 82 | private UnionListener() { |
... | @@ -95,15 +106,47 @@ public final class UnionListener { | ... | @@ -95,15 +106,47 @@ public final class UnionListener { |
95 | 106 | ||
96 | switch (tmpData.getYangConstructType()) { | 107 | switch (tmpData.getYangConstructType()) { |
97 | case LEAF_DATA: | 108 | case LEAF_DATA: |
98 | - unionNode.setUnionName(((YangLeaf) tmpData).getLeafName()); | 109 | + // Set the name of union same as leaf. |
110 | + unionNode.setName(((YangLeaf) tmpData).getLeafName() + UNION_CLASS_SUFFIX); | ||
111 | + // Pop the stack entry to obtain the parent YANG node. | ||
112 | + Parsable leaf = listener.getParsedDataStack().pop(); | ||
113 | + // Add the union node to the parent holder of leaf. | ||
114 | + addChildToParentNode(listener, unionNode); | ||
115 | + // Push the popped entry back to the stack. | ||
116 | + listener.getParsedDataStack().push(leaf); | ||
99 | break; | 117 | break; |
100 | case LEAF_LIST_DATA: | 118 | case LEAF_LIST_DATA: |
101 | - unionNode.setUnionName(((YangLeafList) tmpData).getLeafName()); | 119 | + // Set the name of union same as leaf list. |
120 | + unionNode.setName(((YangLeafList) tmpData).getLeafName() + UNION_CLASS_SUFFIX); | ||
121 | + // Pop the stack entry to obtain the parent YANG node. | ||
122 | + Parsable leafList = listener.getParsedDataStack().pop(); | ||
123 | + // Add the union node to the parent holder of leaf. | ||
124 | + addChildToParentNode(listener, unionNode); | ||
125 | + // Push the popped entry back to the stack. | ||
126 | + listener.getParsedDataStack().push(leafList); | ||
102 | break; | 127 | break; |
103 | case UNION_DATA: | 128 | case UNION_DATA: |
104 | - unionNode.setUnionName(((YangUnion) tmpData).getUnionName()); | 129 | + YangUnion parentUnion = (YangUnion) tmpData; |
130 | + /* | ||
131 | + * In case parent of union is again a union, name of the | ||
132 | + * child union is parent union name suffixed with running | ||
133 | + * integer number, this is done because under union there | ||
134 | + * could be multiple child union types. | ||
135 | + */ | ||
136 | + unionNode.setName(parentUnion.getName() + UNION_CLASS_SUFFIX + parentUnion.getChildUnionNumber()); | ||
137 | + // Increment the running number. | ||
138 | + parentUnion.setChildUnionNumber(parentUnion.getChildUnionNumber() + 1); | ||
139 | + // Add union as a child to parent union. | ||
140 | + addChildToParentNode(listener, unionNode); | ||
105 | break; | 141 | break; |
106 | - // TODO typedef, deviate. | 142 | + case TYPEDEF_DATA: |
143 | + YangTypeDef typeDef = (YangTypeDef) tmpData; | ||
144 | + // Set the name of union same as typedef name. | ||
145 | + unionNode.setName(typeDef.getName() + UNION_CLASS_SUFFIX); | ||
146 | + // Add union as a child to parent type def. | ||
147 | + addChildToParentNode(listener, unionNode); | ||
148 | + break; | ||
149 | + // TODO deviate. | ||
107 | default: | 150 | default: |
108 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, | 151 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, |
109 | ((YangType<?>) typeData).getDataTypeName(), ENTRY)); | 152 | ((YangType<?>) typeData).getDataTypeName(), ENTRY)); |
... | @@ -152,4 +195,25 @@ public final class UnionListener { | ... | @@ -152,4 +195,25 @@ public final class UnionListener { |
152 | constructListenerErrorMessage(MISSING_CURRENT_HOLDER, UNION_DATA, "", EXIT)); | 195 | constructListenerErrorMessage(MISSING_CURRENT_HOLDER, UNION_DATA, "", EXIT)); |
153 | } | 196 | } |
154 | } | 197 | } |
198 | + | ||
199 | + /** | ||
200 | + * Adds the union node to the parent holder. | ||
201 | + * | ||
202 | + * @param listener listener's object | ||
203 | + * @param unionNode union node which needs to be added to parent | ||
204 | + */ | ||
205 | + private static void addChildToParentNode(TreeWalkListener listener, YangUnion unionNode) { | ||
206 | + if (!(listener.getParsedDataStack().peek() instanceof YangNode)) { | ||
207 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNION_DATA, | ||
208 | + "", ENTRY)); | ||
209 | + } else { | ||
210 | + YangNode curNode = (YangNode) listener.getParsedDataStack().peek(); | ||
211 | + try { | ||
212 | + curNode.addChild(unionNode); | ||
213 | + } catch (DataModelException e) { | ||
214 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
215 | + YangConstructType.UNION_DATA, "", ENTRY, e.getMessage())); | ||
216 | + } | ||
217 | + } | ||
218 | + } | ||
155 | } | 219 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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.javamodel; | ||
18 | + | ||
19 | +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
20 | +import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
21 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
22 | + | ||
23 | +/** | ||
24 | + * Represents YANG java info containing interface for java code generator, java | ||
25 | + * file information, java import data and temp java code fragment files. This | ||
26 | + * interface serves as a generic interface and help to unify the generate code | ||
27 | + * entry function. | ||
28 | + */ | ||
29 | +public interface JavaCodeGeneratorInfo extends HasJavaFileInfo, HasTempJavaCodeFragmentFiles, HasJavaImportData { | ||
30 | +} |
... | @@ -16,30 +16,20 @@ | ... | @@ -16,30 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangAugment; | 19 | import org.onosproject.yangutils.datamodel.YangAugment; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 28 | ||
37 | /** | 29 | /** |
38 | * Represents augment information extended to support java code generation. | 30 | * Represents augment information extended to support java code generation. |
39 | */ | 31 | */ |
40 | -public class YangJavaAugment extends YangAugment | 32 | +public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 33 | ||
44 | /** | 34 | /** |
45 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -142,28 +132,11 @@ public class YangJavaAugment extends YangAugment | ... | @@ -142,28 +132,11 @@ public class YangJavaAugment extends YangAugment |
142 | */ | 132 | */ |
143 | @Override | 133 | @Override |
144 | public void generateCodeEntry(String codeGenDir) throws IOException { | 134 | public void generateCodeEntry(String codeGenDir) throws IOException { |
145 | - | 135 | + generateCodeOfNode(this, codeGenDir, false); |
146 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
147 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
163 | } | 136 | } |
164 | 137 | ||
165 | /** | 138 | /** |
166 | - * Create a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG grouping info. |
167 | */ | 140 | */ |
168 | @Override | 141 | @Override |
169 | public void generateCodeExit() { | 142 | public void generateCodeExit() { | ... | ... |
... | @@ -16,30 +16,20 @@ | ... | @@ -16,30 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangCase; | 19 | import org.onosproject.yangutils.datamodel.YangCase; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 28 | ||
37 | /** | 29 | /** |
38 | * Represents case information extended to support java code generation. | 30 | * Represents case information extended to support java code generation. |
39 | */ | 31 | */ |
40 | -public class YangJavaCase extends YangCase | 32 | +public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 33 | ||
44 | /** | 34 | /** |
45 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -75,7 +65,6 @@ public class YangJavaCase extends YangCase | ... | @@ -75,7 +65,6 @@ public class YangJavaCase extends YangCase |
75 | */ | 65 | */ |
76 | @Override | 66 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 67 | public JavaFileInfo getJavaFileInfo() { |
78 | - | ||
79 | if (javaFileInfo == null) { | 68 | if (javaFileInfo == null) { |
80 | throw new TranslatorException("Missing java info in java datamodel node"); | 69 | throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 70 | } |
... | @@ -142,28 +131,11 @@ public class YangJavaCase extends YangCase | ... | @@ -142,28 +131,11 @@ public class YangJavaCase extends YangCase |
142 | */ | 131 | */ |
143 | @Override | 132 | @Override |
144 | public void generateCodeEntry(String codeGenDir) throws IOException { | 133 | public void generateCodeEntry(String codeGenDir) throws IOException { |
145 | - | 134 | + generateCodeOfNode(this, codeGenDir, false); |
146 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
147 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
163 | } | 135 | } |
164 | 136 | ||
165 | /** | 137 | /** |
166 | - * Create a java file using the YANG grouping info. | 138 | + * Creates a java file using the YANG grouping info. |
167 | */ | 139 | */ |
168 | @Override | 140 | @Override |
169 | public void generateCodeExit() { | 141 | public void generateCodeExit() { | ... | ... |
... | @@ -16,30 +16,20 @@ | ... | @@ -16,30 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangChoice; | 19 | import org.onosproject.yangutils.datamodel.YangChoice; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 28 | ||
37 | /** | 29 | /** |
38 | * Represents choice information extended to support java code generation. | 30 | * Represents choice information extended to support java code generation. |
39 | */ | 31 | */ |
40 | -public class YangJavaChoice extends YangChoice | 32 | +public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 33 | ||
44 | /** | 34 | /** |
45 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -75,7 +65,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -75,7 +65,6 @@ public class YangJavaChoice extends YangChoice |
75 | */ | 65 | */ |
76 | @Override | 66 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 67 | public JavaFileInfo getJavaFileInfo() { |
78 | - | ||
79 | if (javaFileInfo == null) { | 68 | if (javaFileInfo == null) { |
80 | throw new TranslatorException("Missing java info in java datamodel node"); | 69 | throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 70 | } |
... | @@ -142,28 +131,12 @@ public class YangJavaChoice extends YangChoice | ... | @@ -142,28 +131,12 @@ public class YangJavaChoice extends YangChoice |
142 | */ | 131 | */ |
143 | @Override | 132 | @Override |
144 | public void generateCodeEntry(String codeGenDir) throws IOException { | 133 | public void generateCodeEntry(String codeGenDir) throws IOException { |
145 | - | 134 | + generateCodeOfNode(this, codeGenDir, false); |
146 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
147 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | 135 | // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); |
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
163 | } | 136 | } |
164 | 137 | ||
165 | /** | 138 | /** |
166 | - * Create a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG grouping info. |
167 | */ | 140 | */ |
168 | @Override | 141 | @Override |
169 | public void generateCodeExit() { | 142 | public void generateCodeExit() { | ... | ... |
... | @@ -16,30 +16,20 @@ | ... | @@ -16,30 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangContainer; | 19 | import org.onosproject.yangutils.datamodel.YangContainer; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 28 | ||
37 | /** | 29 | /** |
38 | * Represents container information extended to support java code generation. | 30 | * Represents container information extended to support java code generation. |
39 | */ | 31 | */ |
40 | -public class YangJavaContainer extends YangContainer | 32 | +public class YangJavaContainer extends YangContainer implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 33 | ||
44 | /** | 34 | /** |
45 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -75,7 +65,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -75,7 +65,6 @@ public class YangJavaContainer extends YangContainer |
75 | */ | 65 | */ |
76 | @Override | 66 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 67 | public JavaFileInfo getJavaFileInfo() { |
78 | - | ||
79 | if (javaFileInfo == null) { | 68 | if (javaFileInfo == null) { |
80 | throw new TranslatorException("Missing java info in java datamodel node"); | 69 | throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 70 | } |
... | @@ -142,28 +131,11 @@ public class YangJavaContainer extends YangContainer | ... | @@ -142,28 +131,11 @@ public class YangJavaContainer extends YangContainer |
142 | */ | 131 | */ |
143 | @Override | 132 | @Override |
144 | public void generateCodeEntry(String codeGenDir) throws IOException { | 133 | public void generateCodeEntry(String codeGenDir) throws IOException { |
145 | - | 134 | + generateCodeOfNode(this, codeGenDir, false); |
146 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
147 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
163 | } | 135 | } |
164 | 136 | ||
165 | /** | 137 | /** |
166 | - * Create a java file using the YANG grouping info. | 138 | + * Create a java file using the YANG container info. |
167 | * | 139 | * |
168 | * @throws IOException IO operation fail | 140 | * @throws IOException IO operation fail |
169 | */ | 141 | */ | ... | ... |
... | @@ -16,30 +16,20 @@ | ... | @@ -16,30 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangGrouping; | 19 | import org.onosproject.yangutils.datamodel.YangGrouping; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 28 | ||
37 | /** | 29 | /** |
38 | * Represents grouping information extended to support java code generation. | 30 | * Represents grouping information extended to support java code generation. |
39 | */ | 31 | */ |
40 | -public class YangJavaGrouping extends YangGrouping | 32 | +public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 33 | ||
44 | /** | 34 | /** |
45 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -75,7 +65,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -75,7 +65,6 @@ public class YangJavaGrouping extends YangGrouping |
75 | */ | 65 | */ |
76 | @Override | 66 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 67 | public JavaFileInfo getJavaFileInfo() { |
78 | - | ||
79 | if (javaFileInfo == null) { | 68 | if (javaFileInfo == null) { |
80 | throw new TranslatorException("Missing java info in java datamodel node"); | 69 | throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 70 | } |
... | @@ -142,28 +131,11 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -142,28 +131,11 @@ public class YangJavaGrouping extends YangGrouping |
142 | */ | 131 | */ |
143 | @Override | 132 | @Override |
144 | public void generateCodeEntry(String codeGenDir) throws IOException { | 133 | public void generateCodeEntry(String codeGenDir) throws IOException { |
145 | - | 134 | + generateCodeOfNode(this, codeGenDir, false); |
146 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
147 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
163 | } | 135 | } |
164 | 136 | ||
165 | /** | 137 | /** |
166 | - * Create a java file using the YANG grouping info. | 138 | + * Creates a java file using the YANG grouping info. |
167 | */ | 139 | */ |
168 | @Override | 140 | @Override |
169 | public void generateCodeExit() { | 141 | public void generateCodeExit() { | ... | ... |
... | @@ -17,31 +17,20 @@ | ... | @@ -17,31 +17,20 @@ |
17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | - | ||
21 | import org.onosproject.yangutils.datamodel.YangInput; | 20 | import org.onosproject.yangutils.datamodel.YangInput; |
22 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
25 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
26 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
28 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
30 | 26 | ||
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 28 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
35 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
36 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
37 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
38 | 29 | ||
39 | /** | 30 | /** |
40 | * Represents input information extended to support java code generation. | 31 | * Represents input information extended to support java code generation. |
41 | */ | 32 | */ |
42 | -public class YangJavaInput extends YangInput | 33 | +public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
43 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
44 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
45 | 34 | ||
46 | /** | 35 | /** |
47 | * Contains information of the java file being generated. | 36 | * Contains information of the java file being generated. |
... | @@ -77,7 +66,6 @@ public class YangJavaInput extends YangInput | ... | @@ -77,7 +66,6 @@ public class YangJavaInput extends YangInput |
77 | */ | 66 | */ |
78 | @Override | 67 | @Override |
79 | public JavaFileInfo getJavaFileInfo() { | 68 | public JavaFileInfo getJavaFileInfo() { |
80 | - | ||
81 | if (javaFileInfo == null) { | 69 | if (javaFileInfo == null) { |
82 | throw new TranslatorException("Missing java info in java datamodel node"); | 70 | throw new TranslatorException("Missing java info in java datamodel node"); |
83 | } | 71 | } |
... | @@ -144,28 +132,11 @@ public class YangJavaInput extends YangInput | ... | @@ -144,28 +132,11 @@ public class YangJavaInput extends YangInput |
144 | */ | 132 | */ |
145 | @Override | 133 | @Override |
146 | public void generateCodeEntry(String codeGenDir) throws IOException { | 134 | public void generateCodeEntry(String codeGenDir) throws IOException { |
147 | - | 135 | + generateCodeOfNode(this, codeGenDir, false); |
148 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
149 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
150 | - getJavaFileInfo().setPackageFilePath( | ||
151 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
152 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
153 | - | ||
154 | - String absloutePath = getAbsolutePackagePath( | ||
155 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
156 | - getJavaFileInfo().getPackageFilePath()); | ||
157 | - createPackage(absloutePath, getName()); | ||
158 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
159 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
160 | - getJavaFileInfo().getJavaName())); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
163 | - | ||
164 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
165 | } | 136 | } |
166 | 137 | ||
167 | /** | 138 | /** |
168 | - * Create a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG grouping info. |
169 | * | 140 | * |
170 | * @throws IOException IO operation fail | 141 | * @throws IOException IO operation fail |
171 | */ | 142 | */ | ... | ... |
... | @@ -16,31 +16,20 @@ | ... | @@ -16,31 +16,20 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangList; | 19 | import org.onosproject.yangutils.datamodel.YangList; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | 25 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
36 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
37 | 28 | ||
38 | /** | 29 | /** |
39 | - * Represents YANG List information extended to support java code generation. | 30 | + * Represents YANG list information extended to support java code generation. |
40 | */ | 31 | */ |
41 | -public class YangJavaList extends YangList | 32 | +public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
42 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
43 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
44 | 33 | ||
45 | /** | 34 | /** |
46 | * Contains the information of the java file being generated. | 35 | * Contains the information of the java file being generated. |
... | @@ -76,7 +65,6 @@ public class YangJavaList extends YangList | ... | @@ -76,7 +65,6 @@ public class YangJavaList extends YangList |
76 | */ | 65 | */ |
77 | @Override | 66 | @Override |
78 | public JavaFileInfo getJavaFileInfo() { | 67 | public JavaFileInfo getJavaFileInfo() { |
79 | - | ||
80 | if (javaFileInfo == null) { | 68 | if (javaFileInfo == null) { |
81 | throw new TranslatorException("Missing java info in java datamodel node"); | 69 | throw new TranslatorException("Missing java info in java datamodel node"); |
82 | } | 70 | } |
... | @@ -143,30 +131,11 @@ public class YangJavaList extends YangList | ... | @@ -143,30 +131,11 @@ public class YangJavaList extends YangList |
143 | */ | 131 | */ |
144 | @Override | 132 | @Override |
145 | public void generateCodeEntry(String codeGenDir) throws IOException { | 133 | public void generateCodeEntry(String codeGenDir) throws IOException { |
146 | - | 134 | + generateCodeOfNode(this, codeGenDir, true); |
147 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
148 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
149 | - | ||
150 | - getJavaFileInfo().setPackageFilePath( | ||
151 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
152 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
153 | - | ||
154 | - String absloutePath = getAbsolutePackagePath( | ||
155 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
156 | - getJavaFileInfo().getPackageFilePath()); | ||
157 | - createPackage(absloutePath, getName()); | ||
158 | - | ||
159 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
160 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
161 | - getJavaFileInfo().getJavaName())); | ||
162 | - | ||
163 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
164 | - | ||
165 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, true); | ||
166 | } | 135 | } |
167 | 136 | ||
168 | /** | 137 | /** |
169 | - * Create a java file using the YANG grouping info. | 138 | + * Creates a java file using the YANG grouping info. |
170 | * | 139 | * |
171 | * @throws IOException IO operation fail | 140 | * @throws IOException IO operation fail |
172 | */ | 141 | */ | ... | ... |
... | @@ -16,30 +16,21 @@ | ... | @@ -16,30 +16,21 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangModule; | 19 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 20 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
25 | +import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; | ||
29 | 26 | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
31 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
36 | 29 | ||
37 | /** | 30 | /** |
38 | * Represents module information extended to support java code generation. | 31 | * Represents module information extended to support java code generation. |
39 | */ | 32 | */ |
40 | -public class YangJavaModule extends YangModule | 33 | +public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
41 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
42 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
43 | 34 | ||
44 | /** | 35 | /** |
45 | * Contains the information of the java file being generated. | 36 | * Contains the information of the java file being generated. |
... | @@ -59,7 +50,7 @@ public class YangJavaModule extends YangModule | ... | @@ -59,7 +50,7 @@ public class YangJavaModule extends YangModule |
59 | private TempJavaCodeFragmentFiles tempFileHandle; | 50 | private TempJavaCodeFragmentFiles tempFileHandle; |
60 | 51 | ||
61 | /** | 52 | /** |
62 | - * Create a YANG node of module type. | 53 | + * Creates a YANG node of module type. |
63 | */ | 54 | */ |
64 | public YangJavaModule() { | 55 | public YangJavaModule() { |
65 | super(); | 56 | super(); |
... | @@ -75,7 +66,6 @@ public class YangJavaModule extends YangModule | ... | @@ -75,7 +66,6 @@ public class YangJavaModule extends YangModule |
75 | */ | 66 | */ |
76 | @Override | 67 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 68 | public JavaFileInfo getJavaFileInfo() { |
78 | - | ||
79 | if (javaFileInfo == null) { | 69 | if (javaFileInfo == null) { |
80 | throw new TranslatorException("Missing java info in java datamodel node"); | 70 | throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 71 | } |
... | @@ -141,23 +131,8 @@ public class YangJavaModule extends YangModule | ... | @@ -141,23 +131,8 @@ public class YangJavaModule extends YangModule |
141 | */ | 131 | */ |
142 | @Override | 132 | @Override |
143 | public void generateCodeEntry(String baseCodeGenDir) throws IOException { | 133 | public void generateCodeEntry(String baseCodeGenDir) throws IOException { |
144 | - | 134 | + String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); |
145 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 135 | + YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, modulePkg); |
146 | - getJavaFileInfo().setPackage(getRootPackage(getVersion(), getNameSpace().getUri(), | ||
147 | - getRevision().getRevDate())); | ||
148 | - getJavaFileInfo().setPackageFilePath( | ||
149 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
150 | - getJavaFileInfo().setBaseCodeGenPath(baseCodeGenDir); | ||
151 | - | ||
152 | - String absloutePath = getAbsolutePackagePath( | ||
153 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
154 | - getJavaFileInfo().getPackageFilePath()); | ||
155 | - | ||
156 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
157 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
158 | - getJavaFileInfo().getJavaName())); | ||
159 | - | ||
160 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
161 | } | 136 | } |
162 | 137 | ||
163 | @Override | 138 | @Override | ... | ... |
... | @@ -17,31 +17,20 @@ | ... | @@ -17,31 +17,20 @@ |
17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | - | ||
21 | import org.onosproject.yangutils.datamodel.YangOutput; | 20 | import org.onosproject.yangutils.datamodel.YangOutput; |
22 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
25 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
26 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
28 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
30 | 26 | ||
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 28 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
35 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
36 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
37 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
38 | 29 | ||
39 | /** | 30 | /** |
40 | * Represents output information extended to support java code generation. | 31 | * Represents output information extended to support java code generation. |
41 | */ | 32 | */ |
42 | -public class YangJavaOutput extends YangOutput | 33 | +public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
43 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
44 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
45 | 34 | ||
46 | /** | 35 | /** |
47 | * Contains information of the java file being generated. | 36 | * Contains information of the java file being generated. |
... | @@ -77,7 +66,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -77,7 +66,6 @@ public class YangJavaOutput extends YangOutput |
77 | */ | 66 | */ |
78 | @Override | 67 | @Override |
79 | public JavaFileInfo getJavaFileInfo() { | 68 | public JavaFileInfo getJavaFileInfo() { |
80 | - | ||
81 | if (javaFileInfo == null) { | 69 | if (javaFileInfo == null) { |
82 | throw new TranslatorException("Missing java info in java datamodel node"); | 70 | throw new TranslatorException("Missing java info in java datamodel node"); |
83 | } | 71 | } |
... | @@ -144,28 +132,11 @@ public class YangJavaOutput extends YangOutput | ... | @@ -144,28 +132,11 @@ public class YangJavaOutput extends YangOutput |
144 | */ | 132 | */ |
145 | @Override | 133 | @Override |
146 | public void generateCodeEntry(String codeGenDir) throws IOException { | 134 | public void generateCodeEntry(String codeGenDir) throws IOException { |
147 | - | 135 | + generateCodeOfNode(this, codeGenDir, false); |
148 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
149 | - getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
150 | - getJavaFileInfo().setPackageFilePath( | ||
151 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
152 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
153 | - | ||
154 | - String absloutePath = getAbsolutePackagePath( | ||
155 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
156 | - getJavaFileInfo().getPackageFilePath()); | ||
157 | - createPackage(absloutePath, getName()); | ||
158 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
159 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
160 | - getJavaFileInfo().getJavaName())); | ||
161 | - | ||
162 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
163 | - | ||
164 | - getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
165 | } | 136 | } |
166 | 137 | ||
167 | /** | 138 | /** |
168 | - * Create a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG grouping info. |
169 | * | 140 | * |
170 | * @throws IOException IO operation fail | 141 | * @throws IOException IO operation fail |
171 | */ | 142 | */ | ... | ... |
... | @@ -16,31 +16,22 @@ | ... | @@ -16,31 +16,22 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | - | ||
20 | import org.onosproject.yangutils.datamodel.YangBelongsTo; | 19 | import org.onosproject.yangutils.datamodel.YangBelongsTo; |
21 | import org.onosproject.yangutils.datamodel.YangSubModule; | 20 | import org.onosproject.yangutils.datamodel.YangSubModule; |
22 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
23 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
24 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
25 | -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
26 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
28 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
26 | +import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; | ||
30 | 27 | ||
31 | 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; |
32 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
36 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
37 | 30 | ||
38 | /** | 31 | /** |
39 | - * Represents Sub module information extended to support java code generation. | 32 | + * Represents sub module information extended to support java code generation. |
40 | */ | 33 | */ |
41 | -public class YangJavaSubModule extends YangSubModule | 34 | +public class YangJavaSubModule extends YangSubModule implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
42 | - implements JavaCodeGenerator, HasJavaFileInfo, | ||
43 | - HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
44 | 35 | ||
45 | /** | 36 | /** |
46 | * Contains the information of the java file being generated. | 37 | * Contains the information of the java file being generated. |
... | @@ -76,7 +67,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -76,7 +67,6 @@ public class YangJavaSubModule extends YangSubModule |
76 | */ | 67 | */ |
77 | @Override | 68 | @Override |
78 | public JavaFileInfo getJavaFileInfo() { | 69 | public JavaFileInfo getJavaFileInfo() { |
79 | - | ||
80 | if (javaFileInfo == null) { | 70 | if (javaFileInfo == null) { |
81 | throw new TranslatorException("Missing java info in java datamodel node"); | 71 | throw new TranslatorException("Missing java info in java datamodel node"); |
82 | } | 72 | } |
... | @@ -150,33 +140,18 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -150,33 +140,18 @@ public class YangJavaSubModule extends YangSubModule |
150 | * Prepare the information for java code generation corresponding to YANG | 140 | * Prepare the information for java code generation corresponding to YANG |
151 | * container info. | 141 | * container info. |
152 | * | 142 | * |
153 | - * @param codeGenDir code generation directory | 143 | + * @param baseCodeGenDir code generation directory |
154 | * @throws IOException IO operation fail | 144 | * @throws IOException IO operation fail |
155 | */ | 145 | */ |
156 | @Override | 146 | @Override |
157 | - public void generateCodeEntry(String codeGenDir) throws IOException { | 147 | + public void generateCodeEntry(String baseCodeGenDir) throws IOException { |
158 | - | 148 | + String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), |
159 | - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 149 | + getRevision().getRevDate()); |
160 | - getJavaFileInfo().setPackage(getRootPackage(getVersion(), | 150 | + YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, subModulePkg); |
161 | - getNameSpaceFromModule(getBelongsTo()), | ||
162 | - getRevision().getRevDate())); | ||
163 | - getJavaFileInfo().setPackageFilePath( | ||
164 | - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
165 | - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
166 | - | ||
167 | - String absloutePath = getAbsolutePackagePath( | ||
168 | - getJavaFileInfo().getBaseCodeGenPath(), | ||
169 | - getJavaFileInfo().getPackageFilePath()); | ||
170 | - | ||
171 | - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
172 | - getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
173 | - getJavaFileInfo().getJavaName())); | ||
174 | - | ||
175 | - getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
176 | } | 151 | } |
177 | 152 | ||
178 | /** | 153 | /** |
179 | - * Create a java file using the YANG grouping info. | 154 | + * Creates a java file using the YANG grouping info. |
180 | */ | 155 | */ |
181 | @Override | 156 | @Override |
182 | public void generateCodeExit() { | 157 | public void generateCodeExit() { | ... | ... |
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.io.IOException; | ||
20 | +import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
21 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
22 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
23 | +import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | ||
24 | + | ||
25 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
26 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
27 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
29 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
30 | + | ||
31 | +/** | ||
32 | + * Represents utility class for YANG java model. | ||
33 | + */ | ||
34 | +public final class YangJavaModelUtils { | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates YANG java model utility. | ||
38 | + */ | ||
39 | + private YangJavaModelUtils() { | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Updates YANG java file package information. | ||
44 | + * | ||
45 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
46 | + * @param codeGenDir code generation directory | ||
47 | + * @throws IOException IO operations fails | ||
48 | + */ | ||
49 | + private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir) | ||
50 | + throws IOException { | ||
51 | + javaCodeGeneratorInfo.getJavaFileInfo() | ||
52 | + .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName()))); | ||
53 | + javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo)); | ||
54 | + javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( | ||
55 | + getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); | ||
56 | + javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Updates YANG java file package information for specified package. | ||
61 | + * | ||
62 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
63 | + * @param codeGenDir code generation directory | ||
64 | + * @throws IOException IO operations fails | ||
65 | + */ | ||
66 | + private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, String pkg) | ||
67 | + throws IOException { | ||
68 | + javaCodeGeneratorInfo.getJavaFileInfo() | ||
69 | + .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName()))); | ||
70 | + javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg); | ||
71 | + javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( | ||
72 | + getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); | ||
73 | + javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Updates temporary java code fragment files. | ||
78 | + * | ||
79 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
80 | + * @throws IOException IO operations fails | ||
81 | + */ | ||
82 | + private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo) throws IOException { | ||
83 | + String absolutePath = getAbsolutePackagePath(javaCodeGeneratorInfo.getJavaFileInfo().getBaseCodeGenPath(), | ||
84 | + javaCodeGeneratorInfo.getJavaFileInfo().getPackageFilePath()); | ||
85 | + | ||
86 | + javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles( | ||
87 | + new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo().getGeneratedFileTypes(), | ||
88 | + absolutePath, javaCodeGeneratorInfo.getJavaFileInfo().getJavaName())); | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * Updates leaf information in temporary java code fragment files. | ||
93 | + * | ||
94 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
95 | + * @throws IOException IO operations fails | ||
96 | + */ | ||
97 | + private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo) | ||
98 | + throws IOException { | ||
99 | + | ||
100 | + if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { | ||
101 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | ||
102 | + .addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo); | ||
103 | + } else { | ||
104 | + // TODO: either write a util for ENUM and UNION or, call the | ||
105 | + // corresponding implementation in ENUM and UNION | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Process generate code entry of YANG node. | ||
111 | + * | ||
112 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
113 | + * @param codeGenDir code generation directory | ||
114 | + * @throws IOException IO operations fails | ||
115 | + */ | ||
116 | + private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir) | ||
117 | + throws IOException { | ||
118 | + if (!(javaCodeGeneratorInfo instanceof YangNode)) { | ||
119 | + // TODO:throw exception | ||
120 | + } | ||
121 | + createTempFragmentFile(javaCodeGeneratorInfo); | ||
122 | + updateLeafInfoInTempFragmentFiles(javaCodeGeneratorInfo); | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Process generate code entry of YANG node. | ||
128 | + * | ||
129 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
130 | + * @param codeGenDir code generation directory | ||
131 | + * @param isMultiInstance flag to indicate whether it's a list | ||
132 | + * @throws IOException IO operations fails | ||
133 | + */ | ||
134 | + public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, | ||
135 | + boolean isMultiInstance) throws IOException { | ||
136 | + if (!(javaCodeGeneratorInfo instanceof YangNode)) { | ||
137 | + // TODO:throw exception | ||
138 | + } | ||
139 | + updatePackageInfo(javaCodeGeneratorInfo, codeGenDir); | ||
140 | + generateTempFiles(javaCodeGeneratorInfo, codeGenDir); | ||
141 | + | ||
142 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | ||
143 | + .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Process generate code entry of root node. | ||
148 | + * | ||
149 | + * @param javaCodeGeneratorInfo YANG java file info node | ||
150 | + * @param codeGenDir code generation directory | ||
151 | + * @param rootPkg package of the root node | ||
152 | + * @throws IOException IO operations fails | ||
153 | + */ | ||
154 | + public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, | ||
155 | + String rootPkg) throws IOException { | ||
156 | + if (!(javaCodeGeneratorInfo instanceof YangNode)) { | ||
157 | + // TODO:throw exception | ||
158 | + } | ||
159 | + updatePackageInfo(javaCodeGeneratorInfo, codeGenDir, rootPkg); | ||
160 | + generateTempFiles(javaCodeGeneratorInfo, codeGenDir); | ||
161 | + } | ||
162 | +} |
... | @@ -64,8 +64,8 @@ public class EnumListenerTest { | ... | @@ -64,8 +64,8 @@ public class EnumListenerTest { |
64 | assertThat(leafInfo.getLeafName(), is("speed")); | 64 | assertThat(leafInfo.getLeafName(), is("speed")); |
65 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); | 65 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); |
66 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); | 66 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); |
67 | - assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(), | 67 | + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), |
68 | - is("speed")); | 68 | + is("speed_enum")); |
69 | 69 | ||
70 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); | 70 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); |
71 | for (YangEnum tmp : enumSet) { | 71 | for (YangEnum tmp : enumSet) { | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
... | @@ -64,8 +64,8 @@ public class ValueListenerTest { | ... | @@ -64,8 +64,8 @@ public class ValueListenerTest { |
64 | assertThat(leafInfo.getLeafName(), is("speed")); | 64 | assertThat(leafInfo.getLeafName(), is("speed")); |
65 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); | 65 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); |
66 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); | 66 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); |
67 | - assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(), | 67 | + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), |
68 | - is("speed")); | 68 | + is("speed_enum")); |
69 | 69 | ||
70 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); | 70 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); |
71 | for (YangEnum tmp : enumSet) { | 71 | for (YangEnum tmp : enumSet) { |
... | @@ -103,8 +103,8 @@ public class ValueListenerTest { | ... | @@ -103,8 +103,8 @@ public class ValueListenerTest { |
103 | assertThat(leafInfo.getLeafName(), is("speed")); | 103 | assertThat(leafInfo.getLeafName(), is("speed")); |
104 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); | 104 | assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); |
105 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); | 105 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); |
106 | - assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(), | 106 | + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), |
107 | - is("speed")); | 107 | + is("speed_enum")); |
108 | 108 | ||
109 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); | 109 | Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); |
110 | for (YangEnum tmp : enumSet) { | 110 | for (YangEnum tmp : enumSet) { | ... | ... |
-
Please register or login to post a comment