blob: 72060adee1917c707e390b42a8c54bf05ca242dd [file] [log] [blame]
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05303 *
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.yangutils.datamodel;
18
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053019import java.util.LinkedList;
20import java.util.List;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022import org.onosproject.yangutils.datamodel.utils.Parsable;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053024
25import 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 Ramadeac28b2016-06-20 15:12:43 +053049 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053050 * | 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 saraswald9822e92016-04-05 15:13:44 +053059 * Represents data model node to maintain information defined in YANG rpc.
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053060 */
61public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053062 CollisionDetector, YangIfFeatureHolder {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053063
Bharat saraswal96dfef02016-06-16 00:29:12 +053064 private static final long serialVersionUID = 806201613L;
65
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053066 /**
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 Ramadeac28b2016-06-20 15:12:43 +053087 * List of if-feature.
88 */
89 private List<YangIfFeature> ifFeatureList;
90
91 /**
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053092 * 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 Sd4deb062016-04-15 18:08:57 +0530116 if (getName().equals(identifierName)) {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530117 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as rpc \""
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530118 + getName() + "\"");
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530119 }
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 Ramadeac28b2016-06-20 15:12:43 +0530166
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 Agrawale3ed0d92016-03-23 19:04:17 +0530184}