Adding JsonSchema parser implementation for simulator and Updating Raml Parser.
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / Response.cpp
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 #include "Response.h"\r
22 \r
23 namespace RAML\r
24 {\r
25 \r
26     std::map<std::string, HeaderPtr> const &Response::getHeaders() const\r
27     {\r
28         return m_headers;\r
29     }\r
30     void Response::setHeader(const std::string &headerName, const HeaderPtr &header)\r
31     {\r
32         m_headers[headerName] = header;\r
33     }\r
34     std::string Response::getDescription() const\r
35     {\r
36         return m_description;\r
37     }\r
38     void Response::setDescription(const std::string &description)\r
39     {\r
40         m_description = description;\r
41     }\r
42     void Response::setResponseBody(const std::string &typeName)\r
43     {\r
44         m_responseBody[typeName] = std::make_shared<RequestResponseBody>(typeName);\r
45     }\r
46     void Response::setResponseBody(const std::string &type, const RequestResponseBodyPtr &body)\r
47     {\r
48         m_responseBody[type] = body;\r
49     }\r
50     std::map<std::string, RequestResponseBodyPtr> const &Response::getResponseBody() const\r
51     {\r
52         return m_responseBody;\r
53     }\r
54     RequestResponseBodyPtr Response::getResponseBody(const std::string &bodyType)\r
55     {\r
56         return m_responseBody[bodyType];\r
57     }\r
58 \r
59     void Response::readResponse(const YAML::Node &yamlNode)\r
60     {\r
61         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
62         {\r
63             std::string key = READ_NODE_AS_STRING(it->first);\r
64 \r
65             if (key == Keys::Description)\r
66                 setDescription(READ_NODE_AS_STRING(it->second));\r
67             else if (key == Keys::Body)\r
68             {\r
69                 YAML::Node responseBody = it->second;\r
70 \r
71                 for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
72                 {\r
73                     std::string type = READ_NODE_AS_STRING(tt->first);\r
74                     setResponseBody(type, std::make_shared<RequestResponseBody>(type, tt->second, m_includeResolver));\r
75                 }\r
76             }\r
77             else if (key == Keys::Headers)\r
78             {\r
79                 YAML::Node paramNode = it->second;\r
80                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
81                 {\r
82                     setHeader(READ_NODE_AS_STRING(tt->first), std::make_shared<Header>(tt->second));\r
83                 }\r
84             }\r
85         }\r
86     }\r
87 \r
88 }\r