blob: cc2a223b98ba5174759a08aeef4707efc9e5c861 [file] [log] [blame]
sonu gupta1bb37b82016-11-11 16:51:18 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sonu gupta1bb37b82016-11-11 16:51:18 +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.yms.app.ydt;
18
sonu guptaeff184b2016-11-24 12:43:49 +053019import org.onosproject.yangutils.datamodel.YangSchemaNode;
20import org.onosproject.yms.app.ydt.exceptions.YdtException;
sonu gupta1bb37b82016-11-11 16:51:18 +053021
22import static org.onosproject.yms.app.ydt.YdtConstants.FMT_DUP_ENTRY;
23import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
24import 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 Ramafd339c42016-12-01 19:19:56 +053030public class YdtSingleInstanceLeafNode extends YdtNode {
sonu gupta1bb37b82016-11-11 16:51:18 +053031
32 /*
33 * Value of the leaf.
34 */
35 private String value;
36
sonu guptaeff184b2016-11-24 12:43:49 +053037 /*
38 * Value of the leaf.
39 */
40 private Boolean isKeyLeaf = false;
41
sonu gupta1bb37b82016-11-11 16:51:18 +053042 /**
43 * Creates a YANG single instance leaf node.
44 *
sonu guptaeff184b2016-11-24 12:43:49 +053045 * @param node schema of YDT single instance leaf node
sonu gupta1bb37b82016-11-11 16:51:18 +053046 */
sonu guptaeff184b2016-11-24 12:43:49 +053047 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 gupta1bb37b82016-11-11 16:51:18 +053058 }
59
60 @Override
61 public String getValue() {
62 return value;
63 }
64
65 @Override
sonu guptaeff184b2016-11-24 12:43:49 +053066 public void addValue(String value) throws YdtException {
sonu gupta1bb37b82016-11-11 16:51:18 +053067 // Check the value against corresponding data-type.
sonu guptaeff184b2016-11-24 12:43:49 +053068 //TODO validation need to be decided
69// try {
70// getYangSchemaNode().isValueValid(value);
71// } catch (Exception e) {
72// throw new YdtException(e.getLocalizedMessage());
73// }
sonu gupta1bb37b82016-11-11 16:51:18 +053074
75 // After validation is successful then add value to node.
76 this.value = value;
77 }
78
79
80 @Override
sonu guptaeff184b2016-11-24 12:43:49 +053081 public void addValueWithoutValidation(String value, boolean isKeyLeaf) {
sonu gupta1bb37b82016-11-11 16:51:18 +053082 this.value = value;
sonu guptaeff184b2016-11-24 12:43:49 +053083 this.isKeyLeaf = isKeyLeaf;
sonu gupta1bb37b82016-11-11 16:51:18 +053084 }
85
86 @Override
sonu guptaeff184b2016-11-24 12:43:49 +053087 public void validDuplicateEntryProcessing() throws YdtException {
88 throw new YdtException(errorMsg(FMT_DUP_ENTRY, getName()));
sonu gupta1bb37b82016-11-11 16:51:18 +053089 }
90}