Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 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 | * The "grouping" statement is used to define a reusable block of nodes, |
| 29 | * which may be used locally in the module, in modules that include it, |
| 30 | * and by other modules that import from it. It takes one argument, |
| 31 | * which is an identifier, followed by a block of sub-statements that |
| 32 | * holds detailed grouping information. |
| 33 | * |
| 34 | * The "grouping" statement is not a data definition statement and, as |
| 35 | * such, does not define any nodes in the schema tree. |
| 36 | * |
| 37 | * A grouping is like a "structure" or a "record" in conventional |
| 38 | * programming languages. |
| 39 | * Once a grouping is defined, it can be referenced in a "uses" |
| 40 | * statement. A grouping MUST NOT reference itself, |
| 41 | * neither directly nor indirectly through a chain of other groupings. |
| 42 | * |
| 43 | * If the grouping is defined at the top level of a YANG module or |
| 44 | * submodule, the grouping's identifier MUST be unique within the |
| 45 | * module. |
| 46 | * |
| 47 | * A grouping is more than just a mechanism for textual substitution, |
| 48 | * but defines a collection of nodes. Identifiers appearing inside the |
| 49 | * grouping are resolved relative to the scope in which the grouping is |
| 50 | * defined, not where it is used. Prefix mappings, type names, grouping |
| 51 | * names, and extension usage are evaluated in the hierarchy where the |
| 52 | * "grouping" statement appears. For extensions, this means that |
| 53 | * extensions are applied to the grouping node, not the uses node. |
| 54 | * |
| 55 | * The grouping's sub-statements |
| 56 | * |
| 57 | * +--------------+---------+-------------+------------------+ |
| 58 | * | substatement | section | cardinality |data model mapping| |
| 59 | * +--------------+---------+-------------+------------------+ |
| 60 | * | anyxml | 7.10 | 0..n |-not supported | |
| 61 | * | choice | 7.9 | 0..n |-child nodes | |
| 62 | * | container | 7.5 | 0..n |-child nodes | |
| 63 | * | description | 7.19.3 | 0..1 |-string | |
| 64 | * | grouping | 7.11 | 0..n |-child nodes | |
| 65 | * | leaf | 7.6 | 0..n |-YangLeaf | |
| 66 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
| 67 | * | list | 7.8 | 0..n |-child nodes | |
| 68 | * | reference | 7.19.4 | 0..1 |-string | |
| 69 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 70 | * | typedef | 7.3 | 0..n |-child nodes | |
| 71 | * | uses | 7.12 | 0..n |-child nodes | |
| 72 | * +--------------+---------+-------------+------------------+ |
| 73 | */ |
| 74 | |
| 75 | /** |
| 76 | * Data model node to maintain information defined in YANG grouping. |
| 77 | */ |
| 78 | public class YangGrouping extends YangNode |
| 79 | implements YangLeavesHolder, YangCommonInfo, Parsable { |
| 80 | |
| 81 | /** |
| 82 | * Name of the grouping. |
| 83 | */ |
| 84 | private String name; |
| 85 | |
| 86 | /** |
| 87 | * Description. |
| 88 | */ |
| 89 | private String description; |
| 90 | |
| 91 | /** |
| 92 | * List of leaves. |
| 93 | */ |
| 94 | @SuppressWarnings("rawtypes") |
| 95 | private List<YangLeaf> listOfLeaf; |
| 96 | |
| 97 | /** |
| 98 | * List of leaf lists. |
| 99 | */ |
| 100 | @SuppressWarnings("rawtypes") |
| 101 | private List<YangLeafList> listOfLeafList; |
| 102 | |
| 103 | /** |
| 104 | * Reference of the module. |
| 105 | */ |
| 106 | private String reference; |
| 107 | |
| 108 | /** |
| 109 | * Status of the node. |
| 110 | */ |
| 111 | private YangStatusType status; |
| 112 | |
| 113 | /** |
| 114 | * Creates the grouping node. |
| 115 | */ |
| 116 | public YangGrouping() { |
| 117 | super(YangNodeType.GROUPING_NODE); |
| 118 | } |
| 119 | |
| 120 | /* (non-Javadoc) |
| 121 | * @see org.onosproject.yangutils.datamodel.YangNode#getName() |
| 122 | */ |
| 123 | @Override |
| 124 | public String getName() { |
| 125 | return name; |
| 126 | } |
| 127 | |
| 128 | /* (non-Javadoc) |
| 129 | * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) |
| 130 | */ |
| 131 | @Override |
| 132 | public void setName(String name) { |
| 133 | this.name = name; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Get the description. |
| 138 | * |
| 139 | * @return the description. |
| 140 | */ |
| 141 | public String getDescription() { |
| 142 | return description; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Set the description. |
| 147 | * |
| 148 | * @param description set the description. |
| 149 | */ |
| 150 | public void setDescription(String description) { |
| 151 | this.description = description; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the list of leaves. |
| 156 | * |
| 157 | * @return the list of leaves. |
| 158 | */ |
| 159 | @SuppressWarnings("rawtypes") |
| 160 | public List<YangLeaf> getListOfLeaf() { |
| 161 | return listOfLeaf; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Set the list of leaves. |
| 166 | * |
| 167 | * @param leafsList the list of leaf to set. |
| 168 | */ |
| 169 | @SuppressWarnings("rawtypes") |
| 170 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
| 171 | listOfLeaf = leafsList; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Add a leaf. |
| 176 | * |
| 177 | * @param leaf the leaf to be added. |
| 178 | */ |
| 179 | @SuppressWarnings("rawtypes") |
| 180 | public void addLeaf(YangLeaf<?> leaf) { |
| 181 | if (getListOfLeaf() == null) { |
| 182 | setListOfLeaf(new LinkedList<YangLeaf>()); |
| 183 | } |
| 184 | |
| 185 | getListOfLeaf().add(leaf); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Get the list of leaf-list. |
| 190 | * |
| 191 | * @return the list of leaf-list. |
| 192 | */ |
| 193 | @SuppressWarnings("rawtypes") |
| 194 | public List<YangLeafList> getListOfLeafList() { |
| 195 | return listOfLeafList; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Set the list of leaf-list. |
| 200 | * |
| 201 | * @param listOfLeafList the list of leaf-list to set. |
| 202 | */ |
| 203 | @SuppressWarnings("rawtypes") |
| 204 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
| 205 | this.listOfLeafList = listOfLeafList; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Add a leaf-list. |
| 210 | * |
| 211 | * @param leafList the leaf-list to be added. |
| 212 | */ |
| 213 | @SuppressWarnings("rawtypes") |
| 214 | public void addLeafList(YangLeafList<?> leafList) { |
| 215 | if (getListOfLeafList() == null) { |
| 216 | setListOfLeafList(new LinkedList<YangLeafList>()); |
| 217 | } |
| 218 | |
| 219 | getListOfLeafList().add(leafList); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Get the textual reference. |
| 224 | * |
| 225 | * @return the reference. |
| 226 | */ |
| 227 | public String getReference() { |
| 228 | return reference; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Set the textual reference. |
| 233 | * |
| 234 | * @param reference the reference to set. |
| 235 | */ |
| 236 | public void setReference(String reference) { |
| 237 | this.reference = reference; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Get the status. |
| 242 | * |
| 243 | * @return the status. |
| 244 | */ |
| 245 | public YangStatusType getStatus() { |
| 246 | return status; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Set the status. |
| 251 | * |
| 252 | * @param status the status to set. |
| 253 | */ |
| 254 | public void setStatus(YangStatusType status) { |
| 255 | this.status = status; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Returns the type of the data. |
| 260 | * |
| 261 | * @return returns GROUPING_DATA. |
| 262 | */ |
| 263 | public ParsableDataType getParsableDataType() { |
| 264 | return ParsableDataType.GROUPING_DATA; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Validate the data on entering the corresponding parse tree node. |
| 269 | * |
| 270 | * @throws DataModelException a violation of data model rules. |
| 271 | */ |
| 272 | public void validateDataOnEntry() throws DataModelException { |
| 273 | // TODO auto-generated method stub, to be implemented by parser |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Validate the data on exiting the corresponding parse tree node. |
| 278 | * |
| 279 | * @throws DataModelException a violation of data model rules. |
| 280 | */ |
| 281 | public void validateDataOnExit() throws DataModelException { |
| 282 | // TODO auto-generated method stub, to be implemented by parser |
| 283 | } |
| 284 | |
| 285 | /* (non-Javadoc) |
| 286 | * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() |
| 287 | */ |
| 288 | public void generateJavaCodeEntry() { |
| 289 | // TODO Auto-generated method stub |
| 290 | |
| 291 | } |
| 292 | |
| 293 | /* (non-Javadoc) |
| 294 | * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() |
| 295 | */ |
| 296 | public void generateJavaCodeExit() { |
| 297 | // TODO Auto-generated method stub |
| 298 | |
| 299 | } |
| 300 | |
| 301 | /* (non-Javadoc) |
| 302 | * @see org.onosproject.yangutils.datamodel.YangNode#getPackage() |
| 303 | */ |
| 304 | @Override |
| 305 | public String getPackage() { |
| 306 | // TODO Auto-generated method stub |
| 307 | return null; |
| 308 | } |
| 309 | |
| 310 | /* (non-Javadoc) |
| 311 | * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String) |
| 312 | */ |
| 313 | @Override |
| 314 | public void setPackage(String pkg) { |
| 315 | // TODO Auto-generated method stub |
| 316 | |
| 317 | } |
| 318 | } |