Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / Action.h
1 /******************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  ******************************************************************/\r
20 \r
21 /**\r
22  * @file   Action.h\r
23  *\r
24  * @brief   This file provides data Model for RAML Action.\r
25  */\r
26 \r
27 #ifndef ACTION_H\r
28 #define ACTION_H\r
29 \r
30 #include <map>\r
31 #include <list>\r
32 #include <string>\r
33 #include "ActionType.h"\r
34 #include "Header.h"\r
35 #include "QueryParameter.h"\r
36 #include "RequestResponseBody.h"\r
37 #include "UriParameter.h"\r
38 #include "Response.h"\r
39 #include "Utils.h"\r
40 #include "IncludeResolver.h"\r
41 \r
42 namespace RAML\r
43 {\r
44     /**\r
45      * @class   Action\r
46      * @brief   This class provides data Model for RAML Action.\r
47      */\r
48     class Action\r
49     {\r
50         public:\r
51             /**\r
52                  * This method is for getting Type from Action.\r
53                  *\r
54                  * @return Type as string.\r
55                  */\r
56             virtual ActionType getType() const;\r
57 \r
58             /**\r
59                  * This method is for setting Type to Action.\r
60                  *\r
61                  * @param type - Type as string\r
62                  */\r
63             virtual void setType(const ActionType &type);\r
64 \r
65             /**\r
66                  * This method is for getting Description from Action.\r
67                  *\r
68                  * @return Description as string.\r
69                  */\r
70             virtual std::string getDescription() const;\r
71 \r
72             /**\r
73                  * This method is for setting Description to Action.\r
74                  *\r
75                  * @param description - Description as string\r
76                  */\r
77             virtual void setDescription(const std::string &description);\r
78 \r
79             /**\r
80                  * This method is for getting Header from Action.\r
81                  *\r
82                  * @return map of Header name and Pointer to Header.\r
83                  */\r
84             virtual std::map<std::string, HeaderPtr > const &getHeaders() const;\r
85 \r
86             /**\r
87                  * This method is for setting Header to Action.\r
88                  *\r
89                  * @param headerName - Header name as string\r
90                  * @param header - Pointer to Header\r
91                  */\r
92             virtual void setHeader(const std::string &headerName, const HeaderPtr &header);\r
93 \r
94             /**\r
95                  * This method is for getting QueryParameter from Action.\r
96                  *\r
97                  * @return map of QueryParameter name and Pointer to QueryParameter.\r
98                  */\r
99             virtual std::map<std::string, QueryParameterPtr > const &getQueryParameters()const;\r
100 \r
101             /**\r
102                  * This method is for setting QueryParameter to Action.\r
103                  *\r
104                  * @param paramName - QueryParameter name as string\r
105                  * @param queryParameter - Pointer to QueryParameter\r
106                  */\r
107             virtual void setQueryParameter(const std::string &paramName,\r
108                                            const QueryParameterPtr &queryParameter);\r
109 \r
110             /**\r
111                  * This method is for getting RequestResponseBody from Action.\r
112                  *\r
113                  * @param bodyType - bodyType name as string\r
114                  *\r
115                  * @return Pointer to RequestResponseBody\r
116                  */\r
117             virtual RequestResponseBodyPtr getRequestBody(const std::string &bodyType);\r
118 \r
119             /**\r
120                  * This method is for getting RequestResponseBody from Action.\r
121                  *\r
122                  * @return map of RequestResponseBody name and Pointer to RequestResponseBody.\r
123                  */\r
124             virtual std::map<std::string, RequestResponseBodyPtr> const &getRequestBody() const;\r
125 \r
126             /**\r
127                  * This method is for setting RequestResponseBody to Action.\r
128                  *\r
129                  * @param typeName - RequestResponseBody name as string\r
130                  */\r
131             virtual void setRequestBody(const std::string &typeName);\r
132 \r
133             /**\r
134                  * This method is for setting Type to Action.\r
135                  *\r
136                  * @param typeName - RequestResponseBody name as string\r
137                  * @param body - Pointer to RequestResponseBody\r
138                  */\r
139             virtual void setRequestBody(const std::string &typeName ,\r
140                                         const RequestResponseBodyPtr &body);\r
141 \r
142             /**\r
143                  * This method is for getting Response from Action.\r
144                  *\r
145                  * @param responseCode - Response code as string\r
146                  *\r
147                  * @return Pointer to Response\r
148                  */\r
149             virtual ResponsePtr getResponse(const std::string &responseCode);\r
150 \r
151             /**\r
152                  * This method is for getting Response from Action.\r
153                  *\r
154                  * @return map of response code and Pointer to Response\r
155                  */\r
156             virtual std::map<std::string, ResponsePtr> const &getResponses() const;\r
157 \r
158             /**\r
159                  * This method is for setting Response to Action.\r
160                  *\r
161                  * @param responseCode - responseCode as string\r
162                  * @param response - Pointer to Response\r
163                  */\r
164             virtual void setResponse(const std::string &responseCode, const ResponsePtr &response);\r
165 \r
166             /**\r
167                  * This method is for getting Protocols from Action.\r
168                  *\r
169                  * @return list of Protocols as string.\r
170                  */\r
171             virtual std::list<std::string> const &getProtocols() const;\r
172 \r
173             /**\r
174                  * This method is for setting Protocols to Action.\r
175                  *\r
176                  * @param protocol - protocol as string\r
177                  */\r
178             virtual void setProtocol(const std::string &protocol);\r
179 \r
180             /**\r
181                  * This method is for getting BaseUriParameter from Action.\r
182                  *\r
183                  * @return map of BaseUriParameter name and pointer to UriParameter.\r
184                  */\r
185             virtual std::map< std::string, UriParameterPtr > const &getBaseUriParameters() const;\r
186 \r
187             /**\r
188                  * This method is for setting BaseUriParameter to Action.\r
189                  *\r
190                  * @param paramName - BaseUriParameter name as string\r
191                  * @param baseUriParameter - pointer to UriParameter.\r
192                  */\r
193             virtual void setBaseUriParameter(const std::string &paramName ,\r
194                                              const UriParameterPtr &baseUriParameter);\r
195 \r
196             /**\r
197                  * This method is for getting Traits from Action.\r
198                  *\r
199                  * @return list of traits as string.\r
200                  */\r
201             virtual std::list<std::string> const &getTraits() const;\r
202 \r
203             /**\r
204                  * This method is for setting Trait to Action.\r
205                  *\r
206                  * @param trait - trait as string\r
207                  */\r
208             virtual void setTrait(const std::string &trait);\r
209 \r
210             /**\r
211                   * Constructor of Action.\r
212                   */\r
213             Action(): m_includeResolver(NULL) { }\r
214 \r
215             /**\r
216                    * Constructor of Action.\r
217                    *\r
218                    * @param actionType - type of action in ActionType enum\r
219                    * @param yamlNode - Reference to YamlNode for reading the Action\r
220                    * @param includeResolver - Reference to IncludeResolver for reading external files\r
221                    *\r
222                    */\r
223             Action(const ActionType actionType, const YAML::Node &yamlNode,\r
224                    const IncludeResolverPtr &includeResolver)\r
225                 : m_includeResolver(includeResolver)\r
226             {\r
227                 readAction(actionType, yamlNode);\r
228             }\r
229 \r
230             /**\r
231                   * copy Constructor of Action.\r
232                   */\r
233             Action(const Action &) = default;\r
234         private:\r
235             virtual void readAction(const ActionType actionType, const YAML::Node &yamlNode);\r
236 \r
237 \r
238         private:\r
239             ActionType m_type;\r
240             std::string m_description;\r
241             std::map<std::string, HeaderPtr> m_headers;\r
242             std::map<std::string, QueryParameterPtr> m_queryParameters;\r
243             std::map<std::string, RequestResponseBodyPtr> m_requestBody;\r
244             std::map<std::string, ResponsePtr> m_responses;\r
245             std::list<std::string> m_protocols;\r
246             std::map< std::string, UriParameterPtr > m_baseUriParameters;\r
247             std::list<std::string> m_trait;\r
248 \r
249         private:\r
250             IncludeResolverPtr m_includeResolver;\r
251     };\r
252 \r
253     /** ActionPtr - shared Ptr to Action.*/\r
254     typedef std::shared_ptr<Action> ActionPtr;\r
255 }\r
256 #endif\r