Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / RequestResponseBody.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 "RequestResponseBody.h"\r
22 \r
23 namespace RAML\r
24 {\r
25 \r
26     std::string RequestResponseBody::getType() const\r
27     {\r
28         return m_type;\r
29     }\r
30     void RequestResponseBody::setType(const std::string &type)\r
31     {\r
32         m_type = type;\r
33     }\r
34     SchemaPtr const &RequestResponseBody::getSchema() const\r
35     {\r
36         return m_schema;\r
37     }\r
38     void RequestResponseBody::setSchema(const SchemaPtr &schema)\r
39     {\r
40         m_schema = schema;\r
41     }\r
42     std::string RequestResponseBody::getExample() const\r
43     {\r
44         return m_example;\r
45     }\r
46     void RequestResponseBody::setExample(const std::string &example)\r
47     {\r
48         m_example = example;\r
49     }\r
50     std::map<std::string, FormParameterPtr > const &RequestResponseBody::getFormParameters() const\r
51     {\r
52         return m_formParameters ;\r
53     }\r
54     void RequestResponseBody::setFormParameter(const std::string &paramName,\r
55             const FormParameterPtr  &formParameter)\r
56     {\r
57         m_formParameters[paramName] = formParameter;\r
58     }\r
59     void RequestResponseBody::readRequestResponseBody(const std::string &type,\r
60             const YAML::Node &yamlNode)\r
61     {\r
62         m_type = type;\r
63         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
64         {\r
65             std::string key = READ_NODE_AS_STRING(it->first);\r
66 \r
67             if (key == Keys::Schema)\r
68             {\r
69                 IncludeResolver::FileType fileType = m_includeResolver->getFileType(it->second);\r
70                 if ((fileType == IncludeResolver::FileType::JSON) ||\r
71                     (fileType == IncludeResolver::FileType::FILE))\r
72                 {\r
73                     setSchema(std::make_shared<Schema>(m_includeResolver->readFromFile(it->second),\r
74                                                        m_includeResolver));\r
75                 }\r
76                 else\r
77                 {\r
78                     std::string value = READ_NODE_AS_STRING(it->second);\r
79                     setSchema(std::make_shared<Schema>(value, m_includeResolver));\r
80                 }\r
81             }\r
82             else if (key == Keys::Example)\r
83                 setExample(READ_NODE_AS_STRING(it->second));\r
84             else if (key == Keys::FormParameters)\r
85             {\r
86                 YAML::Node paramNode = it->second;\r
87                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
88                 {\r
89                     setFormParameter(READ_NODE_AS_STRING(tt->first),\r
90                                      std::make_shared<FormParameter>(tt->second));\r
91                 }\r
92             }\r
93         }\r
94     }\r
95 \r
96 }\r