sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +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 | |
| 17 | package org.onosproject.yms.app.ydt; |
| 18 | |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.YangSchemaNode; |
| 20 | import org.onosproject.yms.app.ydt.exceptions.YdtException; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 21 | |
| 22 | import static org.onosproject.yms.app.ydt.YdtConstants.FMT_DUP_ENTRY; |
| 23 | import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg; |
| 24 | import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE; |
| 25 | |
| 26 | /** |
| 27 | * Represents YDT single instance leaf node which is an atomic element |
| 28 | * and doesn't have any child. |
| 29 | */ |
Vidyashree Rama | fd339c4 | 2016-12-01 19:19:56 +0530 | [diff] [blame] | 30 | public class YdtSingleInstanceLeafNode extends YdtNode { |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Value of the leaf. |
| 34 | */ |
| 35 | private String value; |
| 36 | |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 37 | /* |
| 38 | * Value of the leaf. |
| 39 | */ |
| 40 | private Boolean isKeyLeaf = false; |
| 41 | |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 42 | /** |
| 43 | * Creates a YANG single instance leaf node. |
| 44 | * |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 45 | * @param node schema of YDT single instance leaf node |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 46 | */ |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 47 | YdtSingleInstanceLeafNode(YangSchemaNode node) { |
| 48 | super(SINGLE_INSTANCE_LEAF_VALUE_NODE, node); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the flag indicating that requested leaf is key-leaf or not. |
| 53 | * |
| 54 | * @return isKeyLeaf true, for key leaf; false non key leaf |
| 55 | */ |
| 56 | public Boolean isKeyLeaf() { |
| 57 | return isKeyLeaf; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String getValue() { |
| 62 | return value; |
| 63 | } |
| 64 | |
| 65 | @Override |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 66 | public void addValue(String value) throws YdtException { |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 67 | // Check the value against corresponding data-type. |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 68 | //TODO validation need to be decided |
| 69 | // try { |
| 70 | // getYangSchemaNode().isValueValid(value); |
| 71 | // } catch (Exception e) { |
| 72 | // throw new YdtException(e.getLocalizedMessage()); |
| 73 | // } |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 74 | |
| 75 | // After validation is successful then add value to node. |
| 76 | this.value = value; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | @Override |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 81 | public void addValueWithoutValidation(String value, boolean isKeyLeaf) { |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 82 | this.value = value; |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 83 | this.isKeyLeaf = isKeyLeaf; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 87 | public void validDuplicateEntryProcessing() throws YdtException { |
| 88 | throw new YdtException(errorMsg(FMT_DUP_ENTRY, getName())); |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 89 | } |
| 90 | } |