Committed by
Gerrit Code Review
[ONOS-3885, ONOS-3886, ONOS-3887] Implement YANG sub-module, container and list data model
Change-Id: Id9be89054db0f4c4f84e62547d3b6851cfed3de2
Showing
11 changed files
with
1755 additions
and
27 deletions
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.yangutils.datamodel; | ||
17 | + | ||
18 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
19 | +import org.onosproject.yangutils.parser.Parsable; | ||
20 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
21 | + | ||
22 | +/*- | ||
23 | + * Reference 6020. | ||
24 | + * | ||
25 | + * The "belongs-to" statement specifies the module to which the | ||
26 | + * submodule belongs. The argument is an identifier that is the name of | ||
27 | + * the module. | ||
28 | + * | ||
29 | + * A submodule MUST only be included by the module to which it belongs, | ||
30 | + * or by another submodule that belongs to that module. | ||
31 | + * | ||
32 | + * The mandatory "prefix" sub-statement assigns a prefix for the module | ||
33 | + * to which the submodule belongs. All definitions in the local | ||
34 | + * submodule and any included submodules can be accessed by using the | ||
35 | + * prefix. | ||
36 | + * | ||
37 | + * The belongs-to's sub-statements | ||
38 | + * | ||
39 | + * +--------------+---------+-------------+ | ||
40 | + * | substatement | section | cardinality | | ||
41 | + * +--------------+---------+-------------+ | ||
42 | + * | prefix | 7.1.4 | 1 | | ||
43 | + * +--------------+---------+-------------+ | ||
44 | + */ | ||
45 | + | ||
46 | +/** | ||
47 | + * Maintains the belongs-to data type information. | ||
48 | + */ | ||
49 | +public class YangBelongsTo implements Parsable { | ||
50 | + | ||
51 | + /** | ||
52 | + * Reference RFC 6020. | ||
53 | + * | ||
54 | + * The "belongs-to" statement specifies the module to which the submodule | ||
55 | + * belongs. The argument is an identifier that is the name of the module. | ||
56 | + */ | ||
57 | + private String belongsToModuleName; | ||
58 | + | ||
59 | + /** | ||
60 | + * Reference RFC 6020. | ||
61 | + * | ||
62 | + * The mandatory "prefix" substatement assigns a prefix for the module to | ||
63 | + * which the submodule belongs. All definitions in the local submodule and | ||
64 | + * any included submodules can be accessed by using the prefix. | ||
65 | + */ | ||
66 | + private String prefix; | ||
67 | + | ||
68 | + /** | ||
69 | + * Create a belongs to object. | ||
70 | + */ | ||
71 | + public YangBelongsTo() { | ||
72 | + | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Get the belongs to module name. | ||
77 | + * | ||
78 | + * @return the belongs to module name | ||
79 | + */ | ||
80 | + public String getBelongsToModuleName() { | ||
81 | + return belongsToModuleName; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Set the belongs to module name. | ||
86 | + * | ||
87 | + * @param belongsToModuleName the belongs to module name to set | ||
88 | + * | ||
89 | + */ | ||
90 | + public void setBelongsToModuleName(String belongsToModuleName) { | ||
91 | + this.belongsToModuleName = belongsToModuleName; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Get the prefix. | ||
96 | + * | ||
97 | + * @return the prefix. | ||
98 | + */ | ||
99 | + public String getPrefix() { | ||
100 | + return prefix; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Set the prefix. | ||
105 | + * | ||
106 | + * @param prefix the prefix to set | ||
107 | + */ | ||
108 | + public void setPrefix(String prefix) { | ||
109 | + this.prefix = prefix; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns the type of the data as belongs-to. | ||
114 | + * | ||
115 | + * @return ParsedDataType returns BELONGS_TO_DATA | ||
116 | + */ | ||
117 | + public ParsableDataType getParsableDataType() { | ||
118 | + return ParsableDataType.BELONGS_TO_DATA; | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Validate the data on entering the corresponding parse tree node. | ||
123 | + * | ||
124 | + * @throws DataModelException a violation of data model rules. | ||
125 | + */ | ||
126 | + public void validateDataOnEntry() throws DataModelException { | ||
127 | + // TODO auto-generated method stub, to be implemented by parser | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Validate the data on exiting the corresponding parse tree node. | ||
132 | + * | ||
133 | + * @throws DataModelException a violation of data model rules. | ||
134 | + */ | ||
135 | + public void validateDataOnExit() throws DataModelException { | ||
136 | + // TODO auto-generated method stub, to be implemented by parser | ||
137 | + } | ||
138 | +} |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.datamodel; | ||
18 | + | ||
19 | +import java.util.LinkedList; | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.parser.Parsable; | ||
24 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
25 | +import org.onosproject.yangutils.utils.io.CachedFileHandle; | ||
26 | +/*- | ||
27 | + * Reference RFC 6020. | ||
28 | + * | ||
29 | + * The "container" statement is used to define an interior data node in the | ||
30 | + * schema tree. It takes one argument, which is an identifier, followed by a | ||
31 | + * block of sub-statements that holds detailed container information. | ||
32 | + * | ||
33 | + * A container node does not have a value, but it has a list of child nodes in | ||
34 | + * the data tree. The child nodes are defined in the container's sub-statements. | ||
35 | + * | ||
36 | + * Containers with Presence | ||
37 | + * | ||
38 | + * YANG supports two styles of containers, those that exist only for organizing | ||
39 | + * the hierarchy of data nodes, and those whose presence in the configuration | ||
40 | + * has an explicit meaning. | ||
41 | + * | ||
42 | + * In the first style, the container has no meaning of its own, existing only to | ||
43 | + * contain child nodes. This is the default style. | ||
44 | + * | ||
45 | + * For example, the set of scrambling options for Synchronous Optical Network | ||
46 | + * (SONET) interfaces may be placed inside a "scrambling" container to enhance | ||
47 | + * the organization of the configuration hierarchy, and to keep these nodes | ||
48 | + * together. The "scrambling" node itself has no meaning, so removing the node | ||
49 | + * when it becomes empty relieves the user from performing this task. | ||
50 | + * | ||
51 | + * In the second style, the presence of the container itself is configuration | ||
52 | + * data, representing a single bit of configuration data. The container acts as | ||
53 | + * both a configuration knob and a means of organizing related configuration. | ||
54 | + * These containers are explicitly created and deleted. | ||
55 | + * | ||
56 | + * YANG calls this style a "presence container" and it is indicated using the | ||
57 | + * "presence" statement, which takes as its argument a text string indicating | ||
58 | + * what the presence of the node means. | ||
59 | + * | ||
60 | + * The container's Substatements | ||
61 | + * | ||
62 | + * +--------------+---------+-------------+------------------+ | ||
63 | + * | substatement | section | cardinality |data model mapping| | ||
64 | + * +--------------+---------+-------------+------------------+ | ||
65 | + * | anyxml | 7.10 | 0..n | -not supported | | ||
66 | + * | choice | 7.9 | 0..n | -child nodes | | ||
67 | + * | config | 7.19.1 | 0..1 | -boolean | | ||
68 | + * | container | 7.5 | 0..n | -child nodes | | ||
69 | + * | description | 7.19.3 | 0..1 | -string | | ||
70 | + * | grouping | 7.11 | 0..n | -child nodes | | ||
71 | + * | if-feature | 7.18.2 | 0..n | -TODO | | ||
72 | + * | leaf | 7.6 | 0..n | -YangLeaf | | ||
73 | + * | leaf-list | 7.7 | 0..n | -YangLeafList | | ||
74 | + * | list | 7.8 | 0..n | -child nodes | | ||
75 | + * | must | 7.5.3 | 0..n | -TODO | | ||
76 | + * | presence | 7.5.5 | 0..1 | -boolean | | ||
77 | + * | reference | 7.19.4 | 0..1 | -string | | ||
78 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
79 | + * | typedef | 7.3 | 0..n | -child nodes | | ||
80 | + * | uses | 7.12 | 0..n | -child nodes | | ||
81 | + * | when | 7.19.5 | 0..1 | -TODO | | ||
82 | + * +--------------+---------+-------------+------------------+ | ||
83 | + */ | ||
84 | + | ||
85 | +/** | ||
86 | + * Data model node to maintain information defined in YANG container. | ||
87 | + */ | ||
88 | +public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable { | ||
89 | + | ||
90 | + /** | ||
91 | + * Name of the container. | ||
92 | + */ | ||
93 | + private String name; | ||
94 | + | ||
95 | + /** | ||
96 | + * If container maintains config data. | ||
97 | + */ | ||
98 | + private boolean isConfig; | ||
99 | + | ||
100 | + /** | ||
101 | + * Description of container. | ||
102 | + */ | ||
103 | + private String description; | ||
104 | + | ||
105 | + /** | ||
106 | + * List of leaves contained. | ||
107 | + */ | ||
108 | + @SuppressWarnings("rawtypes") | ||
109 | + private List<YangLeaf> listOfLeaf; | ||
110 | + | ||
111 | + /** | ||
112 | + * List of leaf-lists contained. | ||
113 | + */ | ||
114 | + @SuppressWarnings("rawtypes") | ||
115 | + private List<YangLeafList> listOfLeafList; | ||
116 | + | ||
117 | + /** | ||
118 | + * If it is a presence container, then the textual documentation of presence | ||
119 | + * usage. | ||
120 | + */ | ||
121 | + private String presence; | ||
122 | + | ||
123 | + /** | ||
124 | + * Reference of the module. | ||
125 | + */ | ||
126 | + private String reference; | ||
127 | + | ||
128 | + /** | ||
129 | + * Status of the node. | ||
130 | + */ | ||
131 | + private YangStatusType status; | ||
132 | + | ||
133 | + /** | ||
134 | + * package of the generated java code. | ||
135 | + */ | ||
136 | + private String pkg; | ||
137 | + | ||
138 | + /** | ||
139 | + * Cached Java File Handle. | ||
140 | + */ | ||
141 | + private CachedFileHandle fileHandle; | ||
142 | + | ||
143 | + /** | ||
144 | + * Create a container node. | ||
145 | + */ | ||
146 | + public YangContainer() { | ||
147 | + super(YangNodeType.CONTAINER_NODE); | ||
148 | + } | ||
149 | + | ||
150 | + /* (non-Javadoc) | ||
151 | + * @see org.onosproject.yangutils.datamodel.YangNode#getName() | ||
152 | + */ | ||
153 | + @Override | ||
154 | + public String getName() { | ||
155 | + return name; | ||
156 | + } | ||
157 | + | ||
158 | + /* (non-Javadoc) | ||
159 | + * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) | ||
160 | + */ | ||
161 | + @Override | ||
162 | + public void setName(String name) { | ||
163 | + this.name = name; | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Get the config flag. | ||
168 | + * | ||
169 | + * @return the isConfig | ||
170 | + */ | ||
171 | + public boolean isConfig() { | ||
172 | + return isConfig; | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * Set the config flag. | ||
177 | + * | ||
178 | + * @param isCfg the config flag. | ||
179 | + */ | ||
180 | + public void setConfig(boolean isCfg) { | ||
181 | + isConfig = isCfg; | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Get the description. | ||
186 | + * | ||
187 | + * @return the description. | ||
188 | + */ | ||
189 | + public String getDescription() { | ||
190 | + return description; | ||
191 | + } | ||
192 | + | ||
193 | + /** | ||
194 | + * Set the description. | ||
195 | + * | ||
196 | + * @param description set the description. | ||
197 | + */ | ||
198 | + public void setDescription(String description) { | ||
199 | + this.description = description; | ||
200 | + } | ||
201 | + | ||
202 | + /** | ||
203 | + * Get the list of leaves. | ||
204 | + * | ||
205 | + * @return the list of leaves. | ||
206 | + */ | ||
207 | + @SuppressWarnings("rawtypes") | ||
208 | + public List<YangLeaf> getListOfLeaf() { | ||
209 | + return listOfLeaf; | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Set the list of leaves. | ||
214 | + * | ||
215 | + * @param leafsList the list of leaf to set. | ||
216 | + */ | ||
217 | + @SuppressWarnings("rawtypes") | ||
218 | + private void setListOfLeaf(List<YangLeaf> leafsList) { | ||
219 | + listOfLeaf = leafsList; | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * Add a leaf. | ||
224 | + * | ||
225 | + * @param leaf the leaf to be added. | ||
226 | + */ | ||
227 | + @SuppressWarnings("rawtypes") | ||
228 | + public void addLeaf(YangLeaf<?> leaf) { | ||
229 | + if (getListOfLeaf() == null) { | ||
230 | + setListOfLeaf(new LinkedList<YangLeaf>()); | ||
231 | + } | ||
232 | + | ||
233 | + getListOfLeaf().add(leaf); | ||
234 | + } | ||
235 | + | ||
236 | + /** | ||
237 | + * Get the list of leaf-list. | ||
238 | + * | ||
239 | + * @return the list of leaf-list. | ||
240 | + */ | ||
241 | + @SuppressWarnings("rawtypes") | ||
242 | + public List<YangLeafList> getListOfLeafList() { | ||
243 | + return listOfLeafList; | ||
244 | + } | ||
245 | + | ||
246 | + /** | ||
247 | + * Set the list of leaf-list. | ||
248 | + * | ||
249 | + * @param listOfLeafList the list of leaf-list to set. | ||
250 | + */ | ||
251 | + @SuppressWarnings("rawtypes") | ||
252 | + private void setListOfLeafList(List<YangLeafList> listOfLeafList) { | ||
253 | + this.listOfLeafList = listOfLeafList; | ||
254 | + } | ||
255 | + | ||
256 | + /** | ||
257 | + * Add a leaf-list. | ||
258 | + * | ||
259 | + * @param leafList the leaf-list to be added. | ||
260 | + */ | ||
261 | + @SuppressWarnings("rawtypes") | ||
262 | + public void addLeafList(YangLeafList<?> leafList) { | ||
263 | + if (getListOfLeafList() == null) { | ||
264 | + setListOfLeafList(new LinkedList<YangLeafList>()); | ||
265 | + } | ||
266 | + | ||
267 | + getListOfLeafList().add(leafList); | ||
268 | + } | ||
269 | + | ||
270 | + /** | ||
271 | + * Get the presence string if present. | ||
272 | + * | ||
273 | + * @return the isPressence. | ||
274 | + */ | ||
275 | + public String getPresence() { | ||
276 | + return presence; | ||
277 | + } | ||
278 | + | ||
279 | + /** | ||
280 | + * Set the presence string. | ||
281 | + * | ||
282 | + * @param presence the presence flag | ||
283 | + */ | ||
284 | + public void setPresence(String presence) { | ||
285 | + this.presence = presence; | ||
286 | + } | ||
287 | + | ||
288 | + /** | ||
289 | + * Get the textual reference. | ||
290 | + * | ||
291 | + * @return the reference. | ||
292 | + */ | ||
293 | + public String getReference() { | ||
294 | + return reference; | ||
295 | + } | ||
296 | + | ||
297 | + /** | ||
298 | + * Set the textual reference. | ||
299 | + * | ||
300 | + * @param reference the reference to set. | ||
301 | + */ | ||
302 | + public void setReference(String reference) { | ||
303 | + this.reference = reference; | ||
304 | + } | ||
305 | + | ||
306 | + /** | ||
307 | + * Get the status. | ||
308 | + * | ||
309 | + * @return the status. | ||
310 | + */ | ||
311 | + public YangStatusType getStatus() { | ||
312 | + return status; | ||
313 | + } | ||
314 | + | ||
315 | + /** | ||
316 | + * Set the status. | ||
317 | + * | ||
318 | + * @param status the status to set. | ||
319 | + */ | ||
320 | + public void setStatus(YangStatusType status) { | ||
321 | + this.status = status; | ||
322 | + } | ||
323 | + | ||
324 | + /** | ||
325 | + * Get the cached file handle. | ||
326 | + * | ||
327 | + * @return the fileHandle | ||
328 | + */ | ||
329 | + public CachedFileHandle getFileHandle() { | ||
330 | + return fileHandle; | ||
331 | + } | ||
332 | + | ||
333 | + /** | ||
334 | + * Set the cached file handle. | ||
335 | + * | ||
336 | + * @param handle the fileHandle to set | ||
337 | + */ | ||
338 | + public void setFileHandle(CachedFileHandle handle) { | ||
339 | + fileHandle = handle; | ||
340 | + } | ||
341 | + | ||
342 | + /** | ||
343 | + * Returns the type of the data. | ||
344 | + * | ||
345 | + * @return returns CONTAINER_DATA. | ||
346 | + */ | ||
347 | + public ParsableDataType getParsableDataType() { | ||
348 | + return ParsableDataType.CONTAINER_DATA; | ||
349 | + } | ||
350 | + | ||
351 | + /** | ||
352 | + * Validate the data on entering the corresponding parse tree node. | ||
353 | + * | ||
354 | + * @throws DataModelException a violation of data model rules. | ||
355 | + */ | ||
356 | + public void validateDataOnEntry() throws DataModelException { | ||
357 | + // TODO auto-generated method stub, to be implemented by parser | ||
358 | + } | ||
359 | + | ||
360 | + /** | ||
361 | + * Validate the data on exiting the corresponding parse tree node. | ||
362 | + * | ||
363 | + * @throws DataModelException a violation of data model rules. | ||
364 | + */ | ||
365 | + public void validateDataOnExit() throws DataModelException { | ||
366 | + // TODO auto-generated method stub, to be implemented by parser | ||
367 | + } | ||
368 | + | ||
369 | + /** | ||
370 | + * Get the mapped java package. | ||
371 | + * | ||
372 | + * @return the java package | ||
373 | + */ | ||
374 | + @Override | ||
375 | + public String getPackage() { | ||
376 | + return pkg; | ||
377 | + } | ||
378 | + | ||
379 | + /** | ||
380 | + * Set the mapped java package. | ||
381 | + * | ||
382 | + * @param pcg the package to set | ||
383 | + */ | ||
384 | + @Override | ||
385 | + public void setPackage(String pcg) { | ||
386 | + pkg = pcg; | ||
387 | + } | ||
388 | + | ||
389 | + /** | ||
390 | + * Generate the java code corresponding to YANG container. | ||
391 | + */ | ||
392 | + public void generateJavaCodeEntry() { | ||
393 | + //TODO: autogenerated method stub, to be implemented | ||
394 | + return; | ||
395 | + } | ||
396 | + | ||
397 | + /** | ||
398 | + * Free resources used to generate code. | ||
399 | + */ | ||
400 | + public void generateJavaCodeExit() { | ||
401 | + //TODO: autogenerated method stub, to be implemented | ||
402 | + return; | ||
403 | + } | ||
404 | +} |
... | @@ -22,18 +22,21 @@ package org.onosproject.yangutils.datamodel; | ... | @@ -22,18 +22,21 @@ package org.onosproject.yangutils.datamodel; |
22 | public enum YangDataTypes { | 22 | public enum YangDataTypes { |
23 | /** | 23 | /** |
24 | * Reference:RFC 6020. | 24 | * Reference:RFC 6020. |
25 | + * | ||
25 | * int8 represents integer values between -128 and 127, inclusively. | 26 | * int8 represents integer values between -128 and 127, inclusively. |
26 | */ | 27 | */ |
27 | INT8, | 28 | INT8, |
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Reference:RFC 6020. | 31 | * Reference:RFC 6020. |
32 | + * | ||
31 | * int16 represents integer values between -32768 and 32767, inclusively. | 33 | * int16 represents integer values between -32768 and 32767, inclusively. |
32 | */ | 34 | */ |
33 | INT16, | 35 | INT16, |
34 | 36 | ||
35 | /** | 37 | /** |
36 | * Reference:RFC 6020. | 38 | * Reference:RFC 6020. |
39 | + * | ||
37 | * int32 represents integer values between -2147483648 and 2147483647, | 40 | * int32 represents integer values between -2147483648 and 2147483647, |
38 | * inclusively. | 41 | * inclusively. |
39 | */ | 42 | */ |
... | @@ -41,6 +44,7 @@ public enum YangDataTypes { | ... | @@ -41,6 +44,7 @@ public enum YangDataTypes { |
41 | 44 | ||
42 | /** | 45 | /** |
43 | * Reference:RFC 6020. | 46 | * Reference:RFC 6020. |
47 | + * | ||
44 | * int64 represents integer values between -9223372036854775808 and | 48 | * int64 represents integer values between -9223372036854775808 and |
45 | * 9223372036854775807, inclusively. | 49 | * 9223372036854775807, inclusively. |
46 | */ | 50 | */ |
... | @@ -48,24 +52,28 @@ public enum YangDataTypes { | ... | @@ -48,24 +52,28 @@ public enum YangDataTypes { |
48 | 52 | ||
49 | /** | 53 | /** |
50 | * Reference:RFC 6020. | 54 | * Reference:RFC 6020. |
55 | + * | ||
51 | * uint8 represents integer values between 0 and 255, inclusively. | 56 | * uint8 represents integer values between 0 and 255, inclusively. |
52 | */ | 57 | */ |
53 | UINT8, | 58 | UINT8, |
54 | 59 | ||
55 | /** | 60 | /** |
56 | * Reference:RFC 6020. | 61 | * Reference:RFC 6020. |
62 | + * | ||
57 | * uint16 represents integer values between 0 and 65535, inclusively. | 63 | * uint16 represents integer values between 0 and 65535, inclusively. |
58 | */ | 64 | */ |
59 | UINT16, | 65 | UINT16, |
60 | 66 | ||
61 | /** | 67 | /** |
62 | * Reference:RFC 6020. | 68 | * Reference:RFC 6020. |
69 | + * | ||
63 | * uint32 represents integer values between 0 and 4294967295, inclusively. | 70 | * uint32 represents integer values between 0 and 4294967295, inclusively. |
64 | */ | 71 | */ |
65 | UINT32, | 72 | UINT32, |
66 | 73 | ||
67 | /** | 74 | /** |
68 | * Reference:RFC 6020. | 75 | * Reference:RFC 6020. |
76 | + * | ||
69 | * uint64 represents integer values between 0 and 18446744073709551615, | 77 | * uint64 represents integer values between 0 and 18446744073709551615, |
70 | * inclusively. | 78 | * inclusively. |
71 | */ | 79 | */ |
... | @@ -73,6 +81,7 @@ public enum YangDataTypes { | ... | @@ -73,6 +81,7 @@ public enum YangDataTypes { |
73 | 81 | ||
74 | /** | 82 | /** |
75 | * Reference:RFC 6020. | 83 | * Reference:RFC 6020. |
84 | + * | ||
76 | * The decimal64 type represents a subset of the real numbers, which can be | 85 | * The decimal64 type represents a subset of the real numbers, which can be |
77 | * represented by decimal numerals. The value space of decimal64 is the set | 86 | * represented by decimal numerals. The value space of decimal64 is the set |
78 | * of numbers that can be obtained by multiplying a 64-bit signed integer by | 87 | * of numbers that can be obtained by multiplying a 64-bit signed integer by |
... | @@ -83,6 +92,7 @@ public enum YangDataTypes { | ... | @@ -83,6 +92,7 @@ public enum YangDataTypes { |
83 | 92 | ||
84 | /** | 93 | /** |
85 | * Reference:RFC 6020. | 94 | * Reference:RFC 6020. |
95 | + * | ||
86 | * The string built-in type represents human-readable strings in YANG. Legal | 96 | * The string built-in type represents human-readable strings in YANG. Legal |
87 | * characters are tab, carriage return, line feed, and the legal characters | 97 | * characters are tab, carriage return, line feed, and the legal characters |
88 | * of Unicode and ISO/IEC 10646 | 98 | * of Unicode and ISO/IEC 10646 |
... | @@ -91,12 +101,14 @@ public enum YangDataTypes { | ... | @@ -91,12 +101,14 @@ public enum YangDataTypes { |
91 | 101 | ||
92 | /** | 102 | /** |
93 | * Reference:RFC 6020. | 103 | * Reference:RFC 6020. |
104 | + * | ||
94 | * The boolean built-in type represents a boolean value. | 105 | * The boolean built-in type represents a boolean value. |
95 | */ | 106 | */ |
96 | BOOLEAN, | 107 | BOOLEAN, |
97 | 108 | ||
98 | /** | 109 | /** |
99 | * Reference:RFC 6020. | 110 | * Reference:RFC 6020. |
111 | + * | ||
100 | * The enumeration built-in type represents values from a set of assigned | 112 | * The enumeration built-in type represents values from a set of assigned |
101 | * names. | 113 | * names. |
102 | */ | 114 | */ |
... | @@ -104,6 +116,7 @@ public enum YangDataTypes { | ... | @@ -104,6 +116,7 @@ public enum YangDataTypes { |
104 | 116 | ||
105 | /** | 117 | /** |
106 | * Reference:RFC 6020. | 118 | * Reference:RFC 6020. |
119 | + * | ||
107 | * The bits built-in type represents a bit set. That is, a bits value is a | 120 | * The bits built-in type represents a bit set. That is, a bits value is a |
108 | * set of flags identified by small integer position numbers starting at 0. | 121 | * set of flags identified by small integer position numbers starting at 0. |
109 | * Each bit number has an assigned name. | 122 | * Each bit number has an assigned name. |
... | @@ -112,6 +125,7 @@ public enum YangDataTypes { | ... | @@ -112,6 +125,7 @@ public enum YangDataTypes { |
112 | 125 | ||
113 | /** | 126 | /** |
114 | * Reference:RFC 6020. | 127 | * Reference:RFC 6020. |
128 | + * | ||
115 | * The binary built-in type represents any binary data, i.e., a sequence of | 129 | * The binary built-in type represents any binary data, i.e., a sequence of |
116 | * octets. | 130 | * octets. |
117 | */ | 131 | */ |
... | @@ -119,6 +133,7 @@ public enum YangDataTypes { | ... | @@ -119,6 +133,7 @@ public enum YangDataTypes { |
119 | 133 | ||
120 | /** | 134 | /** |
121 | * Reference:RFC 6020. | 135 | * Reference:RFC 6020. |
136 | + * | ||
122 | * The leafref type is used to reference a particular leaf instance in the | 137 | * The leafref type is used to reference a particular leaf instance in the |
123 | * data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf | 138 | * data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf |
124 | * instances, and the leafref value space is the set of values of these leaf | 139 | * instances, and the leafref value space is the set of values of these leaf |
... | @@ -139,12 +154,14 @@ public enum YangDataTypes { | ... | @@ -139,12 +154,14 @@ public enum YangDataTypes { |
139 | 154 | ||
140 | /** | 155 | /** |
141 | * Reference:RFC 6020. | 156 | * Reference:RFC 6020. |
157 | + * | ||
142 | * The identityref type is used to reference an existing identity. | 158 | * The identityref type is used to reference an existing identity. |
143 | */ | 159 | */ |
144 | IDENTITYREF, | 160 | IDENTITYREF, |
145 | 161 | ||
146 | /** | 162 | /** |
147 | * Reference:RFC 6020. | 163 | * Reference:RFC 6020. |
164 | + * | ||
148 | * The empty built-in type represents a leaf that does not have any value, | 165 | * The empty built-in type represents a leaf that does not have any value, |
149 | * it conveys information by its presence or absence. | 166 | * it conveys information by its presence or absence. |
150 | * | 167 | * |
... | @@ -154,6 +171,7 @@ public enum YangDataTypes { | ... | @@ -154,6 +171,7 @@ public enum YangDataTypes { |
154 | 171 | ||
155 | /** | 172 | /** |
156 | * Reference:RFC 6020. | 173 | * Reference:RFC 6020. |
174 | + * | ||
157 | * The union built-in type represents a value that corresponds to one of its | 175 | * The union built-in type represents a value that corresponds to one of its |
158 | * member types. | 176 | * member types. |
159 | * | 177 | * |
... | @@ -175,6 +193,7 @@ public enum YangDataTypes { | ... | @@ -175,6 +193,7 @@ public enum YangDataTypes { |
175 | 193 | ||
176 | /** | 194 | /** |
177 | * Reference:RFC 6020. | 195 | * Reference:RFC 6020. |
196 | + * | ||
178 | * The instance-identifier built-in type is used to uniquely identify a | 197 | * The instance-identifier built-in type is used to uniquely identify a |
179 | * particular instance node in the data tree. | 198 | * particular instance node in the data tree. |
180 | * | 199 | * | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.datamodel; | ||
18 | + | ||
19 | +import java.util.LinkedList; | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.parser.Parsable; | ||
24 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
25 | + | ||
26 | +/*- | ||
27 | + * The "list" statement is used to define an interior data node in the | ||
28 | + * schema tree. A list node may exist in multiple instances in the data | ||
29 | + * tree. Each such instance is known as a list entry. The "list" | ||
30 | + * statement takes one argument, which is an identifier, followed by a | ||
31 | + * block of sub-statements that holds detailed list information. | ||
32 | + * | ||
33 | + * A list entry is uniquely identified by the values of the list's keys, | ||
34 | + * if defined. | ||
35 | + * | ||
36 | + * The list's sub-statements | ||
37 | + * | ||
38 | + * +--------------+---------+-------------+------------------+ | ||
39 | + * | substatement | section | cardinality |data model mapping| | ||
40 | + * +--------------+---------+-------------+------------------+ | ||
41 | + * | anyxml | 7.10 | 0..n |-not supported | | ||
42 | + * | choice | 7.9 | 0..n |-child nodes | | ||
43 | + * | config | 7.19.1 | 0..1 |-boolean | | ||
44 | + * | container | 7.5 | 0..n |-child nodes | | ||
45 | + * | description | 7.19.3 | 0..1 |-string | | ||
46 | + * | grouping | 7.11 | 0..n |-child nodes | | ||
47 | + * | if-feature | 7.18.2 | 0..n |-TODO | | ||
48 | + * | key | 7.8.2 | 0..1 |-String list | | ||
49 | + * | leaf | 7.6 | 0..n |-YangLeaf | | ||
50 | + * | leaf-list | 7.7 | 0..n |-YangLeafList | | ||
51 | + * | list | 7.8 | 0..n |-child nodes | | ||
52 | + * | max-elements | 7.7.4 | 0..1 |-int | | ||
53 | + * | min-elements | 7.7.3 | 0..1 |-int | | ||
54 | + * | must | 7.5.3 | 0..n |-TODO | | ||
55 | + * | ordered-by | 7.7.5 | 0..1 |-TODO | | ||
56 | + * | reference | 7.19.4 | 0..1 |-string | | ||
57 | + * | status | 7.19.2 | 0..1 |-YangStatus | | ||
58 | + * | typedef | 7.3 | 0..n |-child nodes | | ||
59 | + * | unique | 7.8.3 | 0..n |-TODO | | ||
60 | + * | uses | 7.12 | 0..n |-child nodes(TODO)| | ||
61 | + * | when | 7.19.5 | 0..1 |-TODO | | ||
62 | + * +--------------+---------+-------------+------------------+ | ||
63 | + */ | ||
64 | + | ||
65 | +/** | ||
66 | + * List data represented in YANG. | ||
67 | + */ | ||
68 | +public class YangList extends YangNode | ||
69 | + implements YangLeavesHolder, YangCommonInfo, Parsable { | ||
70 | + | ||
71 | + /** | ||
72 | + * name of the YANG list. | ||
73 | + */ | ||
74 | + private String name; | ||
75 | + | ||
76 | + /** | ||
77 | + * If list maintains config data. | ||
78 | + */ | ||
79 | + private boolean isConfig; | ||
80 | + | ||
81 | + /** | ||
82 | + * Description of list. | ||
83 | + */ | ||
84 | + private String description; | ||
85 | + | ||
86 | + /** | ||
87 | + * Reference RFC 6020. | ||
88 | + * | ||
89 | + * The "key" statement, which MUST be present if the list represents | ||
90 | + * configuration, and MAY be present otherwise, takes as an argument a | ||
91 | + * string that specifies a space-separated list of leaf identifiers of this | ||
92 | + * list. A leaf identifier MUST NOT appear more than once in the key. Each | ||
93 | + * such leaf identifier MUST refer to a child leaf of the list. The leafs | ||
94 | + * can be defined directly in sub-statements to the list, or in groupings | ||
95 | + * used in the list. | ||
96 | + * | ||
97 | + * The combined values of all the leafs specified in the key are used to | ||
98 | + * uniquely identify a list entry. All key leafs MUST be given values when a | ||
99 | + * list entry is created. Thus, any default values in the key leafs or their | ||
100 | + * types are ignored. It also implies that any mandatory statement in the | ||
101 | + * key leafs are ignored. | ||
102 | + * | ||
103 | + * A leaf that is part of the key can be of any built-in or derived type, | ||
104 | + * except it MUST NOT be the built-in type "empty". | ||
105 | + * | ||
106 | + * All key leafs in a list MUST have the same value for their "config" as | ||
107 | + * the list itself. | ||
108 | + * | ||
109 | + * List of key leaf names. | ||
110 | + */ | ||
111 | + private List<String> keyList; | ||
112 | + | ||
113 | + /** | ||
114 | + * List of leaves. | ||
115 | + */ | ||
116 | + @SuppressWarnings("rawtypes") | ||
117 | + private List<YangLeaf> listOfLeaf; | ||
118 | + | ||
119 | + /** | ||
120 | + * List of leaf-lists. | ||
121 | + */ | ||
122 | + @SuppressWarnings("rawtypes") | ||
123 | + private List<YangLeafList> listOfLeafList; | ||
124 | + | ||
125 | + /** | ||
126 | + * The "max-elements" statement, which is optional, takes as an argument a | ||
127 | + * positive integer or the string "unbounded", which puts a constraint on | ||
128 | + * valid list entries. A valid leaf-list or list always has at most | ||
129 | + * max-elements entries. | ||
130 | + * | ||
131 | + * If no "max-elements" statement is present, it defaults to "unbounded". | ||
132 | + */ | ||
133 | + private int maxElelements; | ||
134 | + | ||
135 | + /** | ||
136 | + * The "min-elements" statement, which is optional, takes as an argument a | ||
137 | + * non-negative integer that puts a constraint on valid list entries. A | ||
138 | + * valid leaf-list or list MUST have at least min-elements entries. | ||
139 | + * | ||
140 | + * If no "min-elements" statement is present, it defaults to zero. | ||
141 | + * | ||
142 | + * The behavior of the constraint depends on the type of the leaf-list's or | ||
143 | + * list's closest ancestor node in the schema tree that is not a non- | ||
144 | + * presence container: | ||
145 | + * | ||
146 | + * o If this ancestor is a case node, the constraint is enforced if any | ||
147 | + * other node from the case exists. | ||
148 | + * | ||
149 | + * o Otherwise, it is enforced if the ancestor node exists. | ||
150 | + */ | ||
151 | + private int minElements; | ||
152 | + | ||
153 | + /** | ||
154 | + * reference. | ||
155 | + */ | ||
156 | + private String reference; | ||
157 | + | ||
158 | + /** | ||
159 | + * Status of the node. | ||
160 | + */ | ||
161 | + | ||
162 | + private YangStatusType status; | ||
163 | + | ||
164 | + /** | ||
165 | + * Constructor. | ||
166 | + * | ||
167 | + * @param type list node | ||
168 | + */ | ||
169 | + public YangList(YangNodeType type) { | ||
170 | + super(type); | ||
171 | + } | ||
172 | + | ||
173 | + /* (non-Javadoc) | ||
174 | + * @see org.onosproject.yangutils.datamodel.YangNode#getName() | ||
175 | + */ | ||
176 | + @Override | ||
177 | + public String getName() { | ||
178 | + return name; | ||
179 | + } | ||
180 | + | ||
181 | + /* (non-Javadoc) | ||
182 | + * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) | ||
183 | + */ | ||
184 | + @Override | ||
185 | + public void setName(String name) { | ||
186 | + this.name = name; | ||
187 | + } | ||
188 | + | ||
189 | + /** | ||
190 | + * Get the config flag. | ||
191 | + * | ||
192 | + * @return the isConfig | ||
193 | + */ | ||
194 | + public boolean isConfig() { | ||
195 | + return isConfig; | ||
196 | + } | ||
197 | + | ||
198 | + /** | ||
199 | + * Set the config flag. | ||
200 | + * | ||
201 | + * @param isCfg the config flag. | ||
202 | + */ | ||
203 | + public void setConfig(boolean isCfg) { | ||
204 | + isConfig = isCfg; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Get the description. | ||
209 | + * | ||
210 | + * @return the description. | ||
211 | + */ | ||
212 | + public String getDescription() { | ||
213 | + return description; | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
217 | + * Set the description. | ||
218 | + * | ||
219 | + * @param description set the description. | ||
220 | + */ | ||
221 | + public void setDescription(String description) { | ||
222 | + this.description = description; | ||
223 | + } | ||
224 | + | ||
225 | + /** | ||
226 | + * Get the list of key field names. | ||
227 | + * | ||
228 | + * @return the list of key field names. | ||
229 | + */ | ||
230 | + public List<String> getKeyList() { | ||
231 | + return keyList; | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Set the list of key field names. | ||
236 | + * | ||
237 | + * @param keyList the list of key field names. | ||
238 | + */ | ||
239 | + private void setKeyList(List<String> keyList) { | ||
240 | + this.keyList = keyList; | ||
241 | + } | ||
242 | + | ||
243 | + /** | ||
244 | + * Add a key field name. | ||
245 | + * | ||
246 | + * @param key key field name. | ||
247 | + */ | ||
248 | + public void addKey(String key) { | ||
249 | + if (getKeyList() == null) { | ||
250 | + setKeyList(new LinkedList<String>()); | ||
251 | + } | ||
252 | + | ||
253 | + getKeyList().add(key); | ||
254 | + } | ||
255 | + | ||
256 | + /** | ||
257 | + * Get the list of leaves. | ||
258 | + * | ||
259 | + * @return the list of leaves. | ||
260 | + */ | ||
261 | + @SuppressWarnings("rawtypes") | ||
262 | + public List<YangLeaf> getListOfLeaf() { | ||
263 | + return listOfLeaf; | ||
264 | + } | ||
265 | + | ||
266 | + /** | ||
267 | + * Set the list of leaves. | ||
268 | + * | ||
269 | + * @param leafsList the list of leaf to set. | ||
270 | + */ | ||
271 | + @SuppressWarnings("rawtypes") | ||
272 | + private void setListOfLeaf(List<YangLeaf> leafsList) { | ||
273 | + listOfLeaf = leafsList; | ||
274 | + } | ||
275 | + | ||
276 | + /** | ||
277 | + * Add a leaf. | ||
278 | + * | ||
279 | + * @param leaf the leaf to be added. | ||
280 | + */ | ||
281 | + @SuppressWarnings("rawtypes") | ||
282 | + public void addLeaf(YangLeaf<?> leaf) { | ||
283 | + if (getListOfLeaf() == null) { | ||
284 | + setListOfLeaf(new LinkedList<YangLeaf>()); | ||
285 | + } | ||
286 | + | ||
287 | + getListOfLeaf().add(leaf); | ||
288 | + } | ||
289 | + | ||
290 | + /** | ||
291 | + * Get the list of leaf-list. | ||
292 | + * | ||
293 | + * @return the list of leaf-list. | ||
294 | + */ | ||
295 | + @SuppressWarnings("rawtypes") | ||
296 | + public List<YangLeafList> getListOfLeafList() { | ||
297 | + return listOfLeafList; | ||
298 | + } | ||
299 | + | ||
300 | + /** | ||
301 | + * Set the list of leaf-list. | ||
302 | + * | ||
303 | + * @param listOfLeafList the list of leaf-list to set. | ||
304 | + */ | ||
305 | + @SuppressWarnings("rawtypes") | ||
306 | + private void setListOfLeafList(List<YangLeafList> listOfLeafList) { | ||
307 | + this.listOfLeafList = listOfLeafList; | ||
308 | + } | ||
309 | + | ||
310 | + /** | ||
311 | + * Add a leaf-list. | ||
312 | + * | ||
313 | + * @param leafList the leaf-list to be added. | ||
314 | + */ | ||
315 | + @SuppressWarnings("rawtypes") | ||
316 | + public void addLeafList(YangLeafList<?> leafList) { | ||
317 | + if (getListOfLeafList() == null) { | ||
318 | + setListOfLeafList(new LinkedList<YangLeafList>()); | ||
319 | + } | ||
320 | + | ||
321 | + getListOfLeafList().add(leafList); | ||
322 | + } | ||
323 | + | ||
324 | + /** | ||
325 | + * Get the max elements. | ||
326 | + * | ||
327 | + * @return the max elements. | ||
328 | + */ | ||
329 | + public int getMaxElelements() { | ||
330 | + return maxElelements; | ||
331 | + } | ||
332 | + | ||
333 | + /** | ||
334 | + * Set the max elements. | ||
335 | + * | ||
336 | + * @param maxElelements the max elements. | ||
337 | + */ | ||
338 | + public void setMaxElelements(int maxElelements) { | ||
339 | + this.maxElelements = maxElelements; | ||
340 | + } | ||
341 | + | ||
342 | + /** | ||
343 | + * Get the minimum elements. | ||
344 | + * | ||
345 | + * @return the minimum elements. | ||
346 | + */ | ||
347 | + public int getMinElements() { | ||
348 | + return minElements; | ||
349 | + } | ||
350 | + | ||
351 | + /** | ||
352 | + * Set the minimum elements. | ||
353 | + * | ||
354 | + * @param minElements the minimum elements. | ||
355 | + */ | ||
356 | + public void setMinElements(int minElements) { | ||
357 | + this.minElements = minElements; | ||
358 | + } | ||
359 | + | ||
360 | + /** | ||
361 | + * Get the textual reference. | ||
362 | + * | ||
363 | + * @return the reference. | ||
364 | + */ | ||
365 | + public String getReference() { | ||
366 | + return reference; | ||
367 | + } | ||
368 | + | ||
369 | + /** | ||
370 | + * Set the textual reference. | ||
371 | + * | ||
372 | + * @param reference the reference to set. | ||
373 | + */ | ||
374 | + public void setReference(String reference) { | ||
375 | + this.reference = reference; | ||
376 | + } | ||
377 | + | ||
378 | + /** | ||
379 | + * Get the status. | ||
380 | + * | ||
381 | + * @return the status. | ||
382 | + */ | ||
383 | + public YangStatusType getStatus() { | ||
384 | + return status; | ||
385 | + } | ||
386 | + | ||
387 | + /** | ||
388 | + * Set the status. | ||
389 | + * | ||
390 | + * @param status the status to set. | ||
391 | + */ | ||
392 | + public void setStatus(YangStatusType status) { | ||
393 | + this.status = status; | ||
394 | + } | ||
395 | + | ||
396 | + /** | ||
397 | + * Returns the type of the parsed data. | ||
398 | + * | ||
399 | + * @return returns LIST_DATA. | ||
400 | + */ | ||
401 | + public ParsableDataType getParsableDataType() { | ||
402 | + return ParsableDataType.LIST_DATA; | ||
403 | + } | ||
404 | + | ||
405 | + /** | ||
406 | + * Validate the data on entering the corresponding parse tree node. | ||
407 | + * | ||
408 | + * @throws DataModelException a violation of data model rules. | ||
409 | + */ | ||
410 | + public void validateDataOnEntry() throws DataModelException { | ||
411 | + // TODO auto-generated method stub, to be implemented by parser | ||
412 | + } | ||
413 | + | ||
414 | + /** | ||
415 | + * Validate the data on exiting the corresponding parse tree node. | ||
416 | + * | ||
417 | + * @throws DataModelException a violation of data model rules. | ||
418 | + */ | ||
419 | + public void validateDataOnExit() throws DataModelException { | ||
420 | + // TODO auto-generated method stub, to be implemented by parser | ||
421 | + } | ||
422 | + | ||
423 | + /* (non-Javadoc) | ||
424 | + * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() | ||
425 | + */ | ||
426 | + public void generateJavaCodeEntry() { | ||
427 | + // TODO Auto-generated method stub | ||
428 | + | ||
429 | + } | ||
430 | + | ||
431 | + /* (non-Javadoc) | ||
432 | + * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() | ||
433 | + */ | ||
434 | + public void generateJavaCodeExit() { | ||
435 | + // TODO Auto-generated method stub | ||
436 | + | ||
437 | + } | ||
438 | + | ||
439 | + /* (non-Javadoc) | ||
440 | + * @see org.onosproject.yangutils.datamodel.YangNode#getPackage() | ||
441 | + */ | ||
442 | + @Override | ||
443 | + public String getPackage() { | ||
444 | + // TODO Auto-generated method stub | ||
445 | + return null; | ||
446 | + } | ||
447 | + | ||
448 | + /* (non-Javadoc) | ||
449 | + * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String) | ||
450 | + */ | ||
451 | + @Override | ||
452 | + public void setPackage(String pkg) { | ||
453 | + // TODO Auto-generated method stub | ||
454 | + | ||
455 | + } | ||
456 | +} |
... | @@ -17,7 +17,14 @@ package org.onosproject.yangutils.datamodel; | ... | @@ -17,7 +17,14 @@ package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import java.util.LinkedList; | 18 | import java.util.LinkedList; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | -/* | 20 | + |
21 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
22 | +import org.onosproject.yangutils.parser.Parsable; | ||
23 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
24 | +import org.onosproject.yangutils.translator.CodeGenerator; | ||
25 | +import org.onosproject.yangutils.utils.io.CachedFileHandle; | ||
26 | + | ||
27 | +/*- | ||
21 | * Reference:RFC 6020. | 28 | * Reference:RFC 6020. |
22 | * The "module" statement defines the module's name, | 29 | * The "module" statement defines the module's name, |
23 | * and groups all statements that belong to the module together. The "module" | 30 | * and groups all statements that belong to the module together. The "module" |
... | @@ -57,14 +64,11 @@ import java.util.List; | ... | @@ -57,14 +64,11 @@ import java.util.List; |
57 | * +--------------+---------+-------------+-----------------------+ | 64 | * +--------------+---------+-------------+-----------------------+ |
58 | */ | 65 | */ |
59 | 66 | ||
60 | -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
61 | -import org.onosproject.yangutils.parser.Parsable; | ||
62 | -import org.onosproject.yangutils.parser.ParsableDataType; | ||
63 | - | ||
64 | /** | 67 | /** |
65 | * Data model node to maintain information defined in YANG module. | 68 | * Data model node to maintain information defined in YANG module. |
66 | */ | 69 | */ |
67 | -public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable { | 70 | +public class YangModule extends YangNode |
71 | + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator { | ||
68 | 72 | ||
69 | /** | 73 | /** |
70 | * Name of the module. | 74 | * Name of the module. |
... | @@ -73,6 +77,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -73,6 +77,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
73 | 77 | ||
74 | /** | 78 | /** |
75 | * Reference:RFC 6020. | 79 | * Reference:RFC 6020. |
80 | + * | ||
76 | * The "contact" statement provides contact information for the module. The | 81 | * The "contact" statement provides contact information for the module. The |
77 | * argument is a string that is used to specify contact information for the | 82 | * argument is a string that is used to specify contact information for the |
78 | * person or persons to whom technical queries concerning this module should | 83 | * person or persons to whom technical queries concerning this module should |
... | @@ -83,6 +88,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -83,6 +88,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
83 | 88 | ||
84 | /** | 89 | /** |
85 | * Reference:RFC 6020. | 90 | * Reference:RFC 6020. |
91 | + * | ||
86 | * The "description" statement takes as an argument a string that contains a | 92 | * The "description" statement takes as an argument a string that contains a |
87 | * human-readable textual description of this definition. The text is | 93 | * human-readable textual description of this definition. The text is |
88 | * provided in a language (or languages) chosen by the module developer; for | 94 | * provided in a language (or languages) chosen by the module developer; for |
... | @@ -119,6 +125,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -119,6 +125,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
119 | 125 | ||
120 | /** | 126 | /** |
121 | * Reference:RFC 6020. | 127 | * Reference:RFC 6020. |
128 | + * | ||
122 | * The "organization" statement defines the party responsible for this | 129 | * The "organization" statement defines the party responsible for this |
123 | * module. The argument is a string that is used to specify a textual | 130 | * module. The argument is a string that is used to specify a textual |
124 | * description of the organization(s) under whose auspices this module was | 131 | * description of the organization(s) under whose auspices this module was |
... | @@ -147,26 +154,34 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -147,26 +154,34 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
147 | private byte version; | 154 | private byte version; |
148 | 155 | ||
149 | /** | 156 | /** |
157 | + * package of the generated java code. | ||
158 | + */ | ||
159 | + private String pkg; | ||
160 | + | ||
161 | + /** | ||
162 | + * Cached Java File Handle. | ||
163 | + */ | ||
164 | + private CachedFileHandle fileHandle; | ||
165 | + | ||
166 | + /** | ||
150 | * Create a YANG node of module type. | 167 | * Create a YANG node of module type. |
151 | */ | 168 | */ |
152 | public YangModule() { | 169 | public YangModule() { |
153 | super(YangNodeType.MODULE_NODE); | 170 | super(YangNodeType.MODULE_NODE); |
154 | } | 171 | } |
155 | 172 | ||
156 | - /** | 173 | + /* (non-Javadoc) |
157 | - * Get the module name. | 174 | + * @see org.onosproject.yangutils.datamodel.YangNode#getName() |
158 | - * | ||
159 | - * @return the module name. | ||
160 | */ | 175 | */ |
176 | + @Override | ||
161 | public String getName() { | 177 | public String getName() { |
162 | return name; | 178 | return name; |
163 | } | 179 | } |
164 | 180 | ||
165 | - /** | 181 | + /* (non-Javadoc) |
166 | - * set the module name. | 182 | + * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) |
167 | - * | ||
168 | - * @param moduleName the module name to set. | ||
169 | */ | 183 | */ |
184 | + @Override | ||
170 | public void setName(String moduleName) { | 185 | public void setName(String moduleName) { |
171 | name = moduleName; | 186 | name = moduleName; |
172 | } | 187 | } |
... | @@ -375,7 +390,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -375,7 +390,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
375 | * @param org the organization to set. | 390 | * @param org the organization to set. |
376 | */ | 391 | */ |
377 | public void setOrganization(String org) { | 392 | public void setOrganization(String org) { |
378 | - this.organization = org; | 393 | + organization = org; |
379 | } | 394 | } |
380 | 395 | ||
381 | /** | 396 | /** |
... | @@ -451,6 +466,44 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -451,6 +466,44 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
451 | } | 466 | } |
452 | 467 | ||
453 | /** | 468 | /** |
469 | + * Get the mapped java package. | ||
470 | + * | ||
471 | + * @return the java package | ||
472 | + */ | ||
473 | + @Override | ||
474 | + public String getPackage() { | ||
475 | + return pkg; | ||
476 | + } | ||
477 | + | ||
478 | + /** | ||
479 | + * Set the mapped java package. | ||
480 | + * | ||
481 | + * @param pcg the package to set | ||
482 | + */ | ||
483 | + @Override | ||
484 | + public void setPackage(String pcg) { | ||
485 | + pkg = pcg; | ||
486 | + } | ||
487 | + | ||
488 | + /** | ||
489 | + * Get the cached file handle. | ||
490 | + * | ||
491 | + * @return the fileHandle | ||
492 | + */ | ||
493 | + public CachedFileHandle getFileHandle() { | ||
494 | + return fileHandle; | ||
495 | + } | ||
496 | + | ||
497 | + /** | ||
498 | + * Set the cached file handle. | ||
499 | + * | ||
500 | + * @param handle the fileHandle to set | ||
501 | + */ | ||
502 | + public void setFileHandle(CachedFileHandle handle) { | ||
503 | + fileHandle = handle; | ||
504 | + } | ||
505 | + | ||
506 | + /** | ||
454 | * Returns the type of the parsed data. | 507 | * Returns the type of the parsed data. |
455 | * | 508 | * |
456 | * @return returns MODULE_DATA. | 509 | * @return returns MODULE_DATA. |
... | @@ -476,4 +529,22 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, | ... | @@ -476,4 +529,22 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, |
476 | public void validateDataOnExit() throws DataModelException { | 529 | public void validateDataOnExit() throws DataModelException { |
477 | // TODO auto-generated method stub, to be implemented by parser | 530 | // TODO auto-generated method stub, to be implemented by parser |
478 | } | 531 | } |
532 | + | ||
533 | + /** | ||
534 | + * Generates java code for module. | ||
535 | + */ | ||
536 | + public void generateJavaCodeEntry() { | ||
537 | + //TODO: autogenerated method stub, to be implemented | ||
538 | + | ||
539 | + return; | ||
540 | + } | ||
541 | + | ||
542 | + /** | ||
543 | + * Free resources used to generate code. | ||
544 | + */ | ||
545 | + public void generateJavaCodeExit() { | ||
546 | + //TODO: autogenerated method stub, to be implemented | ||
547 | + return; | ||
548 | + } | ||
549 | + | ||
479 | } | 550 | } | ... | ... |
... | @@ -16,25 +16,36 @@ | ... | @@ -16,25 +16,36 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | +import org.onosproject.yangutils.translator.CodeGenerator; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Base class of a node in data model tree. | 22 | * Base class of a node in data model tree. |
22 | */ | 23 | */ |
23 | -public abstract class YangNode { | 24 | +public abstract class YangNode implements CodeGenerator { |
24 | 25 | ||
25 | - /* Type of information maintained in node */ | 26 | + /** |
27 | + * Type of node. | ||
28 | + */ | ||
26 | private YangNodeType nodeType; | 29 | private YangNodeType nodeType; |
27 | 30 | ||
28 | - /* Parent reference */ | 31 | + /** |
32 | + * Parent reference. | ||
33 | + */ | ||
29 | private YangNode parent; | 34 | private YangNode parent; |
30 | 35 | ||
31 | - /* First child reference */ | 36 | + /** |
37 | + * First child reference. | ||
38 | + */ | ||
32 | private YangNode child; | 39 | private YangNode child; |
33 | 40 | ||
34 | - /* Next sibling reference */ | 41 | + /** |
42 | + * Next sibling reference. | ||
43 | + */ | ||
35 | private YangNode nextSibling; | 44 | private YangNode nextSibling; |
36 | 45 | ||
37 | - /* Previous sibling reference */ | 46 | + /** |
47 | + * Previous sibling reference. | ||
48 | + */ | ||
38 | private YangNode previousSibling; | 49 | private YangNode previousSibling; |
39 | 50 | ||
40 | /** | 51 | /** |
... | @@ -213,4 +224,33 @@ public abstract class YangNode { | ... | @@ -213,4 +224,33 @@ public abstract class YangNode { |
213 | curNode.setNextSibling(newChild); | 224 | curNode.setNextSibling(newChild); |
214 | return; | 225 | return; |
215 | } | 226 | } |
227 | + | ||
228 | + /** | ||
229 | + * Get the YANG name of the node. | ||
230 | + * | ||
231 | + * @return the name of node as defined in YANG file. | ||
232 | + */ | ||
233 | + public abstract String getName(); | ||
234 | + | ||
235 | + /** | ||
236 | + * Set the YANG name of the node. | ||
237 | + * | ||
238 | + * @param name the name of node as defined in YANG file. | ||
239 | + */ | ||
240 | + public abstract void setName(String name); | ||
241 | + | ||
242 | + /** | ||
243 | + * Get the mapped java package. | ||
244 | + * | ||
245 | + * @return the java package | ||
246 | + */ | ||
247 | + public abstract String getPackage(); | ||
248 | + | ||
249 | + /** | ||
250 | + * Set the mapped java package. | ||
251 | + * | ||
252 | + * @param pkg the package to set | ||
253 | + */ | ||
254 | + public abstract void setPackage(String pkg); | ||
255 | + | ||
216 | } | 256 | } | ... | ... |
... | @@ -23,27 +23,30 @@ package org.onosproject.yangutils.datamodel; | ... | @@ -23,27 +23,30 @@ package org.onosproject.yangutils.datamodel; |
23 | */ | 23 | */ |
24 | 24 | ||
25 | /** | 25 | /** |
26 | - * ENUM to represent the status of YANG entities. | 26 | + * Represents the status of YANG entities. |
27 | */ | 27 | */ |
28 | public enum YangStatusType { | 28 | public enum YangStatusType { |
29 | /** | 29 | /** |
30 | * Reference:RFC 6020. | 30 | * Reference:RFC 6020. |
31 | + * | ||
31 | * "current" means that the definition is current and valid. | 32 | * "current" means that the definition is current and valid. |
32 | */ | 33 | */ |
33 | CURRENT, | 34 | CURRENT, |
34 | 35 | ||
35 | /** | 36 | /** |
36 | * Reference:RFC 6020. | 37 | * Reference:RFC 6020. |
37 | - * "deprecated" indicates an obsolete definition, but it permits new/ | 38 | + * |
38 | - * continued implementation in order to foster interoperability with | 39 | + * "deprecated" indicates an obsolete definition, but it |
39 | - * older/existing implementations. | 40 | + * permits new/ continued implementation in order to foster interoperability |
41 | + * with older/existing implementations. | ||
40 | */ | 42 | */ |
41 | DEPRECATED, | 43 | DEPRECATED, |
42 | 44 | ||
43 | /** | 45 | /** |
44 | * Reference:RFC 6020. | 46 | * Reference:RFC 6020. |
45 | - * "obsolete" means the definition is obsolete and SHOULD NOT be implemented | 47 | + * |
46 | - * and/or can be removed from implementations. | 48 | + * "obsolete" means the definition is obsolete and |
49 | + * SHOULD NOT be implemented and/or can be removed from implementations. | ||
47 | */ | 50 | */ |
48 | OBSOLETE | 51 | OBSOLETE |
49 | } | 52 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.yangutils.datamodel; | ||
17 | + | ||
18 | +import java.util.LinkedList; | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
22 | +import org.onosproject.yangutils.parser.Parsable; | ||
23 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
24 | + | ||
25 | +/* | ||
26 | + * Reference RFC 6020. | ||
27 | + * | ||
28 | + * While the primary unit in YANG is a module, a YANG module can itself | ||
29 | + * be constructed out of several submodules. Submodules allow a module | ||
30 | + * designer to split a complex model into several pieces where all the | ||
31 | + * submodules contribute to a single namespace, which is defined by the | ||
32 | + * module that includes the submodules. | ||
33 | + * | ||
34 | + * The "submodule" statement defines the submodule's name, and groups | ||
35 | + * all statements that belong to the submodule together. The | ||
36 | + * "submodule" statement's argument is the name of the submodule, | ||
37 | + * followed by a block of sub-statements that hold detailed submodule | ||
38 | + * information. | ||
39 | + * | ||
40 | + * The submodule's sub-statements | ||
41 | + * | ||
42 | + * +--------------+---------+-------------+------------------+ | ||
43 | + * | substatement | section | cardinality |data model mapping| | ||
44 | + * +--------------+---------+-------------+------------------+ | ||
45 | + * | anyxml | 7.10 | 0..n | - not supported | | ||
46 | + * | augment | 7.15 | 0..n | - child nodes | | ||
47 | + * | belongs-to | 7.2.2 | 1 | - YangBelongsTo | | ||
48 | + * | choice | 7.9 | 0..n | - child nodes | | ||
49 | + * | contact | 7.1.8 | 0..1 | - string | | ||
50 | + * | container | 7.5 | 0..n | - child nodes | | ||
51 | + * | description | 7.19.3 | 0..1 | - string | | ||
52 | + * | deviation | 7.18.3 | 0..n | - TODO | | ||
53 | + * | extension | 7.17 | 0..n | - TODO | | ||
54 | + * | feature | 7.18.1 | 0..n | - TODO | | ||
55 | + * | grouping | 7.11 | 0..n | - child nodes | | ||
56 | + * | identity | 7.16 | 0..n | - TODO | | ||
57 | + * | import | 7.1.5 | 0..n | - YangImport | | ||
58 | + * | include | 7.1.6 | 0..n | - YangInclude | | ||
59 | + * | leaf | 7.6 | 0..n | - YangLeaf | | ||
60 | + * | leaf-list | 7.7 | 0..n | - YangLeafList | | ||
61 | + * | list | 7.8 | 0..n | - child nodes | | ||
62 | + * | notification | 7.14 | 0..n | - TODO | | ||
63 | + * | organization | 7.1.7 | 0..1 | - string | | ||
64 | + * | reference | 7.19.4 | 0..1 | - string | | ||
65 | + * | revision | 7.1.9 | 0..n | - string | | ||
66 | + * | rpc | 7.13 | 0..n | - TODO | | ||
67 | + * | typedef | 7.3 | 0..n | - child nodes | | ||
68 | + * | uses | 7.12 | 0..n | - child nodes | | ||
69 | + * | YANG-version | 7.1.2 | 0..1 | - int | | ||
70 | + * +--------------+---------+-------------+------------------+ | ||
71 | + */ | ||
72 | +/** | ||
73 | + * Data model node to maintain information defined in YANG sub-module. | ||
74 | + */ | ||
75 | +public class YangSubModule extends YangNode | ||
76 | + implements YangLeavesHolder, YangDesc, YangReference, Parsable { | ||
77 | + | ||
78 | + /** | ||
79 | + * Name of sub module. | ||
80 | + */ | ||
81 | + private String name; | ||
82 | + | ||
83 | + /** | ||
84 | + * Module to which it belongs to. | ||
85 | + */ | ||
86 | + private YangBelongsTo belongsTo; | ||
87 | + | ||
88 | + /** | ||
89 | + * Reference RFC 6020. | ||
90 | + * | ||
91 | + * The "contact" statement provides contact information for the module. The | ||
92 | + * argument is a string that is used to specify contact information for the | ||
93 | + * person or persons to whom technical queries concerning this module should | ||
94 | + * be sent, such as their name, postal address, telephone number, and | ||
95 | + * electronic mail address. | ||
96 | + */ | ||
97 | + private String contact; | ||
98 | + | ||
99 | + /** | ||
100 | + * Description. | ||
101 | + */ | ||
102 | + private String description; | ||
103 | + | ||
104 | + /** | ||
105 | + * List of YANG modules imported. | ||
106 | + */ | ||
107 | + private List<YangImport> importList; | ||
108 | + | ||
109 | + /** | ||
110 | + * List of YANG sub-modules included. | ||
111 | + */ | ||
112 | + private List<YangInclude> includeList; | ||
113 | + | ||
114 | + /** | ||
115 | + * List of leaves at root level in the sub-module. | ||
116 | + */ | ||
117 | + @SuppressWarnings("rawtypes") | ||
118 | + private List<YangLeaf> listOfLeaf; | ||
119 | + | ||
120 | + /** | ||
121 | + * List of leaf-lists at root level in the sub-module. | ||
122 | + */ | ||
123 | + @SuppressWarnings("rawtypes") | ||
124 | + private List<YangLeafList> listOfLeafList; | ||
125 | + | ||
126 | + /** | ||
127 | + * organization owner of the sub-module. | ||
128 | + */ | ||
129 | + private String organization; | ||
130 | + | ||
131 | + /** | ||
132 | + * reference of the sub-module. | ||
133 | + */ | ||
134 | + private String reference; | ||
135 | + | ||
136 | + /** | ||
137 | + * revision info of the sub-module. | ||
138 | + */ | ||
139 | + private YangRevision revision; | ||
140 | + | ||
141 | + /** | ||
142 | + * YANG version. | ||
143 | + */ | ||
144 | + private byte version; | ||
145 | + | ||
146 | + /** | ||
147 | + * Create a sub module node. | ||
148 | + */ | ||
149 | + public YangSubModule() { | ||
150 | + super(YangNodeType.SUB_MODULE_NODE); | ||
151 | + } | ||
152 | + | ||
153 | + /* (non-Javadoc) | ||
154 | + * @see org.onosproject.yangutils.datamodel.YangNode#getName() | ||
155 | + */ | ||
156 | + @Override | ||
157 | + public String getName() { | ||
158 | + return name; | ||
159 | + } | ||
160 | + | ||
161 | + /* (non-Javadoc) | ||
162 | + * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) | ||
163 | + */ | ||
164 | + @Override | ||
165 | + public void setName(String subModuleName) { | ||
166 | + name = subModuleName; | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Get the module info. | ||
171 | + * | ||
172 | + * @return the belongs to info | ||
173 | + */ | ||
174 | + public YangBelongsTo getBelongsTo() { | ||
175 | + return belongsTo; | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Set the module info. | ||
180 | + * | ||
181 | + * @param belongsTo module info to set. | ||
182 | + */ | ||
183 | + public void setBelongsTo(YangBelongsTo belongsTo) { | ||
184 | + this.belongsTo = belongsTo; | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Get the contact. | ||
189 | + * | ||
190 | + * @return the contact. | ||
191 | + */ | ||
192 | + public String getContact() { | ||
193 | + return contact; | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Set the contact. | ||
198 | + * | ||
199 | + * @param contact the contact to set | ||
200 | + */ | ||
201 | + public void setContact(String contact) { | ||
202 | + this.contact = contact; | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Get the description. | ||
207 | + * | ||
208 | + * @return the description. | ||
209 | + */ | ||
210 | + public String getDescription() { | ||
211 | + return description; | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
215 | + * Set the description. | ||
216 | + * | ||
217 | + * @param description set the description. | ||
218 | + */ | ||
219 | + public void setDescription(String description) { | ||
220 | + this.description = description; | ||
221 | + } | ||
222 | + | ||
223 | + /** | ||
224 | + * Get the list of imported modules. | ||
225 | + * | ||
226 | + * @return the list of imported modules. | ||
227 | + */ | ||
228 | + public List<YangImport> getImportList() { | ||
229 | + return importList; | ||
230 | + } | ||
231 | + | ||
232 | + /** | ||
233 | + * prevent setting the import list from outside. | ||
234 | + * | ||
235 | + * @param importList the import list to set. | ||
236 | + */ | ||
237 | + private void setImportList(List<YangImport> importList) { | ||
238 | + this.importList = importList; | ||
239 | + } | ||
240 | + | ||
241 | + /** | ||
242 | + * Add the imported module information to the import list. | ||
243 | + * | ||
244 | + * @param importedModule module being imported. | ||
245 | + */ | ||
246 | + public void addImportedInfo(YangImport importedModule) { | ||
247 | + | ||
248 | + if (getImportList() == null) { | ||
249 | + setImportList(new LinkedList<YangImport>()); | ||
250 | + } | ||
251 | + | ||
252 | + getImportList().add(importedModule); | ||
253 | + | ||
254 | + return; | ||
255 | + } | ||
256 | + | ||
257 | + /** | ||
258 | + * Get the list of included sub modules. | ||
259 | + * | ||
260 | + * @return the included list of sub modules. | ||
261 | + */ | ||
262 | + public List<YangInclude> getIncludeList() { | ||
263 | + return includeList; | ||
264 | + } | ||
265 | + | ||
266 | + /** | ||
267 | + * Set the list of included sub modules. | ||
268 | + * | ||
269 | + * @param includeList the included list to set. | ||
270 | + */ | ||
271 | + private void setIncludeList(List<YangInclude> includeList) { | ||
272 | + this.includeList = includeList; | ||
273 | + } | ||
274 | + | ||
275 | + /** | ||
276 | + * Add the included sub module information to the include list. | ||
277 | + * | ||
278 | + * @param includeModule submodule being included. | ||
279 | + */ | ||
280 | + public void addIncludedInfo(YangInclude includeModule) { | ||
281 | + | ||
282 | + if (getIncludeList() == null) { | ||
283 | + setIncludeList(new LinkedList<YangInclude>()); | ||
284 | + } | ||
285 | + | ||
286 | + getIncludeList().add(includeModule); | ||
287 | + return; | ||
288 | + } | ||
289 | + | ||
290 | + /** | ||
291 | + * Get the list of leaves. | ||
292 | + * | ||
293 | + * @return the list of leaves. | ||
294 | + */ | ||
295 | + @SuppressWarnings("rawtypes") | ||
296 | + public List<YangLeaf> getListOfLeaf() { | ||
297 | + return listOfLeaf; | ||
298 | + } | ||
299 | + | ||
300 | + /** | ||
301 | + * Set the list of leaves. | ||
302 | + * | ||
303 | + * @param leafsList the list of leaf to set. | ||
304 | + */ | ||
305 | + @SuppressWarnings("rawtypes") | ||
306 | + private void setListOfLeaf(List<YangLeaf> leafsList) { | ||
307 | + listOfLeaf = leafsList; | ||
308 | + } | ||
309 | + | ||
310 | + /** | ||
311 | + * Add a leaf. | ||
312 | + * | ||
313 | + * @param leaf the leaf to be added. | ||
314 | + */ | ||
315 | + @SuppressWarnings("rawtypes") | ||
316 | + public void addLeaf(YangLeaf<?> leaf) { | ||
317 | + if (getListOfLeaf() == null) { | ||
318 | + setListOfLeaf(new LinkedList<YangLeaf>()); | ||
319 | + } | ||
320 | + | ||
321 | + getListOfLeaf().add(leaf); | ||
322 | + } | ||
323 | + | ||
324 | + /** | ||
325 | + * Get the list of leaf-list. | ||
326 | + * | ||
327 | + * @return the list of leaf-list. | ||
328 | + */ | ||
329 | + @SuppressWarnings("rawtypes") | ||
330 | + public List<YangLeafList> getListOfLeafList() { | ||
331 | + return listOfLeafList; | ||
332 | + } | ||
333 | + | ||
334 | + /** | ||
335 | + * Set the list of leaf-list. | ||
336 | + * | ||
337 | + * @param listOfLeafList the list of leaf-list to set. | ||
338 | + */ | ||
339 | + @SuppressWarnings("rawtypes") | ||
340 | + private void setListOfLeafList(List<YangLeafList> listOfLeafList) { | ||
341 | + this.listOfLeafList = listOfLeafList; | ||
342 | + } | ||
343 | + | ||
344 | + /** | ||
345 | + * Add a leaf-list. | ||
346 | + * | ||
347 | + * @param leafList the leaf-list to be added. | ||
348 | + */ | ||
349 | + @SuppressWarnings("rawtypes") | ||
350 | + public void addLeafList(YangLeafList<?> leafList) { | ||
351 | + if (getListOfLeafList() == null) { | ||
352 | + setListOfLeafList(new LinkedList<YangLeafList>()); | ||
353 | + } | ||
354 | + | ||
355 | + getListOfLeafList().add(leafList); | ||
356 | + } | ||
357 | + | ||
358 | + /** | ||
359 | + * Get the sub-modules organization. | ||
360 | + * | ||
361 | + * @return the organization. | ||
362 | + */ | ||
363 | + public String getOrganization() { | ||
364 | + return organization; | ||
365 | + } | ||
366 | + | ||
367 | + /** | ||
368 | + * Set the sub-modules organization. | ||
369 | + * | ||
370 | + * @param org the organization to set. | ||
371 | + */ | ||
372 | + public void setOrganization(String org) { | ||
373 | + organization = org; | ||
374 | + } | ||
375 | + | ||
376 | + /** | ||
377 | + * Get the textual reference. | ||
378 | + * | ||
379 | + * @return the reference. | ||
380 | + */ | ||
381 | + public String getReference() { | ||
382 | + return reference; | ||
383 | + } | ||
384 | + | ||
385 | + /** | ||
386 | + * Set the textual reference. | ||
387 | + * | ||
388 | + * @param reference the reference to set. | ||
389 | + */ | ||
390 | + public void setReference(String reference) { | ||
391 | + this.reference = reference; | ||
392 | + } | ||
393 | + | ||
394 | + /** | ||
395 | + * Get the revision. | ||
396 | + * | ||
397 | + * @return the revision. | ||
398 | + */ | ||
399 | + public YangRevision getRevision() { | ||
400 | + return revision; | ||
401 | + } | ||
402 | + | ||
403 | + /** | ||
404 | + * Set the revision. | ||
405 | + * | ||
406 | + * @param revision the revision to set. | ||
407 | + */ | ||
408 | + public void setRevision(YangRevision revision) { | ||
409 | + this.revision = revision; | ||
410 | + } | ||
411 | + | ||
412 | + /** | ||
413 | + * Get the version. | ||
414 | + * | ||
415 | + * @return the version. | ||
416 | + */ | ||
417 | + public byte getVersion() { | ||
418 | + return version; | ||
419 | + } | ||
420 | + | ||
421 | + /** | ||
422 | + * Set the version. | ||
423 | + * | ||
424 | + * @param version the version to set. | ||
425 | + */ | ||
426 | + public void setVersion(byte version) { | ||
427 | + this.version = version; | ||
428 | + } | ||
429 | + | ||
430 | + /** | ||
431 | + * Returns the type of the parsed data. | ||
432 | + * | ||
433 | + * @return returns SUB_MODULE_DATA. | ||
434 | + */ | ||
435 | + public ParsableDataType getParsableDataType() { | ||
436 | + return ParsableDataType.SUB_MODULE_DATA; | ||
437 | + } | ||
438 | + | ||
439 | + /** | ||
440 | + * Validate the data on entering the corresponding parse tree node. | ||
441 | + * | ||
442 | + * @throws DataModelException a violation of data model rules. | ||
443 | + */ | ||
444 | + public void validateDataOnEntry() throws DataModelException { | ||
445 | + // TODO auto-generated method stub, to be implemented by parser | ||
446 | + } | ||
447 | + | ||
448 | + /** | ||
449 | + * Validate the data on exiting the corresponding parse tree node. | ||
450 | + * | ||
451 | + * @throws DataModelException a violation of data model rules. | ||
452 | + */ | ||
453 | + public void validateDataOnExit() throws DataModelException { | ||
454 | + // TODO auto-generated method stub, to be implemented by parser | ||
455 | + } | ||
456 | + | ||
457 | + /* (non-Javadoc) | ||
458 | + * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() | ||
459 | + */ | ||
460 | + public void generateJavaCodeEntry() { | ||
461 | + // TODO Auto-generated method stub | ||
462 | + | ||
463 | + } | ||
464 | + | ||
465 | + /* (non-Javadoc) | ||
466 | + * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() | ||
467 | + */ | ||
468 | + public void generateJavaCodeExit() { | ||
469 | + // TODO Auto-generated method stub | ||
470 | + | ||
471 | + } | ||
472 | + | ||
473 | + /* (non-Javadoc) | ||
474 | + * @see org.onosproject.yangutils.datamodel.YangNode#getPackage() | ||
475 | + */ | ||
476 | + @Override | ||
477 | + public String getPackage() { | ||
478 | + // TODO Auto-generated method stub | ||
479 | + return null; | ||
480 | + } | ||
481 | + | ||
482 | + /* (non-Javadoc) | ||
483 | + * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String) | ||
484 | + */ | ||
485 | + @Override | ||
486 | + public void setPackage(String pkg) { | ||
487 | + // TODO Auto-generated method stub | ||
488 | + | ||
489 | + } | ||
490 | +} |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.translator; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstraction of an entity which provides Code generator functionalities. | ||
21 | + */ | ||
22 | +public interface CodeGenerator { | ||
23 | + | ||
24 | + /** | ||
25 | + * Traverse the schema of application and generate corresponding code. | ||
26 | + */ | ||
27 | + void generateJavaCodeEntry(); | ||
28 | + | ||
29 | + /** | ||
30 | + * Traverse the schema of application and generate corresponding code. | ||
31 | + */ | ||
32 | + void generateJavaCodeExit(); | ||
33 | + | ||
34 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/GeneratedFileType.java
0 → 100644
1 | +/*Copyright 2016.year Open Networking Laboratory | ||
2 | + | ||
3 | +Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | +you may not use this file except in compliance with the License. | ||
5 | +You may obtain a copy of the License at | ||
6 | + | ||
7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | +Unless required by applicable law or agreed to in writing, software | ||
10 | +distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | +See the License for the specific language governing permissions and | ||
13 | +limitations under the License.*/ | ||
14 | +package org.onosproject.yangutils.translator; | ||
15 | + | ||
16 | +/** | ||
17 | + * Type of files generated. | ||
18 | + */ | ||
19 | +public enum GeneratedFileType { | ||
20 | + /** | ||
21 | + * interface file. | ||
22 | + */ | ||
23 | + INTERFACE, | ||
24 | + | ||
25 | + /** | ||
26 | + * class file. | ||
27 | + */ | ||
28 | + BUILDER_CLASS, | ||
29 | + | ||
30 | + /** | ||
31 | + * interface and class file. | ||
32 | + */ | ||
33 | + BOTH | ||
34 | +} |
1 | +/*Copyright 2016.year Open Networking Laboratory | ||
2 | + | ||
3 | +Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | +you may not use this file except in compliance with the License. | ||
5 | +You may obtain a copy of the License at | ||
6 | + | ||
7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | +Unless required by applicable law or agreed to in writing, software | ||
10 | +distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | +See the License for the specific language governing permissions and | ||
13 | +limitations under the License.*/ | ||
14 | +package org.onosproject.yangutils.utils.io; | ||
15 | + | ||
16 | +import org.onosproject.yangutils.translator.GeneratedFileType; | ||
17 | + | ||
18 | +/** | ||
19 | + * Cached java file handle, which supports the addition of member attributes and | ||
20 | + * methods. | ||
21 | + */ | ||
22 | +public interface CachedFileHandle { | ||
23 | + | ||
24 | + /** | ||
25 | + * Add a new attribute to the file(s). | ||
26 | + * | ||
27 | + * @param attrType data type of the added attribute. | ||
28 | + * @param name name of the attribute. | ||
29 | + * @param isListAttr if the current added attribute needs to be maintained | ||
30 | + * in a list. | ||
31 | + * @param fileTypes types of files in which the attribute needs to be added. | ||
32 | + */ | ||
33 | + void addAttributeInfo(String attrType, String name, boolean isListAttr, GeneratedFileType fileTypes); | ||
34 | + | ||
35 | + /** | ||
36 | + * Flushes the cached contents to the target file, frees used resources. | ||
37 | + */ | ||
38 | + void close(); | ||
39 | +} |
-
Please register or login to post a comment