blob: 0bd7036b9142a6e358da51a9af7af9df2367ada9 [file] [log] [blame]
sonu gupta1bb37b82016-11-11 16:51:18 +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.yms.app.ydt;
18
19import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
20
21import static org.onosproject.yms.app.ydt.YdtConstants.FMT_DUP_ENTRY;
22import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
23import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE;
24
25/**
26 * Represents YDT single instance leaf node which is an atomic element
27 * and doesn't have any child.
28 */
29class YdtSingleInstanceLeafNode extends YdtNode {
30
31 /*
32 * Value of the leaf.
33 */
34 private String value;
35
36 /**
37 * Creates a YANG single instance leaf node.
38 *
39 * @param id node identifier of YDT single instance leaf node
40 */
41 protected YdtSingleInstanceLeafNode(YangSchemaNodeIdentifier id) {
42 super(SINGLE_INSTANCE_LEAF_VALUE_NODE, id);
43 }
44
45 @Override
46 public String getValue() {
47 return value;
48 }
49
50 @Override
51 public void addValue(String value) {
52 // Check the value against corresponding data-type.
53 try {
54 getYangSchemaNode().isValueValid(value);
55 } catch (Exception e) {
56 errorHandler(e.getLocalizedMessage(), this);
57 }
58
59 // After validation is successful then add value to node.
60 this.value = value;
61 }
62
63
64 @Override
65 public void addValueWithoutValidation(String value) {
66 this.value = value;
67 }
68
69 @Override
70 public void validDuplicateEntryProcessing() {
71 errorHandler(errorMsg(FMT_DUP_ENTRY, getYdtNodeIdentifier().getName()),
72 this);
73 }
74}