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