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
405 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 | +} |
This diff is collapsed. Click to expand it.
| ... | @@ -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 | * | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -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 | } | ... | ... |
This diff is collapsed. Click to expand it.
| 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