Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +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.yangutils.datamodel; |
| 18 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 19 | import java.util.ArrayList; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 20 | import java.util.LinkedList; |
| 21 | import java.util.List; |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 22 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 25 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 26 | |
| 27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 28 | |
| 29 | /* |
| 30 | * Reference RFC 6020. |
| 31 | * |
| 32 | * The "input" statement, which is optional, is used to define input |
| 33 | * parameters to the RPC operation. It does not take an argument. The |
| 34 | * substatements to "input" define nodes under the RPC's input node. |
| 35 | * |
| 36 | * If a leaf in the input tree has a "mandatory" statement with the |
| 37 | * value "true", the leaf MUST be present in a NETCONF RPC invocation. |
| 38 | * Otherwise, the server MUST return a "missing-element" error. |
| 39 | * |
| 40 | * If a leaf in the input tree has a default value, the NETCONF server |
| 41 | * MUST use this value in the same cases as described in Section 7.6.1. |
| 42 | * In these cases, the server MUST operationally behave as if the leaf |
| 43 | * was present in the NETCONF RPC invocation with the default value as |
| 44 | * its value. |
| 45 | * |
| 46 | * If a "config" statement is present for any node in the input tree, |
| 47 | * the "config" statement is ignored. |
| 48 | * |
| 49 | * If any node has a "when" statement that would evaluate to false, then |
| 50 | * this node MUST NOT be present in the input tree. |
| 51 | * |
| 52 | * The input substatements |
| 53 | * |
| 54 | * +--------------+---------+-------------+------------------+ |
| 55 | * | substatement | section | cardinality |data model mapping| |
| 56 | * +--------------+---------+-------------+------------------+ |
| 57 | * | anyxml | 7.10 | 0..n | -not supported | |
| 58 | * | choice | 7.9 | 0..n | -child nodes | |
| 59 | * | container | 7.5 | 0..n | -child nodes | |
| 60 | * | grouping | 7.11 | 0..n | -child nodes | |
| 61 | * | leaf | 7.6 | 0..n | -YangLeaf | |
| 62 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
| 63 | * | list | 7.8 | 0..n | -child nodes | |
| 64 | * | typedef | 7.3 | 0..n | -child nodes | |
| 65 | * | uses | 7.12 | 0..n | -child nodes | |
| 66 | * +--------------+---------+-------------+------------------+ |
| 67 | */ |
| 68 | |
| 69 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 70 | * Represents data model node to maintain information defined in YANG input. |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 71 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 72 | public class YangInput |
| 73 | extends YangNode |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 74 | implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 75 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 76 | private static final long serialVersionUID = 806201608L; |
| 77 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 78 | /** |
| 79 | * Name of the input. |
| 80 | */ |
| 81 | private String name; |
| 82 | |
| 83 | /** |
| 84 | * List of leaves contained. |
| 85 | */ |
| 86 | private List<YangLeaf> listOfLeaf; |
| 87 | |
| 88 | /** |
| 89 | * List of leaf-lists contained. |
| 90 | */ |
| 91 | private List<YangLeafList> listOfLeafList; |
| 92 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 93 | private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>(); |
| 94 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 95 | /** |
| 96 | * Create a rpc input node. |
| 97 | */ |
| 98 | public YangInput() { |
| 99 | super(YangNodeType.INPUT_NODE); |
| 100 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 101 | listOfLeafList = new LinkedList<YangLeafList>(); |
| 102 | } |
| 103 | |
| 104 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 105 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 106 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 107 | // Detect colliding child. |
| 108 | detectCollidingChildUtil(identifierName, dataType, this); |
| 109 | } |
| 110 | |
| 111 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 112 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 113 | throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 114 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 115 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \"" |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 116 | + getName() + "\""); |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public YangConstructType getYangConstructType() { |
| 122 | return YangConstructType.INPUT_DATA; |
| 123 | } |
| 124 | |
| 125 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 126 | public void validateDataOnEntry() |
| 127 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 128 | //TODO: implement the method. |
| 129 | } |
| 130 | |
| 131 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 132 | public void validateDataOnExit() |
| 133 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 134 | //TODO: implement the method. |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public List<YangLeaf> getListOfLeaf() { |
| 139 | return listOfLeaf; |
| 140 | } |
| 141 | |
| 142 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 143 | public void setListOfLeaf(List<YangLeaf> leafsList) { |
| 144 | listOfLeaf = leafsList; |
| 145 | } |
| 146 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 147 | @Override |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 148 | public void addLeaf(YangLeaf leaf) { |
| 149 | getListOfLeaf().add(leaf); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public List<YangLeafList> getListOfLeafList() { |
| 154 | return listOfLeafList; |
| 155 | } |
| 156 | |
| 157 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 158 | public void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
| 159 | this.listOfLeafList = listOfLeafList; |
| 160 | } |
| 161 | |
| 162 | @Override |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 163 | public void addLeafList(YangLeafList leafList) { |
| 164 | getListOfLeafList().add(leafList); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String getName() { |
| 169 | return name; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void setName(String name) { |
| 174 | this.name = name; |
| 175 | } |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 176 | |
| 177 | @Override |
| 178 | public void addAugmentation(YangAugmentedInfo augmentInfo) { |
| 179 | yangAugmentedInfo.add(augmentInfo); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public void removeAugmentation(YangAugmentedInfo augmentInfo) { |
| 184 | yangAugmentedInfo.remove(augmentInfo); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public List<YangAugmentedInfo> getAugmentedInfoList() { |
| 189 | return yangAugmentedInfo; |
| 190 | } |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 191 | } |