blob: c4025b6322f07b204dde4c94648de949be901848 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05303 *
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 */
16package org.onosproject.yangutils.datamodel;
17
18import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053020import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053021
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/**
Bharat saraswald9822e92016-04-05 15:13:44 +053052 * Represents data model node to maintain information defined in YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053053 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053054public class YangUses extends YangNode implements YangCommonInfo, Parsable, Resolvable {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053055
56 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053057 * YANG node identifier.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053058 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053059 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053060
61 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053062 * Referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053063 */
64 private YangGrouping refGroup;
65
66 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053067 * Description of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053068 */
69 private String description;
70
71 /**
72 * YANG reference.
73 */
74 private String reference;
75
76 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053077 * Status of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053078 */
79 private YangStatusType status;
80
81 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053082 * Status of resolution. If completely resolved enum value is "RESOLVED",
83 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
84 * is added to uses/type but it's not resolved value of enum should be
85 * "PARTIALLY_RESOLVED".
86 */
87 private ResolvableStatus resolvableStatus;
88
89 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053090 * Creates an YANG uses node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053091 */
92 public YangUses() {
93 super(YangNodeType.USES_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053094 nodeIdentifier = new YangNodeIdentifier();
95 resolvableStatus = ResolvableStatus.UNRESOLVED;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053096 }
97
98 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053099 * Returns the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530100 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530101 * @return the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530102 */
103 public YangGrouping getRefGroup() {
104 return refGroup;
105 }
106
107 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530108 * Sets the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530109 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530110 * @param refGroup the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111 */
112 public void setRefGroup(YangGrouping refGroup) {
113 this.refGroup = refGroup;
114 }
115
116 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530117 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530118 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530119 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530121 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530122 public String getDescription() {
123 return description;
124 }
125
126 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530129 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530131 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530132 public void setDescription(String description) {
133 this.description = description;
134 }
135
136 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530137 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530139 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530140 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530141 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530142 public String getReference() {
143 return reference;
144 }
145
146 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530147 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530148 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530149 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530151 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152 public void setReference(String reference) {
153 this.reference = reference;
154 }
155
156 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530157 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530159 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530161 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530162 public YangStatusType getStatus() {
163 return status;
164 }
165
166 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530167 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530168 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530169 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530170 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530171 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530172 public void setStatus(YangStatusType status) {
173 this.status = status;
174 }
175
176 /**
177 * Returns the type of the data.
178 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530179 * @return returns USES_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530180 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530181 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530182 public YangConstructType getYangConstructType() {
183 return YangConstructType.USES_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 }
185
186 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530187 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530188 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530189 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530190 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530191 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 public void validateDataOnEntry() throws DataModelException {
193 // TODO auto-generated method stub, to be implemented by parser
194 }
195
196 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530197 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530199 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530200 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530201 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530202 public void validateDataOnExit() throws DataModelException {
203 // TODO auto-generated method stub, to be implemented by parser
204 }
205
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 @Override
207 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530208 return nodeIdentifier.getName();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530209 }
210
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530211 @Override
212 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530213 nodeIdentifier.setName(name);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 }
215
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530216 /**
217 * Returns node identifier.
218 *
219 * @return node identifier
220 */
221 public YangNodeIdentifier getNodeIdentifier() {
222 return nodeIdentifier;
223 }
224
225 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530226 * Sets node identifier.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530227 *
228 * @param nodeIdentifier the node identifier
229 */
230 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
231 this.nodeIdentifier = nodeIdentifier;
232 }
233
234 /**
235 * Returns prefix associated with uses.
236 *
237 * @return prefix associated with uses
238 */
239 public String getPrefix() {
240 return nodeIdentifier.getPrefix();
241 }
242
243 /**
244 * Get prefix associated with uses.
245 *
246 * @param prefix prefix associated with uses
247 */
248 public void setPrefix(String prefix) {
249 nodeIdentifier.setPrefix(prefix);
250 }
251
252 @Override
253 public void resolve() {
254 //TODO: implement the method.
255 }
256
257 @Override
258 public ResolvableStatus getResolvableStatus() {
259 return resolvableStatus;
260 }
261
262 @Override
263 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
264 this.resolvableStatus = resolvableStatus;
265 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266}