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