Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / RamlResource.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   RamlResource.h\r
23  *\r
24  * @brief   This file provides data Model for RAML RamlResource.\r
25  */\r
26 \r
27 #ifndef RESOURCE_H\r
28 #define RESOURCE_H\r
29 \r
30 #include <map>\r
31 #include <list>\r
32 #include <string>\r
33 #include "UriParameter.h"\r
34 #include "ActionType.h"\r
35 #include "Action.h"\r
36 #include "RamlUtils.h"\r
37 #include "IncludeResolver.h"\r
38 \r
39 namespace RAML\r
40 {\r
41     /**\r
42      * @class   RamlResource\r
43      * @brief   This class provides data Model for RAML RamlResource.\r
44      */\r
45     class RamlResource\r
46     {\r
47         public:\r
48             /**\r
49                  * This method is for getting DisplayName from RamlResource.\r
50                  *\r
51                  * @return DisplayName as string.\r
52                  */\r
53             virtual std::string getDisplayName() const;\r
54 \r
55             /**\r
56                  * This method is for setting DisplayName to RamlResource.\r
57                  *\r
58                  * @param displayName - DisplayName as string\r
59                  */\r
60             virtual void setDisplayName(const std::string &displayName);\r
61 \r
62             /**\r
63                  * This method is for getting Description from RamlResource.\r
64                  *\r
65                  * @return Description as string.\r
66                  */\r
67             virtual std::string getDescription() const;\r
68 \r
69             /**\r
70                  * This method is for setting Description to RamlResource.\r
71                  *\r
72                  * @param description - Description as string\r
73                  */\r
74             virtual void setDescription(const std::string &description);\r
75 \r
76             /**\r
77                  * This method is for getting ParentUri from RamlResource.\r
78                  *\r
79                  * @return ParentUri as string.\r
80                  */\r
81             virtual std::string getParentUri() const;\r
82 \r
83             /**\r
84                  * This method is for setting ParentUri to RamlResource.\r
85                  *\r
86                  * @param parentUri - ParentUri as string\r
87                  */\r
88             virtual void setParentUri(const std::string &parentUri);\r
89 \r
90             /**\r
91                  * This method is for getting RelativeUri from RamlResource.\r
92                  *\r
93                  * @return RelativeUri as string.\r
94                  */\r
95             virtual std::string getRelativeUri() const;\r
96 \r
97             /**\r
98                  * This method is for setting RelativeUri to RamlResource.\r
99                  *\r
100                  * @param relativeUri - RelativeUri as string\r
101                  */\r
102             virtual void setRelativeUri(const std::string &relativeUri);\r
103 \r
104             /**\r
105                  * This method is for getting UriParameter from RamlResource.\r
106                  *\r
107                  * @return map of UriParameter name and Pointer to UriParameter.\r
108                  */\r
109             virtual std::map<std::string, UriParameterPtr> const &getUriParameters() const;\r
110 \r
111             /**\r
112                  * This method is for setting UriParameter to RamlResource.\r
113                  *\r
114                  * @param paramName - name of UriParameter as string\r
115                  * @param uriParameter - pointer to UriParameter\r
116                  */\r
117             virtual void setUriParameter(const std::string &paramName, const UriParameterPtr &uriParameter);\r
118 \r
119             /**\r
120                  * This method is for getting BaseUriParameter from RamlResource.\r
121                  *\r
122                  * @return map of BaseUriParameter name and Pointer to UriParameter.\r
123                  */\r
124             virtual std::map<std::string, UriParameterPtr > const &getBaseUriParameters() const;\r
125 \r
126             /**\r
127                  * This method is for setting BaseUriParameter to RamlResource.\r
128                  *\r
129                  * @param paramName - name of BaseUriParameter as string\r
130                  * @param baseUriParameter - pointer to UriParameter\r
131                  */\r
132             virtual void setBaseUriParameter(const std::string &paramName,\r
133                                              const UriParameterPtr &baseUriParameter);\r
134 \r
135             /**\r
136                  * This method is for getting Action from RamlResource.\r
137                  *\r
138                  * @param actionType - type of action as ActionType\r
139                  *\r
140                  * @return Pointer to Action.\r
141                  */\r
142             virtual ActionPtr getAction(ActionType actionType);\r
143 \r
144             /**\r
145                  * This method is for getting Action from RamlResource.\r
146                  *\r
147                  * @return map of ActionType and Pointer to Action.\r
148                  */\r
149             virtual std::map<ActionType , ActionPtr> const &getActions() const;\r
150 \r
151             /**\r
152                  * This method is for setting Action to RamlResource.\r
153                  *\r
154                  * @param actiontype - type of action\r
155                  * @param action - pointer to Action\r
156                  */\r
157             virtual void setAction(const ActionType &actiontype , const ActionPtr &action );\r
158 \r
159             /**\r
160                  * This method is for getting child Resource from RamlResource.\r
161                  *\r
162                  * @return map of Resource name and Pointer to RamlResource.\r
163                  */\r
164             virtual std::map<std::string, std::shared_ptr<RamlResource> > const &getResources() const;\r
165 \r
166             /**\r
167                  * This method is for setting child Resource to RamlResource.\r
168                  *\r
169                  * @param resourceName - name of Resource as string\r
170                  * @param resources - pointer to RamlResource\r
171                  */\r
172             virtual void setResource(const std::string &resourceName,\r
173                                      const std::shared_ptr<RamlResource> &resources);\r
174 \r
175             /**\r
176                  * This method is for getting Traits from RamlResource.\r
177                  *\r
178                  * @return list of Traits name.\r
179                  */\r
180             virtual std::list<std::string> const &getTraits() const;\r
181 \r
182             /**\r
183                   * This method is for setting Traits to RamlResource.\r
184                   *\r
185                   * @param trait - name of Traits\r
186                   */\r
187             virtual void setTrait(const std::string &trait);\r
188 \r
189             /**\r
190                  * This method is for getting ResourceType from RamlResource.\r
191                  *\r
192                  * @return ResourceType name.\r
193                  */\r
194             virtual std::string getResourceType() const;\r
195 \r
196             /**\r
197                    * This method is for setting ResourceType to RamlResource.\r
198                    *\r
199                    * @param type - name of ResourceType\r
200                    */\r
201             virtual void setResourceType(const std::string &type);\r
202 \r
203             /**\r
204                  * This method is for getting ResourceUri from RamlResource.\r
205                  *\r
206                  * @return ResourceUri as string.\r
207                  */\r
208             virtual std::string getResourceUri() const;\r
209 \r
210             /**\r
211                   * Constructor of RamlResource.\r
212                   */\r
213             RamlResource(): m_includeResolver(NULL) {}\r
214 \r
215             /**\r
216                    * Constructor of RamlResource.\r
217                    *\r
218                    * @param resourceKey - name of the Resource\r
219                    * @param yamlNode - Reference to YamlNode for reading the RamlResource\r
220                    * @param includeResolver - Reference to IncludeResolver for reading external files\r
221                    * @param parentUri - Uri of the Parent to form the Absolute Uri\r
222                    *\r
223                    */\r
224             RamlResource(const std::string resourceKey, const YAML::Node &yamlNode ,\r
225                          const IncludeResolverPtr &includeResolver,\r
226                          const std::string &parentUri) : m_includeResolver(includeResolver)\r
227             {\r
228                 readResource(resourceKey, yamlNode, parentUri);\r
229             }\r
230         private:\r
231             void readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
232                               const std::string &parentUri);\r
233         private:\r
234             std::string m_displayName;\r
235             std::string m_description;\r
236             std::string m_relativeUri;\r
237             std::map<std::string, UriParameterPtr> m_uriParameters;\r
238             std::map<std::string, UriParameterPtr > m_baseUriParameters;\r
239             std::map<ActionType , ActionPtr> m_actions;\r
240             std::list<std::string> m_traits;\r
241             std::string m_resourceType;\r
242             std::string m_parentUri;\r
243             std::map<std::string, std::shared_ptr<RamlResource> > m_resources;\r
244             IncludeResolverPtr m_includeResolver;\r
245     };\r
246 \r
247     /** RamlResourcePtr - shared Ptr to RamlResource.*/\r
248     typedef std::shared_ptr<RamlResource> RamlResourcePtr;\r
249 }\r
250 #endif\r