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