blob: 613237afc21e1a467f68e2768fa624ca59887ca4 [file] [log] [blame]
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +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 */
16
17package org.onosproject.yangutils.datamodel;
18
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053019import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053020import org.onosproject.yangutils.linker.impl.ResolvableStatus;
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053021import com.google.common.base.Strings;
22
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053023import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053024import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
25import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
26import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
27import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY;
28import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION;
29import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
30import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
31import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
32import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053033import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
34import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053035import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
36import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
37import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
38
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053039/**
Bharat saraswald9822e92016-04-05 15:13:44 +053040 * Represents the derived information.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053041 *
42 * @param <T> extended information.
43 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053044public class YangDerivedInfo<T> implements LocationInfo {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053045
46 /**
47 * YANG typedef reference.
48 */
49 private YangTypeDef referredTypeDef;
50
51 /**
52 * Resolved additional information about data type after linking, example
53 * restriction info, named values, etc. The extra information is based
54 * on the data type. Based on the data type, the extended info can vary.
55 */
56 private T resolvedExtendedInfo;
57
58 /**
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053059 * Line number of pattern restriction in YANG file.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053060 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053061 private int lineNumber;
62
63 /**
64 * Position of pattern restriction in line.
65 */
66 private int charPositionInLine;
67
68 /**
69 * Effective built-in type, requried in case type of typedef is again a
70 * derived type. This information is to be added during linking.
71 */
72 private YangDataTypes effectiveBuiltInType;
73
74 /**
75 * Length restriction string to temporary store the length restriction when the type
76 * is derived.
77 */
78 private String lengthRestrictionString;
79
80 /**
81 * Range restriction string to temporary store the range restriction when the type
82 * is derived.
83 */
84 private String rangeRestrictionString;
85
86 /**
87 * Pattern restriction string to temporary store the pattern restriction when the type
88 * is derived.
89 */
90 private YangPatternRestriction patternRestriction;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053091
92 /**
93 * Returns the referred typedef reference.
94 *
95 * @return referred typedef reference
96 */
97 public YangTypeDef getReferredTypeDef() {
98 return referredTypeDef;
99 }
100
101 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530102 * Sets the referred typedef reference.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530103 *
104 * @param referredTypeDef referred typedef reference
105 */
106 public void setReferredTypeDef(YangTypeDef referredTypeDef) {
107 this.referredTypeDef = referredTypeDef;
108 }
109
110 /**
111 * Returns resolved extended information after successful linking.
112 *
113 * @return resolved extended information
114 */
115 public T getResolvedExtendedInfo() {
116 return resolvedExtendedInfo;
117 }
118
119 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530120 * Sets resolved extended information after successful linking.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530121 *
122 * @param resolvedExtendedInfo resolved extended information
123 */
124 public void setResolvedExtendedInfo(T resolvedExtendedInfo) {
125 this.resolvedExtendedInfo = resolvedExtendedInfo;
126 }
127
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530128 @Override
129 public int getLineNumber() {
130 return lineNumber;
131 }
132
133 @Override
134 public int getCharPosition() {
135 return charPositionInLine;
136 }
137
138 @Override
139 public void setLineNumber(int lineNumber) {
140 this.lineNumber = lineNumber;
141 }
142
143 @Override
144 public void setCharPosition(int charPositionInLine) {
145 this.charPositionInLine = charPositionInLine;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530146 }
147
148 /**
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530149 * Returns the length restriction string.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530150 *
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530151 * @return the length restriction string
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530152 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530153 public String getLengthRestrictionString() {
154 return lengthRestrictionString;
155 }
156
157 /**
158 * Sets the length restriction string.
159 *
160 * @param lengthRestrictionString the length restriction string
161 */
162 public void setLengthRestrictionString(String lengthRestrictionString) {
163 this.lengthRestrictionString = lengthRestrictionString;
164 }
165
166 /**
167 * Returns the range restriction string.
168 *
169 * @return the range restriction string
170 */
171 public String getRangeRestrictionString() {
172 return rangeRestrictionString;
173 }
174
175 /**
176 * Sets the range restriction string.
177 *
178 * @param rangeRestrictionString the range restriction string
179 */
180 public void setRangeRestrictionString(String rangeRestrictionString) {
181 this.rangeRestrictionString = rangeRestrictionString;
182 }
183
184 /**
185 * Returns the pattern restriction.
186 *
187 * @return the pattern restriction
188 */
189 public YangPatternRestriction getPatternRestriction() {
190 return patternRestriction;
191 }
192
193 /**
194 * Sets the pattern restriction.
195 *
196 * @param patternRestriction the pattern restriction
197 */
198 public void setPatternRestriction(YangPatternRestriction patternRestriction) {
199 this.patternRestriction = patternRestriction;
200 }
201
202 /**
203 * Returns effective built-in type.
204 *
205 * @return effective built-in type
206 */
207 public YangDataTypes getEffectiveBuiltInType() {
208 return effectiveBuiltInType;
209 }
210
211 /**
212 * Sets effective built-in type.
213 *
214 * @param effectiveBuiltInType effective built-in type
215 */
216 public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
217 this.effectiveBuiltInType = effectiveBuiltInType;
218 }
219
220 /**
221 * Resolves the type derived info, by obtaining the effective built-in type
222 * and resolving the restrictions.
223 *
224 * @return resolution status
225 * @throws DataModelException a violation in data mode rule
226 */
227 public ResolvableStatus resolve() throws DataModelException {
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530228 YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530229 /*
230 * Checks the data type of the referred typedef, if it's derived,
231 * obtain effective built-in type and restrictions from it's derived
232 * info, otherwise take from the base type of type itself.
233 */
234 if (baseType.getDataType() == DERIVED) {
235 /*
236 * Check whether the referred typedef is resolved.
237 */
238 if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530239 throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530240 }
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530241 /*
242 * Check if the referred typedef is intra file resolved, if yes sets
243 * current status also to intra file resolved .
244 */
245 if (getReferredTypeDef().getTypeDefBaseType().getResolvableStatus() == INTRA_FILE_RESOLVED) {
246 return INTRA_FILE_RESOLVED;
247 }
248 setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
249 .getEffectiveBuiltInType());
Bharat saraswalcad0e652016-05-26 23:48:38 +0530250 YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530251 /*
252 * Check whether the effective built-in type can have range
253 * restrictions, if yes call resolution of range.
254 */
255 if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
256 if (refDerivedInfo.getResolvedExtendedInfo() == null) {
257 resolveRangeRestriction(null);
258 /*
259 * Return the resolution status as resolved, if it's not
260 * resolve range/string restriction will throw exception
261 * in previous function.
262 */
263 return RESOLVED;
264 } else {
265 if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
266 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
267 "type.");
268 }
269 resolveRangeRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
270 /*
271 * Return the resolution status as resolved, if it's not
272 * resolve range/string restriction will throw exception
273 * in previous function.
274 */
275 return RESOLVED;
276 }
277 /*
278 * If the effective built-in type is of type string calls
279 * for string resolution.
280 */
281 } else if (getEffectiveBuiltInType() == STRING) {
282 if (refDerivedInfo.getResolvedExtendedInfo() == null) {
283 resolveStringRestriction(null);
284 /*
285 * Return the resolution status as resolved, if it's not
286 * resolve range/string restriction will throw exception
287 * in previous function.
288 */
289 return RESOLVED;
290 } else {
291 if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangStringRestriction)) {
292 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
293 "type.");
294 }
295 resolveStringRestriction((YangStringRestriction) refDerivedInfo.getResolvedExtendedInfo());
296 /*
297 * Return the resolution status as resolved, if it's not
298 * resolve range/string restriction will throw exception
299 * in previous function.
300 */
301 return RESOLVED;
302 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530303 } else if (getEffectiveBuiltInType() == BINARY) {
304 if (refDerivedInfo.getResolvedExtendedInfo() == null) {
305 resolveLengthRestriction(null);
306 /*
307 * Return the resolution status as resolved, if it's not
308 * resolve length restriction will throw exception
309 * in previous function.
310 */
311 return RESOLVED;
312 } else {
313 if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
314 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
315 "type.");
316 }
317 resolveLengthRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
318 /*
319 * Return the resolution status as resolved, if it's not
320 * resolve length restriction will throw exception
321 * in previous function.
322 */
323 return RESOLVED;
324 }
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530325 }
326 } else {
Bharat saraswalcad0e652016-05-26 23:48:38 +0530327 setEffectiveBuiltInType(baseType.getDataType());
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530328 /*
329 * Check whether the effective built-in type can have range
330 * restrictions, if yes call resolution of range.
331 */
332 if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
333 if (baseType.getDataTypeExtendedInfo() == null) {
334 resolveRangeRestriction(null);
335 /*
336 * Return the resolution status as resolved, if it's not
337 * resolve range/string restriction will throw exception
338 * in previous function.
339 */
340 return RESOLVED;
341 } else {
342 if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
343 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
344 "type.");
345 }
346 resolveRangeRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
347 /*
348 * Return the resolution status as resolved, if it's not
349 * resolve range/string restriction will throw exception
350 * in previous function.
351 */
352 return RESOLVED;
353 }
354 /*
355 * If the effective built-in type is of type string calls
356 * for string resolution.
357 */
358 } else if (getEffectiveBuiltInType() == STRING) {
359 if (baseType.getDataTypeExtendedInfo() == null) {
360 resolveStringRestriction(null);
361 /*
362 * Return the resolution status as resolved, if it's not
363 * resolve range/string restriction will throw exception
364 * in previous function.
365 */
366 return RESOLVED;
367 } else {
368 if (!(baseType.getDataTypeExtendedInfo() instanceof YangStringRestriction)) {
369 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
370 "type.");
371 }
372 resolveStringRestriction((YangStringRestriction) baseType.getDataTypeExtendedInfo());
373 /*
374 * Return the resolution status as resolved, if it's not
375 * resolve range/string restriction will throw exception
376 * in previous function.
377 */
378 return RESOLVED;
379 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530380 } else if (getEffectiveBuiltInType() == BINARY) {
381 if (baseType.getDataTypeExtendedInfo() == null) {
382 resolveLengthRestriction(null);
383 /*
384 * Return the resolution status as resolved, if it's not
385 * resolve length restriction will throw exception
386 * in previous function.
387 */
388 return RESOLVED;
389 } else {
390 if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
391 throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
392 "type.");
393 }
394 resolveLengthRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
395 /*
396 * Return the resolution status as resolved, if it's not
397 * resolve length restriction will throw exception
398 * in previous function.
399 */
400 return RESOLVED;
401 }
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530402 }
403 }
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530404 /*
405 * Check if the data type is the one which can't be restricted, in
406 * this case check whether no self restrictions should be present.
407 */
408 if (isOfValidNonRestrictedType(getEffectiveBuiltInType())) {
409 if (Strings.isNullOrEmpty(getLengthRestrictionString())
410 && Strings.isNullOrEmpty(getRangeRestrictionString())
411 && getPatternRestriction() == null) {
412 return RESOLVED;
413 } else {
414 throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
415 }
416 }
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530417 // Throw exception for unsupported types
418 throw new DataModelException("Linker error: Unable to process the derived type.");
419 }
420
421 /**
422 * Resolves the string restrictions.
423 *
424 * @param refStringRestriction referred string restriction of typedef
425 * @throws DataModelException a violation in data model rule
426 */
427 private void resolveStringRestriction(YangStringRestriction refStringRestriction) throws DataModelException {
428 YangStringRestriction curStringRestriction = null;
429 YangRangeRestriction refRangeRestriction = null;
430 YangPatternRestriction refPatternRestriction = null;
431
432 /*
433 * Check that range restriction should be null when built-in type is
434 * string.
435 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530436 if (!Strings.isNullOrEmpty(getRangeRestrictionString())) {
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530437 DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
438 "should't be present for string data type.");
439 dataModelException.setLine(lineNumber);
440 dataModelException.setCharPosition(charPositionInLine);
441 throw dataModelException;
442 }
443
444 /*
445 * If referred restriction and self restriction both are null, no
446 * resolution is required.
447 */
448 if (refStringRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())
449 && getPatternRestriction() == null) {
450 return;
451 }
452
453 /*
454 * If referred string restriction is not null, take value of length
455 * and pattern restriction and assign.
456 */
457 if (refStringRestriction != null) {
458 refRangeRestriction = refStringRestriction.getLengthRestriction();
459 refPatternRestriction = refStringRestriction.getPatternRestriction();
460 }
461
462 YangRangeRestriction lengthRestriction = resolveLengthRestriction(refRangeRestriction);
463 YangPatternRestriction patternRestriction = resolvePatternRestriction(refPatternRestriction);
464
465 /*
466 * Check if either of length or pattern restriction is present, if yes
467 * create string restriction and assign value.
468 */
469 if (lengthRestriction != null || patternRestriction != null) {
470 curStringRestriction = new YangStringRestriction();
471 curStringRestriction.setLengthRestriction(lengthRestriction);
472 curStringRestriction.setPatternRestriction(patternRestriction);
473 }
474 setResolvedExtendedInfo((T) curStringRestriction);
475 }
476
477 /**
478 * Resolves pattern restriction.
479 *
480 * @param refPatternRestriction referred pattern restriction of typedef
481 * @return resolved pattern restriction
482 */
483 private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPatternRestriction) {
484 /*
485 * If referred restriction and self restriction both are null, no
486 * resolution is required.
487 */
488 if (refPatternRestriction == null && getPatternRestriction() == null) {
489 return null;
490 }
491
492 /*
493 * If self restriction is null, and referred restriction is present
494 * shallow copy the referred to self.
495 */
496 if (getPatternRestriction() == null) {
497 return refPatternRestriction;
498 }
499
500 /*
501 * If referred restriction is null, and self restriction is present
502 * carry out self resolution.
503 */
504 if (refPatternRestriction == null) {
505 return getPatternRestriction();
506 }
507
508 /*
509 * Get patterns of referred type and add it to current pattern
510 * restrictions.
511 */
512 for (String pattern : refPatternRestriction.getPatternList()) {
513 getPatternRestriction().addPattern(pattern);
514 }
515 return getPatternRestriction();
516 }
517
518 /**
519 * Resolves the length restrictions.
520 *
521 * @param refLengthRestriction referred length restriction of typedef
522 * @return resolved length restriction
523 * @throws DataModelException a violation in data model rule
524 */
525 private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction) throws
526 DataModelException {
527
528 /*
529 * If referred restriction and self restriction both are null, no
530 * resolution is required.
531 */
532 if (refLengthRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())) {
533 return null;
534 }
535
536 /*
537 * If self restriction is null, and referred restriction is present
538 * shallow copy the referred to self.
539 */
540 if (Strings.isNullOrEmpty(getLengthRestrictionString())) {
541 return refLengthRestriction;
542 }
543
544 /*
545 * If referred restriction is null, and self restriction is present
546 * carry out self resolution.
547 */
548 if (refLengthRestriction == null) {
549 YangRangeRestriction curLengthRestriction = processLengthRestriction(null, lineNumber,
550 charPositionInLine, false, getLengthRestrictionString());
551 return curLengthRestriction;
552 }
553
554 /*
555 * Carry out self resolution based with obtained effective built-in
556 * type and MIN/MAX values as per the referred typedef's values.
557 */
558 YangRangeRestriction curLengthRestriction = processLengthRestriction(refLengthRestriction, lineNumber,
559 charPositionInLine, true, getLengthRestrictionString());
560
561 // Resolve the range with referred typedef's restriction.
562 resolveLengthAndRangeRestriction(refLengthRestriction, curLengthRestriction);
563 return curLengthRestriction;
564 }
565
566 /**
567 * Resolves the length/range self and referred restriction, to check whether
568 * the all the range interval in self restriction is stricter than the
569 * referred typedef's restriction.
570 *
571 * @param refRestriction referred restriction
572 * @param curRestriction self restriction
573 */
574 private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
575 YangRangeRestriction curRestriction) throws DataModelException {
576 for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
577 if (!(curInterval instanceof YangRangeInterval)) {
578 throw new DataModelException("Linker error: Current range intervals not processed correctly.");
579 }
580 try {
581 refRestriction.isValidInterval((YangRangeInterval) curInterval);
582 } catch (DataModelException e) {
583 DataModelException dataModelException = new DataModelException(e);
584 dataModelException.setLine(lineNumber);
585 dataModelException.setCharPosition(charPositionInLine);
586 throw dataModelException;
587 }
588 }
589 }
590
591 /**
592 * Resolves the range restrictions.
593 *
594 * @param refRangeRestriction referred range restriction of typedef
595 * @throws DataModelException a violation in data model rule
596 */
597 private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction) throws DataModelException {
598
599 /*
600 * Check that string restriction should be null when built-in type is
601 * of range type.
602 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530603 if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) {
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530604 DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
605 "restriction should't be present for int/uint/decimal data type.");
606 dataModelException.setLine(lineNumber);
607 dataModelException.setCharPosition(charPositionInLine);
608 throw dataModelException;
609 }
610
611 /*
612 * If referred restriction and self restriction both are null, no
613 * resolution is required.
614 */
615 if (refRangeRestriction == null && Strings.isNullOrEmpty(getRangeRestrictionString())) {
616 return;
617 }
618
619 /*
620 * If self restriction is null, and referred restriction is present
621 * shallow copy the referred to self.
622 */
623 if (Strings.isNullOrEmpty(getRangeRestrictionString())) {
624 setResolvedExtendedInfo((T) refRangeRestriction);
625 return;
626 }
627
628 /*
629 * If referred restriction is null, and self restriction is present
630 * carry out self resolution.
631 */
632 if (refRangeRestriction == null) {
633 YangRangeRestriction curRangeRestriction = processRangeRestriction(null, lineNumber,
634 charPositionInLine, false, getRangeRestrictionString(), getEffectiveBuiltInType());
635 setResolvedExtendedInfo((T) curRangeRestriction);
636 return;
637 }
638
639 /*
640 * Carry out self resolution based with obtained effective built-in
641 * type and MIN/MAX values as per the referred typedef's values.
642 */
643 YangRangeRestriction curRangeRestriction = processRangeRestriction(refRangeRestriction, lineNumber,
644 charPositionInLine, true, getRangeRestrictionString(), getEffectiveBuiltInType());
645
646 // Resolve the range with referred typedef's restriction.
647 resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
648 setResolvedExtendedInfo((T) curRangeRestriction);
649 }
650
651 /**
652 * Returns whether the data type is of non restricted type.
653 *
654 * @param dataType data type to be checked
655 * @return true, if data type can't be restricted, false otherwise
656 */
657 private boolean isOfValidNonRestrictedType(YangDataTypes dataType) {
Bharat saraswalcad0e652016-05-26 23:48:38 +0530658 return dataType == BOOLEAN
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530659 || dataType == ENUMERATION
660 || dataType == BITS
661 || dataType == EMPTY
662 || dataType == UNION
663 || dataType == IDENTITYREF
Bharat saraswalcad0e652016-05-26 23:48:38 +0530664 || dataType == LEAFREF;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530665 }
666}