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 | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame^] | 19 | import java.util.LinkedList; |
| 20 | import java.util.List; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 24 | |
| 25 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 26 | |
| 27 | /* |
| 28 | * Reference RFC 6020. |
| 29 | * |
| 30 | * The "rpc" statement is used to define a NETCONF RPC operation. It |
| 31 | * takes one argument, which is an identifier, followed by a block of |
| 32 | * substatements that holds detailed rpc information. This argument is |
| 33 | * the name of the RPC, and is used as the element name directly under |
| 34 | * the <rpc> element, as designated by the substitution group |
| 35 | * "rpcOperation" in [RFC4741]. |
| 36 | * |
| 37 | * The "rpc" statement defines an rpc node in the schema tree. Under |
| 38 | * the rpc node, a schema node with the name "input", and a schema node |
| 39 | * with the name "output" are also defined. The nodes "input" and |
| 40 | * "output" are defined in the module's namespace. |
| 41 | * |
| 42 | * The rpc substatements |
| 43 | * |
| 44 | * +--------------+---------+-------------+------------------+ |
| 45 | * | substatement | section | cardinality |data model mapping| |
| 46 | * +--------------+---------+-------------+------------------+ |
| 47 | * | description | 7.19.3 | 0..1 | -string | |
| 48 | * | grouping | 7.11 | 0..n | -child nodes | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame^] | 49 | * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 50 | * | input | 7.13.2 | 0..1 | -child nodes | |
| 51 | * | output | 7.13.3 | 0..1 | -child nodes | |
| 52 | * | reference | 7.19.4 | 0..1 | -string | |
| 53 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 54 | * | typedef | 7.3 | 0..n | -child nodes | |
| 55 | * +--------------+---------+-------------+------------------+ |
| 56 | */ |
| 57 | |
| 58 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 59 | * Represents data model node to maintain information defined in YANG rpc. |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 60 | */ |
| 61 | public class YangRpc extends YangNode implements YangCommonInfo, Parsable, |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame^] | 62 | CollisionDetector, YangIfFeatureHolder { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 63 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 64 | private static final long serialVersionUID = 806201613L; |
| 65 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 66 | /** |
| 67 | * Name of the rpc. |
| 68 | */ |
| 69 | private String name; |
| 70 | |
| 71 | /** |
| 72 | * Description of rpc. |
| 73 | */ |
| 74 | private String description; |
| 75 | |
| 76 | /** |
| 77 | * Reference of the module. |
| 78 | */ |
| 79 | private String reference; |
| 80 | |
| 81 | /** |
| 82 | * Status of the node. |
| 83 | */ |
| 84 | private YangStatusType status = YangStatusType.CURRENT; |
| 85 | |
| 86 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame^] | 87 | * List of if-feature. |
| 88 | */ |
| 89 | private List<YangIfFeature> ifFeatureList; |
| 90 | |
| 91 | /** |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 92 | * Create a rpc node. |
| 93 | */ |
| 94 | public YangRpc() { |
| 95 | super(YangNodeType.RPC_NODE); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String getName() { |
| 100 | return name; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void setName(String name) { |
| 105 | this.name = name; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 110 | // Detect colliding child. |
| 111 | detectCollidingChildUtil(identifierName, dataType, this); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 116 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 117 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as rpc \"" |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 118 | + getName() + "\""); |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public YangConstructType getYangConstructType() { |
| 124 | return YangConstructType.RPC_DATA; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void validateDataOnEntry() throws DataModelException { |
| 129 | //TODO: implement the method. |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void validateDataOnExit() throws DataModelException { |
| 134 | //TODO: implement the method. |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public String getDescription() { |
| 139 | return description; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void setDescription(String description) { |
| 144 | this.description = description; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public String getReference() { |
| 149 | return reference; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void setReference(String reference) { |
| 154 | this.reference = reference; |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public YangStatusType getStatus() { |
| 159 | return status; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void setStatus(YangStatusType status) { |
| 164 | this.status = status; |
| 165 | } |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame^] | 166 | |
| 167 | @Override |
| 168 | public List<YangIfFeature> getIfFeatureList() { |
| 169 | return ifFeatureList; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 174 | if (getIfFeatureList() == null) { |
| 175 | setIfFeatureList(new LinkedList<>()); |
| 176 | } |
| 177 | getIfFeatureList().add(ifFeature); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 182 | this.ifFeatureList = ifFeatureList; |
| 183 | } |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 184 | } |