blob: 151477da70dc6afda564518fdf11e6c4309d3232 [file] [log] [blame]
Vidyashree Rama13b4c552016-06-20 15:12:43 +05301/*
2 * Copyright 2016-present 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
17package org.onosproject.yangutils.datamodel;
18
19import java.io.Serializable;
20import java.util.Iterator;
21import java.util.List;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053022
Vidyashree Rama13b4c552016-06-20 15:12:43 +053023import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24import org.onosproject.yangutils.datamodel.utils.Parsable;
25import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
26import org.onosproject.yangutils.datamodel.utils.YangConstructType;
27
28/*
29 * Reference RFC 6020.
30 *
31 * The "if-feature" statement makes its parent statement conditional.
32 * The argument is the name of a feature, as defined by a "feature"
33 * statement. The parent statement is implemented by servers that
34 * support this feature. If a prefix is present on the feature name, it
35 * refers to a feature defined in the module that was imported with that
36 * prefix, or the local module if the prefix matches the local module's
37 * prefix. Otherwise, a feature with the matching name MUST be defined
38 * in the current module or an included submodule.
39 *
40 * Since submodules cannot include the parent module, any features in
41 * the module that need to be exposed to submodules MUST be defined in a
42 * submodule. Submodules can then include this submodule to find the
43 * definition of the feature.
44 */
45
46/**
47 * Represents data model node to maintain information defined in YANG if-feature.
48 */
49public class YangIfFeature implements Parsable, Resolvable, Serializable {
50
51 private static final long serialVersionUID = 806201635L;
52
53 /**
54 * if-feature argument.
55 */
Bharat saraswal2da23bf2016-08-25 15:28:39 +053056 private YangNodeIdentifier name;
Vidyashree Rama13b4c552016-06-20 15:12:43 +053057
58 /**
59 * Referred feature information.
60 */
Bharat saraswal2da23bf2016-08-25 15:28:39 +053061 private YangFeature referredFeature;
Vidyashree Rama13b4c552016-06-20 15:12:43 +053062
63 /**
64 * Referred feature parent information.
65 */
Bharat saraswal2da23bf2016-08-25 15:28:39 +053066 private YangNode referredFeatureHolder;
Vidyashree Rama13b4c552016-06-20 15:12:43 +053067
68 /**
69 * Status of resolution. If completely resolved enum value is "RESOLVED",
70 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
71 * is added to uses/type but it's not resolved value of enum should be
72 * "INTRA_FILE_RESOLVED".
73 */
74 private ResolvableStatus resolvableStatus;
75
76 /**
77 * Returns referred feature holder.
78 *
79 * @return referred feature holder
80 */
81 public YangNode getReferredFeatureHolder() {
82 return referredFeatureHolder;
83 }
84
85 /**
86 * Sets the referred feature holder.
87 *
88 * @param referredFeatureHolder referred feature holder
89 */
90 public void setReferredFeatureHolder(YangNode referredFeatureHolder) {
91 this.referredFeatureHolder = referredFeatureHolder;
92 }
93
94 /**
95 * Returns prefix associated with identifier.
96 *
97 * @return prefix associated with identifier
98 */
99 public String getPrefix() {
100 return name.getPrefix();
101 }
102
103 /**
104 * Sets prefix associated with identifier.
105 *
106 * @param prefix prefix associated with identifier
107 */
108 public void setPrefix(String prefix) {
109 name.setPrefix(prefix);
110 }
111
112 /**
113 * Returns referred feature associated with if-feature.
114 *
115 * @return referred feature associated with if-feature
116 */
117 public YangFeature getReferredFeature() {
118 return referredFeature;
119 }
120
121 /**
122 * Sets referred feature associated with if-feature.
123 *
124 * @param referredFeature referred feature associated with if-feature
125 */
126 public void setReferredFeature(YangFeature referredFeature) {
127 this.referredFeature = referredFeature;
128 }
129
130 /**
131 * Returns the YANG name of if-feature.
132 *
133 * @return the name of if-feature as defined in YANG file
134 */
135 public YangNodeIdentifier getName() {
136 return name;
137 }
138
139 /**
140 * Sets the YANG name of if-feature.
141 *
142 * @param name the name of if-feature as defined in YANG file
143 */
144 public void setName(YangNodeIdentifier name) {
145 this.name = name;
146 }
147
148 @Override
149 public YangConstructType getYangConstructType() {
150 return YangConstructType.IF_FEATURE_DATA;
151 }
152
153 @Override
154 public void validateDataOnEntry() throws DataModelException {
155 // do nothing, no validation required for if-feature
156 }
157
158 @Override
159 public void validateDataOnExit() throws DataModelException {
160 // do nothing, no validation required for if-feature
161 }
162
163 @Override
164 public ResolvableStatus getResolvableStatus() {
165 return resolvableStatus;
166 }
167
168 @Override
169 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
170 this.resolvableStatus = resolvableStatus;
171 }
172
173 @Override
janani bebb143d2016-07-14 19:35:22 +0530174 public Object resolve() throws DataModelException {
Vidyashree Rama13b4c552016-06-20 15:12:43 +0530175 YangFeature feature = getReferredFeature();
176
177 // check whether feature has if-feature
178 List<YangIfFeature> ifFeatureList = feature.getIfFeatureList();
179 if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
180 Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
181 while (ifFeatureIterator.hasNext()) {
182 YangIfFeature ifFeature = ifFeatureIterator.next();
183 if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) {
184 setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
janani bebb143d2016-07-14 19:35:22 +0530185 return null;
Vidyashree Rama13b4c552016-06-20 15:12:43 +0530186 }
187 }
188 }
janani bebb143d2016-07-14 19:35:22 +0530189 return null;
Vidyashree Rama13b4c552016-06-20 15:12:43 +0530190 }
191}