Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 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; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 21 | |
| 22 | /*- |
| 23 | * Reference RFC 6020. |
| 24 | * |
| 25 | * The "uses" statement is used to reference a "grouping" definition. It takes |
| 26 | * one argument, which is the name of the grouping. |
| 27 | * |
| 28 | * The effect of a "uses" reference to a grouping is that the nodes defined by |
| 29 | * the grouping are copied into the current schema tree, and then updated |
| 30 | * according to the "refine" and "augment" statements. |
| 31 | * |
| 32 | * The identifiers defined in the grouping are not bound to a namespace until |
| 33 | * the contents of the grouping are added to the schema tree via a "uses" |
| 34 | * statement that does not appear inside a "grouping" statement, at which point |
| 35 | * they are bound to the namespace of the current module. |
| 36 | * |
| 37 | * The uses's sub-statements |
| 38 | * |
| 39 | * +--------------+---------+-------------+------------------+ |
| 40 | * | substatement | section | cardinality |data model mapping| |
| 41 | * +--------------+---------+-------------+------------------+ |
| 42 | * | augment | 7.15 | 0..1 | -child nodes | |
| 43 | * | description | 7.19.3 | 0..1 | -string | |
| 44 | * | if-feature | 7.18.2 | 0..n | -TODO | |
| 45 | * | refine | 7.12.2 | 0..1 | -TODO | |
| 46 | * | reference | 7.19.4 | 0..1 | -string | |
| 47 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 48 | * | when | 7.19.5 | 0..1 | -TODO | |
| 49 | * +--------------+---------+-------------+------------------+ |
| 50 | */ |
| 51 | /** |
| 52 | * Data model node to maintain information defined in YANG uses. |
| 53 | * |
| 54 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 55 | public class YangUses extends YangNode implements YangCommonInfo, Parsable, Resolvable { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 56 | |
| 57 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 58 | * YANG node identifier. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 59 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 60 | private YangNodeIdentifier nodeIdentifier; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 61 | |
| 62 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 63 | * Referred group. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 64 | */ |
| 65 | private YangGrouping refGroup; |
| 66 | |
| 67 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 68 | * Description of YANG uses. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 69 | */ |
| 70 | private String description; |
| 71 | |
| 72 | /** |
| 73 | * YANG reference. |
| 74 | */ |
| 75 | private String reference; |
| 76 | |
| 77 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 78 | * Status of YANG uses. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 79 | */ |
| 80 | private YangStatusType status; |
| 81 | |
| 82 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 83 | * Status of resolution. If completely resolved enum value is "RESOLVED", |
| 84 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef |
| 85 | * is added to uses/type but it's not resolved value of enum should be |
| 86 | * "PARTIALLY_RESOLVED". |
| 87 | */ |
| 88 | private ResolvableStatus resolvableStatus; |
| 89 | |
| 90 | /** |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 91 | * Create an YANG uses node. |
| 92 | */ |
| 93 | public YangUses() { |
| 94 | super(YangNodeType.USES_NODE); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 95 | nodeIdentifier = new YangNodeIdentifier(); |
| 96 | resolvableStatus = ResolvableStatus.UNRESOLVED; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 100 | * Returns the referred group. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 101 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 102 | * @return the referred group |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 103 | */ |
| 104 | public YangGrouping getRefGroup() { |
| 105 | return refGroup; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Set the referred group. |
| 110 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 111 | * @param refGroup the referred group |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 112 | */ |
| 113 | public void setRefGroup(YangGrouping refGroup) { |
| 114 | this.refGroup = refGroup; |
| 115 | } |
| 116 | |
| 117 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 118 | * Returns the description. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 119 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 120 | * @return the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 121 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 122 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 123 | public String getDescription() { |
| 124 | return description; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Set the description. |
| 129 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 130 | * @param description set the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 131 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 132 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 133 | public void setDescription(String description) { |
| 134 | this.description = description; |
| 135 | } |
| 136 | |
| 137 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 138 | * Returns the textual reference. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 139 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 140 | * @return the reference |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 141 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 142 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 143 | public String getReference() { |
| 144 | return reference; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Set the textual reference. |
| 149 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 150 | * @param reference the reference to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 151 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 152 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 153 | public void setReference(String reference) { |
| 154 | this.reference = reference; |
| 155 | } |
| 156 | |
| 157 | /** |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 158 | * Returns the status. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 159 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | * @return the status |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 161 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 162 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 163 | public YangStatusType getStatus() { |
| 164 | return status; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Set the status. |
| 169 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 170 | * @param status the status to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 171 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 172 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 173 | public void setStatus(YangStatusType status) { |
| 174 | this.status = status; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Returns the type of the data. |
| 179 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 180 | * @return returns USES_DATA |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 181 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 182 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 183 | public YangConstructType getYangConstructType() { |
| 184 | return YangConstructType.USES_DATA; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Validate the data on entering the corresponding parse tree node. |
| 189 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 190 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 191 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 192 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 193 | public void validateDataOnEntry() throws DataModelException { |
| 194 | // TODO auto-generated method stub, to be implemented by parser |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Validate the data on exiting the corresponding parse tree node. |
| 199 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 200 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 201 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 202 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 203 | public void validateDataOnExit() throws DataModelException { |
| 204 | // TODO auto-generated method stub, to be implemented by parser |
| 205 | } |
| 206 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 207 | @Override |
| 208 | public String getName() { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 209 | return nodeIdentifier.getName(); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 210 | } |
| 211 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 212 | @Override |
| 213 | public void setName(String name) { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 214 | nodeIdentifier.setName(name); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 215 | } |
| 216 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 217 | /** |
| 218 | * Returns node identifier. |
| 219 | * |
| 220 | * @return node identifier |
| 221 | */ |
| 222 | public YangNodeIdentifier getNodeIdentifier() { |
| 223 | return nodeIdentifier; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Set node identifier. |
| 228 | * |
| 229 | * @param nodeIdentifier the node identifier |
| 230 | */ |
| 231 | public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) { |
| 232 | this.nodeIdentifier = nodeIdentifier; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Returns prefix associated with uses. |
| 237 | * |
| 238 | * @return prefix associated with uses |
| 239 | */ |
| 240 | public String getPrefix() { |
| 241 | return nodeIdentifier.getPrefix(); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Get prefix associated with uses. |
| 246 | * |
| 247 | * @param prefix prefix associated with uses |
| 248 | */ |
| 249 | public void setPrefix(String prefix) { |
| 250 | nodeIdentifier.setPrefix(prefix); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void resolve() { |
| 255 | //TODO: implement the method. |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public ResolvableStatus getResolvableStatus() { |
| 260 | return resolvableStatus; |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
| 265 | this.resolvableStatus = resolvableStatus; |
| 266 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 267 | } |