Committed by
Gerrit Code Review
[ONOS-3892] implement YANG leaf data model
Change-Id: I996d4d3d60a0ad2142e173c6ba26c9cc355ccc80
Showing
5 changed files
with
955 additions
and
0 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:RFC 6020. | ||
| 24 | + * The "import" statement makes definitions from one module available | ||
| 25 | + * inside another module or submodule. The argument is the name of the | ||
| 26 | + * module to import, and the statement is followed by a block of | ||
| 27 | + * sub statements that holds detailed import information. | ||
| 28 | + * When a module is imported, the importing module may: | ||
| 29 | + * o use any grouping and typedef defined at the top level in the | ||
| 30 | + * imported module or its submodules. | ||
| 31 | + * | ||
| 32 | + * o use any extension, feature, and identity defined in the imported | ||
| 33 | + * module or its submodules. | ||
| 34 | + * | ||
| 35 | + * o use any node in the imported module's schema tree in "must", | ||
| 36 | + * "path", and "when" statements, or as the target node in "augment" | ||
| 37 | + * and "deviation" statements. | ||
| 38 | + * | ||
| 39 | + * The mandatory "prefix" sub statement assigns a prefix for the imported | ||
| 40 | + * module that is scoped to the importing module or submodule. Multiple | ||
| 41 | + * "import" statements may be specified to import from different | ||
| 42 | + * modules. | ||
| 43 | + * When the optional "revision-date" sub-statement is present, any | ||
| 44 | + * typedef, grouping, extension, feature, and identity referenced by | ||
| 45 | + * definitions in the local module are taken from the specified revision | ||
| 46 | + * of the imported module. It is an error if the specified revision of | ||
| 47 | + * the imported module does not exist. If no "revision-date" | ||
| 48 | + * sub-statement is present, it is undefined from which revision of the | ||
| 49 | + * module they are taken. | ||
| 50 | + * | ||
| 51 | + * Multiple revisions of the same module MUST NOT be imported. | ||
| 52 | + * | ||
| 53 | + * The import's Substatements | ||
| 54 | + * | ||
| 55 | + * +---------------+---------+-------------+------------------+ | ||
| 56 | + * | substatement | section | cardinality |data model mapping| | ||
| 57 | + * +---------------+---------+-------------+------------------+ | ||
| 58 | + * | prefix | 7.1.4 | 1 | string | | ||
| 59 | + * | revision-date | 7.1.5.1 | 0..1 | string | | ||
| 60 | + * +---------------+---------+-------------+------------------+ | ||
| 61 | + */ | ||
| 62 | +/** | ||
| 63 | + * Maintains the information about the imported modules. | ||
| 64 | + */ | ||
| 65 | +public class YangImport implements Parsable { | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Name of the module that is being imported. | ||
| 69 | + */ | ||
| 70 | + private String name; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Prefix used to identify the entities from the imported module. | ||
| 74 | + */ | ||
| 75 | + private String prefixId; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Reference:RFC 6020. | ||
| 79 | + * The import's "revision-date" statement is used to specify the exact | ||
| 80 | + * version of the module to import. The "revision-date" statement MUST match | ||
| 81 | + * the most recent "revision" statement in the imported module. organization | ||
| 82 | + * which defined the YANG module. | ||
| 83 | + */ | ||
| 84 | + private String revision; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Default constructor. | ||
| 88 | + */ | ||
| 89 | + public YangImport() { | ||
| 90 | + | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * Get the imported module name. | ||
| 95 | + * | ||
| 96 | + * @return the module name. | ||
| 97 | + */ | ||
| 98 | + public String getModuleName() { | ||
| 99 | + return name; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Set module name. | ||
| 104 | + * | ||
| 105 | + * @param moduleName the module name to set | ||
| 106 | + */ | ||
| 107 | + public void setModuleName(String moduleName) { | ||
| 108 | + name = moduleName; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Get the prefix used to identify the entities from the imported module. | ||
| 113 | + * | ||
| 114 | + * @return the prefix used to identify the entities from the imported | ||
| 115 | + * module. | ||
| 116 | + */ | ||
| 117 | + public String getPrefixId() { | ||
| 118 | + return prefixId; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * Set prefix identifier. | ||
| 123 | + * | ||
| 124 | + * @param prefixId set the prefix identifier of the imported module. | ||
| 125 | + */ | ||
| 126 | + public void setPrefixId(String prefixId) { | ||
| 127 | + this.prefixId = prefixId; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Get the revision of the imported module. | ||
| 132 | + * | ||
| 133 | + * @return the revision of the imported module. | ||
| 134 | + */ | ||
| 135 | + public String getRevision() { | ||
| 136 | + return revision; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Set the revision of the imported module. | ||
| 141 | + * | ||
| 142 | + * @param rev set the revision of the imported module. | ||
| 143 | + */ | ||
| 144 | + public void setRevision(String rev) { | ||
| 145 | + revision = rev; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Returns the type of the parsed data. | ||
| 150 | + * | ||
| 151 | + * @return returns IMPORT_DATA | ||
| 152 | + */ | ||
| 153 | + public ParsableDataType getParsableDataType() { | ||
| 154 | + return ParsableDataType.IMPORT_DATA; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Validate the data on entering the corresponding parse tree node. | ||
| 159 | + * | ||
| 160 | + * @throws DataModelException a violation of data model rules | ||
| 161 | + */ | ||
| 162 | + public void validateDataOnEntry() throws DataModelException { | ||
| 163 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * Validate the data on exiting the corresponding parse tree node. | ||
| 169 | + * | ||
| 170 | + * @throws DataModelException a violation of data model rules | ||
| 171 | + */ | ||
| 172 | + public void validateDataOnExit() throws DataModelException { | ||
| 173 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 174 | + | ||
| 175 | + } | ||
| 176 | +} |
| 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:RFC 6020. | ||
| 24 | + * The "include" statement is used to make content from a submodule | ||
| 25 | + * available to that submodule's parent module, or to another submodule | ||
| 26 | + * of that parent module. The argument is an identifier that is the | ||
| 27 | + * name of the submodule to include. | ||
| 28 | + * The includes's Substatements | ||
| 29 | + * | ||
| 30 | + * +---------------+---------+-------------+------------------+ | ||
| 31 | + * | substatement | section | cardinality |data model mapping| | ||
| 32 | + * +---------------+---------+-------------+------------------+ | ||
| 33 | + * | revision-date | 7.1.5.1 | 0..1 | string | | ||
| 34 | + * +---------------+---------+-------------+------------------+ | ||
| 35 | + */ | ||
| 36 | +/** | ||
| 37 | + * Maintains the information about the included sub-modules. | ||
| 38 | + * | ||
| 39 | + */ | ||
| 40 | +public class YangInclude implements Parsable { | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Name of the sub-module that is being included. | ||
| 44 | + */ | ||
| 45 | + private String subModuleName; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * The include's "revision-date" statement is used to specify the exact | ||
| 49 | + * version of the submodule to import. | ||
| 50 | + */ | ||
| 51 | + private String revision; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * Default constructor. | ||
| 55 | + */ | ||
| 56 | + public YangInclude() { | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Get the name of included sub-module. | ||
| 61 | + * | ||
| 62 | + * @return the sub-module name | ||
| 63 | + */ | ||
| 64 | + public String getSubModuleName() { | ||
| 65 | + return subModuleName; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Set the name of included sub-modules. | ||
| 70 | + * | ||
| 71 | + * @param subModuleName the sub-module name to set | ||
| 72 | + */ | ||
| 73 | + public void setSubModuleName(String subModuleName) { | ||
| 74 | + this.subModuleName = subModuleName; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Get the revision. | ||
| 79 | + * | ||
| 80 | + * @return the revision | ||
| 81 | + */ | ||
| 82 | + public String getRevision() { | ||
| 83 | + return revision; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Set the revision. | ||
| 88 | + * | ||
| 89 | + * @param revision the revision to set | ||
| 90 | + */ | ||
| 91 | + public void setRevision(String revision) { | ||
| 92 | + this.revision = revision; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Returns the type of parsed data. | ||
| 97 | + * | ||
| 98 | + * @return returns INCLUDE_DATA | ||
| 99 | + */ | ||
| 100 | + public ParsableDataType getParsableDataType() { | ||
| 101 | + return ParsableDataType.INCLUDE_DATA; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Validate the data on entering the corresponding parse tree node. | ||
| 106 | + * | ||
| 107 | + * @throws DataModelException a violation of data model rules | ||
| 108 | + */ | ||
| 109 | + public void validateDataOnEntry() throws DataModelException { | ||
| 110 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 111 | + | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Validate the data on exiting the corresponding parse tree node. | ||
| 116 | + * | ||
| 117 | + * @throws DataModelException a violation of data model rules | ||
| 118 | + */ | ||
| 119 | + public void validateDataOnExit() throws DataModelException { | ||
| 120 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | +} |
| 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 20 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
| 22 | + | ||
| 23 | +/* | ||
| 24 | + * Reference:RFC 6020. | ||
| 25 | + * The "leaf" statement is used to define a leaf node in the schema | ||
| 26 | + * tree. It takes one argument, which is an identifier, followed by a | ||
| 27 | + * block of sub-statements that holds detailed leaf information. | ||
| 28 | + * | ||
| 29 | + * A leaf node has a value, but no child nodes in the data tree. | ||
| 30 | + * Conceptually, the value in the data tree is always in the canonical | ||
| 31 | + * form. | ||
| 32 | + * | ||
| 33 | + * A leaf node exists in zero or one instances in the data tree. | ||
| 34 | + * | ||
| 35 | + * The "leaf" statement is used to define a scalar variable of a | ||
| 36 | + * particular built-in or derived type. | ||
| 37 | + * | ||
| 38 | + * The leaf's sub-statements | ||
| 39 | + * | ||
| 40 | + * +--------------+---------+-------------+------------------+ | ||
| 41 | + * | substatement | section | cardinality |data model mapping| | ||
| 42 | + * +--------------+---------+-------------+------------------+ | ||
| 43 | + * | config | 7.19.1 | 0..1 | - boolean | | ||
| 44 | + * | default | 7.6.4 | 0..1 | - TODO | | ||
| 45 | + * | description | 7.19.3 | 0..1 | - string | | ||
| 46 | + * | if-feature | 7.18.2 | 0..n | - TODO | | ||
| 47 | + * | mandatory | 7.6.5 | 0..1 | - boolean | | ||
| 48 | + * | must | 7.5.3 | 0..n | - TODO | | ||
| 49 | + * | reference | 7.19.4 | 0..1 | - string | | ||
| 50 | + * | status | 7.19.2 | 0..1 | - YangStatus | | ||
| 51 | + * | type | 7.6.3 | 1 | - YangType | | ||
| 52 | + * | units | 7.3.3 | 0..1 | - String | | ||
| 53 | + * | when | 7.19.5 | 0..1 | - TODO | | ||
| 54 | + * +--------------+---------+-------------+------------------+ | ||
| 55 | + */ | ||
| 56 | +/** | ||
| 57 | + * Leaf data represented in YANG. | ||
| 58 | + * | ||
| 59 | + * @param <T> YANG data type | ||
| 60 | + */ | ||
| 61 | +public class YangLeaf<T> implements YangCommonInfo, Parsable { | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Name of leaf. | ||
| 65 | + */ | ||
| 66 | + private String name; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * If the leaf is a config parameter. | ||
| 70 | + */ | ||
| 71 | + private boolean isConfig; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * description of leaf. | ||
| 75 | + */ | ||
| 76 | + private String description; | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * If mandatory leaf. | ||
| 80 | + */ | ||
| 81 | + private boolean isMandatory; | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * The textual reference to this leaf. | ||
| 85 | + */ | ||
| 86 | + private String reference; | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * Status of leaf in YANG definition. | ||
| 90 | + */ | ||
| 91 | + private YangStatusType status; | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * Textual units info. | ||
| 95 | + */ | ||
| 96 | + private String units; | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * Data type of the leaf. | ||
| 100 | + */ | ||
| 101 | + private YangType<T> dataType; | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Default constructor to create a YANG leaf. | ||
| 105 | + */ | ||
| 106 | + public YangLeaf() { | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Get the name of leaf. | ||
| 111 | + * | ||
| 112 | + * @return the leaf name. | ||
| 113 | + */ | ||
| 114 | + public String getLeafName() { | ||
| 115 | + return name; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Set the name of leaf. | ||
| 120 | + * | ||
| 121 | + * @param leafName the leaf name to set. | ||
| 122 | + */ | ||
| 123 | + public void setLeafName(String leafName) { | ||
| 124 | + this.name = leafName; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Get the config flag. | ||
| 129 | + * | ||
| 130 | + * @return if config flag. | ||
| 131 | + */ | ||
| 132 | + public boolean isConfig() { | ||
| 133 | + return isConfig; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * Set the config flag. | ||
| 138 | + * | ||
| 139 | + * @param isCfg the flag value to set. | ||
| 140 | + */ | ||
| 141 | + public void setConfig(boolean isCfg) { | ||
| 142 | + isConfig = isCfg; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * Get the description. | ||
| 147 | + * | ||
| 148 | + * @return the description. | ||
| 149 | + */ | ||
| 150 | + public String getDescription() { | ||
| 151 | + return description; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * Set the description. | ||
| 156 | + * | ||
| 157 | + * @param description set the description. | ||
| 158 | + */ | ||
| 159 | + public void setDescription(String description) { | ||
| 160 | + this.description = description; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Get if the leaf is mandatory. | ||
| 165 | + * | ||
| 166 | + * @return if leaf is mandatory. | ||
| 167 | + */ | ||
| 168 | + public boolean isMandatory() { | ||
| 169 | + return isMandatory; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Set if the leaf is mandatory. | ||
| 174 | + * | ||
| 175 | + * @param isReq if the leaf is mandatory | ||
| 176 | + */ | ||
| 177 | + public void setMandatory(boolean isReq) { | ||
| 178 | + isMandatory = isReq; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * Get the textual reference. | ||
| 183 | + * | ||
| 184 | + * @return the reference. | ||
| 185 | + */ | ||
| 186 | + public String getReference() { | ||
| 187 | + return reference; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + /** | ||
| 191 | + * Set the textual reference. | ||
| 192 | + * | ||
| 193 | + * @param reference the reference to set. | ||
| 194 | + */ | ||
| 195 | + public void setReference(String reference) { | ||
| 196 | + this.reference = reference; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + /** | ||
| 200 | + * Get the status. | ||
| 201 | + * | ||
| 202 | + * @return the status. | ||
| 203 | + */ | ||
| 204 | + public YangStatusType getStatus() { | ||
| 205 | + return status; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + /** | ||
| 209 | + * Set the status. | ||
| 210 | + * | ||
| 211 | + * @param status the status to set. | ||
| 212 | + */ | ||
| 213 | + public void setStatus(YangStatusType status) { | ||
| 214 | + this.status = status; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * Get the units. | ||
| 219 | + * | ||
| 220 | + * @return the units. | ||
| 221 | + */ | ||
| 222 | + public String getUnits() { | ||
| 223 | + return units; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + /** | ||
| 227 | + * Set the units. | ||
| 228 | + * | ||
| 229 | + * @param units the units to set. | ||
| 230 | + */ | ||
| 231 | + public void setUnits(String units) { | ||
| 232 | + this.units = units; | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + /** | ||
| 236 | + * Get the data type. | ||
| 237 | + * | ||
| 238 | + * @return the data type. | ||
| 239 | + */ | ||
| 240 | + public YangType<T> getDataType() { | ||
| 241 | + return dataType; | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + /** | ||
| 245 | + * Set the data type. | ||
| 246 | + * | ||
| 247 | + * @param dataType the data type to set. | ||
| 248 | + */ | ||
| 249 | + public void setDataType(YangType<T> dataType) { | ||
| 250 | + this.dataType = dataType; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + /** | ||
| 254 | + * Returns the type of the parsed data. | ||
| 255 | + * | ||
| 256 | + * @return returns LEAF_DATA. | ||
| 257 | + */ | ||
| 258 | + public ParsableDataType getParsableDataType() { | ||
| 259 | + return ParsableDataType.LEAF_DATA; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * Validate the data on entering the corresponding parse tree node. | ||
| 264 | + * | ||
| 265 | + * @throws DataModelException a violation of data model rules. | ||
| 266 | + */ | ||
| 267 | + public void validateDataOnEntry() throws DataModelException { | ||
| 268 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 269 | + | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + /** | ||
| 273 | + * Validate the data on exiting the corresponding parse tree node. | ||
| 274 | + * | ||
| 275 | + * @throws DataModelException a violation of data model rules. | ||
| 276 | + */ | ||
| 277 | + public void validateDataOnExit() throws DataModelException { | ||
| 278 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 279 | + | ||
| 280 | + } | ||
| 281 | +} |
| 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 20 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
| 22 | + | ||
| 23 | +/* | ||
| 24 | + * Reference:RFC 6020. | ||
| 25 | + * Where the "leaf" statement is used to define a simple scalar variable | ||
| 26 | + * of a particular type, the "leaf-list" statement is used to define an | ||
| 27 | + * array of a particular type. The "leaf-list" statement takes one | ||
| 28 | + * argument, which is an identifier, followed by a block of | ||
| 29 | + * sub-statements that holds detailed leaf-list information. | ||
| 30 | + * | ||
| 31 | + * The values in a leaf-list MUST be unique. | ||
| 32 | + * | ||
| 33 | + * The leaf-list's sub-statements | ||
| 34 | + * | ||
| 35 | + * +--------------+---------+-------------+------------------+ | ||
| 36 | + * | substatement | section | cardinality |data model mapping| | ||
| 37 | + * +--------------+---------+-------------+------------------+ | ||
| 38 | + * | config | 7.19.1 | 0..1 | -boolean | | ||
| 39 | + * | description | 7.19.3 | 0..1 | -string | | ||
| 40 | + * | if-feature | 7.18.2 | 0..n | -TODO | | ||
| 41 | + * | max-elements | 7.7.4 | 0..1 | -int | | ||
| 42 | + * | min-elements | 7.7.3 | 0..1 | -int | | ||
| 43 | + * | must | 7.5.3 | 0..n | -TODO | | ||
| 44 | + * | ordered-by | 7.7.5 | 0..1 | -TODO | | ||
| 45 | + * | reference | 7.19.4 | 0..1 | -string | | ||
| 46 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
| 47 | + * | type | 7.4 | 1 | -YangType | | ||
| 48 | + * | units | 7.3.3 | 0..1 | -string | | ||
| 49 | + * | when | 7.19.5 | 0..1 | -TODO | | ||
| 50 | + * +--------------+---------+-------------+------------------+ | ||
| 51 | + */ | ||
| 52 | +/** | ||
| 53 | + * Leaf-list data represented in YANG. | ||
| 54 | + * | ||
| 55 | + * @param <T> YANG data type | ||
| 56 | + */ | ||
| 57 | +public class YangLeafList<T> implements YangCommonInfo, Parsable { | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Name of leaf-list. | ||
| 61 | + */ | ||
| 62 | + private String name; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * If the leaf-list is a config parameter. | ||
| 66 | + */ | ||
| 67 | + private boolean isConfig; | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * Description of leaf-list. | ||
| 71 | + */ | ||
| 72 | + private String description; | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Reference:RFC 6020. | ||
| 76 | + * The "max-elements" statement, which is optional, takes as an argument a | ||
| 77 | + * positive integer or the string "unbounded", which puts a constraint on | ||
| 78 | + * valid list entries. A valid leaf-list or list always has at most | ||
| 79 | + * max-elements entries. | ||
| 80 | + * | ||
| 81 | + * If no "max-elements" statement is present, it defaults to "unbounded". | ||
| 82 | + */ | ||
| 83 | + private int maxElelements; | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Reference:RFC 6020. | ||
| 87 | + * The "min-elements" statement, which is optional, takes as an argument a | ||
| 88 | + * non-negative integer that puts a constraint on valid list entries. A | ||
| 89 | + * valid leaf-list or list MUST have at least min-elements entries. | ||
| 90 | + * | ||
| 91 | + * If no "min-elements" statement is present, it defaults to zero. | ||
| 92 | + * | ||
| 93 | + * The behavior of the constraint depends on the type of the leaf-list's or | ||
| 94 | + * list's closest ancestor node in the schema tree that is not a non- | ||
| 95 | + * presence container: | ||
| 96 | + * | ||
| 97 | + * o If this ancestor is a case node, the constraint is enforced if any | ||
| 98 | + * other node from the case exists. | ||
| 99 | + * | ||
| 100 | + * o Otherwise, it is enforced if the ancestor node exists. | ||
| 101 | + */ | ||
| 102 | + private int minElements; | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * The textual reference to this leaf-list. | ||
| 106 | + */ | ||
| 107 | + private String reference; | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Status of the leaf-list in the YANG definition. | ||
| 111 | + */ | ||
| 112 | + private YangStatusType status; | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Textual units. | ||
| 116 | + */ | ||
| 117 | + private String units; | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * Data type of leaf-list. | ||
| 121 | + */ | ||
| 122 | + private YangType<T> dataType; | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * Default Constructor to create a YANG leaf-list. | ||
| 126 | + */ | ||
| 127 | + public YangLeafList() { | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Get the leaf-list name. | ||
| 132 | + * | ||
| 133 | + * @return the leaf-list name. | ||
| 134 | + */ | ||
| 135 | + public String getLeafName() { | ||
| 136 | + return name; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Set the leaf-list name. | ||
| 141 | + * | ||
| 142 | + * @param leafListName the leaf-list name to set. | ||
| 143 | + */ | ||
| 144 | + public void setLeafName(String leafListName) { | ||
| 145 | + this.name = leafListName; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Get the config flag. | ||
| 150 | + * | ||
| 151 | + * @return the config flag. | ||
| 152 | + */ | ||
| 153 | + public boolean isConfig() { | ||
| 154 | + return isConfig; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Set the config flag. | ||
| 159 | + * | ||
| 160 | + * @param isCfg the config flag. | ||
| 161 | + */ | ||
| 162 | + public void setConfig(boolean isCfg) { | ||
| 163 | + isConfig = isCfg; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * Get the description. | ||
| 168 | + * | ||
| 169 | + * @return the description. | ||
| 170 | + */ | ||
| 171 | + public String getDescription() { | ||
| 172 | + return description; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * Set the description. | ||
| 177 | + * | ||
| 178 | + * @param description set the description. | ||
| 179 | + */ | ||
| 180 | + public void setDescription(String description) { | ||
| 181 | + this.description = description; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + /** | ||
| 185 | + * Get the max elements no. | ||
| 186 | + * | ||
| 187 | + * @return the max elements no. | ||
| 188 | + */ | ||
| 189 | + public int getMaxElelements() { | ||
| 190 | + return maxElelements; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * Set the max elements no. | ||
| 195 | + * | ||
| 196 | + * @param maxElelements max elements no. | ||
| 197 | + */ | ||
| 198 | + public void setMaxElelements(int maxElelements) { | ||
| 199 | + this.maxElelements = maxElelements; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + /** | ||
| 203 | + * Get the min elements no. | ||
| 204 | + * | ||
| 205 | + * @return the min elements no. | ||
| 206 | + */ | ||
| 207 | + public int getMinElements() { | ||
| 208 | + return minElements; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * Set the min elements no. | ||
| 213 | + * | ||
| 214 | + * @param minElements the min elements no. | ||
| 215 | + */ | ||
| 216 | + public void setMinElements(int minElements) { | ||
| 217 | + this.minElements = minElements; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + /** | ||
| 221 | + * Get the textual reference. | ||
| 222 | + * | ||
| 223 | + * @return the reference. | ||
| 224 | + */ | ||
| 225 | + public String getReference() { | ||
| 226 | + return reference; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + /** | ||
| 230 | + * Set the textual reference. | ||
| 231 | + * | ||
| 232 | + * @param reference the reference to set. | ||
| 233 | + */ | ||
| 234 | + public void setReference(String reference) { | ||
| 235 | + this.reference = reference; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * Get the status. | ||
| 240 | + * | ||
| 241 | + * @return the status. | ||
| 242 | + */ | ||
| 243 | + public YangStatusType getStatus() { | ||
| 244 | + return status; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + /** | ||
| 248 | + * Set the status. | ||
| 249 | + * | ||
| 250 | + * @param status the status to set. | ||
| 251 | + */ | ||
| 252 | + public void setStatus(YangStatusType status) { | ||
| 253 | + this.status = status; | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + /** | ||
| 257 | + * Get the units. | ||
| 258 | + * | ||
| 259 | + * @return the units. | ||
| 260 | + */ | ||
| 261 | + public String getUnits() { | ||
| 262 | + return units; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + /** | ||
| 266 | + * Set the units. | ||
| 267 | + * | ||
| 268 | + * @param units the units to set. | ||
| 269 | + */ | ||
| 270 | + public void setUnits(String units) { | ||
| 271 | + this.units = units; | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * Get the data type. | ||
| 276 | + * | ||
| 277 | + * @return the data type. | ||
| 278 | + */ | ||
| 279 | + public YangType<T> getDataType() { | ||
| 280 | + return dataType; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + /** | ||
| 284 | + * Set the data type. | ||
| 285 | + * | ||
| 286 | + * @param dataType the data type to set. | ||
| 287 | + */ | ||
| 288 | + public void setDataType(YangType<T> dataType) { | ||
| 289 | + this.dataType = dataType; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /** | ||
| 293 | + * Returns the type of the parsed data. | ||
| 294 | + * | ||
| 295 | + * @return returns LEAF_LIST_DATA. | ||
| 296 | + */ | ||
| 297 | + public ParsableDataType getParsableDataType() { | ||
| 298 | + return ParsableDataType.LEAF_LIST_DATA; | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + /** | ||
| 302 | + * Validate the data on entering the corresponding parse tree node. | ||
| 303 | + * | ||
| 304 | + * @throws DataModelException a violation of data model rules. | ||
| 305 | + */ | ||
| 306 | + public void validateDataOnEntry() throws DataModelException { | ||
| 307 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 308 | + | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + /** | ||
| 312 | + * Validate the data on exiting the corresponding parse tree node. | ||
| 313 | + * | ||
| 314 | + * @throws DataModelException a violation of data model rules. | ||
| 315 | + */ | ||
| 316 | + public void validateDataOnExit() throws DataModelException { | ||
| 317 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 318 | + | ||
| 319 | + } | ||
| 320 | +} |
| 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.datamodel; | ||
| 15 | + | ||
| 16 | +import java.util.List; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Abstraction of atomic configurable/status entity. It is used to abstract the | ||
| 20 | + * data holders of leaf or leaf list. Used in leaves parsing or attribute code | ||
| 21 | + * generation. | ||
| 22 | + */ | ||
| 23 | +public interface YangLeavesHolder { | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Get the list of leaves from data holder like container / list. | ||
| 27 | + * | ||
| 28 | + * @return the list of leaves. | ||
| 29 | + */ | ||
| 30 | + @SuppressWarnings("rawtypes") | ||
| 31 | + public List<YangLeaf> getListOfLeaf(); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Add a leaf in data holder like container / list. | ||
| 35 | + * | ||
| 36 | + * @param leaf the leaf to be added. | ||
| 37 | + */ | ||
| 38 | + void addLeaf(YangLeaf<?> leaf); | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * Get the list of leaf-list from data holder like container / list. | ||
| 42 | + * | ||
| 43 | + * @return the list of leaf-list. | ||
| 44 | + */ | ||
| 45 | + @SuppressWarnings("rawtypes") | ||
| 46 | + List<YangLeafList> getListOfLeafList(); | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Add a leaf-list in data holder like container / list. | ||
| 50 | + * | ||
| 51 | + * @param leafList the leaf-list to be added. | ||
| 52 | + */ | ||
| 53 | + void addLeafList(YangLeafList<?> leafList); | ||
| 54 | +} |
-
Please register or login to post a comment